Skip to content
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

Dtree constructor #221

Merged
merged 56 commits into from
Nov 2, 2024
Merged

Dtree constructor #221

merged 56 commits into from
Nov 2, 2024

Conversation

aladinor
Copy link
Member

@aladinor aladinor commented Oct 27, 2024

refactored the code to use the DataTree.from_dict constructor to create the DataTree structure instead of manually setting each node during the creation process.

@kmuehlbauer
Copy link
Collaborator

@aladinor I very much agree to your proposal of using the more intuitive from_dict approach. I've incorporated your changes from #220 over in #218. It works!

@kmuehlbauer kmuehlbauer mentioned this pull request Oct 28, 2024
2 tasks
@aladinor
Copy link
Member Author

aladinor commented Oct 28, 2024

Thanks, @kmuehlbauer, for implementing this in #223. I was working during the weekend doing some tests, and I had some questions before submitting other changes. However, I think I can add them under the new head node. On the other hand, I realized that some backends might not contain the georeference and calibration groups. I understand they might be optional, but compared to cfradial, which includes all of them, should we include them as empty nodes/groups to make them similar in the data model/structure?

@kmuehlbauer
Copy link
Collaborator

On the other hand, I realized that some backends might not contain the georeference and calibration groups. I understand they might be optional, but compared to cfradial, which includes all of them, should we include them as empty nodes/groups to make them similar in the data model/structure?

@aladinor Thanks! Yes, I agree. Citing from the FM301 docs for radar_parameters, radar_calibration groups:

This group may be omitted from the file if no radar parameters are to be stored.

So we are on safe ground, to have these subgroups available, even when they are empty.

@aladinor aladinor reopened this Oct 29, 2024
@aladinor
Copy link
Member Author

aladinor commented Oct 29, 2024

@kmuehlbauer I did some refactoring for keeping all radar_parameters, georeferencing, and calibration subgroups. I am working to make sure all backends look similar. Let me know what you think about this to "copy" this into the others. For now, Iris and Datamet backends are ready. Should I submit all of them in just one PR?

This is how a cfradial dtree will look like

<xarray.DataTree>
Group: /Dimensions:              (sweep: 9)
│   Dimensions without coordinates: sweepData variables:
│       volume_number        int32 4B ...
│       platform_type        |S32 32B ...
│       primary_axis         |S32 32B ...
│       status_str           |S1 1B ...
│       instrument_type      |S32 32B ...
│       time_coverage_start  |S32 32B ...
│       time_coverage_end    |S32 32B ...
│       latitude             float64 8B ...
│       longitude            float64 8B ...
│       altitude             float64 8B ...
│       sweep_group_name     (sweep) <U7 252B 'sweep_0' 'sweep_1' ... 'sweep_8'sweep_fixed_angle    (sweep) float32 36B ...
│   Attributes: (12/13)
│       Conventions:         CF/Radial instrument_parameters radar_parameters rad...
│       version:             1.2title:               TIMREXinstitution:         
│       references:          
│       source:              
│       ...                  ...
│       comment:             
│       instrument_name:     SPOLRVP8site_name:           
│       scan_name:           
│       scan_id:             0platform_is_mobile:  false
├── Group: /sweep_0Dimensions:                    (azimuth: 483, range: 996)
│       Coordinates:
│           time                       (azimuth) datetime64[ns] 4kB 2008-06-04T00:15:...
│           elevation                  (azimuth) float32 2kB ...
│           latitude                   float64 8B ...
│           longitude                  float64 8B ...
│           altitude                   float64 8B ...
│         * azimuth                    (azimuth) float32 2kB 0.0 0.75 ... 358.5 359.2* range                      (range) float32 4kB 150.0 300.0 ... 1.494e+05Data variables: (12/18)
│           sweep_number               int32 4B ...
│           sweep_mode                 <U20 80B 'azimuth_surveillance'prt_mode                   |S32 32B ...
│           follow_mode                |S32 32B ...
│           sweep_fixed_angle          float32 4B ...
│           pulse_width                (azimuth) timedelta64[ns] 4kB ...
│           ...                         ...
│           r_calib_index              (azimuth) int8 483B ...
│           measured_transmit_power_h  (azimuth) float32 2kB ...
│           measured_transmit_power_v  (azimuth) float32 2kB ...
│           scan_rate                  (azimuth) float32 2kB ...
│           DBZ                        (azimuth, range) float32 2MB ...
│           VR                         (azimuth, range) float32 2MB ...
├── Group: /sweep_1Dimensions:                    (azimuth: 483, range: 996)
│       Coordinates:
│           time                       (azimuth) datetime64[ns] 4kB 2008-06-04T00:16:...
│           elevation                  (azimuth) float32 2kB ...
│           latitude                   float64 8B ...
│           longitude                  float64 8B ...
│           altitude                   float64 8B ...
│         * azimuth                    (azimuth) float32 2kB 0.0 0.75 ... 358.5 359.2* range                      (range) float32 4kB 150.0 300.0 ... 1.494e+05Data variables: (12/18)
│           sweep_number               int32 4B ...
│           sweep_mode                 <U20 80B 'azimuth_surveillance'prt_mode                   |S32 32B ...
│           follow_mode                |S32 32B ...
│           sweep_fixed_angle          float32 4B ...
│           pulse_width                (azimuth) timedelta64[ns] 4kB ...
│           ...                         ...
│           r_calib_index              (azimuth) int8 483B ...
│           measured_transmit_power_h  (azimuth) float32 2kB ...
│           measured_transmit_power_v  (azimuth) float32 2kB ...
│           scan_rate                  (azimuth) float32 2kB ...
│           DBZ                        (azimuth, range) float32 2MB ...
│           VR                         (azimuth, range) float32 2MB ...
├── Group: /sweep_2Dimensions:                    (azimuth: 482, range: 996)
│       Coordinates:
│           time                       (azimuth) datetime64[ns] 4kB 2008-06-04T00:17:...
│           elevation                  (azimuth) float32 2kB ...
│           latitude                   float64 8B ...
│           longitude                  float64 8B ...
│           altitude                   float64 8B ...
│         * azimuth                    (azimuth) float32 2kB 0.0 0.75 ... 358.5 359.2* range                      (range) float32 4kB 150.0 300.0 ... 1.494e+05Data variables: (12/18)
│           sweep_number               int32 4B ...
│           sweep_mode                 <U20 80B 'azimuth_surveillance'prt_mode                   |S32 32B ...
│           follow_mode                |S32 32B ...
│           sweep_fixed_angle          float32 4B ...
│           pulse_width                (azimuth) timedelta64[ns] 4kB ...
│           ...                         ...
│           r_calib_index              (azimuth) int8 482B ...
│           measured_transmit_power_h  (azimuth) float32 2kB ...
│           measured_transmit_power_v  (azimuth) float32 2kB ...
│           scan_rate                  (azimuth) float32 2kB ...
│           DBZ                        (azimuth, range) float32 2MB ...
│           VR                         (azimuth, range) float32 2MB ...

