From a1f05a1f815472666b52a6ac4cba03ba2f20fad3 Mon Sep 17 00:00:00 2001 From: bitterbark Date: Wed, 8 Jan 2025 10:52:50 -0700 Subject: [PATCH 1/3] small fix --- tools/catalog_builder/parsers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/catalog_builder/parsers.py b/tools/catalog_builder/parsers.py index 258257a99..f40dc7fb4 100644 --- a/tools/catalog_builder/parsers.py +++ b/tools/catalog_builder/parsers.py @@ -217,7 +217,7 @@ def parse_gfdl_am5_data(file_name: str): if hasattr(gfdl_info['variables'], catalog_info['variable_id']): var_metadata = gfdl_info['variables'].get(catalog_info['variable_id']) else: - raise KeyError(f'{catalog_info['variable_id']} not found in {gfdl_fieldlist}') + raise KeyError(f"{catalog_info['variable_id']} not found in {gfdl_fieldlist}") if hasattr(var_metadata, 'standard_name'): catalog_info.update({'standard_name': var_metadata.standard_name}) if hasattr(var_metadata, 'long_name'): From 08fd40c989edfe2f962d609871aa4592ccbc88d2 Mon Sep 17 00:00:00 2001 From: bitterbark Date: Tue, 4 Mar 2025 17:15:51 -0700 Subject: [PATCH 2/3] Fix time range to work with YYYYMMDD or YYYYMMDDHH as well as original YYYY --- diagnostics/MJO_suite/daily_netcdf.ncl | 43 +++++++++++++++++++++----- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/diagnostics/MJO_suite/daily_netcdf.ncl b/diagnostics/MJO_suite/daily_netcdf.ncl index 566f5b1a8..e90dc8a68 100644 --- a/diagnostics/MJO_suite/daily_netcdf.ncl +++ b/diagnostics/MJO_suite/daily_netcdf.ncl @@ -17,6 +17,36 @@ begin end if end ; procedure debug_print +undef("check_date_format") +function check_date_format(date_in,date_type,routine_name,debug) +begin + if (date_in.lt.1.e4) then ; input just YYYY, need to add MMDDHH + if (date_type.eq."start") then + date_suffix = 101*100 + else if (date_type.eq."end") then + date_suffix = 1231*10 + else + print("ERROR: "+routine_name+" No date_type given to function check_date_format") + end if + end if + + debug_print("Incoming "+date_type+" date YYYY format: "+date_in,routine_name,debug) + date_out = date_in*1000000+ date_suffix + debug_print("Corrected "+date_type+" date to:"+date_out,routine_name,debug) + + else + if (date_in .lt. 100000000) ; YYYYMMDD + debug_print("Incoming "+date_type+" date YYYYMMDD format: "+date_in,routine_name,debug) + date_out = date_in*100 ;; HH = 00 + debug_print("Corrected "+date_type+" date to:"+date_out,routine_name,debug) + else + debug_print("Found start date format YYYYMMDDHH: "+yr,routine_name,debug) + date_out = date_in + end if ; YYYYMMDD + end if ; YYYY + + return date_out +end ; function check_date_format begin ; read daily output files from CAM2 and process the data @@ -63,12 +93,10 @@ nd = dimsizes(time_all) i2 = nd(0) - 1 debug_print("Time range in file: "+time_all(0)+" -"+time_all(i2),routine_name,debug) - ; in hours to match cd_calendar/ut_calendar output YYYYMMDDHH - ; uses 18 hrs for endtime since 6-hourly is the most high res we expect - ; should still work for daily, just finds YYYY123100 - start_time = yr1*1000000+101*100 - end_time = yr2*1000000+1231*100+18 - debug_print("Time range requested: "+start_time+" "+end_time,routine_name,debug) +; Check if date came in as YYYYMMDD or YYYY (historic) +start_time = check_date_format(yr1,"start",routine_name,debug) +end_time = check_date_format(yr2,"end",routine_name,debug) + tol = 24 ; 24 hours tolerance allows for different time resolutions do i=0,dimsizes(time_all)-1 ; debug_print("examining times "+i+" "+time_all(i),routine_name,debug) @@ -108,8 +136,7 @@ if ( isMonotonic(date) .ne. 1 ) then exit ; exit on error end if -; DRB: used to do pr, rlut separately. Folding them into the loop instead. -; **here first just use read_model_file for pr here, then put into var loop below +; First just use read_model_file for pr here, then put into var loop below ; precipitation rate (pr) print("daily_netcdf.ncl reading "+file_pr+" for making precip file!") From df8cb75827ba15ef11e54d09e0aec2ac28fcbbb9 Mon Sep 17 00:00:00 2001 From: bitterbark Date: Thu, 13 Mar 2025 16:52:01 -0600 Subject: [PATCH 3/3] fix for dataset/time requested case --- src/preprocessor.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/preprocessor.py b/src/preprocessor.py index 275076666..3dc7322a1 100644 --- a/src/preprocessor.py +++ b/src/preprocessor.py @@ -927,13 +927,17 @@ def crop_date_range(self, case_date_range: util.DateRange, xr_ds, time_coord) -> date_range_cf_start = self.cast_to_cftime(case_date_range.start.lower, cal) date_range_cf_end = self.cast_to_cftime(case_date_range.end.lower, cal) + # dataset has no overlap with the user-specified date range if ds_start < date_range_cf_start and ds_end < date_range_cf_start or \ ds_end > date_range_cf_end and ds_start > date_range_cf_end: new_xr_ds = None # dataset falls entirely within user-specified date range elif ds_start >= date_range_cf_start and ds_end <= date_range_cf_end: new_xr_ds = xr_ds.sel({time_coord.name: slice(ds_start, ds_end)}) - # dataset overlaps user-specified date range start + # dataset overlaps user-specified date range start (corrected) + elif ds_start <= date_range_cf_start <= ds_end <= date_range_cf_end: + new_xr_ds = xr_ds.sel({time_coord.name: slice(date_range_cf_start, ds_end)}) + # dataset overlaps user-specified date range start (orig) elif date_range_cf_start < ds_start and \ date_range_cf_start <= ds_end <= date_range_cf_end: new_xr_ds = xr_ds.sel({time_coord.name: slice(date_range_cf_start, ds_end)}) @@ -943,6 +947,12 @@ def crop_date_range(self, case_date_range: util.DateRange, xr_ds, time_coord) -> # dataset contains all of requested date range elif date_range_cf_start >= ds_start and date_range_cf_end <= ds_end: new_xr_ds = xr_ds.sel({time_coord.name: slice(date_range_cf_start, date_range_cf_end)}) + else: + print(f'ERROR: new_xr_ds is unset because of incompatibility of time:') + print(f' Dataset start: {ds_start=}') + print(f' Dataset end : {ds_end=}') + print(f' Requested start: {date_range_cf_start=}') + print(f' Requested end : {date_range_cf_end=}') return new_xr_ds