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

Read WKT geotiff #698

Closed
gerritholl opened this issue Apr 5, 2019 · 3 comments
Closed

Read WKT geotiff #698

gerritholl opened this issue Apr 5, 2019 · 3 comments
Assignees
Labels

Comments

@gerritholl
Copy link
Member

gerritholl commented Apr 5, 2019

Feature Request

Is your feature request related to a problem? Please describe.

I have a geotiff file in which the area is described with WKT: the xarray open_rasterio function sets the crs attribute to the string 'PROJCS["Geostationary_Satellite_View",GEOGCS["GCS_Unknown",DATUM["D_unknown",SPHEROID["Unknown",6378169,295.4880658970008]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Geostationary_Satellite"],PARAMETER["central_meridian",0],PARAMETER["satellite_height",35785831],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["Meter",1]]'. The generic_image reader in satpy uses pyresample.utils.proj4_str_to_dict to convert the latter to a dict, but the latter does not understand this format and just returns a dictionary with the entire WKS string as a key and the key True. When this dict then gets passed to pyproj.Proj, the latter returns a RuntimeError: b'projection not named'.

The script:

from satpy.scene import Scene
from satpy.utils import debug_on; debug_on()
import glob
from datetime import datetime
imlist = glob.glob("/media/nas/x21308/DEM/dem_eu_1km.tif")
sc = Scene(reader="generic_image", filenames=imlist)
sc.load(["image"])
print(sc["image"].area)

results in:

/media/nas/x21324/miniconda3/envs/py37c/lib/python3.7/site-packages/dask/config.py:168: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  data = yaml.load(f.read()) or {}
/media/nas/x21324/miniconda3/envs/py37c/lib/python3.7/site-packages/distributed/config.py:20: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  defaults = yaml.load(f)
[DEBUG: 2019-04-05 12:43:23 : satpy.scene] Setting 'PPP_CONFIG_DIR' to '/home/gholl/checkouts/geotools/etc/'
[DEBUG: 2019-04-05 12:43:23 : satpy.readers] Reading ['/media/nas/x21324/miniconda3/envs/py37c/lib/python3.7/site-packages/satpy/etc/readers/generic_image.yaml']
[DEBUG: 2019-04-05 12:43:23 : satpy.readers.yaml_reader] Assigning to generic_image: ['/media/nas/x21308/DEM/dem_eu_1km.tif']
[DEBUG: 2019-04-05 12:43:23 : rasterio.env] Entering env context: <rasterio.env.Env object at 0x7f83125269e8>
[DEBUG: 2019-04-05 12:43:23 : rasterio.env] Starting outermost env
[DEBUG: 2019-04-05 12:43:23 : rasterio.env] No GDAL environment exists
[DEBUG: 2019-04-05 12:43:23 : rasterio.env] New GDAL environment <rasterio._env.GDALEnv object at 0x7f8312526710> created
[DEBUG: 2019-04-05 12:43:23 : rasterio._env] GDAL_DATA found in environment: '/media/nas/x21324/miniconda3/envs/py37c/share/gdal'.
[DEBUG: 2019-04-05 12:43:23 : rasterio._env] PROJ_LIB found in environment: '/media/nas/x21324/miniconda3/envs/py37c/share/proj'.
[DEBUG: 2019-04-05 12:43:23 : rasterio._env] Started GDALEnv <rasterio._env.GDALEnv object at 0x7f8312526710>.
[DEBUG: 2019-04-05 12:43:23 : rasterio.env] Got a copy of environment <rasterio._env.GDALEnv object at 0x7f8312526710> options
[DEBUG: 2019-04-05 12:43:23 : rasterio.env] Entered env context: <rasterio.env.Env object at 0x7f83125269e8>
[DEBUG: 2019-04-05 12:43:23 : rasterio._base] Nodata success: 0, Nodata value: -10000000000.000000
[DEBUG: 2019-04-05 12:43:23 : rasterio._base] Dataset <open DatasetReader name='/media/nas/x21308/DEM/dem_eu_1km.tif' mode='r'> is started.
[DEBUG: 2019-04-05 12:43:23 : rasterio.env] Exiting env context: <rasterio.env.Env object at 0x7f83125269e8>
[DEBUG: 2019-04-05 12:43:23 : rasterio.env] Cleared existing <rasterio._env.GDALEnv object at 0x7f8312526710> options
[DEBUG: 2019-04-05 12:43:23 : rasterio._env] Stopped GDALEnv <rasterio._env.GDALEnv object at 0x7f8312526710>.
[DEBUG: 2019-04-05 12:43:23 : rasterio.env] Exiting outermost env
[DEBUG: 2019-04-05 12:43:23 : rasterio.env] Exited env context: <rasterio.env.Env object at 0x7f83125269e8>
Traceback (most recent call last):
  File "mwe.py", line 6, in <module>
    sc = Scene(reader="generic_image", filenames=imlist)
  File "/media/nas/x21324/miniconda3/envs/py37c/lib/python3.7/site-packages/satpy/scene.py", line 158, in __init__
    reader_kwargs=reader_kwargs)
  File "/media/nas/x21324/miniconda3/envs/py37c/lib/python3.7/site-packages/satpy/scene.py", line 203, in create_reader_instances
    ppp_config_dir=self.ppp_config_dir)
  File "/media/nas/x21324/miniconda3/envs/py37c/lib/python3.7/site-packages/satpy/readers/__init__.py", line 753, in load_readers
    reader_instance.create_filehandlers(loadables, fh_kwargs=reader_kwargs_without_filter)
  File "/media/nas/x21324/miniconda3/envs/py37c/lib/python3.7/site-packages/satpy/readers/yaml_reader.py", line 511, in create_filehandlers
    fh_kwargs=fh_kwargs)
  File "/media/nas/x21324/miniconda3/envs/py37c/lib/python3.7/site-packages/satpy/readers/yaml_reader.py", line 497, in new_filehandlers_for_filetype
    return list(filtered_iter)
  File "/media/nas/x21324/miniconda3/envs/py37c/lib/python3.7/site-packages/satpy/readers/yaml_reader.py", line 469, in filter_fh_by_metadata
    for filehandler in filehandlers:
  File "/media/nas/x21324/miniconda3/envs/py37c/lib/python3.7/site-packages/satpy/readers/yaml_reader.py", line 412, in new_filehandler_instances
    yield filetype_cls(filename, filename_info, filetype_info, *req_fh, **fh_kwargs)
  File "/media/nas/x21324/miniconda3/envs/py37c/lib/python3.7/site-packages/satpy/readers/generic_image.py", line 56, in __init__
    self.read()
  File "/media/nas/x21324/miniconda3/envs/py37c/lib/python3.7/site-packages/satpy/readers/generic_image.py", line 65, in read
    self.area = self.get_geotiff_area_def(data.crs)
  File "/media/nas/x21324/miniconda3/envs/py37c/lib/python3.7/site-packages/satpy/readers/generic_image.py", line 87, in get_geotiff_area_def
    return get_geotiff_area_def(self.finfo['filename'], crs)
  File "/media/nas/x21324/miniconda3/envs/py37c/lib/python3.7/site-packages/satpy/readers/generic_image.py", line 120, in get_geotiff_area_def
    x_size, y_size, area_extent)
  File "/media/nas/x21324/miniconda3/envs/py37c/lib/python3.7/site-packages/pyresample/geometry.py", line 887, in __init__
    proj = Proj(**proj_dict)
  File "/media/nas/x21324/miniconda3/envs/py37c/lib/python3.7/site-packages/pyproj/__init__.py", line 362, in __new__
    return _proj.Proj.__new__(self, projstring)
  File "_proj.pyx", line 129, in _proj.Proj.__cinit__
