From e2995f27dd9113c71aa19b98f31f887bb228811c Mon Sep 17 00:00:00 2001 From: Ana Ordonez Date: Tue, 15 Aug 2023 13:44:58 -0700 Subject: [PATCH 1/3] add custom grid --- .../mean_climate/mean_climate_driver.py | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/pcmdi_metrics/mean_climate/mean_climate_driver.py b/pcmdi_metrics/mean_climate/mean_climate_driver.py index 3eac17b48..7c77bb894 100755 --- a/pcmdi_metrics/mean_climate/mean_climate_driver.py +++ b/pcmdi_metrics/mean_climate/mean_climate_driver.py @@ -101,24 +101,31 @@ print('--- prepare mean climate metrics calculation ---') # generate target grid -if target_grid == "2.5x2.5": - # target grid for regridding - t_grid = xc.create_uniform_grid(-88.875, 88.625, 2.5, 0, 357.5, 2.5) - if debug: - print('type(t_grid):', type(t_grid)) # Expected type is 'xarray.core.dataset.Dataset' - print('t_grid:', t_grid) - # identical target grid in cdms2 to use generateLandSeaMask function that is yet to exist in xcdat - t_grid_cdms2 = cdms2.createUniformGrid(-88.875, 72, 2.5, 0, 144, 2.5) - # generate land sea mask for the target grid - sft = cdutil.generateLandSeaMask(t_grid_cdms2) - if debug: - print('sft:', sft) - print('sft.getAxisList():', sft.getAxisList()) - # add sft to target grid dataset - t_grid['sftlf'] = (['lat', 'lon'], np.array(sft)) - if debug: - print('t_grid (after sftlf added):', t_grid) - t_grid.to_netcdf('target_grid.nc') +res=target_grid.split("x") +lat_res=float(res[0]) +lon_res=float(res[1]) +start_lat=-90+lat_res/2 +start_lon=0 +end_lat = 90-lat_res/2 +end_lon = 360-lon_res +nlat = ((end_lat - start_lat) * 1/lat_res) + 1 +nlon = ((end_lon - start_lon) * 1/lon_res) + 1 +t_grid=xc.create_uniform_grid(start_lat,end_lat,lat_res,start_lon,end_lon,lon_res) +if debug: + print('type(t_grid):', type(t_grid)) # Expected type is 'xarray.core.dataset.Dataset' + print('t_grid:', t_grid) +# identical target grid in cdms2 to use generateLandSeaMask function that is yet to exist in xcdat +t_grid_cdms2 = cdms2.createUniformGrid(start_lat,nlat,lat_res,start_lon,nlon,lon_res) +# generate land sea mask for the target grid +sft = cdutil.generateLandSeaMask(t_grid_cdms2) +if debug: + print('sft:', sft) + print('sft.getAxisList():', sft.getAxisList()) +# add sft to target grid dataset +t_grid['sftlf'] = (['lat', 'lon'], np.array(sft)) +if debug: + print('t_grid (after sftlf added):', t_grid) + t_grid.to_netcdf('target_grid.nc') # load obs catalogue json egg_pth = resources.resource_path() From 371c3f1dc0e8c3460db7b897a3224dc346857ed2 Mon Sep 17 00:00:00 2001 From: Ana Ordonez Date: Thu, 17 Aug 2023 11:24:33 -0700 Subject: [PATCH 2/3] explicit float --- pcmdi_metrics/mean_climate/mean_climate_driver.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pcmdi_metrics/mean_climate/mean_climate_driver.py b/pcmdi_metrics/mean_climate/mean_climate_driver.py index a14d0ed37..5d41bca63 100755 --- a/pcmdi_metrics/mean_climate/mean_climate_driver.py +++ b/pcmdi_metrics/mean_climate/mean_climate_driver.py @@ -105,12 +105,12 @@ res=target_grid.split("x") lat_res=float(res[0]) lon_res=float(res[1]) -start_lat=-90+lat_res/2 -start_lon=0 -end_lat = 90-lat_res/2 -end_lon = 360-lon_res -nlat = ((end_lat - start_lat) * 1/lat_res) + 1 -nlon = ((end_lon - start_lon) * 1/lon_res) + 1 +start_lat=-90.+lat_res/2 +start_lon=0. +end_lat = 90.-lat_res/2 +end_lon = 360.-lon_res +nlat = ((end_lat - start_lat) * 1./lat_res) + 1 +nlon = ((end_lon - start_lon) * 1./lon_res) + 1 t_grid=xc.create_uniform_grid(start_lat,end_lat,lat_res,start_lon,end_lon,lon_res) if debug: print('type(t_grid):', type(t_grid)) # Expected type is 'xarray.core.dataset.Dataset' From ca6d38a53d18f2219331631f068a3073215af70e Mon Sep 17 00:00:00 2001 From: Ana Ordonez Date: Thu, 17 Aug 2023 11:25:15 -0700 Subject: [PATCH 3/3] add default target grid --- pcmdi_metrics/mean_climate/lib/create_mean_climate_parser.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pcmdi_metrics/mean_climate/lib/create_mean_climate_parser.py b/pcmdi_metrics/mean_climate/lib/create_mean_climate_parser.py index 02719bd73..06633b1e0 100644 --- a/pcmdi_metrics/mean_climate/lib/create_mean_climate_parser.py +++ b/pcmdi_metrics/mean_climate/lib/create_mean_climate_parser.py @@ -98,6 +98,7 @@ def create_mean_climate_parser(): dest="target_grid", help='Options are "2.5x2.5" or an actual cdms2 grid object', required=False, + default="2.5x2.5" ) parser.add_argument(