-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor nxsunit #13
Refactor nxsunit #13
Conversation
…pdate unit tests to match
… units into a list
…t tests to match functionality
…ct calculation issues found during testing.
Still waiting for review by @pkienzle and @lucas-wilkins (though the latter will be after Jan 1 I guess?). @wpotrzebowski may also take a look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not that familiar with this code base but code looks good. Minor stylistic remark There are few places with for loops with single letter variables. I haven't tested functionality yet.
|
||
# Find the scale for the given units - default to dimensionless | ||
self.scalemap = [DIMENSIONS.get(dimension, DIMENSIONS['dimensionless']) for dimension in self.dimension] | ||
base = self._get_scale_for_units(self._units) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe better to return scalebase and scaleoffset as two separate variables?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks OK
return map | ||
units = {} | ||
units.update([(name, scale) for name, scale in kw.items()]) | ||
units.update([(name + 's', scale) for name, scale in kw.items()]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know you've not really changed anything here, but plurals are not always made by adding an 's'. e.g. inches.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, but this class works mostly in SI units. Here is a list of edge cases we might come up against where this fails, based on my understanding of the NIST guide to SI:
- Anything Imperial that isn't a temperature
- Potential solution: add imperial lengths and weights
- What I am willing to do for this PR: I will continue to omit this. The scattering community doesn't work in inch(es)/feet/pounds/etc.
microohm
andkiloohm
will be generated by the class, butmicrohm
andkilohm
are the correct forms.- Potential solution: explicitly add these as resistance units
- What I am willing to do for this PR: I could implement this pretty quickly if there is a call for it.
- units in long-form, e.g.
meters per second squared
-or-meters per square second
- Potential solution 1: convert
<square|cubic> <unit>
or<unit> <squared|cubed>
tounit^<2|3>
- Potential solution 2: convert
per
to/
- What I am willing to do for this PR: I ignored this because long-form is typically reserved for textual content, not data units, but implementation would be fairly quick. I'd also need to add some reasonable unit tests.
- Potential solution 1: convert
is this ready to merge? |
This overhauls the nxsunit module to allow scaling with offsets, and scaling of multi-dimensional and complex units, e.g. SESANS A^-2*cm^-1 will treat the A^-2 and cm^-1 as separate components, each independently scalable. Unit tests were moved from within the module to the global unit test suite.
Fixes #5
Fixes(?) SasView/sasview#2035 - @pkienzle what do you think?