Skip to content

Commit

Permalink
Add bin_area to the inversion flowlines (#1744)
Browse files Browse the repository at this point in the history
  • Loading branch information
fmaussion committed Sep 16, 2024
1 parent 5d87481 commit 3ec3cb0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
13 changes: 13 additions & 0 deletions oggm/core/centerlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions oggm/tests/test_prepro.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3ec3cb0

Please sign in to comment.