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

Array Interface? #1

Open
rafaqz opened this issue Nov 27, 2019 · 3 comments
Open

Array Interface? #1

rafaqz opened this issue Nov 27, 2019 · 3 comments

Comments

@rafaqz
Copy link

rafaqz commented Nov 27, 2019

Hi, I was pleased to find this package existed!

At some stage I want to add a GRIB wrapper to GeoData.jl, leveraging this package. It will give a common interface and conversion to NetCDF, GeoTiff, grd and other formats.

It's much easier to write a reliable interface, and do a lot of other things if there is already an Array interface wrapping access to the underlying data as if it is a regular julia array. This can still happen inside a safe function, dispatching on the type that is passed into the do block/anonymous function.

NCDatasets.jl does this quite well for their Variable type:
https://github.com/Alexander-Barth/NCDatasets.jl/blob/master/src/NCDatasets.jl#L1063-L1130

Anyway, just a thought if you are doing any more work on this package

Cheers

Edit: in case its not clear, using indexing woudl be to allow loading subsets of the data from disk without loading the whole file, which can be much quicker when you have to load a lot of files.

@weech
Copy link
Owner

weech commented Dec 17, 2019

Hi, sorry for the late response.
This package is a very thin wrapper around ecCodes, and implementing Array would preclude "loading subsets of the data from disk without loading the whole file". ecCodes provides an iterator interface, so, in order to have random access, you would have to read through the entire file. There might be a way to get around that, but I wouldn't know how.

@rafaqz
Copy link
Author

rafaqz commented Dec 17, 2019

Ok my memory of how grib works is shaky, I've only really used it from Haskel years ago. How are you actually retrieving 2d raster data?

@weech
Copy link
Owner

weech commented Dec 17, 2019

I don't know how ecCodes works internally, and the GRIB standard is complicated. The interface ecCodes provides is basically an iterator that returns pointers to message handles, and get/set functions that take a message handle pointer, a string that is the key you want to get/set, and a pointer to an array. To get the 2d raster data, you iterate through the file (using the function codes_grib_handle_new_from_file) until you are at the variable you want, and then call the getter function (codes_get_double_array) with the key "values".
The getter function fills a pre-allocated array with the raster data.

Edited with more details

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

No branches or pull requests

2 participants