def test_set_width(self): entity = gpd.read_file(self.rgi_file).iloc[0] gdir = oggm.GlacierDirectory(entity, base_dir=self.testdir) gis.define_glacier_region(gdir) gis.glacier_masks(gdir) centerlines.compute_centerlines(gdir) centerlines.initialize_flowlines(gdir) centerlines.compute_downstream_line(gdir) centerlines.compute_downstream_bedshape(gdir) centerlines.catchment_area(gdir) centerlines.catchment_intersections(gdir) centerlines.catchment_width_geom(gdir) centerlines.catchment_width_correction(gdir) # Test that area and area-altitude elev is fine with utils.ncDataset(gdir.get_filepath('gridded_data')) as nc: mask = nc.variables['glacier_mask'][:] topo = nc.variables['topo_smoothed'][:] rhgt = topo[np.where(mask)][:] fls = gdir.read_pickle('inversion_flowlines') hgt, widths = gdir.get_inversion_flowline_hw() bs = 100 bins = np.arange(utils.nicenumber(np.min(hgt), bs, lower=True), utils.nicenumber(np.max(hgt), bs) + 1, bs) h1, b = np.histogram(hgt, weights=widths, density=True, bins=bins) h2, b = np.histogram(rhgt, density=True, bins=bins) h1 = h1 / np.sum(h1) h2 = h2 / np.sum(h2) assert utils.rmsd(h1, h2) < 0.02 # less than 2% error new_area = np.sum(widths * fls[-1].dx * gdir.grid.dx) np.testing.assert_allclose(new_area, gdir.rgi_area_m2) centerlines.terminus_width_correction(gdir, new_width=714) fls = gdir.read_pickle('inversion_flowlines') hgt, widths = gdir.get_inversion_flowline_hw() # Check that the width is ok np.testing.assert_allclose(fls[-1].widths[-1] * gdir.grid.dx, 714) # Check for area distrib bins = np.arange(utils.nicenumber(np.min(hgt), bs, lower=True), utils.nicenumber(np.max(hgt), bs) + 1, bs) h1, b = np.histogram(hgt, weights=widths, density=True, bins=bins) h2, b = np.histogram(rhgt, density=True, bins=bins) h1 = h1 / np.sum(h1) h2 = h2 / np.sum(h2) assert utils.rmsd(h1, h2) < 0.02 # less than 2% error new_area = np.sum(widths * fls[-1].dx * gdir.grid.dx) np.testing.assert_allclose(new_area, gdir.rgi_area_m2)
def test_set_width(self): entity = gpd.read_file(self.rgi_file).iloc[0] gdir = oggm.GlacierDirectory(entity, base_dir=self.testdir) gis.define_glacier_region(gdir, entity=entity) gis.glacier_masks(gdir) centerlines.compute_centerlines(gdir) centerlines.initialize_flowlines(gdir) centerlines.compute_downstream_line(gdir) centerlines.compute_downstream_bedshape(gdir) centerlines.catchment_area(gdir) centerlines.catchment_intersections(gdir) centerlines.catchment_width_geom(gdir) centerlines.catchment_width_correction(gdir) # Test that area and area-altitude elev is fine with utils.ncDataset(gdir.get_filepath('gridded_data')) as nc: mask = nc.variables['glacier_mask'][:] topo = nc.variables['topo_smoothed'][:] rhgt = topo[np.where(mask)][:] fls = gdir.read_pickle('inversion_flowlines') hgt, widths = gdir.get_inversion_flowline_hw() bs = 100 bins = np.arange(utils.nicenumber(np.min(hgt), bs, lower=True), utils.nicenumber(np.max(hgt), bs) + 1, bs) h1, b = np.histogram(hgt, weights=widths, density=True, bins=bins) h2, b = np.histogram(rhgt, density=True, bins=bins) h1 = h1 / np.sum(h1) h2 = h2 / np.sum(h2) assert utils.rmsd(h1, h2) < 0.02 # less than 2% error new_area = np.sum(widths * fls[-1].dx * gdir.grid.dx) np.testing.assert_allclose(new_area, gdir.rgi_area_m2) centerlines.terminus_width_correction(gdir, new_width=714) fls = gdir.read_pickle('inversion_flowlines') hgt, widths = gdir.get_inversion_flowline_hw() # Check that the width is ok np.testing.assert_allclose(fls[-1].widths[-1] * gdir.grid.dx, 714) # Check for area distrib bins = np.arange(utils.nicenumber(np.min(hgt), bs, lower=True), utils.nicenumber(np.max(hgt), bs) + 1, bs) h1, b = np.histogram(hgt, weights=widths, density=True, bins=bins) h2, b = np.histogram(rhgt, density=True, bins=bins) h1 = h1 / np.sum(h1) h2 = h2 / np.sum(h2) assert utils.rmsd(h1, h2) < 0.02 # less than 2% error new_area = np.sum(widths * fls[-1].dx * gdir.grid.dx) np.testing.assert_allclose(new_area, gdir.rgi_area_m2)