-
Notifications
You must be signed in to change notification settings - Fork 69
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
Add function to create a layer of prisms #186
Conversation
I suspect that ETOPO1 is referenced on the geoid (need to check), so we might want to add the geoid height (from the reference ellipsoid) to the topography + bathymetry grid before creating the terrain layer. |
@lperozzi Would you like to review this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add another points that I've remarked today. If the aim is to extract the topographic correction for the observations stations from the prisms gravity forward, we should be careful with the bord effects.
plt.colorbar(tmp, label="mGal") | ||
ax.set_aspect("equal") | ||
plt.tight_layout() | ||
plt.show() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not have any specifical comments. The code is clear and easy to read, however I have a question.
Starting form a land survey, it is also possible to compute the prisms['top']
by gridding the elevation data, using verde
for example? Instead to have a DEM or topographic grid for the region?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! You'll probably want to apply some gridding or downsampling to your topographic grid in order to build the prisms: there's no point to use a very high resolution DEM to apply terrain correction, while if you have some topographic height measurements and low resolution DEM you can combine them using a gridder. But those tasks should be carried out by the user.
Thanks for the feedback @lperozzi!
Nice! Can't wait to see them! |
I totally agree, maybe we should change the gallery example so it takes a larger region than the survey area for building the prisms. Thanks for noticing it! |
Would be nice to use the new |
@leouieda I'm trying to finish this PR. I think it's almost ready, but I'm using the prisms_layer feature for the Transform21 tutorial and I found that it can create some problems when the I decided to be conservative and raise and error if any nan is present on Another option is to have a What do you think? |
This reverts commit be344ca.
The method builds the list of prism boundaries and ignores the ones that has nans on their top or bottom boundaries before passing them into the prism_gravity() function. The density of the prisms is caught from the "density" data_var present in the xarray.Dataset by default.
We decided to allow |
Had to disable the proteceted-access on the entire test_prisms_layer.py file, otherwise pylint will keep complaining about it, even if I disable it function wise or even line wise.
harmonica/forward/prisms_layer.py
Outdated
nonans_bottom = np.logical_not(np.isnan(self._obj.bottom.values)) | ||
return np.logical_and(nonans_top, nonans_bottom) | ||
|
||
def get_prisms(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def get_prisms(self): | |
def to_prisms(self): |
This fits better with the rest of the xarray methods: http://xarray.pydata.org/en/stable/pandas.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could keep this private for now and provide it after if desired.
harmonica/forward/prisms_layer.py
Outdated
# have no nans on their top and bottom | ||
nonans_boundaries = self._get_nonans_prisms_mask().ravel() | ||
# Get density array | ||
density = getattr(self._obj, density_name).values.ravel() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
density = getattr(self._obj, density_name).values.ravel() | |
density = self._obj[density_name].values.ravel() |
Works for density names that aren't valid Python variable names.
Write a private method that returns a mask for every prism whose top boundary, bottom boundary or density is nan. Raise a warning if the density array has a nan where neither the top or bottom is nan. Rename the get_prisms() method to _to_prisms() and make it private. Update and improve the tests.
Run the check when defining the prism layer and when computing the spacing of the layer.
I think this is ready to go. I'll merge it even the CIs are failing: the docs build is failing because it can't download the new South Africa topography dataset. If |
Add function that creates a layer of prisms as a
xr.Dataset
which containsthe coordinates of the center of each prism, its top and bottom boundaries (as
xarray coordinates) and each property (as density, magnetization, etc) as data
array. Add
PrismsLayer
class as a dataset accesorfor
xr.Dataset
s, which allows to define several attributes, properties andmethods for the prism layer, which can be accessed through the
prisms_layer
attribute of the
xr.Dataset
. Add agravity
method that computesgravitational fields generated by every prism in the layer whose top boundary,
bottom boundary or density are not
np.nan
s.Add two gallery examples for the prisms layer, and a new South Africa
topography dataset, which is a downsample of ETOPO1.
This PR may serve as a prototype for solving #83, but for prisms. The one for tesseroids could be equivalent to this one, but with some minor checks due to longitude continuity.
Reminders:
make format
andmake check
to make sure the code follows the style guide.doc/api/index.rst
and the base__init__.py
file for the package.AUTHORS.md
file (if you haven't already) in case you'd like to be listed as an author on the Zenodo archive of the next release.