Skip to content

Commit

Permalink
updated processing of ESAM_Multi
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathancallahan committed Jul 8, 2020
1 parent d2e1cc0 commit bb63a3d
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 38 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Type: Package
Package: PWFSLSmoke
Version: 1.2.111
Version: 1.2.112
Title: Utilities for Working with Air Quality Monitoring Data
Authors@R: c(
person("Jonathan", "Callahan", email="[email protected]", role=c("aut","cre")),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# PWFSLSmoke 1.2.112

* Updated support for parsing AIRSIS "ESAM Multi" format.

# PWFSLSmoke 1.2.111

CRAN manual review suggestions:
Expand Down
8 changes: 4 additions & 4 deletions R/airsis_ESAM_MULTIQualityControl.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ airsis_ESAM_MULTIQualityControl <- function(
valid_Flow = c(1.999, 2.001), # anything other than 2 is bad
valid_AT = c(-Inf, 150),
valid_RHi = c(-Inf, 55),
valid_Conc = c(-Inf, 5000),
valid_Conc = c(-Inf, 5),
flagAndKeep = FALSE
) {

Expand All @@ -48,7 +48,7 @@ airsis_ESAM_MULTIQualityControl <- function(

# > names(tbl)
# [1] "MasterTable_ID" "Alias" "Latitude" "Longitude"
# [5] "Conc.ug.m3." "Flow.l.m." "AT.C." "BP.PA."
# [5] "Conc.mg.m3." "Flow.l.m." "AT.C." "BP.PA."
# [9] "RHx..." "RHi..." "WS.M.S." "WD.Deg."
# [13] "BV.V." "Alarm" "Oceaneering.Unit.Voltage" "TimeStamp"
# [17] "PDate" "monitorName" "monitorType" "monitorSubtype"
Expand Down Expand Up @@ -182,7 +182,7 @@ airsis_ESAM_MULTIQualityControl <- function(
goodFlow <- !is.na(tbl$Flow.l.m.) & tbl$Flow.l.m. >= valid_Flow[1] & tbl$Flow.l.m. <= valid_Flow[2]
goodAT <- !is.na(tbl$AT.C.) & tbl$AT.C. >= valid_AT[1] & tbl$AT.C. <= valid_AT[2]
goodRHi <- !is.na(tbl$RHi...) & tbl$RHi... >= valid_RHi[1] & tbl$RHi... <= valid_RHi[2]
goodConcHr <- !is.na(tbl$Conc.ug.m3.) & tbl$Conc.ug.m3. >= valid_Conc[1] & tbl$Conc.ug.m3. <= valid_Conc[2]
goodConcHr <- !is.na(tbl$Conc.mg.m3.) & tbl$Conc.mg.m3. >= valid_Conc[1] & tbl$Conc.mg.m3. <= valid_Conc[2]
gooddatetime <- !is.na(tbl$datetime) & tbl$datetime < lubridate::now(tzone = "UTC") # saw a future date once

logger.trace("Flow has %s missing or out of range values", sum(!goodFlow))
Expand Down Expand Up @@ -296,7 +296,7 @@ if ( FALSE ) {
valid_Flow = c(1.999, 2.001) # anything other than 2 is bad
valid_AT = c(-Inf, 150)
valid_RHi = c(-Inf, 55)
valid_Conc = c(-Inf, 5000)
valid_Conc = c(-Inf, 5)
flagAndKeep = FALSE

}
12 changes: 2 additions & 10 deletions R/airsis_createDataDataframe.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@ airsis_createDataDataframe <- function(
if ( monitorType == 'EBAM' ) {
pm25Var <- 'ConcHr'
} else if ( monitorType == 'ESAM' ) {
if ( monitorSubtype == 'MULTI' ) {
pm25Var <- 'Conc.ug.m3.'
} else {
pm25Var <- 'Conc.mg.m3.'
}
pm25Var <- 'Conc.mg.m3.'
} else if ( monitorType == 'BAM1020' ) {
pm25Var <- 'Conc..\u00B5g.m3.'
} else {
Expand All @@ -96,11 +92,7 @@ airsis_createDataDataframe <- function(
}

if ( monitorType == 'ESAM' ) {
if ( monitorSubtype == 'MULTI') {
melted$value <- melted$value * 1
} else {
melted$value <- melted$value * 1000
}
melted$value <- melted$value * 1000
}

# Use median if multiple values are found
Expand Down
4 changes: 2 additions & 2 deletions R/airsis_createMonitorObject.R
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ if ( FALSE ) {

# 2020 "ESAM Multi" format -- usfs.2072-5

startdate = MazamaCoreUtils::parseDatetime("2020-06-14", timezone = "UTC")
enddate = MazamaCoreUtils::parseDatetime("2020-06-20", timezone = "UTC")
startdate = MazamaCoreUtils::parseDatetime("2020-07-01", timezone = "UTC")
enddate = MazamaCoreUtils::parseDatetime("2020-07-07", timezone = "UTC")
provider = "usfs"
unitID = 1072
clusterDiameter = 1000
Expand Down
5 changes: 2 additions & 3 deletions R/airsis_identifyMonitorType.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ airsis_identifyMonitorType <- function(df) {

# ----- Different header styles ----------------------------------------------

# USFS_esamMulti, provider = "usfs", unitID=1072-5 (starting in June, 2020)
###"MasterTable_ID,Alias,Latitude,Longitude,Conc(mg/m3),Flow(l/m),AT(C),BP(PA),RHx(%),RHi(%),WS(M/S),WD(Deg),BV(V),Alarm,Oceaneering Unit Voltage,TimeStamp,PDate"
esamMulti_header <- "MasterTable_ID,Alias,Latitude,Longitude,Conc(ug/m3),Flow(l/m),AT(C),BP(PA),RHx(%),RHi(%),WS(M/S),WD(Deg),BV(V),Alarm,Oceaneering Unit Voltage,TimeStamp,PDate"
# USFS_esamMulti, provider = "usfs", unitID=1072-5 (starting in July 08, 2020; was mistakenly in units of ug/m3 before that)
esamMulti_header <- "MasterTable_ID,Alias,Latitude,Longitude,Conc(mg/m3),Flow(l/m),AT(C),BP(PA),RHx(%),RHi(%),WS(M/S),WD(Deg),BV(V),Alarm,Oceaneering Unit Voltage,TimeStamp,PDate"
esamMulti_rawNames <- unlist(stringr::str_split(esamMulti_header, ','))
esamMulti_names <- make.names(esamMulti_rawNames)
# "64424513,USFS 1072,,,2,2.0,33.3,86107,1,13,2.6,175,14,,,6/14/2020 12:05:13 AM,6/14/2020 12:05:00 AM"
Expand Down
1 change: 0 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ RUN install2.r --error -r "https://cran.rstudio.com" \

# Install latest updates from GitHub
RUN installGithub.r \
mazamascience/MazamaCoreUtils \
mazamascience/PWFSLSmoke

4 changes: 3 additions & 1 deletion docker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@

# PRODUCTION version -----------------------------------------------------------
production_build:
docker build --no-cache -t mazamascience/pwfslsmoke:1.2.108 -t mazamascience/pwfslsmoke:latest .
docker build --no-cache -t mazamascience/pwfslsmoke:1.2.112 -t mazamascience/pwfslsmoke:latest .

production_publish:
docker login && docker push mazamascience/pwfslsmoke:1.2.112
28 changes: 13 additions & 15 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ You should then be able to see something like the following:
```
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mazamascience/pwfslsmoke 1.2.108 1824e396e3f3 34 seconds ago 2.61GB
mazamascience/pwfslsmoke 1.2.112 1824e396e3f3 34 seconds ago 2.61GB
mazamascience/pwfslsmoke latest 1824e396e3f3 34 seconds ago 2.61GB
...
```
Expand All @@ -27,7 +27,8 @@ the docker image in `/home/mazama/data/Spatial`.
## Test the Docker Image ##

Having built the docker image we can now test it. The following output was
obtained on April 03, 2019:
obtained on July 08, 2020 -- Fourth of July Fireworks!!!:


```
docker run -ti mazamascience/pwfslsmoke R --vanilla
Expand All @@ -40,30 +41,27 @@ ids <- names(maxValues)
df <- wa$meta[ids,c('siteName','countyName')]
df$max_pm25 <- maxValues
print(df)
siteName countyName max_pm25
840530390006_01 Mobile-White Salmon Klickitat 63.2
TT1010003_01 Inchelium <NA> 51.8
530650002_01 Wellpinit-Spokane Tribe Stevens 51.3
840530739992_01 Maple Falls-Azure Way Whatcom 49.7
530070011_01 Wenatchee-Fifth St Chelan 49.4
530610020_01 Darrington-Fir St Snohomish 49.0
siteName countyName max_pm25
530330080_01 Seattle-Beacon Hill King 943.0
530272002_01 Aberdeen-Division St Grays Harbor 203.7
530611007_01 Marysville-7th Ave Snohomish 134.0
530650005_01 Colville-E 1st St Stevens 123.0
530110024_01 Vancouver-NE 84th Ave Clark 115.0
530350007_01 Bremerton-Spruce Ave Kitsap 113.0
```


## Publish the Docker Image ##

```
docker login
...
docker push mazamascience/pwfslsmoke:1.2.108
make production_publish
```


## Download the Docker Image ##

A recent image can also be obtained from DockerHub with:
This image can also be pulled from DockerHub with:

```
docker pull mazamascience/pwfslsmoke:1.2.108
docker pull mazamascience/pwfslsmoke:1.2.112
```

2 changes: 1 addition & 1 deletion man/airsis_ESAM_MULTIQualityControl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bb63a3d

Please sign in to comment.