Skip to content

Analysis mode is now also derived from non-str sources#44

Merged
forman merged 9 commits into
mainfrom
forman-40-detect_analysis_mode_from_product_type
Apr 16, 2025
Merged

Analysis mode is now also derived from non-str sources#44
forman merged 9 commits into
mainfrom
forman-40-detect_analysis_mode_from_product_type

Conversation

@forman
Copy link
Copy Markdown
Collaborator

@forman forman commented Apr 15, 2025

Analysis mode is now also derived from non-str sources.

Closes #40

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Files with missing lines Coverage Δ
xarray_eopf/amode.py 100.00% <100.00%> (ø)
xarray_eopf/amodes/sentinel2.py 100.00% <100.00%> (ø)
xarray_eopf/backend.py 97.77% <100.00%> (+1.48%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@forman forman requested a review from konstntokas April 15, 2025 15:59
@forman forman marked this pull request as ready for review April 15, 2025 15:59
Copy link
Copy Markdown
Collaborator

@konstntokas konstntokas left a comment

Choose a reason for hiding this comment

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

Everything looks good to me.

Please consider my suggestions below — it would be helpful if you could elaborate on my comments. That said, they’re all minor, so I'm happy to approve with suggestions.

Comment thread xarray_eopf/backend.py
Comment on lines +58 to +61
product_type: Optional product type name, such as `"MSIL1C"`.
Only used if `op_mode="analysis"`. You should not need
pass this argument, if the filename inherent to `filename_or_obj`
adheres to EOPF naming conventions.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
product_type: Optional product type name, such as `"MSIL1C"`.
Only used if `op_mode="analysis"`. You should not need
pass this argument, if the filename inherent to `filename_or_obj`
adheres to EOPF naming conventions.
product_type: Optional product type name, such as `"MSIL1C"`.
Only used if `op_mode="analysis"`; typically not required if
`filename_or_obj` follows EOPF naming conventions.

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.

I prefer staying with my version as filename_or_obj may be some other object which cannot directly follow a naming convention, however its path or root attribute can.

But I like the semicolon.

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.

Rephrased.

Comment thread xarray_eopf/backend.py Outdated
Comment thread xarray_eopf/backend.py
Comment on lines +132 to +135
product_type: Optional product type name, such as `"MSIL1C"`.
Only used if `op_mode="analysis"`. You should not need
pass this argument, if the filename inherent to `filename_or_obj`
adheres to EOPF naming conventions.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
product_type: Optional product type name, such as `"MSIL1C"`.
Only used if `op_mode="analysis"`. You should not need
pass this argument, if the filename inherent to `filename_or_obj`
adheres to EOPF naming conventions.
product_type: Optional product type name, such as `"MSIL1C"`.
Only used if `op_mode="analysis"`; typically not required if
`filename_or_obj` follows EOPF naming conventions.

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.

Same here.

Comment thread xarray_eopf/backend.py Outdated
Comment thread tests/test_amode.py Outdated
self.assertIsInstance(AnalysisMode.guess("TEST.zarr"), TestMode)
self.assertIsInstance(AnalysisMode.guess({}, product_type="TEST"), TestMode)
self.assertIsInstance(
AnalysisMode.guess("TEST.zarr", product_type="REST"), TestMode
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This behavior isn't intuitive to me. It first tries to guess the analysis mode from the product type "REST", which fails, and then proceeds to derive it from "TEST.zarr". I would have expected it to fail outright if the first guess didn't succeed.

That said, perhaps there's a reason you chose to implement it using two separate if statements instead of an ifelif structure?

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.

I agree. If product_type is provided, it should be used and fail if it does not succeed. Will change this. Thanks!

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 tests/test_amode.py
fsspec.filesystem("local").get_mapper("test3.zarr")
)
self.assertIsInstance(path, str)
self.assertEqual("test3.zarr", Path(path).name)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
self.assertEqual("test3.zarr", Path(path).name)
self.assertEqual("test3.zarr", path)

Or am I missing something?

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.

Fine! Copy/paste.

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.

Nope, it was correct! Path(path).name gets the filename of an absolute path.

Comment thread tests/test_amode.py
# From zarr.storage.DirectoryStore
path = AnalysisMode._source_to_path(zarr.storage.DirectoryStore("test4.zarr"))
self.assertIsInstance(path, str)
self.assertEqual("test4.zarr", Path(path).name)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
self.assertEqual("test4.zarr", Path(path).name)
self.assertEqual("test4.zarr", path)

See comment above

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.

Same here, it is correct.

forman and others added 6 commits April 16, 2025 08:43
Co-authored-by: Konstantin Ntokas <38956538+konstntokas@users.noreply.github.com>
Co-authored-by: Konstantin Ntokas <38956538+konstntokas@users.noreply.github.com>
Co-authored-by: Konstantin Ntokas <38956538+konstntokas@users.noreply.github.com>
Co-authored-by: Konstantin Ntokas <38956538+konstntokas@users.noreply.github.com>
@forman forman requested a review from konstntokas April 16, 2025 07:19
@forman forman merged commit 2cccebc into main Apr 16, 2025
2 checks passed
@forman forman deleted the forman-40-detect_analysis_mode_from_product_type branch April 16, 2025 07:56
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.

Derive product type if not explicitly given

2 participants