openradar / xradar

A tool to work in weather radar data in xarray
https://docs.openradarscience.org/projects/xradar
MIT License
91 stars 17 forks source link

Module Design #7

Open mgrover1 opened 1 year ago

mgrover1 commented 1 year ago

Let's think about the design!

We would like users to be able to use the following:

import xarray as xr
import xradar

ds = xr.open_dataset("some_radar_data.nc", engine="xradar")

This would return a datatree, with a tree which contains datasets.

We should use the xwrf package as an inspiration here - https://github.com/xarray-contrib/xwrf, which uses a similar approach and API design.

The general xradar reader here would contain the different formats within it (ex. ODIM_H5, CfRadial1, CfRadial2).

General API

One decision we need to make is whether we should make functionality:

kmuehlbauer commented 1 year ago

@mgrover1 The loading would not work as long as xarray does not adopt datatree unfortunately. Currently we would need to employ datatree functionality directly or to begin with just return a specific sweep.

mgrover1 commented 1 year ago

@kmuehlbauer I think we can do this with the existing datatree API, so it might look like

import datatree as dt
import xradar

ds = dt.open_datatree("some_radar_data.nc", engine="xradar")

We would just need to make sure the backend API is configured to support this

kmuehlbauer commented 1 year ago

I'll try this, but there might be more involved with the Backend API. The thing is, the backend API is relying on getting back single groups from files by calling open_dataset multiple times . With cfradial1 there is only one call to open_dataset. Not sure, if it makes much sense to replicate the multiple open approach for cfradial1 files. Anyway, thanks for the suggestion, I''ll definitely have a look that way.

kmuehlbauer commented 1 year ago

@mgrover1 Ah, and we would need to make datatree work with other engines...

https://github.com/xarray-contrib/datatree/blob/main/datatree/io.py#L55-L60

mgrover1 commented 1 year ago

@kmuehlbauer - what would you think if we redesigned the model module? Right now, it has a collection of helper functions, but each backend/tree needs to put together its own implementation of it; what if we created a main xradar object, that we used in each of the IO modules, as well as submodules?

This object would then have the other methods associated with it (ex. get_x_y_z

ex.

dt= Xradar()

This would also allow us to add special indexing functionality and such (allowing things like dt.isel(azimuth=0)) which is not currently possible since it is not one of our dimensions.

kmuehlbauer commented 1 year ago

You mean like a class wrapper around xr.Dataset? Hmm, how would we get a sweep dataset out of it? Or do you mean accessor based? I think I'm missing something.

mgrover1 commented 1 year ago

I think a wrapper around the datatree...

kmuehlbauer commented 1 year ago

Ok, I can't imagine that right now, but we can try several things. Not bound to a single solution.

mgrover1 commented 1 year ago

I can draft something up :)

jfigui commented 1 year ago

Hi, Personally I favor kdp(xradar) as an approach. Less magic. Cheers,

Jordi