Skip to content
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

Merged
merged 7 commits into from
Jan 17, 2023
Merged

Refactor nxsunit #13

merged 7 commits into from
Jan 17, 2023

Conversation

krzywon
Copy link
Collaborator

@krzywon krzywon commented Aug 19, 2022

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?

@butlerpd
Copy link
Member

butlerpd commented Dec 6, 2022

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.

Copy link

@wpotrzebowski wpotrzebowski left a 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.

sasdata/data_util/nxsunit.py Outdated Show resolved Hide resolved

# 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)

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?

Copy link
Contributor

@lucas-wilkins lucas-wilkins left a 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()])
Copy link
Contributor

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.

Copy link
Collaborator Author

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 and kiloohm will be generated by the class, but microhm and kilohm 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> to unit^<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.

sasdata/data_util/nxsunit.py Outdated Show resolved Hide resolved
@butlerpd
Copy link
Member

is this ready to merge?

@butlerpd butlerpd merged commit 5929637 into master Jan 17, 2023
@krzywon krzywon deleted the nxsunit branch March 31, 2023 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The celsius/kelvin conversion in nxsunit is not correct.
4 participants