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

If there is no valid no data value, file loading fails. #47

Open
marthinwurer opened this issue Oct 8, 2019 · 3 comments
Open

If there is no valid no data value, file loading fails. #47

marthinwurer opened this issue Oct 8, 2019 · 3 comments

Comments

@marthinwurer
Copy link

Line of code and stack trace:

>>> raster = gr.from_file(os.path.expanduser("~/Downloads/datasets/elevation/one_deg.tif"))
Traceback (most recent call last):
  File "/home/benjamin/.pyenv/versions/georasters/lib/python3.7/site-packages/numpy/ma/core.py", line 473, in _check_fill_value
    fill_value = np.array(fill_value, copy=False, dtype=ndtype)
ValueError: cannot convert float NaN to integer
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/home/benjamin/.pyenv/versions/georasters/lib/python3.7/site-packages/georasters/georasters.py", line 1231, in from_file
    data = np.ma.masked_array(data, mask=data == ndv, fill_value=ndv)
  File "/home/benjamin/.pyenv/versions/georasters/lib/python3.7/site-packages/numpy/ma/core.py", line 2893, in __new__
    _data._fill_value = _check_fill_value(fill_value, _data.dtype)
  File "/home/benjamin/.pyenv/versions/georasters/lib/python3.7/site-packages/numpy/ma/core.py", line 479, in _check_fill_value
    raise TypeError(err_msg % (fill_value, ndtype))
TypeError: Cannot convert fill_value nan to dtype int16

I dumped this file using the to_tiff method. I then tried to load it again, and got this stack trace. Are there any workarounds?

@ozak
Copy link
Owner

ozak commented Oct 8, 2019

I would create the file with a ndv. Just assign it to the raster before saving (this needs you to change the underlying masked raster). Seems not well defined if ndv is missing. Although I think it would be good to have an informative message or some workaround.

@marthinwurer
Copy link
Author

I'd think that a warning message and a default no data value for each type would be good. Numpy's masked array library has a function that can get a standard default value for each of their data types, np.ma.core.default_fill_value(). We could use that for unknowns and throw a warning or something.

@ozak
Copy link
Owner

ozak commented Oct 8, 2019

sounds good

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