Regridding
GCPy currently supports regridding of data from:
GEOS-Chem Classic restart files
GEOS-Chem Classic diagnostic files
GCHP restart files
GCHP diagnostic files
HEMCO restart files
HEMCO diagnostic files
As well as any netCDF file adhering to COARDS or CF conventions.
Regridding is supported across any horizontal resolution and any grid type available in GEOS-Chem, including lat/lon (global or non-global), global standard cubed-sphere, and global stretched-grid. GCPy also supports arbitrary vertical regridding across different vertical resolutions.
Regridding with GCPy is currently undergoing an overhaul. As of the current release, regridding is split into two different categories:
Regridding between lat-lon grids using regridding weights computed on the fly by GCPy, and
Regridding either lat-lon or cubed-sphere using regridding weights computed as a preprocessing step.
The latter method may be used for creating GCHP standard grid and stretched grid restart files from either GCHP or GEOS-Chem Classic restart files.
Using Online Regridding Weights
You can regrid existing GEOS-Chem restart or diagnostic files using
GCPy function gcpy.file_regrid(). This function can called
directly from the command line or from within a Python script,
as shown in the (examples) below.
Note
For regridding to or from GCHP stretched-grid restart files, we recommend using the offline regridding weights method.
For a list of input arguments, see gcpy.file_regrid() in the API
reference section.
Examples
Regrid a 4x5 GEOS-Chem Classic restart or diagnostic file to a GEOS-Chem Classic 2x2.5 file:
$ conda activate gcpy_env (gcpy_env) $ python -m gcpy.file_regrid \ --filein /path/to/file_4x5.nc4 \ --dim_format_in classic \ --fileout /path/to/file_2x25.nc4 \ --ll_res_out 2x2.5 \ --dim_format_out classic
Regrid a 4x5 GEOS-Chem Classic restart or diagnostic file to a GCHP C24 restart file:
$ conda activate gcpy_env (gcpy_env) $ python -m gcpy.file_regrid \ --filein /path/to/file_4x5.nc4 \ --dim_format_in classic \ --fileout /path/to/file_c24.nc4 \ --cs_res_out 24 \ --dim_format_out checkpoint
Regrid a GCHP C48 restart file to a GCHP stretched grid C48 restart file. The stretch parameters are:
stretch-factor: 5
target-longitude: -72
target-latitude: 41
$ conda activate gcpy_env (gcpy_env) $ python -m gcpy.file_regrid \ --filein /path/to/file_c48.nc4 \ --dim_format_in checkpoint \ --fileout /path/to/file_c48_sg.nc4 \ --cs_res_out 48 \ --dim_format_out checkpoint \ --sg_params_out 5 -72 41
Regrid the GCHP stretched grid C48 restart file from Example 3 above to a GCHP C24 diagnostic file.
$ conda activate gcpy_env (gcpy_env) $ python -m gcpy.file_regrid \ --filein /path/to/file_c48_sg.nc4 \ --sg_params_in 5 -72 41 \ --dim_format_in checkpoint \ --fileout /path/to/file_c24.nc4 \ --cs_res_out 24 \ --dim_format_out diagnostic
Same example as above, but implemented within a Python script rather than from the comamnd line.
from gcpy.file_regrid import file_regrid file_regrid( "/path/to/file_c48_sg.nc4", # filein "/path/to/file_c24.nc4", # fileout "checkpoint", # dim_format_in "diagnostic", # dim_format_out sg_params_in=[5, -72, 41], cs_res_out=24, )
Using Offline Regridding Weights
This approach requires generating regridding weights using python packages gridspec and sparselt, which are included with the GCPy Python environment.
Regridding with GCPy, gridspec and
sparselt is a three stage process:
Create grid specifications for the source and target grids using
gridspec.Create regridding weights for the transformation using
ESMF_RegridWeightGen.Run the regridding operation using the
gcpy.regrid_restart_file()submodule of GCPy.
Example 1: Standard Lat-Lon to Cubed-Sphere Regridding
This example will show regridding a GC-Classic 4x5 restart file to a GCHP c24 restart file.
Activate your GCPy environment.
$ conda activate gcpy_env # Or whatever your environment's name is
Create a lat-lon source grid specification using
gridspec-create.$ gridspec-create latlon --pole-centered --half-polar 46 72
This will produce 1 file:
regular_lat_lon_46x72.nc.
Create a target grid specification using
gridspec-create.$ gridspec-create gcs 24
This will produce 7 files:
c24_gridspec.ncandc24.tile[1-6].nc
Create the regridding weights for the regridding transformation (46x72 to C24) using
ESMF_RegridWeightGen.$ ESMF_RegridWeightGen \ --source regular_lat_lon_46x72.nc \ --destination c24_gridspec.nc \ --method conserve \ --weight 46x72_to_c24_weights.nc
This will produce a log file,
PET0.RegridWeightGen.Log, and our regridding weights,46x72_to_c24_weights.nc
Use the grid weights produced in previous steps to complete the regridding.
$ python -m gcpy.regrid_restart_file \ GEOSChem.Restart.20190701_0000z.nc4 \ 46x72_to_c24_weights.nc \ GEOSChem.Restart.20190701_0000z.c24_old.nc4
(Click on
gcpy.regrid_restart_file()for a list of input and output arguments to the function.)In this example (lat-lon to cubed-sphere) we need to use a GEOS-Chem Classic restart file as the file to be regridded and a GCHP restart file as the template file.
Note
The resolution of the template file does not matter as long as it contains all of the variables and attributes that you wish to include in the regridded restart file.
After running
gcpy.regrid_restart_file(), a single restart file namednew_restart_file.ncwill be created. You can rename this file and use it to initialize your GCHP C24 simulation.
Deactivate your GCPy environment when finished.
$ conda deactivate
Example 2: Standard Cubed-Sphere to Cubed-Sphere Regridding
We will use the example of regridding the out-of-the-box
GEOSChem.Restart.20190701_0000z.c48.nc4 restart file from
C48 to C60 to demonstrate the standard cubed-sphere regridding process:
Activate your GCPy environment.
$ conda activate gcpy_env # Or whatever your environment's name is
Create a source grid specification using
gridspec-create.$ gridspec-create gcs 48
This will produce 7 files:
c48_gridspec.ncandc48.tile[1-6].nc
Create a target grid specification using
gridspec-create.$ gridspec-create gcs 60
Again, this will produce 7 files:
c60_gridspec.ncandc60.tile[1-6].nc
Create the regridding weights for the regridding transformation (C48 to C60) using
ESMF_RegridWeightGen.$ ESMF_RegridWeightGen \ --source c48_gridspec.nc \ --destination c60_gridspec.nc \ --method conserve \ --weight c48_to_c60_weights.nc
This will produce a log file,
PET0.RegridWeightGen.Log, and our regridding weights,c48_to_c60_weights.nc
Use the grid weights produced in earlier steps to complete the regridding.
$ python -m gcpy.regrid_restart_file \ GEOSChem.Restart.20190701_0000z.c48.nc4 \ c48_to_c60_weights.nc \ GEOSChem.Restart.20190701_0000z.c48.nc4
(Click on
gcpy.regrid_restart_file()to see its input and output arguments.)Because we are regridding from one cubed-sphere grid to another cubed-sphere grid, we can use the file to be regridded as the template file.
After running
gcpy.regrid_restart_file(), a single restart file namednew_restart_file.ncwill be created. You can rename this file as you wish and use it for your GCHP C60 simulation.
Deactivate your GCPy environment when you have finished.
$ conda deactivate
Example 3: Standard to Stretched Cubed-Sphere Regridding
This example regrids the out-of-the-box c48 restart file
(GEOSChem.Restart.20190701_0000z.c48.nc4) from a standard
cubed-sphere grid to a stretched grid. The base resolution will remain
the same at c48. The regridded file will have a stretch factor of 4.0
over Bermuda which means a regional grid resolution of c196 (4
times 48) in that area.
Activate your GCPy environment:
$ conda activate gcpy_env # Or whatever your environment's name is
Create a source grid specification using
gridspec-create.$ gridspec-create gcs 48
This will produce 7 files:
c48_gridspec.ncandc48.tile[1-6].nc
Create a target grid specification using
gridspec-create. This will be for the stretched grid.$ gridspec-create sgcs 48 -s 4.0 -t 32.0 -64.0
Here, the
-soption denotes the stretch factor and the-toption denotes the latitude / longitude of the centre point of the grid stretch.Again, this will produce 7 files:
c48_..._gridspec.ncandc48_..._tile[1-6].nc, where...denotes randomly generated characters. Be sure to look for these since you will need them in the next step.
Create the regridding weights for the regridding transformation (C48 to C48-stretched) using
ESMF_RegridWeightGen, replacingc48_..._gridspec.ncwith the actual name of the file created in the previous step. An example is shown below.$ ESMF_RegridWeightGen \ --source c48_gridspec.nc \ --destination c48_s4d00_tdtdqp9ktebm5_gridspec.nc \ --method conserve \ --weight c48_to_c48_stretched_weights.nc
This will produce a log file,
PET0.RegridWeightGen.Log, and our regridding weights,c48_to_c48_stretched_weights.nc
Use the grid weights produced in earlier steps to complete the regridding.
$ python -m gcpy.regrid_restart_file \ --stretched-grid \ --stretch-factor 4.0 \ --target-latitude 32.0 \ --target-longitude -64.0 \ GEOSChem.Restart.20190701_0000z.c48.nc4 \ c48_to_c48_stretched_weights.nc \ GEOSChem.Restart.20190701_0000z.c48.nc4
(Click on
gcpy.regrid_restart_file()to see its input and output arguments.)Because we are regridding from one cubed-sphere grid to another cubed-sphere grid, we can use the file to be regridded as the template file.
This will produce a single file,
new_restart_file.nc, regridded from C48 standard to C48 stretched with a stretch factor of 4.0 over 32.0N, -64.0E, that you can rename and use as you please.Tip
It is generally a good idea to rename the file to include the grid resolution, stretch factor, and target lat/lon for easy reference. You can copy it somewhere to keep long-term and link to it from the GCHP Restarts subdirectory in the run directory.
$ mv new_restart_file.nc GEOSChem.Restart.20190701_0000z.c120.s4_32N_64E.nc
You can also easily reference the file’s stretch parameters by looking at the global attributes in the file. When using the file as a restart file in GCHP make sure that you use the exact same parameters in both the file’s global attributes and GCHP configuration file
setCommonRunSettings.sh.Deactivate your GCPy environment when you have finished.
$ conda deactivate
Regridding for Plotting in GCPy
When plotting in GCPy (e.g. through
gcpy.plot.compare_single_level() or
gcpy.plot.compare_zonal_mean()), the vast majority of
regridding is handled internally. You can optionally request a
specific horizontal comparison resolution in
gcpy.plot.compare_single_level() and
gcpy.plot.compare_zonal_mean(). Note that all regridding
in these plotting functions only applies to the comparison panels (not
the top two panels which show data directly from each dataset). There
are only two scenarios where you will need to pass extra information
to GCPy to help it determine grids and to regrid when plotting.
Pass stretched-grid file paths
Stretched-grid parameters cannot currently be automatically determined
from grid coordinates. If you are plotting stretched-grid data in
gcpy.plot.compare_single_level() or
gcpy.plot.compare_zonal_mean() (even if regridding to another
format), you need to use the sg_ref_path or
sg_dev_path arguments to pass the path of your original
stretched-grid restart file to GCPy. If using
gcpy.plot.single_panel(), pass the file path using
sg_path. Stretched-grid restart files created using GCPy
contain the specified stretch factor, target longitude, and target
latitude in their metadata. Currently, output files from
stretched-grid runs of GCHP do not contain any metadata that specifies
the stretched-grid used.
Pass vertical grid parameters for non-72/47-level grids
GCPy automatically handles regridding between different vertical grids
when plotting except when you pass a dataset that is not on the
typical 72-level or 47-level vertical grids. If using a different
vertical grid, you will need to pass the corresponding grid
parameters
using the ref_vert_params or dev_vert_params keyword
arguments.
Automatic regridding decision process
When you do not specify a horizontal comparison resolution using the
cmpres argument in gcpy.plot.compare_single_level() and
gcpy.plot.compare_zonal_mean(), GCPy follows several steps to
determine what comparison resolution it should use:
If both input grids are lat/lon, use the highest resolution between them (don’t regrid if they are the same resolution).
Else if one grid is lat/lon and the other is cubed-sphere (standard or stretched-grid), use a 1x1.25 lat/lon grid.
Else if both grids are cubed-sphere and you are plotting zonal means, use a 1x1.25 lat/lon grid.
Else if both grids are standard cubed-sphere, use the highest resolution between them (don’t regrid if they are the same resolution).
Else if one or more grids is a stretched-grid, use the grid of the ref dataset.
For differing vertical grids, the smaller vertical grid is currently used for comparisons.