├── Group: /radar_parametersDimensions:                   ()
│       Data variables:
│           radar_beam_width_h        float32 4B ...
│           radar_antenna_gain_v      float32 4B ...
│           radar_antenna_gain_h      float32 4B ...
│           radar_beam_width_v        float32 4B ...
│           radar_receiver_bandwidth  float32 4B ...
├── Group: /georeferencing_correctionDimensions:                            ()
│       Data variables: (12/16)
│           elevation_correction               float32 4B ...
│           heading_correction                 float32 4B ...
│           eastward_ground_speed_correction   float32 4B ...
│           latitude_correction                float32 4B ...
│           pitch_correction                   float32 4B ...
│           longitude_correction               float32 4B ...
│           ...                                 ...
│           vertical_velocity_correction       float32 4B ...
│           tilt_correction                    float32 4B ...
│           northward_ground_speed_correction  float32 4B ...
│           pressure_altitude_correction       float32 4B ...
│           roll_correction                    float32 4B ...
│           radar_altitude_correction          float32 4B ...
└── Group: /radar_calibration
        Dimensions:                   ()
        Data variables: (12/45)
            time                      |S32 32B ...
            pulse_width               timedelta64[ns] 8B ...
            xmit_power_h              float32 4B ...
            xmit_power_v              float32 4B ...
            two_way_waveguide_loss_h  float32 4B ...
            two_way_waveguide_loss_v  float32 4B ...
            ...                        ...
            test_power_h              float32 4B ...
            test_power_v              float32 4B ...
            receiver_slope_hc         float32 4B ...
            receiver_slope_vc         float32 4B ...
            receiver_slope_hx         float32 4B ...
            receiver_slope_vx         float32 4B ...

Copy link

codecov bot commented Oct 29, 2024

Codecov Report

Attention: Patch coverage is 94.55782% with 8 lines in your changes missing coverage. Please review.

Project coverage is 92.80%. Comparing base (b88218e) to head (9c626c4).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
xradar/io/backends/common.py 92.15% 4 Missing ⚠️
xradar/io/backends/hpl.py 72.72% 3 Missing ⚠️
xradar/io/backends/metek.py 88.88% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #221   +/-   ##
=======================================
  Coverage   92.79%   92.80%           
=======================================
  Files          26       26           
  Lines        4957     5003   +46     
=======================================
+ Hits         4600     4643   +43     
- Misses        357      360    +3     
Flag Coverage Δ
notebooktests 79.03% <88.43%> (+0.09%) ⬆️
unittests 91.22% <91.15%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@kmuehlbauer
Copy link
Collaborator

@aladinor Yes, make this a bulk refactor. No need to separate I think. But do as you prefer.

