def test_staggered_diagnostics(self): mb = LinearMassBalance(2600.) fls = dummy_constant_bed() model = FluxBasedModel(fls, mb_model=mb, y0=0.) model.run_until(700) assert_allclose(mb.get_specific_mb(fls=fls), 0, atol=10) # Check the flux just for fun fl = model.flux_stag[0] assert fl[0] == 0 # Now check the diags df = model.get_diagnostics() fl = model.fls[0] df['my_flux'] = np.cumsum(mb.get_annual_mb(fl.surface_h) * fl.widths_m * fl.dx_meter * cfg.SEC_IN_YEAR).clip(0) df = df.loc[df['ice_thick'] > 0] # Also convert ours df['ice_flux'] *= cfg.SEC_IN_YEAR df['ice_velocity'] *= cfg.SEC_IN_YEAR df['tributary_flux'] *= cfg.SEC_IN_YEAR assert_allclose(np.abs(df['ice_flux'] - df['my_flux']), 0, atol=35e3) assert df['ice_velocity'].max() > 25 assert df['tributary_flux'].max() == 0 fls = dummy_width_bed_tributary() model = FluxBasedModel(fls, mb_model=mb, y0=0.) model.run_until(500) df = model.get_diagnostics() df['ice_velocity'] *= cfg.SEC_IN_YEAR df['tributary_flux'] *= cfg.SEC_IN_YEAR df = df.loc[df['ice_thick'] > 0] assert df['ice_velocity'].max() > 50 assert df['tributary_flux'].max() > 30e4 df = model.get_diagnostics(fl_id=0) df = df.loc[df['ice_thick'] > 0] df['ice_velocity'] *= cfg.SEC_IN_YEAR df['tributary_flux'] *= cfg.SEC_IN_YEAR assert df['ice_velocity'].max() > 10 assert df['tributary_flux'].max() == 0
def to_minimize(ela_h): mbmod = LinearMassBalance(ela_h[0], grad=mb_gradient) smb = mbmod.get_specific_mb(h, w) return (smb - cmb)**2
def test_constant_bed(self): models = [KarthausModel, FluxBasedModel, MUSCLSuperBeeModel] lens = [] surface_h = [] volume = [] yrs = np.arange(1, 700, 2) for model in models: fls = dummy_constant_bed() mb = LinearMassBalance(2600.) model = model(fls, mb_model=mb, y0=0., glen_a=self.glen_a, fs=self.fs, fixed_dt=10 * SEC_IN_DAY) length = yrs * 0. vol = yrs * 0. for i, y in enumerate(yrs): model.run_until(y) assert model.yr == y length[i] = fls[-1].length_m vol[i] = fls[-1].volume_km3 lens.append(length) volume.append(vol) surface_h.append(fls[-1].surface_h.copy()) # We are almost at equilibrium. Spec MB should be close to 0 assert_allclose(mb.get_specific_mb(fls=fls), 0, atol=10) if do_plot: plt.figure() plt.plot(yrs, lens[0], 'r') plt.plot(yrs, lens[1], 'b') plt.plot(yrs, lens[2], 'g') plt.title('Compare Length') plt.xlabel('years') plt.ylabel('[m]') plt.legend(['Karthaus', 'Flux', 'MUSCL-SuperBee'], loc=2) plt.figure() plt.plot(yrs, volume[0], 'r') plt.plot(yrs, volume[1], 'b') plt.plot(yrs, volume[2], 'g') plt.title('Compare Volume') plt.xlabel('years') plt.ylabel('[km^3]') plt.legend(['Karthaus', 'Flux', 'MUSCL-SuperBee'], loc=2) plt.figure() plt.plot(fls[-1].bed_h, 'k') plt.plot(surface_h[0], 'r') plt.plot(surface_h[1], 'b') plt.plot(surface_h[2], 'g') plt.title('Compare Shape') plt.xlabel('[m]') plt.ylabel('Elevation [m]') plt.legend(['Bed', 'Karthaus', 'Flux', 'MUSCL-SuperBee'], loc=3) plt.show() np.testing.assert_almost_equal(lens[0][-1], lens[1][-1]) np.testing.assert_allclose(volume[0][-1], volume[2][-1], atol=3e-3) np.testing.assert_allclose(volume[1][-1], volume[2][-1], atol=3e-3) assert utils.rmsd(lens[0], lens[2]) < 50. assert utils.rmsd(lens[1], lens[2]) < 50. assert utils.rmsd(volume[0], volume[2]) < 2e-3 assert utils.rmsd(volume[1], volume[2]) < 2e-3 assert utils.rmsd(surface_h[0], surface_h[2]) < 1.0 assert utils.rmsd(surface_h[1], surface_h[2]) < 1.0
def test_numerics(): # We test that our model produces similar results than Jarosh et al 2013. models = [MUSCLSuperBeeModel, ChakraModel] lens = [] surface_h = [] volume = [] yrs = np.arange(1, 700, 2) for model_class in models: mb = LinearMassBalance(2600.) model = model_class(dummy_constant_bed(), mb_model=mb) length = yrs * 0. vol = yrs * 0. for i, y in enumerate(yrs): model.run_until(y) assert model.yr == y length[i] = model.fls[-1].length_m vol[i] = model.fls[-1].volume_km3 lens.append(length) volume.append(vol) surface_h.append(model.fls[-1].surface_h.copy()) # We are almost at equilibrium. Spec MB should be close to 0 assert_allclose(mb.get_specific_mb(fls=model.fls), 0, atol=10) if do_plot: plt.figure() plt.plot(yrs, lens[0]) plt.plot(yrs, lens[1]) plt.title('Compare Length') plt.xlabel('years') plt.ylabel('[m]') plt.legend(['MUSCL-SuperBee', 'Chakra'], loc=2) plt.figure() plt.plot(yrs, volume[0]) plt.plot(yrs, volume[1]) plt.title('Compare Volume') plt.xlabel('years') plt.ylabel('[km^3]') plt.legend(['MUSCL-SuperBee', 'Chakra'], loc=2) plt.figure() plt.plot(model.fls[-1].bed_h, 'k') plt.plot(surface_h[0]) plt.plot(surface_h[1]) plt.title('Compare Shape') plt.xlabel('[m]') plt.ylabel('Elevation [m]') plt.legend(['Bed', 'MUSCL-SuperBee', 'Chakra'], loc=2) plt.show() np.testing.assert_almost_equal(lens[0][-1], lens[1][-1]) np.testing.assert_allclose(volume[0][-1], volume[1][-1], atol=1e-3) assert utils.rmsd(lens[0], lens[1]) < 50. assert utils.rmsd(volume[0], volume[1]) < 2e-3 assert utils.rmsd(surface_h[0], surface_h[1]) < 1.0