Skip to content

Commit

Permalink
fixed isotope logic in sourcesink class. Addes code to deal with
Browse files Browse the repository at this point in the history
interpolated hypsometric data
  • Loading branch information
uliw committed May 30, 2024
1 parent 30de4e1 commit 40068d9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
9 changes: 5 additions & 4 deletions src/esbmtk/extended_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,12 @@ def __init__(self, **kwargs) -> None:
raise SourceSinkPropertiesError(
f"{s.n} needs to be a valid species name"
)
if s in self.isotopes:
isotopes = self.isotopes[s]
if isinstance(self.isotopes, dict):
if s in self.isotopes:
isotopes = self.isotopes[s]
else:
isotopes = False

isotopes = self.isotopes
if type(self).__name__ == "SourceProperties":
a = Source(
name=f"{s.name}",
Expand Down
18 changes: 11 additions & 7 deletions src/esbmtk/sealevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,12 @@ def read_data(self) -> None:
max_el = df.iloc[0, 0] - self.max_elevation
elevation = df.iloc[max_el:, 0].to_numpy()
area = df.iloc[max_el:, 1].to_numpy() * self.sa


dz = df.iloc[0, 0] - df.iloc[1, 0]
if dz != 1: # in case we need to interpolate the data
dzi = np.arange(elevation[0], elevation[-1], -1)
area = np.interp(dzi, elevation, area)
elevation = dzi
# create lookup table with area and area_dz
self.hypdata = np.column_stack(
(
Expand Down Expand Up @@ -197,7 +202,7 @@ def area(self, elevation: int) -> float:
)
)

return self.hypdata[i,1]
return self.hypdata[i, 1]

def area_dz(self, u: float, l: float) -> float:
"""calculate the area between two elevation datums
Expand Down Expand Up @@ -230,7 +235,7 @@ def area_dz(self, u: float, l: float) -> float:

u = self.max_elevation - int(u)
l = self.max_elevation - int(l)

return self.hypdata[u, 1] - self.hypdata[l, 1]

def volume(self, u: float, l: float) -> float:
Expand Down Expand Up @@ -430,8 +435,7 @@ def slice_count(
"""
sub_grid = grid[start:end, ...]

count = np.zeros(int((elevation_maximum - elevation_minimum) // dz),
dtype=float)
count = np.zeros(int((elevation_maximum - elevation_minimum) // dz), dtype=float)

for i, e in enumerate(elevations):
a = np.sum(np.logical_and(sub_grid > e, sub_grid < e + dz), axis=1)
Expand Down Expand Up @@ -480,5 +484,5 @@ def process_slice(
lat_slice = lat[start:end]
weight = np.array([grid_area(lat_val, dx) for lat_val in lat_slice])
return slice_count(
start, end, weight, grid, elevation_minimum, elevation_maximum,
elevations, dz)
start, end, weight, grid, elevation_minimum, elevation_maximum, elevations, dz
)

0 comments on commit 40068d9

Please sign in to comment.