Skip to content

Commit 5ffa2c6

Browse files
authored
51 1d resample fix (#53)
* Fixes #51 - 1D resampling fix for custom mass names * improved check before solve
1 parent 06fdbf1 commit 5ffa2c6

File tree

6 files changed

+19
-6
lines changed

6 files changed

+19
-6
lines changed

CHANGELOG.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
Geomet 0.4.11 (2025-01-25)
2+
==========================
3+
4+
Bugfix
5+
------
6+
7+
- 1D resampling fix for custom mass names (#51)
8+
9+
110
Geomet 0.4.10 (2025-01-23)
211
==========================
312

elphick/geomet/flowsheet/flowsheet.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import yaml
1616
from matplotlib import pyplot as plt
1717
from matplotlib.colors import ListedColormap, LinearSegmentedColormap
18+
from networkx.algorithms.dag import is_directed_acyclic_graph
1819
from plotly.subplots import make_subplots
1920

2021
from elphick.geomet import Sample
@@ -306,6 +307,8 @@ def copy_without_stream_data(self):
306307
def solve(self):
307308
"""Solve missing streams"""
308309

310+
assert is_directed_acyclic_graph(self.graph), "Graph is not a Directed Acyclic Graph (DAG), so cannot be solved."
311+
309312
# Check the number of missing mc's on edges in the network
310313
missing_count: int = sum([1 for u, v, d in self.graph.edges(data=True) if d['mc'] is None])
311314
prev_missing_count = missing_count + 1 # Initialize with a value greater than missing_count

elphick/geomet/interval_sample.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ def resample_1d(self, interval_edges: Union[Iterable, int],
585585
df_upsampled: pd.DataFrame = mass_preserving_interp(self.mass_data,
586586
interval_edges=interval_edges, precision=precision,
587587
include_original_edges=include_original_edges,
588+
mass_wet=None, mass_dry=self.mass_dry_var,
588589
interval_data_as_mass=True)
589590

590591
obj: IntervalSample = IntervalSample(df_upsampled, name=self.name, moisture_in_scope=False,

elphick/geomet/utils/interp.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
def mass_preserving_interp(df_intervals: pd.DataFrame, interval_edges: Union[Iterable, int],
1111
include_original_edges: bool = True, precision: Optional[int] = None,
12-
mass_wet: str = 'mass_wet', mass_dry: str = 'mass_dry',
12+
mass_wet: Optional[str] = 'mass_wet', mass_dry: str = 'mass_dry',
1313
interval_data_as_mass: bool = False) -> pd.DataFrame:
1414
"""Interpolate with zero mass loss using pchip
1515
@@ -81,7 +81,7 @@ def mass_preserving_interp(df_intervals: pd.DataFrame, interval_edges: Union[Ite
8181
# if the new grid extrapolates (on the coarse side), mass will be lost, so we assume that when extrapolating.
8282
# the mass in the extrapolated fractions is zero. By inserting these records the spline will conform.
8383
x_extra = grid_vals[grid_vals > mass_cum.index.max()]
84-
if x_extra:
84+
if len(x_extra) > 0:
8585
cum_max: pd.Series = mass_cum.iloc[-1, :]
8686
mass_cum = mass_cum.reindex(index=mass_cum.index.append(pd.Index(x_extra))) # reindex to enable insert
8787
mass_cum.loc[x_extra, :] = cum_max.values
@@ -180,7 +180,8 @@ def mass_preserving_interp_2d(intervals: pd.DataFrame, interval_edges: dict[str,
180180
# proportion the dim_1 interpolated values by the dim_2 recovery
181181
new_vals: pd.DataFrame = dim_2_deportment.mul(filtered_intervals_mass.loc[dim_1_interp_interval].values)
182182
# create a multiindex by combining the dim_1 and dim_2 intervals
183-
new_index = pd.MultiIndex.from_arrays([pd.IntervalIndex([dim_1_interp_interval] * len(new_vals)), new_vals.index])
183+
new_index = pd.MultiIndex.from_arrays(
184+
[pd.IntervalIndex([dim_1_interp_interval] * len(new_vals)), new_vals.index])
184185
new_vals.index = new_index
185186
chunks.append(new_vals)
186187

@@ -190,4 +191,3 @@ def mass_preserving_interp_2d(intervals: pd.DataFrame, interval_edges: dict[str,
190191
# convert to composition
191192
res = mass_to_composition(res, mass_dry=mass_dry)
192193
return res
193-

elphick/geomet/utils/pandas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def composition_to_mass(df: pd.DataFrame,
8888
df: The pd.DataFrame containing mass. H2O if provided will be ignored. All columns other than the
8989
mass_wet and mass_dry are assumed to be `additive`, that is, dry mass weighting is valid.
9090
Assumes composition is in %w/w units.
91-
mass_wet: The wet mass column, optional. If not provided, it's assumed to be equal to mass_dry.
91+
mass_wet: The wet mass column, optional.
9292
mass_dry: The dry mass column, not optional. Consider solve_mass_moisture prior to this call if needed.
9393
moisture_column_name: if mass_wet is provided, the resultant moisture will be returned with this column name.
9494
If None, and moisture is detected in the input, that column name will be used instead.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tool.poetry]
22
name = "geometallurgy"
33
packages = [{ include = "elphick/geomet" }]
4-
version = "0.4.10"
4+
version = "0.4.11"
55
description = "Tools for the geometallurgist"
66
authors = ["Greg <11791585+elphick@users.noreply.github.com>"]
77
repository = "https://github.com/elphick/geometallurgy"

0 commit comments

Comments
 (0)