Skip to content

Commit 01c7677

Browse files
committed
Interpolate BedMachine v5 and MEaSUREs data onto Humboldt mesh.
Interpolate BedMachine v5 and MEaSUREs data onto Humboldt mesh, following the workflow in the landice/greenland/mesh_gen case.
1 parent 7333744 commit 01c7677

File tree

2 files changed

+88
-6
lines changed

2 files changed

+88
-6
lines changed

compass/landice/tests/humboldt/mesh.py

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
from compass.landice.mesh import build_cell_width, build_mali_mesh
1+
import os
2+
3+
import numpy as np
4+
import xarray as xr
5+
from mpas_tools.scrip.from_mpas import scrip_from_mpas
6+
7+
from compass.landice.mesh import (
8+
build_cell_width,
9+
build_mali_mesh,
10+
clean_up_after_interp,
11+
interp_gridded2mali,
12+
)
213
from compass.model import make_graph_file
314
from compass.step import Step
415

@@ -27,8 +38,9 @@ def __init__(self, test_case):
2738
super().__init__(test_case=test_case, name='mesh', cpus_per_task=128,
2839
min_cpus_per_task=1)
2940

41+
self.mesh_filename = 'Humboldt.nc'
3042
self.add_output_file(filename='graph.info')
31-
self.add_output_file(filename='Humboldt.nc')
43+
self.add_output_file(filename=self.mesh_filename)
3244
self.add_input_file(
3345
filename='humboldt_1km_2024_01_29.epsg3413.icesheetonly.nc',
3446
target='humboldt_1km_2024_01_29.epsg3413.icesheetonly.nc',
@@ -49,21 +61,71 @@ def run(self):
4961
"""
5062
logger = self.logger
5163
section_name = 'mesh'
52-
mesh_name = 'Humboldt.nc'
64+
section_gis = self.config['greenland']
65+
66+
nProcs = section_gis.get('nProcs')
67+
src_proj = section_gis.get("src_proj")
68+
data_path = section_gis.get('data_path')
69+
measures_filename = section_gis.get("measures_filename")
70+
bedmachine_filename = section_gis.get("bedmachine_filename")
71+
72+
measures_dataset = os.path.join(data_path, measures_filename)
73+
bedmachine_dataset = os.path.join(data_path, bedmachine_filename)
5374

5475
logger.info('calling build_cell_width')
5576
cell_width, x1, y1, geom_points, geom_edges, floodMask = \
5677
build_cell_width(
5778
self, section_name=section_name,
58-
gridded_dataset='greenland_2km_2024_01_29.epsg3413.nc')
79+
gridded_dataset='greenland_2km_2024_01_29.epsg3413.nc',
80+
flood_fill_start=[100, 700])
5981

6082
build_mali_mesh(
6183
self, cell_width, x1, y1, geom_points, geom_edges,
62-
mesh_name=mesh_name, section_name=section_name,
84+
mesh_name=self.mesh_filename, section_name=section_name,
6385
gridded_dataset='humboldt_1km_2024_01_29.epsg3413.icesheetonly.nc',
6486
projection='gis-gimp', geojson_file='Humboldt.geojson',
6587
cores=self.cpus_per_task)
6688

89+
# Create scrip file for the newly generated mesh
90+
logger.info('creating scrip file for destination mesh')
91+
dst_scrip_file = f"{self.mesh_filename.split('.')[:-1][0]}_scrip.nc"
92+
scrip_from_mpas(self.mesh_filename, dst_scrip_file)
93+
94+
# Now perform bespoke interpolation of geometry and velocity data
95+
# from their respective sources
96+
interp_gridded2mali(self, bedmachine_dataset, dst_scrip_file, nProcs,
97+
self.mesh_filename, src_proj, variables="all")
98+
99+
# only interpolate a subset of MEaSUREs variables onto the MALI mesh
100+
measures_vars = ['observedSurfaceVelocityX',
101+
'observedSurfaceVelocityY',
102+
'observedSurfaceVelocityUncertainty']
103+
interp_gridded2mali(self, measures_dataset, dst_scrip_file, nProcs,
104+
self.mesh_filename, src_proj,
105+
variables=measures_vars)
106+
107+
# perform some final cleanup details
108+
clean_up_after_interp(self.mesh_filename)
67109
logger.info('creating graph.info')
68-
make_graph_file(mesh_filename=mesh_name,
110+
make_graph_file(mesh_filename=self.mesh_filename,
69111
graph_filename='graph.info')
112+
113+
# Do some final validation of the mesh
114+
ds = xr.open_dataset(self.mesh_filename)
115+
# Ensure basalHeatFlux is positive
116+
ds["basalHeatFlux"] = np.abs(ds.basalHeatFlux)
117+
# Ensure reasonable dHdt values
118+
dHdt = ds["observedThicknessTendency"]
119+
# Arbitrary 5% uncertainty; improve this later
120+
dHdtErr = np.abs(dHdt) * 0.05
121+
# Use threshold of |dHdt| > 1.0 to determine invalid data
122+
mask = np.abs(dHdt) > 1.0
123+
# Assign very large uncertainty where data is missing
124+
dHdtErr = dHdtErr.where(~mask, 1.0)
125+
# Remove ridiculous values
126+
dHdt = dHdt.where(~mask, 0.0)
127+
# Put the updated fields back in the dataset
128+
ds["observedThicknessTendency"] = dHdt
129+
ds["observedThicknessTendencyUncertainty"] = dHdtErr
130+
# Write the data to disk
131+
ds.to_netcdf(self.mesh_filename, 'a')

compass/landice/tests/humboldt/mesh_gen/mesh_gen.cfg

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,23 @@ use_speed = True
4242
use_dist_to_grounding_line = False
4343
use_dist_to_edge = True
4444
use_bed = True
45+
46+
[greenland]
47+
# path to directory containing BedMachine and Measures datasets
48+
# (default value is for Perlmutter)
49+
data_path = /global/cfs/cdirs/fanssie/standard_datasets/GIS_datasets/
50+
51+
# filename of the BedMachine thickness and bedTopography dataset
52+
# (default value is for Perlmutter)
53+
bedmachine_filename = BedMachineGreenland-v5_edits_floodFill_extrap.nc
54+
55+
# filename of the MEaSUREs ice velocity dataset
56+
# (default value is for Perlmutter)
57+
measures_filename = greenland_vel_mosaic500_extrap.nc
58+
59+
# projection of the source datasets, according to the dictionary keys
60+
# create_SCRIP_file_from_planar_rectangular_grid.py from MPAS_Tools
61+
src_proj = gis-gimp
62+
63+
# number of processors to use for ESMF_RegridWeightGen
64+
nProcs = 128

0 commit comments

Comments
 (0)