Skip to content

Use an internal bilinear interpolation instead of scipy for meshDensity and bathymetry#344

Merged
xylar merged 15 commits intoMPAS-Dev:masterfrom
xylar:improve_interp
Sep 4, 2020
Merged

Use an internal bilinear interpolation instead of scipy for meshDensity and bathymetry#344
xylar merged 15 commits intoMPAS-Dev:masterfrom
xylar:improve_interp

Conversation

@xylar
Copy link
Collaborator

@xylar xylar commented Sep 2, 2020

The scipy interpolators are quite slow and inefficient. For bilinear interpolation on a regular grid, it is much more efficient to use numpy.interp in 1D to set up coefficients for doing 2D, bilinear interpolation. A new function mpas_tools.mesh.interpolation.interp_bilin() is added to do this.

xylar added 15 commits August 31, 2020 13:10
Move several tools that are specifically for the ocean to
`mpas_tools.ocean`.

Tools related to defining signed distance functions have been
pulled out of `coastal_tools` and remain in
`mpas_tools.mesh.creation`, since they should be generally useful.

In the function lonlat2xyz, the radius has been added as an
optional parameter, and the Earth radius is now a required
parameter for signed distance functions.
Each function now takes as parameters the results of the function
in define_base_mesh, rather than calling that function.  This is
a much cleaner way to pass in the fields and gives users a lot
more flexibility.

Since bathymetry and floodplain are ocean-specific concepts, the
code for adding them has been moved to mpas_tools.ocean and isn't
appropriate to include in build_spherical_mesh anymore.  So
calling code will need to add these steps after calling
build_shperical_mesh.
Add a warning that build_mesh docs are now completely useless.
This particular meaning of meshDensity is a legacy of the
pre-JIGSAW method for mesh generation and is only used in the
ocean core.
This saves us from having to know the name of the output file
in cases where we don't need to write out and read back the
mesh density.
These add meshDensity and optionally add bathymetry and preserve
floodplain
It is not very safe to use a non-integer step in arange because
round-off causes trouble.  Also, in this case you want to include
the end point in the arange and this was not happening with the
previous code.
@xylar
Copy link
Collaborator Author

xylar commented Sep 2, 2020

This work is based off of #314 and #343.

@xylar
Copy link
Collaborator Author

xylar commented Sep 2, 2020

Testing

I tested this with the coastal/USDEQU120cr10rr2/build_mesh/ test case and the resulting meshDensity field looks similar to what was obtained previously. I need to do a proper diff and make sure changes are at machine roundoff for both meshDensity and bathymetry.

Interpolation is significantly faster with the new routine. I didn't time the difference but it is noticeable.

@xylar xylar merged commit bfd3f9f into MPAS-Dev:master Sep 4, 2020
@xylar xylar deleted the improve_interp branch September 4, 2020 05:50
@xylar
Copy link
Collaborator Author

xylar commented Sep 4, 2020

Implicitly approved by @mark-petersen and @sbrus89 via MPAS-Dev/MPAS-Model#680

mark-petersen added a commit to MPAS-Dev/MPAS-Model that referenced this pull request Sep 9, 2020
Update to version 0.1.11 of the compass environment #688

This brings in several changes from MPAS-Tools:

* Changes to make sure the Earth radius is consistent throughout COMPASS
  and `mpas_tools.ocean` by using the CIME value
  (MPAS-Dev/MPAS-Tools#347 and
  MPAS-Dev/MPAS-Tools#341)

* Improved performance for interpolation of meshDensity and bathymetry
  (MPAS-Dev/MPAS-Tools#344)

* Reorganization of `mpas_tools.mesh.creation`
  (MPAS-Dev/MPAS-Tools#314)
xylar pushed a commit to xylar/old_compass2 that referenced this pull request Oct 12, 2020
Update to version 0.1.11 of the compass environment #688

This brings in several changes from MPAS-Tools:

* Changes to make sure the Earth radius is consistent throughout COMPASS
  and `mpas_tools.ocean` by using the CIME value
  (MPAS-Dev/MPAS-Tools#347 and
  MPAS-Dev/MPAS-Tools#341)

* Improved performance for interpolation of meshDensity and bathymetry
  (MPAS-Dev/MPAS-Tools#344)

* Reorganization of `mpas_tools.mesh.creation`
  (MPAS-Dev/MPAS-Tools#314)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant