Skip to content

Commit

Permalink
Merge pull request #99 from equinor/zero_0_case_handling
Browse files Browse the repository at this point in the history
Zero 0 case handling
  • Loading branch information
smolvik1 authored Jan 13, 2025
2 parents 01ee688 + c4c28ab commit d6e0308
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.8.1
* Added case handling when zero value is 0

## 1.8
* Implemented type hinting
* Removed warning for geometry factors above 4
Expand Down
12 changes: 8 additions & 4 deletions pysand/asd.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ def validate_asd(**kwargs: float) -> bool:
for i in ['v_m', 'GLR', 'GOR']:
if i in kwargs:
if kwargs[i] is None:
raise exc.FunctionInputFail('No calculation is done due to missing {}'.format(i))
raise exc.FunctionInputFail(f'No calculation is done due to missing {i}')
if not isinstance(kwargs[i], (float, int, np.integer)):
raise exc.FunctionInputFail('{} is not a number'.format(i))
raise exc.FunctionInputFail(f'{i} is not a number')
if not kwargs[i] >= 0:
logger.warning('The model has got negative value(s) of {} and returned nan.'.format(i))
logger.warning(f'The model has got negative value(s) of {i} and returned nan.')
return True

def std_step_clampon(v_m: float, GLR: float) -> float:
Expand Down Expand Up @@ -82,7 +82,7 @@ def sand_rate(raw: float, zero: float, step: float, exp: float=1) -> float:

for key, value in {'raw': raw, 'zero': zero, 'step': step, 'exp': exp}.items():
if value is None:
raise exc.FunctionInputFail('No calculation is done due to missing {}'.format(key))
raise exc.FunctionInputFail(f'No calculation is done due to missing {key}')

if raw > zero:
try:
Expand All @@ -94,6 +94,10 @@ def sand_rate(raw: float, zero: float, step: float, exp: float=1) -> float:
if Qs < 0:
logger.warning('Negative step. Sand rate set to NaN')
Qs = np.nan
elif zero == 0:
logger.warning('Zero value is 0. Sand rate set to NaN')
Qs = np.nan

else:
Qs = 0

Expand Down
2 changes: 1 addition & 1 deletion pysand/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.8'
__version__ = '1.8.1'
16 changes: 16 additions & 0 deletions tests/test_asd.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,19 @@ def test_sand_rate_None_input():
kwargs['zero'] = zero
kwargs['step'] = step
kwargs['exp'] = exp

def test_zero_zero_input(caplog):
raw = 5000
zero = 0
step = 500
exp = 1
kwargs = {'raw': raw, 'zero': zero, 'step': step, 'exp': exp}

kwargs['raw'] = raw
kwargs['zero'] = zero
kwargs['step'] = step
kwargs['exp'] = exp

with caplog.at_level(logging.WARNING):
sand_rate(**kwargs)
assert "Zero value is 0. Sand rate set to NaN" in str(caplog.records)

0 comments on commit d6e0308

Please sign in to comment.