From 183640aaf78380adca0a5b8c8434dec713bb9df2 Mon Sep 17 00:00:00 2001 From: YuviPanda Date: Fri, 28 Oct 2022 10:58:00 -0700 Subject: [PATCH] Make it a dict --- recipes/daymet/meta.yaml | 40 +++++++++------------ recipes/daymet/recipe.py | 75 ++++++++++++++++++---------------------- 2 files changed, 50 insertions(+), 65 deletions(-) diff --git a/recipes/daymet/meta.yaml b/recipes/daymet/meta.yaml index b161d9dae4..24b12a75c4 100644 --- a/recipes/daymet/meta.yaml +++ b/recipes/daymet/meta.yaml @@ -1,31 +1,25 @@ -title: 'Global Precipitation Climatology Project' +title: Daymet description: > - Global Precipitation Climatology Project (GPCP) Daily Version 1.3 gridded, merged ty - satellite/gauge precipitation Climate data Record (CDR) from 1996 to present. + Daily Surface Weather and Climatological Summaries (Daymet) provides + long-term, continuous, gridded estimates of daily weather and climatology + variables by interpolating and extrapolating ground-based observations through + statistical modeling techniques. The Daymet data products provide driver data + for biogeochemical terrestrial modeling and have myriad applications in many + Earth science, natural resource, biodiversity, and agricultural research + areas. Daymet weather variables include daily minimum and maximum temperature, + precipitation, vapor pressure, shortwave radiation, snow water equivalent, and + day length produced on a 1 km x 1 km gridded surface over continental North + America and Hawaii from 1980 and over Puerto Rico from 1950 through the end of + the most recent full calendar year. pangeo_forge_version: '0.9.0' pangeo_notebook_version: '2022.06.02' recipes: - - id: gpcp-from-gcs - object: 'recipe:recipe' -provenance: - providers: - - name: 'NOAA NCEI' - description: 'National Oceanographic & Atmospheric Administration National Centers for Environmental Information' - roles: - - host - - licensor - url: https://www.ncei.noaa.gov/products/global-precipitation-climatology-project - - name: 'University of Maryland' - description: > - University of Maryland College Park Earth System Science Interdisciplinary Center - (ESSIC) and Cooperative Institute for Climate and Satellites (CICS). - roles: - - producer - url: http://gpcp.umd.edu/ + dict_object: recipe:recipes +provenance: {} license: 'No constraints on data access or use.' maintainers: - - name: 'Charles Stern' - orcid: '0000-0002-4078-0852' - github: cisaacstern +- name: 'Charles Stern' + orcid: '0000-0002-4078-0852' + github: cisaacstern bakery: id: 'pangeo-ldeo-nsf-earthcube' diff --git a/recipes/daymet/recipe.py b/recipes/daymet/recipe.py index 85a2be9494..04a53b48ba 100644 --- a/recipes/daymet/recipe.py +++ b/recipes/daymet/recipe.py @@ -1,37 +1,37 @@ import datetime -import enum -import os from pangeo_forge_recipes import patterns from pangeo_forge_recipes.recipes import XarrayZarrRecipe -# class Region(str, enum.Enum): -# NA = 'na' -# PR = 'pr' -# HI = 'hi' - - -# class Frequency(str, enum.Enum): -# DAY = 'daily' -# MONTH = 'mon' -# YEAR = 'ann' - - -AGG_VARIABLES = {'prcp', 'swe', 'tmax', 'tmin', 'vp'} -DAILY_VARIABLES = AGG_VARIABLES | {'dayl', 'srad'} - +def make_recipe(region, frequency): + """ + Make a daymet recipe for given region with given frequency. -def make_format_function(region: str, frequency: str): + region is "na", "pr" or "hi" + frequency is "daily", "mon" (monthly) or "ann" (yearly) + """ + # Aggregate variables available AGG_VARIABLES = {'prcp', 'swe', 'tmax', 'tmin', 'vp'} + # We have a few more variables available daily, in addition to the aggregate ones DAILY_VARIABLES = AGG_VARIABLES | {'dayl', 'srad'} - if frequency in {"mon", "ann"}: + + if frequency in {'mon', 'ann'}: + # Aggregated data - monthly or annual + variables = list(AGG_VARIABLES) + + if frequency == 'ann': + nitems_per_file = 1 + kwargs = dict() + else: + nitems_per_file = 12 + kwargs = dict(subset_inputs={'time': 12}) def format_function(variable, time): # https://thredds.daac.ornl.gov/thredds/fileServer/ornldaac/1855/daymet_v4_prcp_monttl_hi_1980.nc assert variable in AGG_VARIABLES - folder = '1852' if frequency == "ann" else '1855' + folder = '1852' if frequency == 'ann' else '1855' if variable == 'prcp': agg = 'ttl' else: @@ -39,39 +39,22 @@ def format_function(variable, time): return f'https://thredds.daac.ornl.gov/thredds/fileServer/ornldaac/{folder}/daymet_v4_{variable}_{frequency}{agg}_{region}_{time:%Y}.nc' else: + variables = list(DAILY_VARIABLES) + nitems_per_file = 365 + kwargs = dict(subset_inputs={'time': 365}) def format_function(variable, time): assert variable in DAILY_VARIABLES # https://thredds.daac.ornl.gov/thredds/fileServer/ornldaac/1840/daymet_v4_daily_hi_dayl_1980.nc return f'https://thredds.daac.ornl.gov/thredds/fileServer/ornldaac/1840/daymet_v4_{frequency}_{region}_{variable}_{time:%Y}.nc' - return format_function - - -def make_recipe(region, frequency): - AGG_VARIABLES = {'prcp', 'swe', 'tmax', 'tmin', 'vp'} - DAILY_VARIABLES = AGG_VARIABLES | {'dayl', 'srad'} - if frequency == "daily": - variables = list(DAILY_VARIABLES) - nitems_per_file = 365 - kwargs = dict(subset_inputs={'time': 365}) - else: - variables = list(AGG_VARIABLES) - - if frequency == "ann": - nitems_per_file = 1 - kwargs = dict() - else: - nitems_per_file = 12 - kwargs = dict(subset_inputs={'time': 12}) - variable_merge_dim = patterns.MergeDim('variable', keys=variables) dates = [datetime.datetime(y, 1, 1) for y in range(1980, 2021)] concat_dim = patterns.ConcatDim('time', keys=dates, nitems_per_file=nitems_per_file) pattern = patterns.FilePattern( - make_format_function(region, frequency), variable_merge_dim, concat_dim + format_function(region, frequency), variable_merge_dim, concat_dim ) recipe = XarrayZarrRecipe(pattern, copy_input_to_local_file=True, **kwargs) @@ -79,4 +62,12 @@ def make_recipe(region, frequency): return recipe -recipe = make_recipe("na", "mon") +regions = ('na', 'hi', 'pr') +frequencies = ('mon', 'ann') + +recipes = {} + +for region in regions: + for freq in frequencies: + id = f'{region}_{freq}' + recipes[id] = make_recipe(region, freq)