-
Notifications
You must be signed in to change notification settings - Fork 34
Simplify proj params #225
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
base: simplify_pixel_grid_params
Are you sure you want to change the base?
Simplify proj params #225
Conversation
PiperOrigin-RevId: 712905652
PiperOrigin-RevId: 712996660
Ensure shape_2d is a tuple
|
||
import ee | ||
from pyproj import Transformer | ||
from rasterio.transform import Affine |
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.
Currently rasterio
and shapely
are optional deps. Do you think they should be required? Like do you imagine that these helpers are essential for supporting the refactor? Given that some helpers are used in the readme examples, I think probably they should be required.
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.
Let's try to use the affine
package directly.
crs_transform[4] = y_scale | ||
case _: | ||
raise TypeError | ||
affine_transform = Affine(*crs_transform) |
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.
Is it necessary to cast as Affine object? I ask because it gets converted to list before being returned - we're not e.g., using any affine methods on the object.
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.
It's probably good for validating, but we should try to use affine
library directly, instead of from rasterio.transform
to avoid the sometimes troublesome dependency.
xee/helpers.py
Outdated
) -> list: | ||
"""Update the CRS transform's scale parameters.""" | ||
match scaling: | ||
case int(xy_scale) | float(xy_scale): |
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.
Given that sometimes y scale is negative and really rarely x is negative (not sure I've ever seen), I wonder if we should only allow tuple - people have to specify x and y explicitly.
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'll remove the option to specify a single scalar. Instead, users must explicitly set x and y scale.
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.
Addressed by d661309
grid_x_min = math.floor(x_min / x_scale) * x_scale | ||
grid_y_max = math.ceil(y_max / y_scale) * y_scale | ||
|
||
affine_transform = Affine.translation(grid_x_min, grid_y_max) * Affine.scale(x_scale, -y_scale) |
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'm not sure we should assume negative y (force negative y). If the data are flipped from provider or other reason, y scale might need to be positive.
Examples of positive y scale data:
print(ee.ImageCollection("COPERNICUS/S5P/NRTI/L3_NO2").first().projection().getInfo()) # positive y
print(ee.ImageCollection("NOAA/GOES/16/FDCF").first().projection().getInfo()) # positive y
xee/ext_integration_test.py
Outdated
for v in ds.values(): | ||
print(f'{v = }') |
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.
Extra print statement.
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.
Removed with 0228871
xee/ext_integration_test.py
Outdated
projection=ee.Projection('EPSG:4326', [0.0025, 0, 0, 0, -0.0025, 0]), | ||
) | ||
def test_extract_grid_params_from_image_collection(self): | ||
dem = ee.ImageCollection("COPERNICUS/DEM/GLO30"); |
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.
Double quotes here.
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.
Simplifies how the desired pixel grid information is specified when opening of datasets.
Previously,
crs
,scale
,projection
andgeometry
were available as parameters.With this change
crs
,crs_transform
, andshape_2d
are used to specify the grid.See #217 for the rational for this change.
Other changes:
Note that this PR does not update code in the
examples/
folder.