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

[QUESTION]Selection of interpolation method in ESMF_RegridWeightGen #258

Closed helpyuan closed 11 months ago

helpyuan commented 1 year ago

Type your question below:

Hi all, I hope to convert a lat/lon grid restart file to a cubed-sphere grid restart file. I followed the tutorials on https://gcpy.readthedocs.io/en/stable/Regridding.html, but the tutorial only provides regerid examples for cubed sphere. The "ESMF_RegridWeightGen --method" for regrinding between a cube-sphere(c48) and a cube-sphere(c60) is "conserve", and a "stretched cubed-sphere" and "cubed-sphere" is also "conserve". But I don't know if the regrid method between "lat/lon" and "cubed-sphere" is also 'conserved', or if is it bilinear. I sincerely hope to receive your help.

yantosca commented 1 year ago

Thanks @helpyuan. If you download the code in the dev branch (instead of main), the LL to CS regridding will work with the file_regrid.py routine. Also see the new instructions on the "latest" documentation:

NOTE: You will have to build a new Python environment using Mambaforge. The instructions are here:

We will hopefully release this as GCPy 1.4.0 along (or soon thereafter) the GEOS-Chem 14.2.0/14.2.1 updates.

Part of the reason that the regridding was broken in the current GCPy release was due to Python package updates that broke backwards compatibility. We seem to have gotten around this by using MambaForge instead of Conda to install the python environment.

Let us know if you encounter any further problems!

yantosca commented 1 year ago

Also I think the lat-lon and cubed-sphere regridding is conservative. Tagging @lizziel.

lizziel commented 1 year ago

You can also take a look at the ESMF docs for ESMF_RegridWeightGen directly here. The function is not part of GCPy, but is actually part of ESMF. The docs will include all options for the function.

helpyuan commented 1 year ago

Thanks @yantosca and @lizziel.

I have been able to regrid LL to CS, but the output does not include the variable "lon". What should I do to make the output result have the variable "lon" ? The output file variables are as follows: regrid_cs_ncfile.log.txt

In addition, this website ((https://gcpy.readthedocs.io/en/latest/Regridding.html) introduces two methods for regriding LL to CS, one of which is gcpy.regrid_restart_file, a function is gcpy.file_regrid. I would like to ask if both of these methods can currently regrid the GC-Classic restart file to the GCHP executable restart file?

lizziel commented 1 year ago

Hi @helpyuan, could you write out the steps you took to regrid LL to CS, including information on the source file?

Both of the options on ReadTheDocs should work for regridding LL to CS. However, if you run into any issues let us know.

helpyuan commented 1 year ago

Hi @lizziel, I used gcpy.file_regrid to regrid LL to CS and my steps are as follows:

python -m gcpy.file_regrid --filein ./GC-Classic/GEOSChem.Restart.TransportTracers.20190101_0000z.nc4 --dim_format_in classic --fileout GCHP.Restart.TransportTracers.20190101_0000z.c48.nc4 --cs_res_out 48 --dim_format_out checkpoint`

The print is as follows:

(gcpy_env) [liumy@ln2 regrid_restart_file]$ python -m gcpy.file_regrid --filein ./GC-Classic/GEOSChem.Restart.TransportTracers.20190101_0000z.nc4 --dim_format_in classic --fileout GCHP.Restart.TransportTracers.20190101_0000z.c48.nc4 --cs_res_out 48 --dim_format_out checkpoint
/data/home/liumy/tools/mambaforge-gcpy/GCPy/gcpy/file_regrid.py:13: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
  if LooseVersion(xe.__version__) < LooseVersion("0.2.1"):
using dimensions ('lat', 'lon') from data variable DELP_DRY as the horizontal dimensions for this dataset.
using dimensions ('lat', 'lon') from data variable DELP_DRY as the horizontal dimensions for this dataset.
using dimensions ('lat', 'lon') from data variable DELP_DRY as the horizontal dimensions for this dataset.
using dimensions ('lat', 'lon') from data variable DELP_DRY as the horizontal dimensions for this dataset.
using dimensions ('lat', 'lon') from data variable DELP_DRY as the horizontal dimensions for this dataset.
using dimensions ('lat', 'lon') from data variable DELP_DRY as the horizontal dimensions for this dataset.
<xarray.Dataset>
Dimensions:                       (time: 1, lev: 72, lat: 288, lon: 48)
Coordinates:
  * time                          (time) float64 0.0
  * lev                           (lev) float64 1.5e-05 2.635e-05 ... 0.9925
  * lat                           (lat) float64 1.0 2.0 3.0 ... 287.0 288.0
Dimensions without coordinates: lon
Data variables: (12/18)
    DELP_DRY                      (time, lev, lat, lon) float64 0.01 ... 15.22
    SPC_SHEmis90dayTracer         (time, lev, lat, lon) float64 1.498e-12 ......
    SPC_NHEmis90dayTracer         (time, lev, lat, lon) float64 1.722e-12 ......
    SPC_GlobEmis90dayTracer       (time, lev, lat, lon) float64 1.549e-12 ......
    SPC_COUniformEmis25dayTracer  (time, lev, lat, lon) float64 8.425e-17 ......
    SPC_COAnthroEmis50dayTracer   (time, lev, lat, lon) float64 9.743e-16 ......
    ...                            ...
    SPC_Be10                      (time, lev, lat, lon) float64 2.07e-18 ... ...
    SPC_Be7Strat                  (time, lev, lat, lon) float64 1.762e-19 ......
    SPC_Be7                       (time, lev, lat, lon) float64 1.762e-19 ......
    SPC_Pb210Strat                (time, lev, lat, lon) float64 4.576e-22 ......
    SPC_Pb210                     (time, lev, lat, lon) float64 5.675e-21 ......
    SPC_Rn222                     (time, lev, lat, lon) float64 0.0 ... 3.896...
Attributes: (12/14)
    title:                           GEOS-Chem diagnostic collection: Restart
    history:                         
    format:                          not found
    conventions:                     COARDS
    ProdDateTime:                    
    reference:                       www.geos-chem.org; wiki.geos-chem.org
    ...                              ...
    simulation_end_date_and_time:    2019-01-01 00:00:00z
    regrid_method:                   conservative
    stretch_factor:                  1.0
    target_longitude:                170.0
    target_latitude:                 -90.0
    cs_res:                          48`

The information of ./GC-Classic/GEOSChem.Restart.TransportTracers.20190101_0000z.nc4 is as follows: GEOSChem.Restart.TransportTracers.20190101_0000z.nc4.log

The information of GCHP.Restart.TransportTracers.20190101_0000z.c48.nc4 is as follows: GCHP.Restart.TransportTracers.20190101_0000z.c48.nc4.log

lizziel commented 1 year ago

Thanks @helpyuan. I'll try it on my end and see what I can figure out. There may be a bug.

lizziel commented 1 year ago

Hi @helpyuan, this issue is being looked at by @yantosca. He is finding several problems with the GCPy regridding for generating a GCHP restart file from GC-Classic. I suggest not using the tool until a new version is released with the fixes.

helpyuan commented 1 year ago

Thanks for the heads up @lizziel!

yantosca commented 1 year ago

@helpyuan: for details see PR #266.

helpyuan commented 1 year ago

Thanks @yantosca.

yantosca commented 1 year ago

Thanks @yantosca and @lizziel.

I have been able to regrid LL to CS, but the output does not include the variable "lon".

This is now fixed with PR #263 having been merged into the dev branch.

helpyuan commented 1 year ago

That's great @yantosca!

yantosca commented 1 year ago

I think we can close out this issue now.