Skip to content

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

Open
wants to merge 25 commits into
base: simplify_pixel_grid_params
Choose a base branch
from

Conversation

tylere
Copy link
Collaborator

@tylere tylere commented Mar 1, 2025

Simplifies how the desired pixel grid information is specified when opening of datasets.
Previously, crs, scale, projection and geometry were available as parameters.
With this change crs, crs_transform, and shape_2d are used to specify the grid.
See #217 for the rational for this change.

Other changes:

  • Adds pixi package manager configuration files (useful for developers who use pixi)
  • Limits Python to 3.12 (to avoid version conflicts among dependencies)
  • Updates the README code examples

Note that this PR does not update code in the examples/ folder.

@tylere tylere requested review from jdbcode and naschmitz March 1, 2025 00:50
@tylere tylere mentioned this pull request Mar 1, 2025

import ee
from pyproj import Transformer
from rasterio.transform import Affine
Copy link
Member

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.

Copy link
Collaborator

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)
Copy link
Member

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.

Copy link
Member

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):
Copy link
Member

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.

Copy link
Collaborator

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.

Copy link
Collaborator Author

@tylere tylere Mar 18, 2025

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)
Copy link
Member

@jdbcode jdbcode Mar 18, 2025

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

for v in ds.values():
print(f'{v = }')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra print statement.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed with 0228871

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");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double quotes here.

Copy link
Collaborator Author

@tylere tylere Mar 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by 9770fae and 68c1905

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants