-
Notifications
You must be signed in to change notification settings - Fork 303
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
Reset of modifier attribute of xr.DataArray when assigning to existing scene DataID #1490
Comments
This isn't a common usage, but this is definitely a bug. There is a little uncertainty right now on what the defined behavior should be when assigning to a Scene with a new name. Obviously it shouldn't reset all of the DataID properties except the name. That's why I'd consider this a bug. I'll let @mraspaud let me know what he thinks and who should try to fix it as he's worked with this stuff the most recently. @mraspaud If you'd rather I try to fix it let me know. It may be better to wait for some of the other refactoring PRs to be merged first. |
I agree this seems buggy. But maybe we should use this opportunity to come up with some specifications on what assigning a dataarray to a scene should do, metadata-wise? |
Agreed. I think this is very similar to @ninahakansson's #1450. She had a different understanding of how assigning to the Scene would work (different from how I expect it) so it would be good to get other's ideas. My assumption, being the person that wrote the original code that did this, is that the
So in this case, Alternatively, we could go with a hard refactor where we utilize the |
Also agree. I think this will be a huge benefit to the user. Ideally the solution would also alleviate the need to use The assignment of a new attribute name in #1450 is interesting would also not have expected this kind of usage but I can see why a user might expect this to work. When I assign a Regarding the utilization of the |
Oh good point! Yeah it would be nice if we could reuse this. For everything else you said, I wonder if we could look closer at how xarray Dataset does things and treats things. Obviously they don't have an idea of a I see a few options:
The thing not handled or discussed here yet is what if someone does |
@djhoese thanks for taking notice of this! Unfortunately this is exactly what I am currently doing in level1c4pps to be able to choose the name of the netcdf variables (attrs["name"]) but otherwise changing the variables as little as possible to avoid loosing attributes etc. Maybe this can be solved by introducing a new attribute "netcdf_name" and use that to decide names of the netcdf variables in cf-writer? |
@ninahakansson I think the right solution for your use case is just to be careful how you are renaming the DataArrays. Something like:
Would that work for you? |
@djhoese I never tried to actually delete a data set from scene before adding it with a new name. I will test that. And as long as we solve the problem with attributes, modifiers getting lost I think it will be fine renaming them in level1c4pps. |
@djhoese I am in favor of option 1. This "imitates" the behavior of xarray datasets where assignment of an existing dataarray in the dataset to a different name also makes a deep copy as far as I see. The only difference in Satpy would be that the The "problematic" case with users trying to set a new name with While not directly related; it would also be nice (again similar to xarray) if multiple datasets could be selected from a scene with a list. |
Describe the bug
When "manually" using the
SunZenithCorrector
modifier the "modifier" attribute of thexr.DataArray
is stripped after it is assigned to the scene with the same key of the dataset which was supplied to the corrector.To Reproduce
While the
xr.DataArray
assigned to "a" has the attribute "modifier" = ("sunz_corrected",) after the assignment to the scene it is stripped away.Obviously the DataID would not reflect the modifier attribute unless the DataID would be updated during assignment to a scene (which as far as I see it isn't).
Maybe this is unconventional usage but regardless of the DataID not reflecting the modifier it seems weird that only the modifier attribute of the
xr.DataArray
gets reset.My "work around" was to delete the DataID from the scene and create a new one from the dataarray like so:
Expected behavior
The expectation when assigning a
xr.DataArray
to an existing key in a scene would be that the oldxr.DataArray
belonging to that key gets overwritten even if the DataID does not reflect the state (e.g. a modifier was applied as in this case) of the data.Environment Info:
from satpy.config import check_satpy; check_satpy()
]Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: