Skip to content
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

Interpolate BedMachine v5 and MEaSUREs data onto Humboldt mesh #866

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compass/landice/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def set_cell_width(self, section_name, thk, bed=None, vx=None, vy=None,
# that distance.
if dist_to_edge is not None:
mask = np.logical_and(
thk == 0.0, dist_to_edge > (3. * cull_distance))
thk == 0.0, dist_to_edge > (35. * np.abs(cull_distance)))
logger.info('Setting cell_width in outer regions to max_spac '
f'for {mask.sum()} cells')
cell_width[mask] = max_spac
Expand Down
2 changes: 1 addition & 1 deletion compass/landice/tests/humboldt/Humboldt.geojson

Large diffs are not rendered by default.

74 changes: 68 additions & 6 deletions compass/landice/tests/humboldt/mesh.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
from compass.landice.mesh import build_cell_width, build_mali_mesh
import os

import numpy as np
import xarray as xr
from mpas_tools.scrip.from_mpas import scrip_from_mpas

from compass.landice.mesh import (
build_cell_width,
build_mali_mesh,
clean_up_after_interp,
interp_gridded2mali,
)
from compass.model import make_graph_file
from compass.step import Step

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

self.mesh_filename = 'Humboldt.nc'
self.add_output_file(filename='graph.info')
self.add_output_file(filename='Humboldt.nc')
self.add_output_file(filename=self.mesh_filename)
self.add_input_file(
filename='humboldt_1km_2024_01_29.epsg3413.icesheetonly.nc',
target='humboldt_1km_2024_01_29.epsg3413.icesheetonly.nc',
Expand All @@ -49,21 +61,71 @@ def run(self):
"""
logger = self.logger
section_name = 'mesh'
mesh_name = 'Humboldt.nc'
section_gis = self.config['greenland']

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

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

logger.info('calling build_cell_width')
cell_width, x1, y1, geom_points, geom_edges, floodMask = \
build_cell_width(
self, section_name=section_name,
gridded_dataset='greenland_2km_2024_01_29.epsg3413.nc')
gridded_dataset='greenland_2km_2024_01_29.epsg3413.nc',
flood_fill_start=[100, 700])

build_mali_mesh(
self, cell_width, x1, y1, geom_points, geom_edges,
mesh_name=mesh_name, section_name=section_name,
mesh_name=self.mesh_filename, section_name=section_name,
gridded_dataset='humboldt_1km_2024_01_29.epsg3413.icesheetonly.nc',
projection='gis-gimp', geojson_file='Humboldt.geojson',
cores=self.cpus_per_task)

# Create scrip file for the newly generated mesh
logger.info('creating scrip file for destination mesh')
dst_scrip_file = f"{self.mesh_filename.split('.')[:-1][0]}_scrip.nc"
scrip_from_mpas(self.mesh_filename, dst_scrip_file)

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

# only interpolate a subset of MEaSUREs variables 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)
logger.info('creating graph.info')
make_graph_file(mesh_filename=mesh_name,
make_graph_file(mesh_filename=self.mesh_filename,
graph_filename='graph.info')

# Do some final validation of the mesh
ds = xr.open_dataset(self.mesh_filename)
# Ensure basalHeatFlux is positive
ds["basalHeatFlux"] = np.abs(ds.basalHeatFlux)
# Ensure reasonable dHdt values
dHdt = ds["observedThicknessTendency"]
# Arbitrary 5% uncertainty; improve this later
dHdtErr = np.abs(dHdt) * 0.05
# Use threshold of |dHdt| > 1.0 to determine invalid data
mask = np.abs(dHdt) > 1.0
# Assign very large uncertainty where data is missing
dHdtErr = dHdtErr.where(~mask, 1.0)
# Remove ridiculous values
dHdt = dHdt.where(~mask, 0.0)
# Put the updated fields back in the dataset
ds["observedThicknessTendency"] = dHdt
ds["observedThicknessTendencyUncertainty"] = dHdtErr
# Write the data to disk
ds.to_netcdf(self.mesh_filename, 'a')
32 changes: 26 additions & 6 deletions compass/landice/tests/humboldt/mesh_gen/mesh_gen.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ y_max = -860000.
# distance from ice margin to cull (km).
# Set to a value <= 0 if you do not want
# to cull based on distance from margin.
cull_distance = 5.0
cull_distance = -1.0

# mesh density parameters
# minimum cell spacing (meters)
min_spac = 1.e3
# maximum cell spacing (meters)
max_spac = 1.e4
max_spac = 2.5e3
# log10 of max speed (m/yr) for cell spacing
high_log_speed = 2.5
# log10 of min speed (m/yr) for cell spacing
Expand All @@ -29,16 +29,36 @@ high_dist = 1.e5
# distance within which cell spacing = min_spac (meters)
low_dist = 1.e4
# distance at which bed topography has no effect
high_dist_bed = 1.e5
high_dist_bed = 8.e4
# distance within which bed topography has maximum effect
low_dist_bed = 5.e4
low_dist_bed = 7.e4
# Bed elev beneath which cell spacing is minimized
low_bed = 50.0
# Bed elev above which cell spacing is maximized
high_bed = 100.0

# mesh density functions
use_speed = True
use_speed = False
use_dist_to_grounding_line = False
use_dist_to_edge = True
use_dist_to_edge = False
use_bed = True

[greenland]
# path to directory containing BedMachine and Measures datasets
# (default value is for Perlmutter)
data_path = /global/cfs/cdirs/fanssie/standard_datasets/GIS_datasets/

# filename of the BedMachine thickness and bedTopography dataset
# (default value is for Perlmutter)
bedmachine_filename = BedMachineGreenland-v5_edits_floodFill_extrap.nc

# filename of the MEaSUREs ice velocity dataset
# (default value is for Perlmutter)
measures_filename = greenland_vel_mosaic500_extrap.nc

# projection of the source datasets, according to the dictionary keys
# create_SCRIP_file_from_planar_rectangular_grid.py from MPAS_Tools
src_proj = gis-gimp

# number of processors to use for ESMF_RegridWeightGen
nProcs = 128
Loading