RuntimeError: b'projection not named'

Describe the solution you'd like
I'm not sure if this issue belongs in satpy or in pyresample, but I would like any solution that allows for reading this geotiff. I've opened the issue here because at affects me as a satpy user and the pyresample dependency would not be visible if it wasn't for the traceback.

Describe any changes to existing user workflow
No backward compatibility issues to speak of.

Additional context
I don't know much about geotiff yet; as a workaround I may be able to convert this geotiff to one where the encoding is described in a way that satpy understands, but I don't know if that is true. I don't know if the geotiff standards proscribes how the location shall be encoded.

This issue may be related to #617. It may be that when #617 is resolved the problem described here vanishes, but I'm not sure about that.

@gerritholl
Copy link
Member Author

gerritholl commented Apr 5, 2019

I forgot to mention the versions I am using:

  • satpy 0.13.0+78.ge9614df0
  • pyresample 1.11.2
  • pyproj 1.9.6
  • proj4 5.2.0
  • xarray 0.11.3
  • rasterio 1.0.21
  • Python 3.7.3

on a openSUSE 15.0 system.

@gerritholl
Copy link
Member Author

Here is a small dem_test.tif file that exhibits the problem.

dem_test.tif.gz

Created from the original using gdalwarp -ts 300 250 dem_eu_1km.tif dem_test.tif.

@djhoese
Copy link
Member

djhoese commented Apr 5, 2019

As mentioned on slack, this is an incompatibility with "xarray <0.12" and "rasterio>=1.0.14". WKT is just another form of describing a CRS compared to PROJ.4. The issue is that rasterio changed their to_string() method to return WKT instead of PROJ.4 which it was doing previously. Xarray and SatPy expected PROJ.4 strings. So either update xarray or downgrade rasterio. Maybe this will get better in the future, but this really wasn't our fault.

@djhoese djhoese closed this as completed Apr 5, 2019
@djhoese djhoese self-assigned this Apr 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants