|
5 | 5 |
|
6 | 6 | # dictionary of 1D variables and vertical index they are define along |
7 | 7 | vars_1D = { "mass balance" : -1, |
8 | | - "surface_enthalpy" : -1, |
9 | | - "surf_melt": -1, |
| 8 | + "surface_enthalpy" : -1, |
| 9 | + "surf_melt": -1, |
10 | 10 | "runoff_frac": -1, |
11 | 11 | "friction heating": 0} |
12 | 12 |
|
@@ -92,18 +92,31 @@ def __preprocess(ds, h_min=10.0): |
92 | 92 | # calculate velocity magnitude from velocity components |
93 | 93 | ds['vel_m'] = calc_magnitude(ds['vel_x'], ds['vel_z']) |
94 | 94 |
|
95 | | - # only compute the percent temperate for coupled runs, |
| 95 | + # only compute the percent temperate for coupled runs, |
96 | 96 | # i.e. skip for isothermal results |
97 | | - if 'enthalpy_h' in ds: |
| 97 | + if 'enthalpy_h' in ds: |
98 | 98 | # calcute the percent temperate |
99 | 99 | ds['percent_temperate'] = calc_percent_temperate(ds) |
100 | 100 |
|
101 | 101 | # calcute the glacier volume as a function of time |
102 | 102 | 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 | + |
103 | 115 | # 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 |
107 | 120 |
|
108 | 121 | return ds |
109 | 122 |
|
|
0 commit comments