Skip to content

Commit 8470643

Browse files
committed
Update spinup args
1 parent 449f6fc commit 8470643

File tree

6 files changed

+30
-27
lines changed

6 files changed

+30
-27
lines changed

pygem/bin/run/run_inversion.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,15 @@ def main():
280280
nargs='+',
281281
help='Randoph Glacier Inventory glacier number (can take multiple)',
282282
)
283-
parser.add_argument(
284-
'-rgi_glac_number_fn',
285-
action='store',
286-
type=str,
287-
default=None,
288-
help='Filepath containing list of rgi_glac_number, helpful for running batches on spc',
289-
),
283+
(
284+
parser.add_argument(
285+
'-rgi_glac_number_fn',
286+
action='store',
287+
type=str,
288+
default=None,
289+
help='Filepath containing list of rgi_glac_number, helpful for running batches on spc',
290+
),
291+
)
290292
parser.add_argument(
291293
'-calibrate_regional_glen_a',
292294
type=str2bool,
@@ -298,13 +300,13 @@ def main():
298300
type=float,
299301
default=None,
300302
help="User-selected inversion Glen's creep parameter value",
301-
)
303+
)
302304
parser.add_argument(
303305
'-fs',
304306
type=float,
305307
default=None,
306308
help="User-selected inversion Orleam's sliding factor value",
307-
)
309+
)
308310
parser.add_argument(
309311
'-ncores',
310312
action='store',
@@ -354,7 +356,7 @@ def main():
354356
run,
355357
ncores=args.ncores,
356358
calibrate_regional_glen_a=args.calibrate_regional_glen_a,
357-
glen_a=args.glen_a,
359+
glen_a=args.glen_a,
358360
fs=args.fs,
359361
reset_gdirs=args.reset_gdirs,
360362
debug=args.debug,

pygem/bin/run/run_spinup.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
def run(glacno_list, mb_model_params, debug=False, **kwargs):
3131
# remove None kwargs
3232
kwargs = {k: v for k, v in kwargs.items() if v is not None}
33-
3433
main_glac_rgi = modelsetup.selectglaciersrgitable(glac_no=glacno_list)
3534
# model dates
36-
dt = modelsetup.datesmodelrun(startyear=1979, endyear=2019)
35+
dt = modelsetup.datesmodelrun(startyear=2000 - kwargs.get('spinup_period', 20), endyear=kwargs.get('ye', 2020))
36+
3737
# load climate data
3838
ref_clim = class_climate.GCM(name='ERA5')
3939

@@ -186,7 +186,7 @@ def main():
186186
help='Fixed spinup period (years). If not provided, OGGM default is used.',
187187
)
188188
parser.add_argument('-target_yr', type=int, default=None)
189-
parser.add_argument('-ye', type=int, default=2020)
189+
parser.add_argument('-ye', type=int, default=None)
190190
parser.add_argument(
191191
'-ncores',
192192
action='store',
@@ -242,6 +242,7 @@ def main():
242242
mb_model_params=args.mb_model_params,
243243
target_yr=args.target_yr,
244244
spinup_period=args.spinup_period,
245+
ye=args.ye,
245246
)
246247
# parallel processing
247248
print(f'Processing with {ncores} cores... \n{glac_no_lsts}')

pygem/mcmc.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,15 +230,15 @@ def log_likelihood(self, m):
230230
if torch.all(pred == float('-inf')):
231231
# Invalid model output -> assign -inf likelihood
232232
return torch.tensor([-float('inf')])
233-
233+
234234
if i == 0:
235235
# --- Base case: mass balance likelihood ---
236236
log_likehood += log_normal_density(
237237
self.obs[i][0], # observed values
238238
mu=pred, # predicted values
239239
sigma=self.obs[i][1], # observation uncertainty
240240
)
241-
241+
242242
elif i == 1 and len(m) > 3:
243243
# --- Extended case: apply density scaling to get binned elevation change ---
244244
# Create density field, separate values for ablation/accumulation zones
@@ -251,9 +251,9 @@ def log_likelihood(self, m):
251251
) # scale prediction by model density values (convert from m ice to m thickness change)
252252

253253
log_likehood += log_normal_density(
254-
self.obs[i][0], # observations
255-
mu=pred, # scaled predictions
256-
sigma=self.obs[i][1], # uncertainty
254+
self.obs[i][0], # observations
255+
mu=pred, # scaled predictions
256+
sigma=self.obs[i][1], # uncertainty
257257
)
258258
return log_likehood
259259

