Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error when trying to serve raster of float datatype containing NaN

See original GitHub issue - - [13/Jul/2020 00:31:22] "GET /singleband/4918/yield/0101201831012018/preview.png?tile_size=[128,128] HTTP/1.1" 500 -
 [-] Exception on /singleband/4918/yield/0101201831012018/preview.png [GET]
Traceback (most recent call last):
  File "/home/abhishek/anaconda3/envs/gis_env/lib/python3.8/site-packages/flask/", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/abhishek/anaconda3/envs/gis_env/lib/python3.8/site-packages/flask/", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/abhishek/anaconda3/envs/gis_env/lib/python3.8/site-packages/flask/", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/abhishek/anaconda3/envs/gis_env/lib/python3.8/site-packages/flask/", line 39, in reraise
    raise value
  File "/home/abhishek/anaconda3/envs/gis_env/lib/python3.8/site-packages/flask/", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/abhishek/anaconda3/envs/gis_env/lib/python3.8/site-packages/flask/", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/abhishek/Project/terracotta/terracotta/server/", line 49, in inner
    return fun(*args, **kwargs)
  File "/home/abhishek/Project/terracotta/terracotta/server/", line 152, in get_singleband_preview
    return _get_singleband_image(keys)
  File "/home/abhishek/Project/terracotta/terracotta/server/", line 166, in _get_singleband_image
    image = singleband(parsed_keys, tile_xyz=tile_xyz, **options)
  File "/home/abhishek/anaconda3/envs/gis_env/lib/python3.8/", line 75, in inner
    return func(*args, **kwds)
  File "/home/abhishek/Project/terracotta/terracotta/handlers/", line 67, in singleband
    out = image.to_uint8(tile_data, *stretch_range_)
  File "/home/abhishek/Project/terracotta/terracotta/", line 148, in to_uint8
    rescaled = contrast_stretch(data, (lower_bound, upper_bound), (1, 255), clip=True)
  File "/home/abhishek/anaconda3/envs/gis_env/lib/python3.8/", line 75, in inner
    return func(*args, **kwds)
  File "/home/abhishek/Project/terracotta/terracotta/", line 134, in contrast_stretch
    out_data -= lower_bound_in
  File "/home/abhishek/anaconda3/envs/gis_env/lib/python3.8/site-packages/numpy/ma/", line 4227, in __isub__
    self._data.__isub__(np.where(self._mask, self.dtype.type(0),
TypeError: ufunc 'subtract' output (typecode 'O') could not be coerced to provided output parameter (typecode 'd') according to the casting rule ''same_kind''

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

dionhaefnercommented, Jul 14, 2020

Yes, there were two problems:

  1. optimize-rasters did not work on rasters smaller than (256, 256).
  2. Rasters containing a nodata value and NaN values could not be served. So, in general, float rasters did work, just not ones that also contain NaNs.
dionhaefnercommented, Jul 14, 2020
Screen Shot 2020-07-14 at 12 09 17

Done. Feel free to reopen of the problem persists.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Downsides to saving rasters with NaN as no data values?
Generally, it's a lot better to use NaN. I can think of one reason not to, however. NaN only exists with floating-point data...
Read more >
Invalid Floating Point Error and Region Settings
It is just at this moment when a new prompt appears with an Invalid Floating Point Error. I did a first try of...
Read more >
How to Fix: ValueError: cannot convert float NaN to integer
This error occurs when you attempt to convert a column in a pandas DataFrame from a float to an integer, yet the column...
Read more >
How do I handle NA values in R for raster layer with datatype ...
When asking the raster what the NA value I get 'negative infinity' and INT2U values are all positive. The result is that the...
Read more >
NoData in raster datasets—Help | ArcGIS for Desktop
Cell values can be either positive or negative, integer, or floating point. Cells can also have a NoData value to represent the absence...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found