Open Trevy05 opened 3 years ago
Hi, can you format the error log to markdown code (using `)? Also, can you show how is your flow direction ?
Greetings, I need more info to address this issue.
Was this raster one that you generated yourself using pysheds/rasterio?
Hi there, trying out this package for flow accumulation computation ... can't pass importing, seems to be something wrong with pyproj
default SRS
steps to reproduce (python 3.9, pysheds 0.3.2):
conda create -n testenv python=3.9
conda activate testenv
conda install pysheds ipython -y
ipython
from pysheds.grid import Grid
then get (dont mind conda env, i installed everything in my base env):
In [3]: from pysheds.grid import Grid
D:\Conda\lib\site-packages\pyproj\__init__.py:89: UserWarning: pyproj unable to set database path.
_pyproj_global_context_initialize()
---------------------------------------------------------------------------
CRSError Traceback (most recent call last)
Input In [3], in <module>
----> 1 from pysheds.grid import Grid
File D:\Conda\lib\site-packages\pysheds\grid.py:7, in <module>
5 _HAS_NUMBA = False
6 if _HAS_NUMBA:
----> 7 from pysheds.sgrid import sGrid as Grid
8 else:
9 from pysheds.pgrid import Grid as Grid
File D:\Conda\lib\site-packages\pysheds\sgrid.py:29, in <module>
26 _pyproj_init = '+init=epsg:4326' if _OLD_PYPROJ else 'epsg:4326'
28 # Import input/output functions
---> 29 import pysheds.io
31 # Import viewing functions
32 from pysheds.sview import Raster, MultiRaster
File D:\Conda\lib\site-packages\pysheds\io.py:9, in <module>
7 from affine import Affine
8 from distutils.version import LooseVersion
----> 9 from pysheds.sview import Raster, ViewFinder, View
11 _OLD_PYPROJ = LooseVersion(pyproj.__version__) < LooseVersion('2.2')
12 _pyproj_crs = lambda Proj: Proj.crs if not _OLD_PYPROJ else Proj
File D:\Conda\lib\site-packages\pysheds\sview.py:304, in <module>
301 obj.metadata = metadata
302 return obj
--> 304 class ViewFinder():
305 """
306 Class that defines a spatial reference system for a Raster or Grid instance.
307 The spatial reference is completely defined by an affine transformation matrix (affine),
(...)
331 dy_dx : Tuple describing the cell size in the y and x directions.
332 """
333 def __init__(self, affine=Affine(1., 0., 0., 0., 1., 0.), shape=(1,1),
334 nodata=0, mask=None, crs=pyproj.Proj(_pyproj_init)):
File D:\Conda\lib\site-packages\pysheds\sview.py:334, in ViewFinder()
304 class ViewFinder():
305 """
306 Class that defines a spatial reference system for a Raster or Grid instance.
307 The spatial reference is completely defined by an affine transformation matrix (affine),
(...)
331 dy_dx : Tuple describing the cell size in the y and x directions.
332 """
333 def __init__(self, affine=Affine(1., 0., 0., 0., 1., 0.), shape=(1,1),
--> 334 nodata=0, mask=None, crs=pyproj.Proj(_pyproj_init)):
335 self.affine = affine
336 self.crs = crs
File D:\Conda\lib\site-packages\pyproj\proj.py:109, in Proj.__init__(self, projparams, preserve_units, **kwargs)
47 def __init__(
48 self, projparams: Any = None, preserve_units: bool = True, **kwargs
49 ) -> None:
50 """
51 A Proj class instance is initialized with proj map projection
52 control parameter key/value pairs. The key/value pairs can
(...)
107 '116.366 39.867'
108 """
--> 109 self.crs = CRS.from_user_input(projparams, **kwargs)
110 # make sure units are meters if preserve_units is False.
111 if not preserve_units and "foot" in self.crs.axis_info[0].unit_name:
112 # ignore export to PROJ string deprecation warning
File D:\Conda\lib\site-packages\pyproj\crs\crs.py:479, in CRS.from_user_input(cls, value, **kwargs)
477 if isinstance(value, cls):
478 return value
--> 479 return cls(value, **kwargs)
File D:\Conda\lib\site-packages\pyproj\crs\crs.py:326, in CRS.__init__(self, projparams, **kwargs)
324 self._local.crs = projparams
325 else:
--> 326 self._local.crs = _CRS(self.srs)
File pyproj\_crs.pyx:2352, in pyproj._crs._CRS.__init__()
CRSError: Invalid projection: epsg:4326: (Internal Proj Error: proj_create: no database context specified)
In [4]: from pysheds.grid import Grid
---------------------------------------------------------------------------
CRSError Traceback (most recent call last)
Input In [4], in <module>
----> 1 from pysheds.grid import Grid
File D:\Conda\lib\site-packages\pysheds\grid.py:7, in <module>
5 _HAS_NUMBA = False
6 if _HAS_NUMBA:
----> 7 from pysheds.sgrid import sGrid as Grid
8 else:
9 from pysheds.pgrid import Grid as Grid
File D:\Conda\lib\site-packages\pysheds\sgrid.py:29, in <module>
26 _pyproj_init = '+init=epsg:4326' if _OLD_PYPROJ else 'epsg:4326'
28 # Import input/output functions
---> 29 import pysheds.io
31 # Import viewing functions
32 from pysheds.sview import Raster, MultiRaster
File D:\Conda\lib\site-packages\pysheds\io.py:9, in <module>
7 from affine import Affine
8 from distutils.version import LooseVersion
----> 9 from pysheds.sview import Raster, ViewFinder, View
11 _OLD_PYPROJ = LooseVersion(pyproj.__version__) < LooseVersion('2.2')
12 _pyproj_crs = lambda Proj: Proj.crs if not _OLD_PYPROJ else Proj
File D:\Conda\lib\site-packages\pysheds\sview.py:304, in <module>
301 obj.metadata = metadata
302 return obj
--> 304 class ViewFinder():
305 """
306 Class that defines a spatial reference system for a Raster or Grid instance.
307 The spatial reference is completely defined by an affine transformation matrix (affine),
(...)
331 dy_dx : Tuple describing the cell size in the y and x directions.
332 """
333 def __init__(self, affine=Affine(1., 0., 0., 0., 1., 0.), shape=(1,1),
334 nodata=0, mask=None, crs=pyproj.Proj(_pyproj_init)):
File D:\Conda\lib\site-packages\pysheds\sview.py:334, in ViewFinder()
304 class ViewFinder():
305 """
306 Class that defines a spatial reference system for a Raster or Grid instance.
307 The spatial reference is completely defined by an affine transformation matrix (affine),
(...)
331 dy_dx : Tuple describing the cell size in the y and x directions.
332 """
333 def __init__(self, affine=Affine(1., 0., 0., 0., 1., 0.), shape=(1,1),
--> 334 nodata=0, mask=None, crs=pyproj.Proj(_pyproj_init)):
335 self.affine = affine
336 self.crs = crs
File D:\Conda\lib\site-packages\pyproj\proj.py:109, in Proj.__init__(self, projparams, preserve_units, **kwargs)
47 def __init__(
48 self, projparams: Any = None, preserve_units: bool = True, **kwargs
49 ) -> None:
50 """
51 A Proj class instance is initialized with proj map projection
52 control parameter key/value pairs. The key/value pairs can
(...)
107 '116.366 39.867'
108 """
--> 109 self.crs = CRS.from_user_input(projparams, **kwargs)
110 # make sure units are meters if preserve_units is False.
111 if not preserve_units and "foot" in self.crs.axis_info[0].unit_name:
112 # ignore export to PROJ string deprecation warning
File D:\Conda\lib\site-packages\pyproj\crs\crs.py:479, in CRS.from_user_input(cls, value, **kwargs)
477 if isinstance(value, cls):
478 return value
--> 479 return cls(value, **kwargs)
File D:\Conda\lib\site-packages\pyproj\crs\crs.py:326, in CRS.__init__(self, projparams, **kwargs)
324 self._local.crs = projparams
325 else:
--> 326 self._local.crs = _CRS(self.srs)
File pyproj\_crs.pyx:2352, in pyproj._crs._CRS.__init__()
CRSError: Invalid projection: epsg:4326: (Internal Proj Error: proj_create: no database context specified)
Ok, this is a pyproj
error : https://github.com/geopandas/geopandas/issues/2270 ...
but the explanation for fixup is shady and NOT documented : https://pyproj4.github.io/pyproj/stable/gotchas.html#internal-proj-error-sqlite-error-on-select
[edit] : Uninstalling postgis solved my problem !
I had the same issue. My application was running in my system but not in remote machine as it had postgis installed in it and PROJ path was redirected to C:\Program Files\PostgreSQL\...
I overcame with this simple import in my code:
import geopandas as gpd
import pyproj
pyproj.datadir.set_data_dir('C:\\Users\\<USERNAME>\\Anaconda3\\envs\\geospatial_env\\Library\\share\\proj') ## set the pyproj data directory
Application code.....
Reinstallation of the packages was not required.
Also as it is mentioned in the docs:
When I try loading my flow direction grid I get the error: CRSError Traceback (most recent call last)