MPAS-Dev / MPAS-Tools

MPAS Tools Repository
Other
37 stars 63 forks source link

Replace calls to `pyproj.transfortm()` #454

Closed xylar closed 2 years ago

xylar commented 2 years ago

When calling set_lat_lon_fields_in_planar_grid.py, I'm seeing:

/home/xylar/miniconda3/envs/ais_mesh/bin/set_lat_lon_fields_in_planar_grid.py:84: DeprecationWarning: This function is deprecated. See: https://pyproj4.github.io/pyproj/stable/gotchas.html#upgrading-to-pyproj-2-from-pyproj-1
  lonCell, latCell = pyproj.transform(projections[options.projection], projections['latlon'], xCell[:], yCell[:], radians=True)

I haven't looked into this too much but it seems like something needs to be updated before this starts breaking. As the warning says, maybe https://pyproj4.github.io/pyproj/stable/gotchas.html#upgrading-to-pyproj-2-from-pyproj-1 is a good place to start.

xylar commented 2 years ago

@hollyhan, @matthewhoffman and @trhille, could you see about fixing this so I can include a fix in the next MPAS-Tools release?

hollyhan commented 2 years ago

@xylar, sorry for the delayed response! I've updated the code set_lat_lon_fields_in_planar_grid.py in the newest commit here: f5a3a9e87360c64c2c76ca6c163f529471b774d4.

Running the script before the fix shows deprecation warning as you've seen:

(base) pn2034311:planar_grid_transformations hollyhan$ ./set_lat_lon_fields_in_planar_grid.py -f ~/Downloads/Antarctic_8to80km.nc -p ais-bedmap2
== Gathering information.  (Invoke with --help for more details. All arguments are optional)

Using ais-bedmap2 projection, defined as: +proj=stere +lat_0=-90 +lat_ts=-71 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +units=m +no_defs
Input file xCell min/max values: -2579104.3263391815 2812394.711808656
Input file yCell min/max values: -2216798.803958245 2309080.616926154
/Users/hollyhan/Desktop/E3SM-Project/MPAS_Tools/MPAS-Tools/mesh_tools/planar_grid_transformations/./set_lat_lon_fields_in_planar_grid.py:84: DeprecationWarning: This function is deprecated. See: https://pyproj4.github.io/pyproj/stable/gotchas.html#upgrading-to-pyproj-2-from-pyproj-1
  lonCell, latCell = pyproj.transform(projections[options.projection], projections['latlon'], xCell[:], yCell[:], radians=True)
/Users/hollyhan/Desktop/E3SM-Project/MPAS_Tools/MPAS-Tools/mesh_tools/planar_grid_transformations/./set_lat_lon_fields_in_planar_grid.py:85: DeprecationWarning: This function is deprecated. See: https://pyproj4.github.io/pyproj/stable/gotchas.html#upgrading-to-pyproj-2-from-pyproj-1
  lonVertex, latVertex = pyproj.transform(projections[options.projection], projections['latlon'], xVertex[:], yVertex[:], radians=True)
/Users/hollyhan/Desktop/E3SM-Project/MPAS_Tools/MPAS-Tools/mesh_tools/planar_grid_transformations/./set_lat_lon_fields_in_planar_grid.py:86: DeprecationWarning: This function is deprecated. See: https://pyproj4.github.io/pyproj/stable/gotchas.html#upgrading-to-pyproj-2-from-pyproj-1
  lonEdge, latEdge = pyproj.transform(projections[options.projection], projections['latlon'], xEdge[:], yEdge[:], radians=True)
Calculated latCell min/max values (radians): -1.569633803735738 -1.091774649960595
Calculated lonCell min/max values (radians): 1.5131680893138319e-05 6.283152067454557
Lat/lon calculations completed.  File has been written.

After the fix, the deprecation warning disappears, and calculated latCell min/max and lonCell min/max values are the same as before:

(base) pn2034311:planar_grid_transformations hollyhan$ ./set_lat_lon_fields_in_planar_grid.py -f ~/Downloads/Antarctic_8to80km.nc -p ais-bedmap2
== Gathering information.  (Invoke with --help for more details. All arguments are optional)

Using ais-bedmap2 projection, defined as: +proj=stere +lat_ts=-71.0 +lat_0=-90 +lon_0=0.0 +k_0=1.0 +x_0=0.0 +y_0=0.0 +ellps=WGS84
Input file xCell min/max values: -2579104.3263391815 2812394.711808656
Input file yCell min/max values: -2216798.803958245 2309080.616926154
Calculated latCell min/max values (radians): -1.569633803735738 -1.091774649960595
Calculated lonCell min/max values (radians): 1.5131680893138319e-05 6.283152067454557
Lat/lon calculations completed.  File has been written.

I'll make a PR on this.

xylar commented 2 years ago

Sounds good. I guess you will rebase and reopen #458 once #455 goes in?

hollyhan commented 2 years ago

Due to some technical issues, I'm not able to reopen this PR after rebasing the branch to origin/master. Instead, I've opened a new PR on this: https://github.com/MPAS-Dev/MPAS-Tools/pull/459.

matthewhoffman commented 2 years ago

Closed by #459