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

NoData issue #117

Open
iferencik opened this issue Jan 28, 2022 · 1 comment
Open

NoData issue #117

iferencik opened this issue Jan 28, 2022 · 1 comment

Comments

@iferencik
Copy link

i am reading a COG and upon opening I am getting the following error

async with COGReader(cog_url) as cog:
    print(cog.nodata)

Traceback (most recent call last): File "/work/py/hrea-zarr/pipeline/core.py", line 54, in <module> asyncio.run( File "/usr/lib/python3.8/asyncio/runners.py", line 44, in run return loop.run_until_complete(main) File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete return future.result() File "/work/py/hrea-zarr/pipeline/core.py", line 13, in read_cog print(cog.nodata) File "/work/python/aiocogeo/aiocogeo/cog.py", line 278, in nodata return self.ifds[0].nodata File "/work/python/aiocogeo/aiocogeo/ifd.py", line 167, in nodata return int(self.NoData.value[0]) if self.NoData else None ValueError: invalid literal for int() with base 10: b'-'

upon a closer lock, the code is trying to convert the NoData tag into an int

the self.NoData attr is

Tag(code=42113, name='NoData', count=25, tag_type=TagType(format='c', size=1), length=25, value=(b'-', b'3', b'.', b'3', b'9', b'9', b'9', b'9', b'9', b'9', b'9', b'9', b'9', b'9', b'9', b'9', b'9', b'9', b'9', b'6', b'e', b'+', b'3', b'8', b'\x00'))

which is a tuple of 1 character bytes objects

Now I am not sure whether the COG file is wrong or aiocogeo is not reading this correctly.
A quick solution that could fix this :

        try:
            return int(b''.join(self.NoData.value).strip(b'\x00')) if self.NoData else None
        except ValueError:
            return float(b''.join(self.NoData.value).strip(b'\x00')) if self.NoData else None

This basically strips the zero terminated string and tries to convert it into an int and then float number.

@KeynesYouDigIt
Copy link

Is there an example file you can point to? Seems like an easy fix and would love to take a crack at it but would want to be able to test it with the same data currently causing the error. Assuming this isn't occurring for most/all cog files.

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