NIEHS / amadeus

https://niehs.github.io/amadeus/
Other
7 stars 1 forks source link

Inconsistent behavior of `process_narr` #51

Closed sigmafelix closed 7 months ago

sigmafelix commented 7 months ago

process_narr runs at all years regardless of the values of date argument.

amadeus::process_narr(path = "../../../../group/set/Projects/NRT-AP-Model/input/narr/omega", variable = "omega", date = c("2020-03-01", "2020-04-30"))
# Cleaning omega data for year 2018...
# Detected pressure levels data...
# Cleaning omega data for year 2018...
# Detected pressure levels data...
# Cleaning omega data for year 2018...
# Detected pressure levels data...
# Cleaning omega data for year 2018...
# Detected pressure levels data...
# Cleaning omega data for year 2018...
# Detected pressure levels data...
# Cleaning omega data for year 2018...
# Detected pressure levels data...
# Cleaning omega data for year 2018...
# Detected pressure levels data...
# Cleaning omega data for year 2018...
# Detected pressure levels data...
# Cleaning omega data for year 2018...
# Detected pressure levels data...
# Cleaning omega data for year 2018...
# Detected pressure levels data...
# Cleaning omega data for year 2018...
# Detected pressure levels data...
# Cleaning omega data for year 2018...
# Detected pressure levels data...
# Cleaning omega data for year 2019...
# Detected pressure levels data...
# Cleaning omega data for year 2019...
# Detected pressure levels data...
# Cleaning omega data for year 2019...
# Detected pressure levels data...
# Cleaning omega data for year 2019...
# Detected pressure levels data...
# Cleaning omega data for year 2019...
# Detected pressure levels data...
# Cleaning omega data for year 2019...
# Detected pressure levels data...
# Cleaning omega data for year 2019...
# Detected pressure levels data...
# Cleaning omega data for year 2019...
# Detected pressure levels data...
# Cleaning omega data for year 2019...
# Detected pressure levels data...
# Cleaning omega data for year 2019...
# Detected pressure levels data...
# Cleaning omega data for year 2019...
# Detected pressure levels data...
# Cleaning omega data for year 2019...
# Detected pressure levels data...
# Cleaning omega data for year 2020...
# Detected pressure levels data...
# Cleaning omega data for year 2020...
# Detected pressure levels data...
# Cleaning omega data for year 2020...
# Detected pressure levels data...
# Cleaning omega data for year 2020...
# Detected pressure levels data...
# Cleaning omega data for year 2020...
# Detected pressure levels data...
# Cleaning omega data for year 2020...
# Detected pressure levels data...
# Cleaning omega data for year 2020...
# Detected pressure levels data...
# Cleaning omega data for year 2020...
# Detected pressure levels data...
# Cleaning omega data for year 2020...
# Detected pressure levels data...
# Cleaning omega data for year 2020...
# Detected pressure levels data...
# Cleaning omega data for year 2020...
# Detected pressure levels data...
# Cleaning omega data for year 2020...
# Detected pressure levels data...
# Cleaning omega data for year 2021...
# Detected pressure levels data...
# Cleaning omega data for year 2021...
# Detected pressure levels data...
# Cleaning omega data for year 2021...
# Detected pressure levels data...
# Cleaning omega data for year 2021...
# Detected pressure levels data...
# Cleaning omega data for year 2021...
# Detected pressure levels data...
# Cleaning omega data for year 2021...
# Detected pressure levels data...
# Cleaning omega data for year 2021...
# Detected pressure levels data...
# Cleaning omega data for year 2021...
# Detected pressure levels data...
# Cleaning omega data for year 2021...
# Detected pressure levels data...
# Cleaning omega data for year 2021...
# Detected pressure levels data...
# Cleaning omega data for year 2021...
# Detected pressure levels data...
# Cleaning omega data for year 2021...
# Detected pressure levels data...
# Cleaning omega data for year 2022...
# Detected pressure levels data...
# Cleaning omega data for year 2022...
# Detected pressure levels data...
# Cleaning omega data for year 2022...
# Detected pressure levels data...
# Cleaning omega data for year 2022...
# Detected pressure levels data...
# Cleaning omega data for year 2022...
# Detected pressure levels data...
# Cleaning omega data for year 2022...
# Detected pressure levels data...
# Cleaning omega data for year 2022...
# Detected pressure levels data...
# Cleaning omega data for year 2022...
# Detected pressure levels data...
# Cleaning omega data for year 2022...
# Detected pressure levels data...
# Cleaning omega data for year 2022...
# Detected pressure levels data...
# Cleaning omega data for year 2022...
# Detected pressure levels data...
# Cleaning omega data for year 2022...
# Detected pressure levels data...
# Error: [subset] no (valid) layer selected

