Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

euler_pole: add PMM plotting functions #935

Merged
merged 24 commits into from
Jan 15, 2023

Conversation

yuankailiu
Copy link
Contributor

@yuankailiu yuankailiu commented Dec 23, 2022

  • add plate boundary files from GSRMv2.1 and MORVEL56

  • functions to read the boundary files and plot

Check here for the usage: https://github.com/yuankailiu/utils/blob/main/notebooks/PMM_plot.ipynb

Description of proposed changes

Reminders

  • Pass Pre-commit check (green)
  • Pass Codacy code review (green)
  • Pass Circle CI test (green)
  • Make sure that your code follows our style. Use the other functions/files as a basis.
  • If modifying functionality, describe changes to function behavior and arguments in a comment below the function declaration.
  • If adding new functionality, add a detailed description to the documentation and/or an example.

+ add plate boundary files from GSRMv2.1 and MORVEL56

+ functions to read the boundary files and plot
+ Consistent NNR model file:
	- src/mintpy/data/plate_boundary/GSRMv2.1/nnr.csv
	- src/mintpy/data/plate_boundary/MRVL56/nnr.csv
	- use camelCase plate names (but caplitalize the first character)

+ Consistent plate boundary file:
	- src/mintpy/data/plate_boundary/GSRMv2.1/plate_outlines.txt
	- src/mintpy/data/plate_boundary/MRVL56/plate_outlines.txt
	- use '> ' before plate abbv. names, good for GMT
	- use longitude, latitude for the columns, good for GMT

+ remove useless script: src/mintpy/data/plate_boundary/GSRMv2.1/split_bnds.py

+ update full reference in README.md under src/mintpy/data/plate_boundary/

+ euler_pole.py: update read_plate_attributes() read_plate_outlines()
@yuankailiu
Copy link
Contributor Author

Checks seem to fail at testing /root/tools/MintPy/tests/objects/ionex.py

But I did not change this file.

attempt to fix the unit test error below:

```
Testing /root/tools/MintPy/tests/objects/ionex.py
Traceback (most recent call last):
  File "/root/tools/MintPy/tests/objects/ionex.py", line 110, in <module>
    test_get_ionex_value()
  File "/root/tools/MintPy/tests/objects/ionex.py", line 93, in test_get_ionex_value
    tec_val = ionex.get_ionex_value(
  File "/root/tools/miniconda3/lib/python3.10/site-packages/mintpy/objects/ionex.py", line 102, in get_ionex_value
    tec_val = interp_3d_maps(
  File "/root/tools/miniconda3/lib/python3.10/site-packages/mintpy/objects/ionex.py", line 184, in interp_3d_maps
    tec_val = interpolate.interpn(
  File "/root/tools/miniconda3/lib/python3.10/site-packages/scipy/interpolate/_rgi.py", line 654, in interpn
    return interp(xi)
  File "/root/tools/miniconda3/lib/python3.10/site-packages/scipy/interpolate/_rgi.py", line 331, in __call__
    indices, norm_distances = self._find_indices(xi.T)
  File "/root/tools/miniconda3/lib/python3.10/site-packages/scipy/interpolate/_rgi.py", line 499, in _find_indices
    return find_indices(self.grid, xi)
  File "_rgi_cython.pyx", line 95, in scipy.interpolate._rgi_cython.find_indices
  File "stringsource", line 660, in View.MemoryView.memoryview_cwrapper
  File "stringsource", line 350, in View.MemoryView.memoryview.__cinit__
ValueError: ndarray is not C-contiguous
```
@yunjunz
Copy link
Member

yunjunz commented Jan 7, 2023

Checks seem to fail at testing /root/tools/MintPy/tests/objects/ionex.py

But I did not change this file.

The same test works well locally on my laptop, and I could not find out the reason on circle CI. As you said, this PR did not touch this part of the code, let's ignore this error.

