def test_tributary(self): models = [KarthausModel, FluxBasedModel] steps = [15 * SEC_IN_DAY, None] flss = [dummy_width_bed(), dummy_width_bed_tributary()] lens = [] surface_h = [] volume = [] yrs = np.arange(1, 500, 2) for model, step, fls in zip(models, steps, flss): mb = LinearMassBalance(2600.) model = model(fls, mb_model=mb, fs=self.fs_old, glen_a=self.aglen_old, fixed_dt=step) 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] = np.sum([f.volume_km3 for f in fls]) lens.append(length) volume.append(vol) 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[1][-1], atol=2e-2) np.testing.assert_allclose(utils.rmsd(lens[0], lens[1]), 0., atol=70) np.testing.assert_allclose(utils.rmsd(volume[0], volume[1]), 0., atol=6e-3) np.testing.assert_allclose(utils.rmsd(surface_h[0], surface_h[1]), 0., atol=5) if do_plot: # pragma: no cover plt.plot(lens[0], 'r') plt.plot(lens[1], 'b') plt.show() plt.plot(volume[0], 'r') plt.plot(volume[1], 'b') plt.show() plt.plot(fls[-1].bed_h, 'k') plt.plot(surface_h[0], 'r') plt.plot(surface_h[1], 'b') plt.show()
def test_tributary(self): models = [KarthausModel, FluxBasedModel] steps = [15 * SEC_IN_DAY, None] flss = [dummy_width_bed(), dummy_width_bed_tributary()] lens = [] surface_h = [] volume = [] yrs = np.arange(1, 500, 2) for model, step, fls in zip(models, steps, flss): mb = LinearMassBalance(2600.) model = model(fls, mb_model=mb, fs=self.fs_old, glen_a=self.aglen_old, fixed_dt=step) length = yrs * 0. vol = yrs * 0. for i, y in enumerate(yrs): model.run_until(y) length[i] = fls[-1].length_m vol[i] = np.sum([f.volume_km3 for f in fls]) lens.append(length) volume.append(vol) 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[1][-1], atol=2e-2) np.testing.assert_allclose(utils.rmsd(lens[0], lens[1]), 0., atol=70) np.testing.assert_allclose(utils.rmsd(volume[0], volume[1]), 0., atol=6e-3) np.testing.assert_allclose(utils.rmsd(surface_h[0], surface_h[1]), 0., atol=5) if do_plot: # pragma: no cover plt.plot(lens[0], 'r') plt.plot(lens[1], 'b') plt.show() plt.plot(volume[0], 'r') plt.plot(volume[1], 'b') plt.show() plt.plot(fls[-1].bed_h, 'k') plt.plot(surface_h[0], 'r') plt.plot(surface_h[1], 'b') plt.show()
def test_varying_width(self): """This test is for a flowline glacier of variying width, i.e with an accumulation area twice as wide as the tongue.""" # TODO: @alexjarosch here we should have a look at MUSCLSuperBeeModel # set do_plot = True to see the plots models = [KarthausModel, FluxBasedModel, MUSCLSuperBeeModel] steps = [15 * SEC_IN_DAY, None, None] lens = [] surface_h = [] volume = [] yrs = np.arange(1, 500, 2) for model, step in zip(models, steps): fls = dummy_width_bed() mb = LinearMassBalance(2600.) model = model(fls, mb_model=mb, glen_a=self.glen_a, fixed_dt=step) length = yrs * 0. vol = yrs * 0. for i, y in enumerate(yrs): model.run_until(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()) 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(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[1][-1], atol=2e-2) np.testing.assert_allclose(utils.rmsd(lens[0], lens[1]), 0., atol=70) np.testing.assert_allclose(utils.rmsd(volume[0], volume[1]), 0., atol=1e-2) np.testing.assert_allclose(utils.rmsd(surface_h[0], surface_h[1]), 0., atol=5)