-
Notifications
You must be signed in to change notification settings - Fork 12
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 a tool to create transect cell and edge fields with edge sign and distance #7
base: master
Are you sure you want to change the base?
Add a tool to create transect cell and edge fields with edge sign and distance #7
Conversation
…added 2D workflow
This was written by Phillip Wolfram years ago. It may be redundant with other scripts and remapping methods in MPAS-Analysis, but I thought this simple script might be useful.
… fastjmd95 comparisons in watermasses sandbox.ipynb
This code is a slightly modified verison of the transect code from Polaris (which is not available as a conda package).
@alicebarthel, I think this tool will be helpful for the transport plots you're working on. It needs to be used in conjunction with MPAS-Dev/geometric_features#202 so we'll need to discuss special instructions for how to install that verson of geometric_features before it gets released. Here's the gist. Create a new environment with the dependences:
Then, go to the location where you've checked out MPAS-Dev/geometric_features#202
(You'll need to set To run this code, go into the subdirectory:
Then, you will need to find the initial condition you want, e.g.:
and then run:
You could safely run with more processes if you run on a compute node. The resulting fields on cells and edges should be useful masks, distances and edge sign (on edges, of course). |
@xylar: this immediately caught my attention, since I've been doing lots of transects and regional open boundary calculations lately. |
@milenaveneziani, the main added value here is that we needed distance along the transect at each edge where the edge sign is non-zero. I don't think we have a way to compute that anywhere else so that's the added value here. |
The edge mask and edge sign is found with the python version of the mask creator but it's otherwise pretty similar. The distance along the transect is computed first at every place that a transect segment intersects with the edges of an MPAS cell (something we already had for MPAS-Analysis), then those distances are averaged back to cells or edges based on all the segments that cross the cell or the diamond shape associated with an edge. |
def add_distance_field(ds, logger): | ||
""" | ||
Add fields on edges and cells that define the (mean) distance along the | ||
transect for each cell or edge in the transect | ||
""" | ||
|
||
dist_cell = np.zeros(ds.sizes['nCells']) | ||
count_cell = np.zeros(ds.sizes['nCells'], dtype=int) | ||
dist_edge = np.zeros(ds.sizes['nEdges']) | ||
count_edge = np.zeros(ds.sizes['nEdges'], dtype=int) | ||
|
||
logger.info('Adding transect distance fields on cells and edges...') | ||
|
||
for segment in range(ds.sizes['nSegments']): | ||
icell = ds.horizCellIndices.isel(nSegments=segment).values | ||
iedge = ds.horizEdgeIndices.isel(nSegments=segment).values | ||
# the distance for the midpoint of the segment is the mean | ||
# of the distances of the end points | ||
dist = 0.5 * (ds.dNode.isel(nHorizNodes=segment) + | ||
ds.dNode.isel(nHorizNodes=segment + 1)) | ||
dist_cell[icell] += dist | ||
count_cell[icell] += 1 | ||
dist_edge[iedge] += dist | ||
count_edge[iedge] += 1 | ||
|
||
mask = count_cell > 0 | ||
dist_cell[mask] /= count_cell[mask] | ||
dist_cell[np.logical_not(mask)] = np.nan | ||
|
||
mask = count_edge > 0 | ||
dist_edge[mask] /= count_edge[mask] | ||
dist_edge[np.logical_not(mask)] = np.nan | ||
|
||
ds['transectDistanceCell'] = ('nCells', dist_cell) | ||
ds['transectDistanceEdge'] = ('nEdges', dist_edge) | ||
logger.info('Done.') |
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.
To me, this part is the important new addition.
The transect
module is just here because the version in Polaris (which this is a copy of) is cleaner than the version in MPAS-Tools but we don't have a way to use it in QuickViz because Polaris isn't a simple conda package that can be installed from conda-forge.
yes, @milenaveneziani I did a first-order analysis by combining the Antarctic shelf regions and using the openBoundaries script. Ordering the edges by longitude was not completely clean around the peninsula, and I wanted to expand the analysis to plot by distance along the edge. In addition, I had to check that the recombining of regions is continuous across the 2 resolutions (LR and SORRM) I've done analysis over. @xylar offered to develop this transect (PR#202) to have a reference 1000-m circum-Antarctic transect, with the distance calculated using the existing tools. |
Thank you both. This is great. I think the reason why you still need to go through |
@milenaveneziani, yes, we also decided that a feature defining the enclosed region would be useful and I did that in: @alicebarthel and @cbegeman, I made the requested changes to MPAS-Dev/geometric_features#202. I will add a script tomorrow that can be used to cut out a square from a closed-loop transect (centered at a given lat/lon and with a given size). I'm too tired to do that tonight even though I wanted to keep the momentum going... |
75eb688
to
ab0f76d
Compare
Okay, I added the tool for cutting the loop, as promised. The updated instructions to replace the last step in are:
the instructions before that are all the same. You may also want to look at the resulting fields in paraview:
|
@alicebarthel, could you test this out on the meshes you plan to analyze (in particular the LR mesh)? It would be important to know if there are gaps in the transect, following @milenaveneziani's concerns. Even if so, we might be okay with that since these are presumably places where there simply isn't any continental shelf according to the model. |
8cd7b55
to
3e2e687
Compare
See the new README for how to use it.