def test_min_slope(self): """ Check what is the min slope a flowline model can produce """ models = [KarthausModel, FluxBasedModel, MUSCLSuperBeeModel] kwargs = [{'fixed_dt': 3 * SEC_IN_DAY}, {}, {}] lens = [] surface_h = [] volume = [] min_slope = [] yrs = np.arange(1, 700, 2) for model, kw in zip(models, kwargs): fls = dummy_constant_bed_obstacle() mb = LinearMassBalance(2600.) model = model(fls, mb_model=mb, y0=0., glen_a=self.glen_a, **kw) length = yrs * 0. vol = yrs * 0. slope = yrs * 0. for i, y in enumerate(yrs): model.run_until(y) fl = fls[-1] length[i] = fl.length_m vol[i] = fl.volume_km3 hgt = np.where(fl.thick > 0, fl.surface_h, np.NaN) sl = np.arctan(-np.gradient(hgt, fl.dx_meter)) slope[i] = np.rad2deg(np.nanmin(sl)) lens.append(length) volume.append(vol) min_slope.append(slope) surface_h.append(fls[-1].surface_h.copy()) np.testing.assert_allclose(lens[0][-1], lens[1][-1], atol=101) np.testing.assert_allclose(volume[0][-1], volume[2][-1], atol=2e-3) np.testing.assert_allclose(volume[1][-1], volume[2][-1], atol=5e-3) self.assertTrue(utils.rmsd(volume[0], volume[2]) < 1e-2) self.assertTrue(utils.rmsd(volume[1], volume[2]) < 1e-2) if do_plot: # pragma: no cover 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(yrs, min_slope[0], 'r') plt.plot(yrs, min_slope[1], 'b') plt.plot(yrs, min_slope[2], 'g') plt.title('Compare min slope') plt.xlabel('years') plt.ylabel('[degrees]') 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()
def test_min_slope(self): """ Check what is the min slope a flowline model can produce """ models = [KarthausModel, FluxBasedModel, MUSCLSuperBeeModel] kwargs = [{'fixed_dt': 3*SEC_IN_DAY}, {}, {}] lens = [] surface_h = [] volume = [] min_slope = [] yrs = np.arange(1, 700, 2) for model, kw in zip(models, kwargs): fls = dummy_constant_bed_obstacle() mb = LinearMassBalance(2600.) model = model(fls, mb_model=mb, y0=0., glen_a=self.glen_a, **kw) length = yrs * 0. vol = yrs * 0. slope = yrs * 0. for i, y in enumerate(yrs): model.run_until(y) fl = fls[-1] length[i] = fl.length_m vol[i] = fl.volume_km3 hgt = np.where(fl.thick > 0, fl.surface_h, np.NaN) sl = np.arctan(-np.gradient(hgt, fl.dx_meter)) slope[i] = np.rad2deg(np.nanmin(sl)) lens.append(length) volume.append(vol) min_slope.append(slope) surface_h.append(fls[-1].surface_h.copy()) np.testing.assert_allclose(lens[0][-1], lens[1][-1], atol=101) np.testing.assert_allclose(volume[0][-1], volume[2][-1], atol=2e-3) np.testing.assert_allclose(volume[1][-1], volume[2][-1], atol=5e-3) self.assertTrue(utils.rmsd(volume[0], volume[2]) < 1e-2) self.assertTrue(utils.rmsd(volume[1], volume[2]) < 1e-2) if do_plot: # pragma: no cover 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(yrs, min_slope[0], 'r') plt.plot(yrs, min_slope[1], 'b') plt.plot(yrs, min_slope[2], 'g') plt.title('Compare min slope') plt.xlabel('years') plt.ylabel('[degrees]') 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()