Update: this is a bug in scipy (scipy/scipy#17717) affecting its interpolate sub-module. Hopefully the next patch release of scipy will include the fix and we don't need to do anything on our side except for waiting.

@yunjunz
Copy link
Member

yunjunz commented Jan 7, 2023

For the NNR PMM value/tables, maybe it's easier to use if we write them in Python, similar to what we have for ITRM2014-PMM, instead of a data file, which requires extra reading?

If so, we could move these variable definitions from mintpy.cli.plate_motion into mintpy.plate_motion, for easier usage.

Update: I am done with changes on my side for this round of PR review. Please feel free to pull the changes and work on them.

@yuankailiu
Copy link
Contributor Author

yuankailiu commented Jan 9, 2023

For the NNR PMM value/tables, maybe it's easier to use if we write them in Python, similar to what we have for ITRM2014-PMM, instead of a data file, which requires extra reading?

If so, we could move these variable definitions from mintpy.cli.plate_motion into mintpy.plate_motion, for easier usage.

Yes, I can do that. Now those files have different units compared with our ITRF2014 dictionary.
The files are in the format of Lat, Lon, and the rotation rate in degrees per Ma.
I can just create dictionaries for them without converting the units. Anyway, these parameters are not supposed to be used in computing the plate motion.

These files still exist just because I need the abbreviated names for the plate polygons.

+ read GSRM and MORVEL56 model parameters (abbrev) from built-in dictionary

+ GSRM and MORVEL56 PMM files (csv) are not in used, but keep them for bookkeeping

+ folder names hosting plate boundaries are modified

+ use original file names for plate boundaries files (consistent with the source)
@yuankailiu
Copy link
Contributor Author

Please take a look at the new updates.

If so, we could move these variable definitions from mintpy.cli.plate_motion into mintpy.plate_motion, for easier usage.

But I don't see why we will need to put those dict() in mintpy.plate_motion? Also where should we put the PLATE_BOUNDARY_FILE ? Right now, it is under the euler_pole.py.

yuankailiu and others added 8 commits January 9, 2023 21:12
refer to: https://github.com/insarlab/MintPy/wiki/plate-motion-package

+ euler_pole.py: put pmm definitions here, plate abbv are upper case

+ cli/plate_motion.py: remove pmm definitions

+ plate_boundary/*/nnr.csv: delete them

+ to-do: move --plate to --om-cart from mintpy.cli.plate_motion to mintpy.plate_motion
src/mintpy/cli/plate_motion.py will not need this dictionary
from mintpy.objects.euler_pole import ITRF2014_PMM
+ use `MORVEL` instead of `MORVEL56` for the folder name, as it's generic for MORVEL and NNR-MORVEL56, to be consistent of using GSRM, instead of GSRMv2.1

+ rename both data files as `plate_outlines.gmt` with shell commands in the README for easy produce

+ euler_pole:
   - update data file path from above changes
   - use `GSRM_V21_PMM` and `NNR_MORVEL56_PMM` for more precise info
Comment on lines 558 to 561
elif 'MORVEL' in pmm_name:
pmm_name = 'MORVEL'
pmm_dict = NNR_MORVEL56_PMM
coord_order = 'lalo'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This place should be 'lola' as well.

Because I also flip the order in the file from the original All_boundary in MORVEL_56.

So we can just set the default as coord_order='lola' and keep the file as it is (and it also makes sense since it has .gmt extension.).

But this way, we no longer keep the original downloaded file untouched. But anyway, I already added those > signs in the file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discussed offline:

  • let's keep the original downloaded file content untouched, for reproducibility.
  • use .lonlat and .latlon as file extensions, instead of .gmt, to be more informative.
  • update the data/plate_boundary/README.md file to be consistent with the above changes.

+ use center_lalo to replace center_lat/lon
+ use satellite_height directly, instead of zoom
+ map center priority: direct input arg > pts_lalo > polygon centroid
+ remove vu as it's not used
Copy link
Member

@yunjunz yunjunz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @yuankailiu for the nice PR. I went through everything and am able to produce a nice plot as below. All looks good to me, pending the above comments as we discussed offline.

from matplotlib import pyplot as plt
from mintpy.objects import euler_pole
from shapely import geometry

plate_pmm = euler_pole.ITRF2014_PMM['Arabia']
epole_obj = euler_pole.EulerPole(wx=plate_pmm.omega_x, wy=plate_pmm.omega_y, wz=plate_pmm.omega_z, unit='mas/yr')

plate_boundary = geometry.Polygon(euler_pole.read_plate_outline('GSRM')['Arabia'])

fig, ax = euler_pole.plot_plate_motion(plate_boundary, epole_obj)
plt.show()

image

+ use the original downloaded files

+ extensions as .lalo or .lola

+ modify euler_pole.py accordingly
@yuankailiu
Copy link
Contributor Author

Thanks @yunjunz for testing. I finish my changes for this PR as we discussed.

By the way, now you can do the following to read the dictionary in your notebook:

plate_boundary = geometry.Polygon(euler_pole.read_plate_outline('GSRM', 'Arabia'))

@yunjunz
Copy link
Member

yunjunz commented Jan 15, 2023

Thank you @yuankailiu for the changes. Built on top of yours, the commit above further simplify the read_plate_outline() call as below. Everything looks good to me now! Merged it when you got a chance please.

plate_boundary = euler_pole.read_plate_outline('GSRM', 'Arabia')

@yunjunz yunjunz changed the title euler_pole.py: add PMM plotting functions euler_pole: add PMM plotting functions Jan 15, 2023
@yuankailiu yuankailiu merged commit ce1aed0 into insarlab:main Jan 15, 2023
@yuankailiu yuankailiu deleted the dev.pmm_plot branch January 15, 2023 23:55
yunjunz added a commit to yunjunz/MintPy that referenced this pull request Aug 9, 2023
+ dependency: add shapely to requirements.txt and setup.py file, as it's used in `objects.euler_pole.py` to plot plate motion since insarlab#935. Note that shapely is the dependency for cartopy already, so this won't really affect the mintpy installation.
yunjunz added a commit to yunjunz/MintPy that referenced this pull request Aug 10, 2023
+ dependency: add shapely to requirements.txt and setup.py file, as it's used in `objects.euler_pole.py` to plot plate motion since insarlab#935. Note that shapely is the dependency for cartopy already, so this won't really affect the mintpy installation.

+ docs/installation/argcomplete: replace conda with brew for bash installation, so that the bash is independent from the conda directory, which can removed more easily/frequently than /usr/local directory from brew.
@yunjunz yunjunz mentioned this pull request Aug 10, 2023
4 tasks
yunjunz added a commit that referenced this pull request Aug 10, 2023
+ `dependency`: add `shapely` to `requirements.txt` and `setup.py` file, as it's used in `objects.euler_pole.py` to plot plate motion since #935. Note that 1) shapely is already a dependency for cartopy, so this won't really affect the mintpy installation; 2) shapely has been added explicitly to the dependency on conda-forge for mintpy (conda-forge/mintpy-feedstock#10)

+ `docs/installation/argcomplete`: replace `conda` with `brew` for bash installation, so that the bash is independent of the conda directory, which can be removed more easily/frequently than `/usr/local directory` from brew.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants