-
-
Notifications
You must be signed in to change notification settings - Fork 53
Add NDCube method to convert to NDData instance. #887
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
Conversation
Allow attributes to be changed via kwargs.
@Cadair: I found time to PR this. Whatever we agree on the call signature, I think this captures the core of the implementation. |
So @Cadair, what's your call signature decorator idea? |
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.
Once #880 is merged, a link in the docstring of this function to the narrative docs in that PR would be helpful in explaining the usefulness of this function as it is not immediately obvious how one would make use of this. This of course could be done in a subsequent PR as that PR depends on this one.
Sounds good. I can include this in #887 |
b2dca8d
to
e59127b
Compare
…eral. And docstring fix.
e59127b
to
d46bcaa
Compare
if extra_coords is COPY: | ||
extra_coords = copy.copy(self._extra_coords) | ||
extra_coords._ndcube = new_nddata | ||
new_nddata._extra_coords = extra_coords | ||
if global_coords is COPY: | ||
new_nddata._global_coords = copy.copy(self._global_coords) |
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.
We should really add these as kwargs to ndcube's constructor lol.
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! Let's keep that as separate to this PR though.
all_kwargs = {key.strip("_"): value for key, value in self.__dict__.items()} | ||
all_kwargs.update(user_kwargs) | ||
# Inspect call signature of new_nddata class and | ||
# remove unsupported items from new_kwargs. | ||
all_kwargs = {key: value for key, value in all_kwargs.items() | ||
if key in inspect.signature(nddata_type).parameters.keys()} |
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 a fan of extracting all the attributes like this, it feels exceptionally brittle.
Do we really need to do this? Can't we just say if you need to copy custom attributes of a non-NDData class you need to specify them as explicit keyword arguments? Then this dictionary comprehension is just for the things where the kwarg value is COPY.
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.
Unless there's a better way to filter the kwargs by the call signature of nddata_type
, then yes, we need this.
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.
That wasn't the part I was objecting to. I'll open a followup PR when I get the chance.
PR Description
This PR introduces a new method
NDCube.to_nddata
, which allows for anNDCube
to be converted to anNDData
(or subclass of same) instance. The motivating use case is to enable users to easily drop coordinate-awareness from their data and thereby perform arithmetic operations with NDCubes.