-
Notifications
You must be signed in to change notification settings - Fork 21
ADD: Cfradial2 Reader #288
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
syedhamidali
wants to merge
9
commits into
openradar:main
Choose a base branch
from
syedhamidali:cfradial2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5095f58
ADD: Cfradial2 Reader
syedhamidali ececf42
FIX: PR serial fix
syedhamidali 9a2e654
FIX: Fix Tests
syedhamidali 5ecd3aa
FIX: Run Black
syedhamidali c173790
FIX: Add zarr to req
syedhamidali 4a22a79
FIX: write to nc instead
syedhamidali 61ef0fd
FIX: Use fixture in pytest
syedhamidali b96f791
FIX: Use fixture in pytest
syedhamidali 3bf46ec
Update docs/history.md
syedhamidali File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,3 +9,4 @@ pyproj | |
| scipy | ||
| xarray >= 2024.10.0 | ||
| xmltodict | ||
| zarr | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| #!/usr/bin/env python | ||
| # Copyright (c) 2023-2025, openradar developers. | ||
| # Distributed under the MIT License. See LICENSE for more info. | ||
|
|
||
| import pytest | ||
| import xarray as xr | ||
| from open_radar_data import DATASETS | ||
|
|
||
| import xradar as xd | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def cfradial1_file(): | ||
| return DATASETS.fetch("cfrad.20080604_002217_000_SPOL_v36_SUR.nc") | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def temp_file(tmp_path): | ||
| return tmp_path / "cfradial2.nc" | ||
|
|
||
|
|
||
| def test_open_cfradial2(temp_file, cfradial1_file): | ||
| # Open the original file using CfRadial1 reader | ||
| dtree = xd.io.open_cfradial1_datatree(cfradial1_file) | ||
|
|
||
| # Write to CfRadial2 NetCDF format | ||
| dtree.to_netcdf(temp_file) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not really sure, but you might have to add kwarg |
||
|
|
||
| # Read back using CfRadial2 reader | ||
| dtree2 = xd.io.open_cfradial2_datatree(temp_file) | ||
|
|
||
| # Check structural correctness | ||
| assert dtree2 is not None, "Failed to open CfRadial2 datatree" | ||
| assert hasattr(dtree2, "children"), "Returned object is not a valid DataTree" | ||
| assert "sweep_0" in dtree2.children, "Missing expected sweep node" | ||
| assert "DBZ" in dtree2["sweep_0"].data_vars, "Missing reflectivity field" | ||
| xr.testing.assert_isomorphic(dtree, dtree2) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| #!/usr/bin/env python | ||
| # Copyright (c) 2022-2025, openradar developers. | ||
| # Distributed under the MIT License. See LICENSE for more info. | ||
|
|
||
| """ | ||
|
|
||
| CfRadial2 | ||
| ========= | ||
|
|
||
| This submodule provides an xarray backend for reading CfRadial2-compliant radar data | ||
| into Xarray `DataTree` structures. It serves as a wrapper around `xarray.open_datatree`. | ||
|
|
||
| Example:: | ||
|
|
||
| import xradar as xd | ||
| dtree = xd.io.open_cfradial2_datatree(filename) | ||
|
|
||
| .. autosummary:: | ||
| :nosignatures: | ||
| :toctree: generated/ | ||
|
|
||
| {} | ||
|
|
||
| """ | ||
|
|
||
| __all__ = [ | ||
| "open_cfradial2_datatree", | ||
| ] | ||
|
|
||
| __doc__ = __doc__.format("\n ".join(__all__)) | ||
|
|
||
| from xarray import open_datatree | ||
|
|
||
|
|
||
| def open_cfradial2_datatree(filename, **kwargs): | ||
| """ | ||
| Open a CfRadial2 file as an xarray DataTree. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| filename : str | ||
| Path to the CfRadial2 file. | ||
| **kwargs : dict | ||
| Additional keyword arguments passed to `xarray.open_datatree`. | ||
|
|
||
| Returns | ||
| ------- | ||
| xarray.DataTree | ||
| The opened DataTree containing the radar data. | ||
| """ | ||
| return open_datatree(filename, **kwargs) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@syedhamidali Maybe my suggestion was a bit brief, but this fixture is already defined in conftest.py as well as the tmp_file fixture. You should be able to just use them here and can remove the re-definitions here.