Skip to content

Biomass reproject + update links#575

Open
HarshiniGirish wants to merge 4 commits into
MAAP-Project:developfrom
HarshiniGirish:biomass_reproject
Open

Biomass reproject + update links#575
HarshiniGirish wants to merge 4 commits into
MAAP-Project:developfrom
HarshiniGirish:biomass_reproject

Conversation

@HarshiniGirish
Copy link
Copy Markdown
Collaborator

No description provided.

@HarshiniGirish HarshiniGirish requested a review from omshinde March 31, 2026 16:05
@review-notebook-app
Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@wildintellect wildintellect requested review from hrodmn and smk0033 and removed request for wildintellect March 31, 2026 17:45
@wildintellect
Copy link
Copy Markdown
Collaborator

I'm redirecting review to @hrodmn and @smk0033 who are working the OGC App Pack example.

@HarshiniGirish
Copy link
Copy Markdown
Collaborator Author

@smk0033 @hrodmn need a review on this notebook please!

Copy link
Copy Markdown
Contributor

@hrodmn hrodmn left a comment

Choose a reason for hiding this comment

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

@HarshiniGirish I'm sorry this PR slipped past me a few months ago!

The STAC item bbox approach is clever but we don't need to do that! I am not sure why these files have a null crs but they are georeferenced. Instead of a crs they have gcps defined (gcps = Ground Control Points).

Here is how you can use it to do the reprojection without guessing using the STAC metadata:

rio_env = rasterio.Env(GDAL_HTTP_HEADERS=f"Authorization: Bearer {token}")
with rio_env:
    with rasterio.open(asset_href) as ds:
        arr = ds.read(1)
        gcps_list, gcp_crs = ds.gcps
        valid = arr[np.isfinite(arr)]
        print("Shape:", arr.shape)
        print("CRS:", ds.crs)
        print("GCPS list:", gcps_list)
        print("GCP CRS:", gcp_crs)
        print("Transform:", ds.transform)
        print("Min/Max:", float(valid.min()), float(valid.max()))

src_arr = arr.copy()
src_height, src_width = src_arr.shape

# Reproject to EPSG:4326 on a clean output grid
dst_crs = "EPSG:4326"  # don't use EPSG:4326 for raster data if possible!

dst_transform, dst_width, dst_height = calculate_default_transform(
    src_crs=gcp_crs,
    dst_crs=dst_crs,
    width=src_width,
    height=src_height,
    gcps=gcps_list
)

reprojected = np.empty((dst_height, dst_width), dtype=src_arr.dtype)

reproject(
    source=src_arr,
    destination=reprojected,
    gcps=gcps_list,
    src_crs=gcp_crs,
    dst_transform=dst_transform,
    dst_crs=dst_crs,
    resampling=Resampling.nearest
)

print("Destination CRS:", dst_crs)
print("Reprojected shape:", reprojected.shape)
print("Destination transform:", dst_transform)

I think we should encourage users to use a different CRS than epsg:4326 for array data like this, so you could figure out roughly where the sample file is then pick a projected CRS that fits the area.

@HarshiniGirish
Copy link
Copy Markdown
Collaborator Author

HarshiniGirish commented Jun 3, 2026

thanks for the feedback @hrodmn. It's up for review again!

@HarshiniGirish HarshiniGirish requested a review from hrodmn June 3, 2026 21:03
@review-notebook-app
Copy link
Copy Markdown

review-notebook-app Bot commented Jun 4, 2026

View / edit / reply to this conversation on ReviewNB

hrodmn commented on 2026-06-04T14:03:26Z
----------------------------------------------------------------

I would just drop the "Because the file already contains ..." sentence because we don't need to reference the STAC item for anything.


@review-notebook-app
Copy link
Copy Markdown

review-notebook-app Bot commented Jun 4, 2026

View / edit / reply to this conversation on ReviewNB

hrodmn commented on 2026-06-04T14:03:27Z
----------------------------------------------------------------

Line #4.    

we can drop references to STAC item bbox everywhere!


@review-notebook-app
Copy link
Copy Markdown

review-notebook-app Bot commented Jun 4, 2026

View / edit / reply to this conversation on ReviewNB

hrodmn commented on 2026-06-04T14:03:28Z
----------------------------------------------------------------

Here's another STAC item bbox reference to remove.


Copy link
Copy Markdown
Contributor

@hrodmn hrodmn left a comment

Choose a reason for hiding this comment

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

Thanks @HarshiniGirish! I left a few more suggestions - let's remove all references to the STAC item bbox approach since we don't need to plant that seed in any reader's mind 😆

The plot at the end suggests that nodata values are not getting masked out so you should take another look at your approach.

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