-
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
Allow lazy execution of the reprojection method #1082
Conversation
The following things are missing, which I'd like to further implement:
|
This function called in |
This now works in a lazy manner. |
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.
A couple of questions/suggestions but approved since I don't need to review again.
CHANGES.md
Outdated
|
||
### Fixes | ||
|
||
* The function `resampling_in_space` now operates lazily and support chunk-wise, |
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 function `resampling_in_space` now operates lazily and support chunk-wise, | |
* The function `resampling_in_space` now operates lazily and supports chunk-wise, |
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.
done
@@ -196,7 +196,7 @@ def resample_in_space( | |||
) | |||
downscaled_dataset = resample_dataset( | |||
source_ds, | |||
((x_scale, 1, 0), (1, y_scale, 0)), |
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.
Why is the scale factor now inverted in this case?
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 came across this through an example and realized that it should be inverted. It is not covered by any test.
The code applies these steps if 0.95 target_gm.x_res > source_gm.x_res
, meaning that the source has a finer resolution than the target resolution. If this is the case the source dataset shall be resampled to a coarser grid, which has a similar resolution like the target grid. But since x_scale < 0.95
, the grid will be even finer. However, the inverse downsamples the source dataset to the desired resolution.
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.
However, I forot to change it in the if source_gm.is_regular:
, which I will correct for in the next push
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 think line 184 (downscaled_gm = source_gm.scale((x_scale, y_scale))
) also needs this inversion.
} | ||
) | ||
if other._xy_coords is None: | ||
_ = other.xy_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.
From code inspection and context, I realize that we're forcing initialization of other._xy_coords
here, but a brief explanatory comment would be welcome :)
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.
done
|
||
# Source has higher resolution than target. | ||
# Downscale first, then rectify | ||
if source_gm.is_regular: | ||
# If source is regular | ||
downscaled_gm = source_gm.scale((x_scale, y_scale)) | ||
downscaled_dataset = resample_dataset( | ||
source_ds, | ||
((x_scale, 1, 0), (1, y_scale, 0)), | ||
size=downscaled_gm.size, | ||
tile_size=source_gm.tile_size, | ||
xy_dim_names=source_gm.xy_dim_names, | ||
var_configs=var_configs, | ||
) |
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 code does not go into this if case. If the source_gm
is regular, an affine transformation will be performed in line 151.
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.
Nice!
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.
Fantastic work, thank you!
Just accept my suggestions which are concerning documentation only - then you can merge right away.
|
||
# Source has higher resolution than target. | ||
# Downscale first, then rectify | ||
if source_gm.is_regular: | ||
# If source is regular | ||
downscaled_gm = source_gm.scale((x_scale, y_scale)) | ||
downscaled_dataset = resample_dataset( | ||
source_ds, | ||
((x_scale, 1, 0), (1, y_scale, 0)), | ||
size=downscaled_gm.size, | ||
tile_size=source_gm.tile_size, | ||
xy_dim_names=source_gm.xy_dim_names, | ||
var_configs=var_configs, | ||
) |
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.
Nice!
Co-authored-by: Norman Fomferra <norman.fomferra@brockmann-consult.de>
Co-authored-by: Norman Fomferra <norman.fomferra@brockmann-consult.de>
Co-authored-by: Norman Fomferra <norman.fomferra@brockmann-consult.de>
Closes #1079
Allow lazy execution of the
resampling_in_space
method. Following changes have been implemented:xy_res
has been added to the functiontransform_grid_mapping()
inxcube/core/gridmapping transform
, which allows the user to set the resolution of the new gridmapping, which speeds up the method, because the estimation of the spatial resolution takes a lot of time if reprojection is required.tile_size
is specified for the resampled grid mapping, it defaults to thetile_size
of the source grid mapping, improving the user-friendliness of resampling and reprojection.Checklist:
New/modified features documented indocs/source/*
CHANGES.md