diff --git a/oggm/core/centerlines.py b/oggm/core/centerlines.py index 7963d926b..7518fcdca 100644 --- a/oggm/core/centerlines.py +++ b/oggm/core/centerlines.py @@ -247,6 +247,19 @@ def widths(self): def widths_m(self): return self.widths * self.map_dx + @property + def bin_area_m2(self): + # area of the grid point + return self.widths_m * self.dx_meter + + @property + def area_m2(self): + return np.sum(self.bin_area_m2) + + @property + def area_km2(self): + return self.area_m2 * 1e-6 + @widths.setter def widths(self, value): self._widths = value diff --git a/oggm/tests/test_prepro.py b/oggm/tests/test_prepro.py index 9b66a07a9..96913a64c 100644 --- a/oggm/tests/test_prepro.py +++ b/oggm/tests/test_prepro.py @@ -1154,6 +1154,12 @@ def test_width(self): np.testing.assert_allclose(area * 10**-6, float(tdf['Area']), rtol=1e-4) + area_attr = 0 + for cl in cls: + area_attr += cl.area_km2 + np.testing.assert_allclose(area_attr, float(tdf['Area']), + rtol=1e-4) + # Check for area distrib bins = np.arange(utils.nicenumber(np.min(hgt), 50, lower=True), utils.nicenumber(np.max(hgt), 50)+1,