Skip to content

Comments

Adds 'clamp' (vs Numpy's 'clip')#4

Merged
brgix merged 1 commit intodevelopfrom
numpy
Aug 3, 2025
Merged

Adds 'clamp' (vs Numpy's 'clip')#4
brgix merged 1 commit intodevelopfrom
numpy

Conversation

@brgix
Copy link
Member

@brgix brgix commented Aug 3, 2025

OSut operates heavily off of OpenStudio's SWIG Python bindings (i.e. import openstudio). It also relies on OSlg as an external logger. In addition, OSut relies on a handful of built-in (internal) Python packages/modules:

  • re
  • math
  • collections
  • dataclasses

Numpy is the only external Python package/module, used solely to clip numbers (within a min/max range). This PR adds an in-house function, clamp: a proxy to Numpy's clip and/or Ruby's clamp.

There's probably not much of an overhead in importing Numpy, yet seems overkill for a single function.

@brgix brgix self-assigned this Aug 3, 2025
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: python -m pip install --upgrade pip setuptools wheel openstudio oslg numpy
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not even sure this numpy pip call was at all required.

with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: python -m pip install --upgrade pip setuptools wheel openstudio oslg numpty
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitHub Actions certainly didn't trip over this "numpty" typo.


if sched.to_ScheduleConstant():
sched = sched.to_ScheduleConstant().get()
minimum = scheduleConstantMinMax(sched)[:min]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yikes. Ruby leftover.

min = 0.050 # minimum ratio value ( 5%)
max = 0.950 # maximum ratio value (95%)
mn = 0.050 # minimum ratio value ( 5%)
mx = 0.950 # maximum ratio value (95%)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yish. Thought I had purged out all min and max variables.

maximum = float(maximum)
return maximum
except:
return 0.0
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No logged warnings or errors if invalid input. Will ultimately return 0.0 if all three parameters can't be converted to floating point numbers.

oslg.log(CN.WRN, "SRR (%.2f) reset to 90% (%s)" % (srr, mth))

srr = numpy.clip(srr, 0.00, 0.10)
srr = clamp(srr, 0.00, 0.10)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar function call/arguments as Numpy's clip. Haven't added unit stress tests, yet all higher-level functions work as intended. Good enough for now.

@brgix brgix added the enhancement New feature or request label Aug 3, 2025
@brgix brgix merged commit bc492db into develop Aug 3, 2025
4 checks passed
@brgix brgix deleted the numpy branch August 3, 2025 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant