geoschem / gcpy

Python toolkit for GEOS-Chem. Contains basic plotting scripts, plus the suite of GEOS-Chem benchmarking utilities.
https://gcpy.readthedocs.io
Other
51 stars 24 forks source link

[BUG/ISSUE] - Regridding GCHP C48 to standard lat x lon #276

Closed kbloxam closed 10 months ago

kbloxam commented 11 months ago

The Bug

I am trying to regrid from C48 to a 2x2.5 lat/lon grid. I have followed the outlined steps in the documentation but when I execute the regrid_restart_file submodule I get the following error:

INFO:root:Input restart file: GEOSChem.SpeciesConc.20150728_0200z.nc4
INFO:root:Regridding weights: c48_to_latlon_2_2_5.nc
INFO:root:Output template restart file: GEOSChem.SpeciesConc.20150728_0200z.nc4
Traceback (most recent call last):
  File "/home/kbloxam/miniconda3/envs/regrid_env/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/kbloxam/miniconda3/envs/regrid_env/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/kbloxam/python/packages/GCPy/gcpy/regrid_restart_file.py", line 559, in <module>
    regrid_restart_file(
  File "/home/kbloxam/python/packages/GCPy/gcpy/regrid_restart_file.py", line 484, in regrid_restart_file
    check_for_nans(dataset)
  File "/home/kbloxam/python/packages/GCPy/gcpy/regrid_restart_file.py", line 444, in check_for_nans
    if dataset[name].isnull().any().item():
  File "/home/kbloxam/miniconda3/envs/regrid_env/lib/python3.9/site-packages/xarray/core/common.py", line 1249, in isnull
    return apply_ufunc(
  File "/home/kbloxam/miniconda3/envs/regrid_env/lib/python3.9/site-packages/xarray/core/computation.py", line 1262, in apply_ufunc
    return apply_dataarray_vfunc(
  File "/home/kbloxam/miniconda3/envs/regrid_env/lib/python3.9/site-packages/xarray/core/computation.py", line 314, in apply_dataarray_vfunc
    result_var = func(*data_vars)
  File "/home/kbloxam/miniconda3/envs/regrid_env/lib/python3.9/site-packages/xarray/core/computation.py", line 724, in apply_variable_ufunc
    dim_sizes = unified_dim_sizes(
  File "/home/kbloxam/miniconda3/envs/regrid_env/lib/python3.9/site-packages/xarray/core/computation.py", line 630, in unified_dim_sizes
    raise ValueError(
ValueError: broadcasting cannot handle duplicate dimensions on a variable: ['nf', 'ncontact', 'ncontact']

To Reproduce

$ gridspec-create gcs 48
$ gridspec-create latlon 90 144
$ ESMF_RegridWeightGen --source c48_gridspec.nc --destination regular_lat_lon_90x144.nc --method conserve --weight c48_to_latlon_2x2_5.nc
$ python -m gcpy.regrid_restart_file GEOSChem.SpeciesConc.20150728_0200z.nc4 c48_to_latlon_2x2_5.nc GEOSChem.SpeciesConc.20150728_0200z.nc4

Expected behavior

I would expect the regridding to work.

Required information:

This produces another error it seems.

AttributeError: module 'gcpy' has no attribute 'show_versions'
lizziel commented 11 months ago

Hi @kbloxam, I think the regrid_restart_file function is only set up to regrid restart files. The file you are trying to regrid is not a GEOS-Chem restart file.

yantosca commented 10 months ago

Hi @kbloxam, thanks for writing. We have just released GCPy 1.4.0 (see https://gcpy.readthedocs.io for updated installation instructions). In this version, I have fixed a few broken issues in the online regrididng weights method (i.e. using the file_regrid.py script). See the updated documentation here: https://gcpy.readthedocs.io/en/stable/Regridding.html

Also, if you only want to plot the data, then you don't have to regrid it. The gcpy.plot.single_panel routine can create a plot from either cubed-sphere or lat-lon data.

yantosca commented 10 months ago

I will close out this issue for now. Feel free to raise another issue if you are still encountering problems.