pygem/plot/graphics.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,16 +296,17 @@ def plot_resid_histogram(obs, preds, title, fontsize=8, show=False, fpath=None):
296296
plt.close(fig)
297297

298298

299-
def plot_mcmc_elev_change_1d(preds, fls, obs, ela, title, fontsize=8, rate=True, uniform_area=True, show=False, fpath=None):
300-
299+
def plot_mcmc_elev_change_1d(
300+
preds, fls, obs, ela, title, fontsize=8, rate=True, uniform_area=True, show=False, fpath=None
301+
):
301302
bin_z = np.array(obs['bin_centers'])
302303
bin_edges = np.array(obs['bin_edges'])
303304

304305
# get initial thickness and surface area
305306
initial_area = fls[0].widths_m * fls[0].dx_meter
306307
initial_thickness = getattr(fls[0], 'thick', None)
307308
initial_surface_h = getattr(fls[0], 'surface_h', None)
308-
# sort initial surface height
309+
# sort initial surface height
309310
sorting = np.argsort(initial_surface_h)
310311
initial_surface_h = initial_surface_h[sorting]
311312
initial_area = initial_area[sorting]
@@ -319,7 +320,7 @@ def plot_mcmc_elev_change_1d(preds, fls, obs, ela, title, fontsize=8, rate=True,
319320
initial_area = obs['bin_area']
320321

321322
if uniform_area:
322-
xvals = np.nancumsum(initial_area)*1e-6
323+
xvals = np.nancumsum(initial_area) * 1e-6
323324
else:
324325
xvals = bin_z
325326

@@ -365,7 +366,6 @@ def elev_to_cum_area(x):
365366
ax[t].axhline(y=0, c='grey', lw=0.5)
366367
preds = np.stack(preds)
367368

368-
369369
ax[t].fill_between(
370370
xvals,
371371
(obs['dh'][:, t] - obs['dh_sigma'][:, t]) / nyrs[t],

pygem/shop/elevchange1d.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def elev_change_1d_to_gdir(
8080
- Each element in 'dates' defines one elevation change period with a start and end date,
8181
stored as strings in 'YYYY-MM-DD' format.
8282
- 'bin_edges' should be a list length N containing the elevation values of each bin edge.
83-
- 'bin_area' should be a list of length N-1 containing the bin areas given by the 'ref_dem' (optional).
83+
- 'bin_area' should be a list of length N-1 containing the bin areas given by the 'ref_dem' (optional).
8484
- 'dh' should contain M lists of length N-1, where M is the number of periods and N is the number of bin edges. Units are in meters.
8585
- 'dh_sigma' should either be M lists of length N-1 (matching 'dh') or a single scalar value. Units are in meters.
8686
- Each list in 'dh' (and optionally 'dh_sigma') corresponds exactly to one period in 'dates'.
@@ -216,14 +216,14 @@ def validate_elev_change_1d_structure(data):
216216
ref_dem_year = data['ref_dem_year']
217217
if not isinstance(ref_dem_year, int):
218218
raise ValueError("'ref_dem_year' must be an integer year.")
219-
219+
220220
# Validate bin_area if present
221221
if 'bin_area' in data:
222222
bin_area = data['bin_area']
223223
if len(bin_area) != N:
224224
raise ValueError(f"'bin_area' must be a list of length {N}.")
225225
if not all(isinstance(x, (int, float)) for x in bin_area):
226-
raise ValueError(f"All 'bin_area' values must be numeric.")
226+
raise ValueError("All 'bin_area' values must be numeric.")
227227

228228
return True
229229

pygem/shop/loso25icebridge.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ def save_elevchange1d(
515515
note: 'ref_dem' is the reference DEM used for elevation-binning.
516516
'ref_dem_year' is the acquisition year of the reference DEM.
517517
'dates' are tuples (or length-2 sublists) of the start and stop date of an individual elevation change record
518-
and are stored as strings in 'YYYY-MM-DD' format.
518+
and are stored as strings in 'YYYY-MM-DD' format.
519519
'bin_edges' should be a list length N containing the elevation values of each bin edge.
520520
'bin_area' should be a list of length N-1 containing the bin areas given by the 'ref_dem' (optional).
521521
'dh' should be M lists of length N-1, where M is the number of date pairs and N is the number of bin edges.

0 commit comments

Comments
 (0)