The example below returns different results from what was supposed to be as set in date argument:

amadeus::process_narr(path = "../../../../group/set/Projects/NRT-AP-Model/input/narr/omega", variable = "omega", date = c("2020-03-01", "2022-01-01"))
# Cleaning omega data for year 2018...
# Detected pressure levels data...
# Cleaning omega data for year 2018...
# Detected pressure levels data...
# Cleaning omega data for year 2018...
# Detected pressure levels data...
# Cleaning omega data for year 2018...
# Detected pressure levels data...
# Cleaning omega data for year 2018...
# Detected pressure levels data...
# Cleaning omega data for year 2018...
# Detected pressure levels data...
# Cleaning omega data for year 2018...
# Detected pressure levels data...
# Cleaning omega data for year 2018...
# Detected pressure levels data...
# Cleaning omega data for year 2018...
# Detected pressure levels data...
# Cleaning omega data for year 2018...
# Detected pressure levels data...
# Cleaning omega data for year 2018...
# Detected pressure levels data...
# Cleaning omega data for year 2018...
# Detected pressure levels data...
# Cleaning omega data for year 2019...
# Detected pressure levels data...
# Cleaning omega data for year 2019...
# Detected pressure levels data...
# Cleaning omega data for year 2019...
# Detected pressure levels data...
# Cleaning omega data for year 2019...
# Detected pressure levels data...
# Cleaning omega data for year 2019...
# Detected pressure levels data...
# Cleaning omega data for year 2019...
# Detected pressure levels data...
# Cleaning omega data for year 2019...
# Detected pressure levels data...
# Cleaning omega data for year 2019...
# Detected pressure levels data...
# Cleaning omega data for year 2019...
# Detected pressure levels data...
# Cleaning omega data for year 2019...
# Detected pressure levels data...
# Cleaning omega data for year 2019...
# Detected pressure levels data...
# Cleaning omega data for year 2019...
# Detected pressure levels data...
# Cleaning omega data for year 2020...
# Detected pressure levels data...
# Cleaning omega data for year 2020...
# Detected pressure levels data...
# Cleaning omega data for year 2020...
# Detected pressure levels data...
# Cleaning omega data for year 2020...
# Detected pressure levels data...
# Cleaning omega data for year 2020...
# Detected pressure levels data...
# Cleaning omega data for year 2020...
# Detected pressure levels data...
# Cleaning omega data for year 2020...
# Detected pressure levels data...
# Cleaning omega data for year 2020...
# Detected pressure levels data...
# Cleaning omega data for year 2020...
# Detected pressure levels data...
# Cleaning omega data for year 2020...
# Detected pressure levels data...
# Cleaning omega data for year 2020...
# Detected pressure levels data...
# Cleaning omega data for year 2020...
# Detected pressure levels data...
# Cleaning omega data for year 2021...
# Detected pressure levels data...
# Cleaning omega data for year 2021...
# Detected pressure levels data...
# Cleaning omega data for year 2021...
# Detected pressure levels data...
# Cleaning omega data for year 2021...
# Detected pressure levels data...
# Cleaning omega data for year 2021...
# Detected pressure levels data...
# Cleaning omega data for year 2021...
# Detected pressure levels data...
# Cleaning omega data for year 2021...
# Detected pressure levels data...
# Cleaning omega data for year 2021...
# Detected pressure levels data...
# Cleaning omega data for year 2021...
# Detected pressure levels data...
# Cleaning omega data for year 2021...
# Detected pressure levels data...
# Cleaning omega data for year 2021...
# Detected pressure levels data...
# Cleaning omega data for year 2021...
# Detected pressure levels data...
# Cleaning omega data for year 2022...
# Detected pressure levels data...
# Cleaning omega data for year 2022...
# Detected pressure levels data...
# Cleaning omega data for year 2022...
# Detected pressure levels data...
# Cleaning omega data for year 2022...
# Detected pressure levels data...
# Cleaning omega data for year 2022...
# Detected pressure levels data...
# Cleaning omega data for year 2022...
# Detected pressure levels data...
# Cleaning omega data for year 2022...
# Detected pressure levels data...
# Cleaning omega data for year 2022...
# Detected pressure levels data...
# Cleaning omega data for year 2022...
# Detected pressure levels data...
# Cleaning omega data for year 2022...
# Detected pressure levels data...
# Cleaning omega data for year 2022...
# Detected pressure levels data...
# Cleaning omega data for year 2022...
# Detected pressure levels data...
# Returning daily omega data from 2020-03-01 to 2022-01-01.
# class       : SpatRaster 
# dimensions  : 277, 349, 10933  (nrow, ncol, nlyr)
# resolution  : 32462.99, 32463  (x, y)
# extent      : -16231.49, 11313351, -16231.5, 8976020  (xmin, xmax, ymin, ymax)
# coord. ref. : +proj=lcc +lat_0=50 +lon_0=-107 +lat_1=50 +lat_2=50 +x_0=5632642.22547 +y_0=4612545.65137 +datum=WGS84 +units=m +no_defs 
# sources     : omega.202101.nc:omega  (899 layers) 
#               omega.202102.nc:omega  (812 layers) 
#               omega.202103.nc:omega  (899 layers) 
#               ... and 21 more source(s)
# varnames    : omega (Daily Omega on Pressure Levels) 
#               omega (Daily Omega on Pressure Levels) 
#               omega (Daily Omega on Pressure Levels) 
#               ...
# names       : omega~10101, omega~10101, omega~10101, omega~10101, omega~10101, omega~10101, ... 
# unit        :    Pascal/s,    Pascal/s,    Pascal/s,    Pascal/s,    Pascal/s,    Pascal/s, ... 
# time (days) : 2021-01-01 to 2022-01-01 

