-
Notifications
You must be signed in to change notification settings - Fork 18
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
Minor adjustments and bug fixing of resampling_in_space #1100
Minor adjustments and bug fixing of resampling_in_space #1100
Conversation
541df45
to
a97ab84
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1100 +/- ##
==========================================
+ Coverage 89.58% 89.59% +0.01%
==========================================
Files 277 277
Lines 21836 21852 +16
==========================================
+ Hits 19561 19579 +18
+ Misses 2275 2273 -2 ☔ View full report in Codecov by Sentry. |
xcube/core/resampling/rectify.py
Outdated
# Handles the case where 2D coordinates are already present in the dataset, | ||
# which typically occurs after a reprojection performed by the | ||
# `resample_in_space` function. | ||
if "transformed_x" and "transformed_y" in source_ds_subset: | ||
source_gm = GridMapping.from_coords( | ||
source_ds_subset.transformed_x, | ||
source_ds_subset.transformed_y, | ||
crs=source_gm.crs, | ||
tile_size=source_gm.tile_size, | ||
) | ||
else: | ||
source_gm = GridMapping.from_dataset(source_ds_subset) |
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.
This works, but I have the feeling this is a workaround. As the coordinates are included in source_ds, it should be possible to call
GridMapping.from_dataset(source_ds_subset, prefer_crs=source_gm.crs)
and get the correct result.
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 changed the setup up the source_ds
in resample_in_space
. I took Sentinel-3 data as inspiration (see notebook https://github.com/xcube-dev/xcube/blob/main/examples/notebooks/resampling/rectify_dataset.ipynb).
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.
The new solution would cause problems with data variables that have a gridmapping attribute that points to a crs variable which might not exist anymore after these changes. I still prefer the solution of a variable "transformed_spatial_ref". However, if you prefer your way, please make sure the attributes are not wrong.
Thank you that you are looking into it so carefully! I need to remove the original coordinates, because if the source ds has I thus would like to keep my suggestion. Further, I delete all grid_mappings from the data variables in the source_ds. I also added a |
Do you really have to? For testing, I kept existing variables crs and spatial_ref and added a new one transformed_spatial_ref. Now, even though the source_gm retrieved from GridMapping.from_dataset() was the UTM one, the tests eventually succeeded. |
I changed it to |
You're right, when I executed this, I had left in the line where x and y were removed from the dataset. I now would accept your solution from before the last two commits. It's still not perfect, but I wouldn't be able to come up with a better solution. |
0ab6d78
to
61fbcda
Compare
@forman can you have a look onto our discussion and my suggested changes. I think a second opinion is useful here. Thank you! |
xcube/core/resampling/spatial.py
Outdated
if "crs" in source_ds: | ||
source_ds = source_ds.drop_vars("crs") | ||
if "spatial_ref" in source_ds: | ||
source_ds = source_ds.drop_vars("spatial_ref") |
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.
This may not be right in cases. You should just drop the grid mapping variable, no matter how it is named. crs
and spatial_ref
are common names, but their names are not a sufficient condition to identify the grid mapping variable. There can even be more than one such variables if multiple CRSes are used.
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 now go through the grid_mapping
in the data variable attributes, and not only delete the attribute with key key grid_mapping
, but also drop the grid mapping variable. Afterwards I still check for the grid mapping variable named with crs
and spatial_ref
. For Sentinel 2 jp2 files e.g. the dataset has the coordinate spatial_ref
, but the data variable has no attribute grid_mapping
.
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.
Thats good.
xcube/core/gridmapping/cfconv.py
Outdated
@@ -72,7 +72,6 @@ def get_dataset_grid_mapping_proxies( | |||
grid_mapping_proxies: dict[Union[Hashable, None], GridMappingProxy] = dict() | |||
|
|||
# Find any grid mapping variables by CF 'grid_mapping' attribute | |||
# |
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 like these spacers so the comment is not glued to the next line, but still connected.
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.
No preference here. I changed it back. :)
Co-authored-by: Norman Fomferra <[email protected]>
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 approve unless I overlooked the place where you added transformed_spatial_ref
. I'd be against it. Instead replace the existing source grid mapping from. If you need a history, place a record into the global history
attribute.
This PR is related to the previous PR #1098. Further I enhanced the testing of
resample_in_space
to cover the case of a reprojection, where a subsetting inrectify_dataset
is performed.Checklist:
Add docstrings and API docs for any new/modified user-facing classes and functionsNew/modified features documented indocs/source/*
CHANGES.md