Skip to content

Subsetting of datasets with 2d coordinates#12

Merged
konstntokas merged 6 commits into
mainfrom
konstntokas-003-subset_irregular_dataset
Sep 22, 2025
Merged

Subsetting of datasets with 2d coordinates#12
konstntokas merged 6 commits into
mainfrom
konstntokas-003-subset_irregular_dataset

Conversation

@konstntokas

@konstntokas konstntokas commented Sep 16, 2025

Copy link
Copy Markdown
Collaborator
  • Improved xcube_resampling.utils.clip_dataset_by_bbox to support datasets with
    2D coordinates. This function is also used internally by
    xcube_resampling.rectify.rectify_dataset.
  • Added reproject_bbox, a utility to reproject a bounding box from one CRS to another.
  • Added bbox_overlap, a utility that computes the fraction of the source bounding box
    overlapped by the target bounding box.
    Closes Implent subsetting of a irregular dataset #3

Checklist:

  • Add unit tests and/or doctests in docstrings
  • Add docstrings and API docs for any new/modified user-facing classes and functions
  • New/modified features documented in docs/
  • Changes documented in CHANGES.md
  • CI checks pass
  • Test coverage remains or increases (target 100%)

@codecov

codecov Bot commented Sep 16, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.37398% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.81%. Comparing base (0ec6c04) to head (25284b8).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
xcube_resampling/rectify.py 94.28% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #12      +/-   ##
==========================================
- Coverage   98.85%   98.81%   -0.05%     
==========================================
  Files          21       21              
  Lines        1924     2021      +97     
==========================================
+ Hits         1902     1997      +95     
- Misses         22       24       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@konstntokas
konstntokas requested a review from forman September 18, 2025 11:34

@forman forman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please also check API of xcube.core.geom for commonalities.

Comment thread xcube_resampling/utils.py Outdated
return target_bbox


def bbox_overlap(source_bbox, target_bbox):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Add types

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

done

Comment thread xcube_resampling/utils.py Outdated
& (ds[y_coord] >= bbox[1])
& (ds[y_coord] <= bbox[3])
)
mask = mask.load()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

load will modify the original dataset which is not always wanted, i.e., users loose chunking. Either make it an option, but preferrably we should stay in dask world if it is a dask array. If this isn't possible, please comment in code, but anyway, use DataArray.compute() or DataArray.values to not modify the original dataset.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Keeping it in dask array, will load the coordinates twice in

rows = np.any(mask, axis=1)
cols = np.any(mask, axis=0)

also when this is implemented in dask. I therefore wanted to specifically load the mask and get the indices using purely numpy.

I change to mask = mask.values, since the array is used in numpy functions only. Further, I added a comment into the code.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

OK!

Comment thread docs/api.md

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You should add required type aliases from constants so the documentation can refer to them.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@konstntokas

Copy link
Copy Markdown
Collaborator Author

Please also check API of xcube.core.geom for commonalities.

I looked at it shortly. I will not be able to work on this this week. I put it on my list and will merge this module with the utils.py in xcube-resampling in the next release.

@konstntokas
konstntokas requested a review from forman September 22, 2025 10:54
@konstntokas
konstntokas merged commit d3c6b65 into main Sep 22, 2025
1 of 3 checks passed
@konstntokas
konstntokas deleted the konstntokas-003-subset_irregular_dataset branch September 22, 2025 11:24
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.

Implent subsetting of a irregular dataset

2 participants