Skip to content

Commit

Permalink
Clean up unified interpolation method and use in antarctic testcase.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewdnolan committed May 16, 2024
1 parent 5906d0e commit 852cf7b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 72 deletions.
60 changes: 0 additions & 60 deletions compass/landice/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -1097,66 +1097,6 @@ def __guess_scrip_name(filename):
# conflicts when multiple interpolations are done?


def interp_ais_measures(self, data_path, mali_scrip, nProcs, dest_file):
"""
Interpolates MEASURES ice velocity dataset
to a MALI mesh
Parameters
----------
data_path : str
path to AIS datasets, including BedMachine
mali_scrip : str
name of scrip file corresponding to destination MALI mesh
nProcs : int
number of processors to use for generating remapping weights
dest_file: str
MALI input file to which data should be remapped
"""

logger = self.logger

logger.info('creating scrip file for velocity dataset')
# Note: writing scrip file to workdir
args = ['create_SCRIP_file_from_planar_rectangular_grid.py',
'-i',
os.path.join(data_path,
'antarctica_ice_velocity_450m_v2_edits_extrap.nc'),
'-s',
'antarctica_ice_velocity_450m_v2.scrip.nc',
'-p', 'ais-bedmap2',
'-r', '2']
check_call(args, logger=logger)

# Generate remapping weights
logger.info('generating gridded dataset -> MPAS weights')
args = ['srun', '-n', nProcs, 'ESMF_RegridWeightGen',
'--source',
'antarctica_ice_velocity_450m_v2.scrip.nc',
'--destination', mali_scrip,
'--weight', 'measures_to_MPAS_weights.nc',
'--method', 'conserve',
"--netcdf4",
"--dst_regional", "--src_regional", '--ignore_unmapped']
check_call(args, logger=logger)

logger.info('calling interpolate_to_mpasli_grid.py')
args = ['interpolate_to_mpasli_grid.py',
'-s',
os.path.join(data_path,
'antarctica_ice_velocity_450m_v2_edits_extrap.nc'),
'-d', dest_file,
'-m', 'e',
'-w', 'measures_to_MPAS_weights.nc',
'-v', 'observedSurfaceVelocityX',
'observedSurfaceVelocityY',
'observedSurfaceVelocityUncertainty']
check_call(args, logger=logger)


def clean_up_after_interp(fname):
"""
Perform some final clean up steps after interpolation
Expand Down
36 changes: 24 additions & 12 deletions compass/landice/tests/antarctica/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
build_cell_width,
build_mali_mesh,
clean_up_after_interp,
interp_ais_bedmachine,
interp_ais_measures,
interp_gridded2mali,
make_region_masks,
preprocess_ais_data,
)
Expand Down Expand Up @@ -61,19 +60,26 @@ def run(self):
"""
logger = self.logger
config = self.config

section_ais = config['antarctica']
data_path = section_ais.get('data_path')

nProcs = section_ais.get('nProcs')
src_proj = section_ais.get("src_proj")
data_path = section_ais.get('data_path')
measures_filename = section_ais.get("measures_filename")
bedmachine_filename = section_ais.get("bedmachine_filename")

measures_dataset = os.path.join(data_path, measures_filename)
bedmachine_dataset = os.path.join(data_path, bedmachine_filename)

section_name = 'mesh'

# do we want to add this to the config file?
source_gridded_dataset = 'antarctica_8km_2024_01_29.nc'
bedmachine_path = os.path.join(
data_path,
'BedMachineAntarctica_2020-07-15_v02_edits_floodFill_extrap_fillVostok.nc') # noqa

bm_updated_gridded_dataset = add_bedmachine_thk_to_ais_gridded_data(
self, source_gridded_dataset, bedmachine_path)
self, source_gridded_dataset, bedmachine_dataset)

logger.info('calling build_cell_width')
cell_width, x1, y1, geom_points, geom_edges, floodFillMask = \
build_cell_width(
Expand All @@ -91,7 +97,7 @@ def run(self):
self, cell_width, x1, y1, geom_points, geom_edges,
mesh_name=self.mesh_filename, section_name=section_name,
gridded_dataset=bm_updated_gridded_dataset,
projection='ais-bedmap2', geojson_file=None)
projection=src_proj, geojson_file=None)

# Now that we have base mesh with standard interpolation
# perform advanced interpolation for specific fields
Expand Down Expand Up @@ -131,10 +137,16 @@ def run(self):

# Now perform bespoke interpolation of geometry and velocity data
# from their respective sources
interp_ais_bedmachine(self, data_path, dst_scrip_file, nProcs,
self.mesh_filename)
interp_ais_measures(self, data_path, dst_scrip_file, nProcs,
self.mesh_filename)
interp_gridded2mali(self, bedmachine_dataset, dst_scrip_file, nProcs,
self.mesh_filename, src_proj, variables="all")

# only interpolate a subset of MEASURES varibles onto the MALI mesh
measures_vars = ['observedSurfaceVelocityX',
'observedSurfaceVelocityY',
'observedSurfaceVelocityUncertainty']
interp_gridded2mali(self, measures_dataset, dst_scrip_file, nProcs,
self.mesh_filename, src_proj,
variables=measures_vars)

# perform some final cleanup details
clean_up_after_interp(self.mesh_filename)
Expand Down

0 comments on commit 852cf7b

Please sign in to comment.