The repr looks great!

@syedhamidali
Copy link
Contributor

syedhamidali commented Oct 29, 2024

Hi @aladinor, @kmuehlbauer I think we should cover the pytests for the below given functions with this PR in the iris.py module to increase codecov. Currently, it is at 85%.

  1. read_from_record
  2. decode_data
  3. get_sweep
  4. array_from_file

@syedhamidali
Copy link
Contributor

I added these above-mentioned pytests in #226

@kmuehlbauer
Copy link
Collaborator

@aladinor I've found the issue with to_zarr. "sweep_group_name" was missing the fixup of the old dtype (int) to the new dtype (str). Not sure what's going on with the GH Actions, though. Maybe a temporal disturbance...

@kmuehlbauer kmuehlbauer reopened this Oct 30, 2024
@kmuehlbauer
Copy link
Collaborator

kmuehlbauer commented Oct 30, 2024

OK, seems like GH Actions has had an incident (https://www.githubstatus.com/)

Copy link
Collaborator

@kmuehlbauer kmuehlbauer left a comment

Choose a reason for hiding this comment

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

This is looking really good. Only the new entries in the radar_calibration subgroup need fixing.

Co-authored-by: Kai Mühlbauer <[email protected]>
xradar/model.py Outdated Show resolved Hide resolved
xradar/model.py Outdated Show resolved Hide resolved
xradar/model.py Outdated Show resolved Hide resolved
xradar/model.py Outdated Show resolved Hide resolved
xradar/model.py Outdated Show resolved Hide resolved
xradar/model.py Outdated Show resolved Hide resolved
@kmuehlbauer
Copy link
Collaborator

@aladinor Sorry, I've bugged a paranthesis ;-)

@kmuehlbauer
Copy link
Collaborator

@aladinor Huge thanks to you! I think we can live with the slight inconsistencies in the model. We can handle that later.

Please add entry in history.md, I'm going to merge if you are ready!

@syedhamidali
Copy link
Contributor

Great job @aladinor! Thank you very much!

@aladinor
Copy link
Member Author

aladinor commented Nov 2, 2024

Thank you @kmuehlbauer and @syedhamidali for your help. Excited to have xradar 0.8.0! soon

@kmuehlbauer kmuehlbauer merged commit 794c606 into openradar:main Nov 2, 2024
12 checks passed
@kmuehlbauer
Copy link
Collaborator

😍 @aladinor 💯

@aladinor aladinor deleted the dtree-constructor branch November 8, 2024 17:08
rcjackson pushed a commit to rcjackson/xradar that referenced this pull request Nov 26, 2024
* refactoring dtree node apend using _attach_sweep_groups function
* refactoring iris datatree to use from_dict constructor
* running pre-commit hook
* refactoring calibration subgroup
* dropping common attributes present in all sweeps
* refactoring to use from_dict datatree constructor
* refactoring loop by iterating only over sweeps
* fixing failing test with attributes
* addding comments
* Update xradar/io/backends/iris.py
* fix lint
* fixing typo
* refactoring datamet backend to use from_dict datatree construnctor
* fixing issue with group test since datamet now has root, georefernce, radar_parameter, and calib groups
* adding some calibration variables from Furuno datasets
* refactoring furuno backeds to use from_dict contructor
* getting ride of unncessary attributes in the root dataset
* updating global attrributes
* adding gamic radar calibration parameters
* refactoring gamic backend to use from_dict datatree constructor
* refactoring code. moving _get_required_root_dataset, _get_subgroup, to common.py file
* using dtree.match to iterate over sweep nodes
* refactoring _get_subgroups and _get_required_root funcition
* fixing typo
* adding _get_radar_calibration fuction
* refactoring and moving _get_requiered_root_Dataset, _get_subgroup, and _get_calibration function to commo.py file
* refactoring and moving _get_calibration function to commo.py file
* refactoring hpl backends to use from_dict contructor and adding sweeps
* using radar_calibration group from common.py in Datamet backend
* using radar calibration subgrup fucntion from common.py in iris backend
* allowing metek to read lines from gzip file when using context manager
* refactoring _get_required_root function to fit with metek backend
* refactoring metek backend to use from_dict constructor
* fixing nexrad test that support the radar_calibration, georeference, and parameter group
* refactoring nexrad backend to use from_dict constructor
* reformating odim test to include calibration, georeference, and radar parameter groups in odim backend
* refactoring odim backend to use from_dict constructor
* refactoring odim export to iterate only over sweeps
* refactoring rainbow test to only iterate over sweeps
* refactoring rainbow backend to use from_dict constructor
* fixin typo
* adding test for _get_requered_root_group, _get_subgroup, and _get_radar_calibration functions
* Update xradar/model.py
* Update history.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

DataTree.from_dict constructor to create the DataTree structure instead of manually setting each node
3 participants