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

ENH: xarray grid output #1477

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Conversation

syedhamidali
Copy link
Contributor

To streamline the process of extracting a subset from pyart.core.grid or the grid object, I propose to add a few more variables to the xarray dataset that mirrors the grid object. When this xarray dataset is written to a NetCDF file, it becomes equivalent to the original pyart.core.grid object.

How can this be utilized?

import pyart

# Reading a grid from a netcdf file
grid = pyart.io.read_grid("file.nc")

# Converting the grid to an xarray dataset
ds = grid.to_xarray()

# Slicing the dataset based on x and y coordinates
ds = ds.sel(x=slice(5000, 70000), y=slice(5000, 70000), drop=True)

# Saving the sliced dataset to a new netcdf file
ds.to_netcdf("outfile.nc")

Subsequently, it is possible to read the modified dataset using pyart as follows:

# Reading the modified dataset with pyart
grid_small = pyart.io.read_grid("outfile.nc")

This enhances the process of working with grid data, making it more convenient and efficient for users.

if self.radar_name is not None:
radar_name = self.radar_name["data"]
ds["radar_name"] = xarray.DataArray(
np.array([b"".join(radar_name)]),
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the reason for using a byte-encoded name here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because some radar data use the following convention:

print(grid.radar_name)
{'long_name': 'Name of radar used to make the grid',
 'data': masked_array(data=[[b'D', b'O', b'W', b'8']],
              mask=False,
        fill_value=b'N/A',
             dtype='|S1')}

To make it look like b'DOW8, because if you read a pyart or radx generated grid using xarray, it shows up like array([b'DOW8'], dtype='|S4'). That's why, I am using byte-encoded name so the result looks like

ds["radar_name"] = xarray.DataArray(
                np.array([b"".join(grid.radar_name)])
print(ds["radar_name"])
array([b'DOW8'], dtype='|S4')

if "_include_lon_0_lat_0" in projection:
include = projection["_include_lon_0_lat_0"]
projection["_include_lon_0_lat_0"] = ["false", "true"][include]
ds["projection"] = xarray.DataArray(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this variable, along with the other origin_latitude, etc. variables belong as coordinates - can you add those to the list of coordinates? I think that is what is causing the failure in CI here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mgrover1 My apologies for the late response; I've been tied up with exams recently and have another busy week ahead. I'll get to it as soon as possible. Thanks for your suggestion.

Copy link
Collaborator

Choose a reason for hiding this comment

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

No worries! Take your time - just let me know when you are ready for another review!

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.

None yet

3 participants