Skip to content

Commit 03b4db3

Browse files
committed
Handle missing thickness to prevent infinite volumes.
With new solver setting, depth is not written on the first timestep if using a restat. This previously was treated as zero depth, resulting in infinite volumes. Now use backfilling of first non-zero volume to before relaitve volume is calculated inorder to avoid infs/nans
1 parent ba35983 commit 03b4db3

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

src/thermal/thermal/open.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
# dictionary of 1D variables and vertical index they are define along
77
vars_1D = { "mass balance" : -1,
8-
"surface_enthalpy" : -1,
9-
"surf_melt": -1,
8+
"surface_enthalpy" : -1,
9+
"surf_melt": -1,
1010
"runoff_frac": -1,
1111
"friction heating": 0}
1212

@@ -92,18 +92,31 @@ def __preprocess(ds, h_min=10.0):
9292
# calculate velocity magnitude from velocity components
9393
ds['vel_m'] = calc_magnitude(ds['vel_x'], ds['vel_z'])
9494

95-
# only compute the percent temperate for coupled runs,
95+
# only compute the percent temperate for coupled runs,
9696
# i.e. skip for isothermal results
97-
if 'enthalpy_h' in ds:
97+
if 'enthalpy_h' in ds:
9898
# calcute the percent temperate
9999
ds['percent_temperate'] = calc_percent_temperate(ds)
100100

101101
# calcute the glacier volume as a function of time
102102
volume = calc_volume(ds)
103+
104+
# Sometimes when using a restart, the first timestep might not write
105+
# dynamic data. This will cause inf volumes, so if initial volume is zero
106+
# get data from second (dynamic) timestep.
107+
initial_volume = float(volume.isel(t=0))
108+
if initial_volume == 0.0:
109+
first_nonzero_idx = int((volume != 0).argmax('t'))
110+
# set the inital volume to be the first non-zero value
111+
initial_volume = float(volume.isel(t=first_nonzero_idx))
112+
# back fill the zero volumes based on first non-zero value
113+
volume.loc[dict(t=slice(0, first_nonzero_idx))] = initial_volume
114+
103115
# write the initial volume in m^2
104-
ds['initial_volume'] = volume.isel(t=0)
105-
# write the time dependent "relative volume"
106-
ds['relative_volume'] = volume / volume.isel(t=0)
116+
ds['initial_volume'] = initial_volume
117+
# write the time dependent "relative volume". If first timeslice is zero,
118+
# set to nan to prevent plotting from being messed up.
119+
ds['relative_volume'] = volume / initial_volume
107120

108121
return ds
109122

0 commit comments

Comments
 (0)