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

How do I read a GeoImage into integral typed numpy arrays? #131

Closed
ra-tolson opened this issue Aug 31, 2017 · 3 comments
Closed

How do I read a GeoImage into integral typed numpy arrays? #131

ra-tolson opened this issue Aug 31, 2017 · 3 comments

Comments

@ra-tolson
Copy link

This is another question related to migrating gips from gippy 0.3 to 1.0.

I've instantiated GeoImages using an existing file in a couple different ways, sometimes in a form that lets me specify a dtype, sometimes not. But regardless of the value of eg image.type().string(), or image[0].type().string(), the numpy array returned by image.read() is always float64. I can work around that by eg image.read().astype('uint16'), but that results in two unneeded type conversions, which hurts performance.

The band I need to process is the 16-bit QA band for landsat C1 data. float64 is obviously a type error if you try to do bit-fiddling on it (>> and & in our case).

@matthewhanson
Copy link
Member

@ags-tolson

The underlying gippy C++ code uses templates, but in order to create Python bindings the templates need to be instantiated first into a specific type. The swig bindings should be taking account for this though by checking the data type then returning an array of the appropriate type, you can see example of some of that logic here in the swig interface file:
https://github.com/gipit/gippy/blob/master/gippy/gippy.i#L154

However, some caveats, if there is a gain or offset, or any function to be applied, then it changes the return array to double, because it can't otherwise tell what the most appropriate data type would be.

All that being said, it sounds like it's not working for some reason and just defaulting to a returning a double. I thought I had tested this quite a bit in version 1.0, since it's a rather complicated thing (multi step, first it has to get the right CImg type array, then it converts to to a numpy array on return, but without copying values and just using pointers), but sounds like it's broken somewhere.

I'll run some additional tests and see what I come up with. Thanks for bringing it up.

ircwaves added a commit to ircwaves/gippy that referenced this issue Sep 19, 2017
@ircwaves
Copy link
Member

GeoRaster.read_raw is a work around.

@matthewhanson
Copy link
Member

This has been resolved on develop with PR #132

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

3 participants