Repository: azavea/raster-vision

Issue:
Cannot handle CRS w/o EPSG
```
Checking for existing output  [####################################]  100%
Saving command configuration to /opt/data/rv_root/chip/xview-object_detection/command-config.json...
Saving command configuration to /opt/data/rv_root/train/xview-object-detection-mobilenet/command-config.json...
Saving command configuration to /opt/data/rv_root/bundle/xview-object-detection-mobilenet/command-config.json...
Saving command configuration to /opt/data/rv_root/predict/xview-object-detection-mobilenet/command-config.json...
Saving command configuration to /opt/data/rv_root/eval/xview-object-detection-mobilenet/command-config.json...
python -m rastervision  run_command /opt/data/rv_root/chip/xview-object_detection/command-config.json
Making training chips...
2019-03-20 16:00:47:rastervision.utils.files: INFO - Downloading s3://azavea-nyc-ml/cogs/000227.tif to /tmp/tmp98w0p7cl/tmpypmuuz6t/tmpqbscq03c/s3/azavea-nyc-ml/cogs/000227.tif
Traceback (most recent call last):
  File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/opt/src/rastervision/__main__.py", line 17, in <module>
    rv.main()
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/opt/src/rastervision/cli/main.py", line 253, in run_command
    rv.runner.CommandRunner.run(command_config_uri)
  File "/opt/src/rastervision/runner/command_runner.py", line 11, in run
    CommandRunner.run_from_proto(msg)
  File "/opt/src/rastervision/runner/command_runner.py", line 17, in run_from_proto
    command.run()
  File "/opt/src/rastervision/command/chip_command.py", line 22, in run
    map(lambda s: s.create_scene(cc.task, tmp_dir), cc.train_scenes))
  File "/opt/src/rastervision/command/chip_command.py", line 22, in <lambda>
    map(lambda s: s.create_scene(cc.task, tmp_dir), cc.train_scenes))
  File "/opt/src/rastervision/data/scene_config.py", line 36, in create_scene
    raster_source = self.raster_source.create_source(tmp_dir)
  File "/opt/src/rastervision/data/raster_source/geotiff_source_config.py", line 70, in create_source
    y_shift_meters=y_shift_meters)
  File "/opt/src/rastervision/data/raster_source/geotiff_source.py", line 46, in __init__
    super().__init__(raster_transformers, temp_dir, channel_order)
  File "/opt/src/rastervision/data/raster_source/rasterio_source.py", line 47, in __init__
    with self.activate():
  File "/opt/src/rastervision/data/activate_mixin.py", line 21, in __enter__
    self.activate()
  File "/opt/src/rastervision/data/activate_mixin.py", line 54, in do_activate
    self._activate()
  File "/opt/src/rastervision/data/raster_source/geotiff_source.py", line 104, in _activate
    super()._activate()
  File "/opt/src/rastervision/data/raster_source/rasterio_source.py", line 106, in _activate
    self._set_crs_transformer()
  File "/opt/src/rastervision/data/raster_source/geotiff_source.py", line 56, in _set_crs_transformer
    self.image_dataset)
  File "/opt/src/rastervision/data/crs_transformer/rasterio_crs_transformer.py", line 59, in from_dataset
    image_crs = dataset.crs['init']
  File "/usr/lib/python3.5/collections/__init__.py", line 986, in __getitem__
    raise KeyError(key)
KeyError: 'init'
/tmp/tmpkon0yhf2/tmpyysq6a82/Makefile:6: recipe for target '0' failed
make: *** [0] Error 1
```


Discussion:

Resolving patch:
diff --git a/rastervision/data/crs_transformer/rasterio_crs_transformer.py b/rastervision/data/crs_transformer/rasterio_crs_transformer.py
--- a/rastervision/data/crs_transformer/rasterio_crs_transformer.py
+++ b/rastervision/data/crs_transformer/rasterio_crs_transformer.py
@@ -17,7 +17,7 @@ def __init__(self, transform, image_crs, map_crs='epsg:4326'):
             map_crs: CRS code
         """
         self.map_proj = pyproj.Proj(init=map_crs)
-        self.image_proj = pyproj.Proj(init=image_crs)
+        self.image_proj = pyproj.Proj(image_crs)
 
         super().__init__(image_crs, map_crs, transform)
 
@@ -56,7 +56,7 @@ def from_dataset(cls, dataset, map_crs='epsg:4326'):
         if dataset.crs is None:
             return IdentityCRSTransformer()
         transform = dataset.transform
-        image_crs = dataset.crs['init']
+        image_crs = dataset.crs
         return cls(transform, image_crs, map_crs)
 
     def get_affine_transform(self):


Test patch:
diff --git a/tests/data/raster_source/test_rasterio_source.py b/tests/data/raster_source/test_rasterio_source.py
--- a/tests/data/raster_source/test_rasterio_source.py
+++ b/tests/data/raster_source/test_rasterio_source.py
@@ -320,6 +320,36 @@ def test_backcompat_image_source(self):
                         .from_proto(msg).build()
         self.assertEqual(rs_config.uris, [uri])
 
+    def test_no_epsg(self):
+        crs = rasterio.crs.CRS()
+        with RVConfig.get_tmp_dir() as tmp_dir:
+            image_path = os.path.join(tmp_dir, 'temp.tif')
+            height = 100
+            width = 100
+            nb_channels = 3
+            with rasterio.open(
+                    image_path,
+                    'w',
+                    driver='GTiff',
+                    height=height,
+                    width=width,
+                    count=nb_channels,
+                    dtype=np.uint8,
+                    crs=crs) as image_dataset:
+                im = np.zeros((height, width, nb_channels)).astype(np.uint8)
+                for channel in range(nb_channels):
+                    image_dataset.write(im[:, :, channel], channel + 1)
+
+            try:
+                rv.RasterSourceConfig.builder(rv.RASTERIO_SOURCE) \
+                                     .with_uri(image_path) \
+                                     .build() \
+                                     .create_source(tmp_dir=tmp_dir)
+            except Exception:
+                self.fail(
+                    'Creating RasterioSource with CRS with no EPSG attribute '
+                    'raised an exception when it should not have.')
+
 
 if __name__ == '__main__':
     unittest.main()