weiji14 / deepicedrain

Mapping and monitoring deep subglacial water activity in Antarctica using remote sensing and machine learning, with ICESat-2!
GNU Lesser General Public License v3.0
30 stars 8 forks source link

Reading multiple ICESat-2 ATL11 point cloud data nicely via Zarr #100

Open weiji14 opened 4 years ago

weiji14 commented 4 years ago

Gathering some notes on how best to read multiple ICESat-2 ATL11 data (basically a point cloud) in a user friendly way, with metadata preserved!

TLDR: Be able to do xr.open_mfdataset("ATL11_*.h5", engine="zarr", ...).

Inspired by the blog post "Cloud-Performant NetCDF4/HDF5 Reading with the Zarr Library". Zarr is an amazing project, and I really like the .zmetadata json file which can be opened with a text editor and tell you stuff about the data. The dream would be to read HDF5 files in an out-of-core manner with Zarr like speed/abilities (through the .zmetadata pointer).

Jupyter notebook demo can be found at https://github.com/rsignell-usgs/hurricane-ike-water-levels/blob/master/coawst_3ways.ipynb. See also discussion thread at https://github.com/zarr-developers/zarr-python/issues/535 on "Using the Zarr library to read HDF5".

Main hurdles to get through, dependent on upstream, there's two 'separate' parts:

Current situation in that I do HDF5 -> Zarr conversion, and read from that. It would be nice to stick to the original HDF5 data source (though I might need to flatten the nested ICESat-2 ATL11 data structure). Note that I'm not necessarily after raw speed, I just prefer readability (i.e. having xarray's wonderful annotated metadata).

Other open Issues/Pull Requests:

Blog posts:

You can tell I had way too many tabs open on my browser :laughing:

weiji14 commented 1 year ago

Putting down some notes on a potential HDF5 -> pandas.DataFrame direct conversion (that skips the intermediate xarray format) using the code at https://github.com/MAAP-Project/gedi-subsetter (thanks @chuckwondo for the pointer!).

Just some things to play with once I get some free time :slightly_smiling_face:

chuckwondo commented 1 year ago

Awesome! Regarding the subset_hdf5 function, that's specific to the structure of GEDI data files (in particular, in relation to the BEAM* top-level groups), so you wouldn't want to use it for non-GEDI data files. For non-GEDI data files, you can directly use H5DataFrame.

weiji14 commented 1 year ago

H5DataFrame works for ICESat-2 ATL03 - https://github.com/ICESAT-2HackWeek/h5cloud/pull/5 :tada: There are some small quirks (e.g. the need to access groups/variable via df["group/variable"] to get at the data), but it should work for ATL11 too :crossed_fingers:

We're actually working on some benchmarks over in that repo (e.g. https://github.com/ICESAT-2HackWeek/h5cloud/pull/9), and the H5DataFrame read method is looking to be ~4x faster than xarray's h5netcdf (and that's without considering the conversion from xarray.Dataset -> pd.DataFrame), so looking real promising!