-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from xylar/add-mpas-vertex-mesh-descriptor
Add `MpasCellMeshDescriptor` and `MpasVertexMeshDescriptor`
- Loading branch information
Showing
18 changed files
with
580 additions
and
340 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/env python | ||
# This software is open source software available under the BSD-3 license. | ||
# | ||
# Copyright (c) 2019 Triad National Security, LLC. All rights reserved. | ||
# Copyright (c) 2019 Lawrence Livermore National Security, LLC. All rights | ||
# reserved. | ||
# Copyright (c) 2019 UT-Battelle, LLC. All rights reserved. | ||
# | ||
# Additional copyright and license information can be found in the LICENSE file | ||
# distributed with this code, or at | ||
# https://raw.githubusercontent.com/MPAS-Dev/pyremap/main/LICENSE | ||
|
||
""" | ||
Creates a mapping file that can be used with ncremap (NCO) to remap MPAS files | ||
to a latitude/longitude grid. | ||
Usage: Copy this script into the main MPAS-Analysis directory (up one level). | ||
Modify the grid name, the path to the MPAS grid file and the output grid | ||
resolution. | ||
""" | ||
|
||
import numpy as np | ||
import xarray as xr | ||
|
||
from pyremap import MpasVertexMeshDescriptor, Remapper, get_polar_descriptor | ||
|
||
|
||
# replace with the MPAS mesh name | ||
inGridName = 'oQU240' | ||
|
||
# replace with the path to the desired mesh or restart file | ||
# As an example, use: | ||
# https://web.lcrc.anl.gov/public/e3sm/inputdata/ocn/mpas-o/oQU240/ocean.QU.240km.151209.nc | ||
inGridFileName = 'ocean.QU.240km.151209.nc' | ||
|
||
inDescriptor = MpasVertexMeshDescriptor(inGridFileName, inGridName) | ||
|
||
# modify the size and resolution of the Antarctic grid as desired | ||
outDescriptor = get_polar_descriptor(Lx=6000., Ly=5000., dx=10., dy=10., | ||
projection='antarctic') | ||
outGridName = outDescriptor.meshName | ||
|
||
mappingFileName = f'map_{inGridName}_vertex_to_{outGridName}_conserve.nc' | ||
|
||
remapper = Remapper(inDescriptor, outDescriptor, mappingFileName) | ||
|
||
# conservative remapping with 4 MPI tasks (using mpirun) | ||
remapper.build_mapping_file(method='conserve', mpiTasks=4, | ||
esmf_parallel_exec='mpirun', include_logs=True) | ||
|
||
# select the SST at the initial time as an example data set | ||
srcFileName = f'vertex_id_{inGridName}.nc' | ||
ds = xr.open_dataset(inGridFileName) | ||
dsOut = xr.Dataset() | ||
dsOut['indexToVertexID'] = ds['indexToVertexID'].astype(float) | ||
dsOut['random'] = ('nVertices', np.random.random(ds.sizes['nVertices'])) | ||
dsOut.to_netcdf(srcFileName) | ||
|
||
# do remapping with ncremap | ||
outFileName = f'vertex_id_{outGridName}_file.nc' | ||
remapper.remap_file(srcFileName, outFileName) | ||
|
||
# do remapping again, this time with python remapping | ||
outFileName = f'vertex_id_{outGridName}_array.nc' | ||
dsOut = remapper.remap(dsOut) | ||
dsOut.to_netcdf(outFileName) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
from pyremap.descriptor import ( | ||
LatLon2DGridDescriptor, | ||
LatLonGridDescriptor, | ||
MpasCellMeshDescriptor, | ||
MpasEdgeMeshDescriptor, | ||
MpasMeshDescriptor, | ||
MpasVertexMeshDescriptor, | ||
PointCollectionDescriptor, | ||
ProjectionGridDescriptor, | ||
get_lat_lon_descriptor, | ||
) | ||
from pyremap.polar import get_polar_descriptor, get_polar_descriptor_from_file | ||
from pyremap.remapper import Remapper | ||
|
||
__version_info__ = (1, 0, 1) | ||
__version_info__ = (1, 1, 0) | ||
__version__ = '.'.join(str(vi) for vi in __version_info__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.