@mitchellmanware Is it as designed or did I miss something in the workflow? More documentation about date argument would be helpful.

mitchellmanware commented 7 months ago

@sigmafelix That is odd, and is not by design. I will investigate.

mitchellmanware commented 7 months ago

@sigmafelix process_narr was missing code which subsets available dates (year-month files in path) to dates of interest as defined by date =. The return messaging was unclear because pressure level files have year-month combination but message only sent the working year. Fix incoming soon on branch mm-narr-fix-0321

mitchellmanware commented 7 months ago

@sigmafelix Patch fixed by filtering available .nc files to unique year-month combinations requested in date =, changing cat() message to include month, and using %Y%m%d format to set terra::time(). See PR https://github.com/NIEHS/amadeus/pull/52

Using same path provided above:

> devtools::load_all()
ℹ Loading amadeus
> d <-  amadeus::process_narr(path = "../../../../group/set/Projects/NRT-AP-Model/input/narr/omega", variable = "omega", date = c("2020-03-01", "2020-04-30"))
Cleaning omega data for March, 2020...
Detected pressure levels data...
Cleaning omega data for April, 2020...
Detected pressure levels data...
Returning daily omega data from 2020-03-01 to 2020-04-30.
> d
class       : SpatRaster 
dimensions  : 277, 349, 1769  (nrow, ncol, nlyr)
resolution  : 32462.99, 32463  (x, y)
extent      : -16231.49, 11313351, -16231.5, 8976020  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=lcc +lat_0=50 +lon_0=-107 +lat_1=50 +lat_2=50 +x_0=5632642.22547 +y_0=4612545.65137 +datum=WGS84 +units=m +no_defs 
sources     : omega.202003.nc:omega  (899 layers) 
              omega.202004.nc:omega  (870 layers) 
varnames    : omega (Daily Omega on Pressure Levels) 
              omega (Daily Omega on Pressure Levels) 
names       : omega~00301, omega~00301, omega~00301, omega~00301, omega~00301, omega~00301, ... 
unit        :    Pascal/s,    Pascal/s,    Pascal/s,    Pascal/s,    Pascal/s,    Pascal/s, ... 
time (days) : 2020-03-01 to 2020-04-30 
> head(names(d))
[1] "omega_level=1000_20200301" "omega_level=975_20200301" 
[3] "omega_level=950_20200301"  "omega_level=925_20200301" 
[5] "omega_level=900_20200301"  "omega_level=875_20200301" 

Meant to comment, not close yet 🫣

sigmafelix commented 7 months ago

@mitchellmanware #52 has issues with process_narr tests where I suppose indexing in subset part missed something.

mitchellmanware commented 7 months ago

@sigmafelix Yes just fixed. The filter now detects whether the "time" part of the variable.time.nc file naming convention is YYYY for monolevel or YYYYMM for pressure levels. This should fix the subsetting issue.

mitchellmanware commented 7 months ago

https://github.com/NIEHS/amadeus/pull/52 is good to go. I am sure there are places to clean up the code/make it more efficient but I can deal with this during modularization next week, but good to have a working function. Thank you for bringing this to my attention.

@sigmafelix