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

215 fix crs error in milads mmsa notebook #216

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

ywkim312
Copy link
Member

@ywkim312 ywkim312 commented Mar 9, 2023

No description provided.

@ywkim312 ywkim312 linked an issue Mar 9, 2023 that may be closed by this pull request
@ywkim312 ywkim312 self-assigned this Mar 9, 2023
@longshuicy
Copy link
Member

I got an error

---------------------------------------------------------------------------
CPLE_OpenFailedError                      Traceback (most recent call last)
File fiona/_shim.pyx:83, in fiona._shim.gdal_open_vector()

File fiona/_err.pyx:291, in fiona._err.exc_wrap_pointer()

CPLE_OpenFailedError: shapefiles/Mem_power_link5_node.shp: No such file or directory

During handling of the above exception, another exception occurred:

DriverError                               Traceback (most recent call last)
Cell In [6], line 2
      1 ### Read EPN node and link inventory data
----> 2 df_EPNnodes  = gpd.read_file("shapefiles/Mem_power_link5_node.shp")
      3 df_EPNlinks  = gpd.read_file("shapefiles/Mem_power_link5.shp")
      5 ### Plot EPN shapefiles

File ~/opt/miniconda3/envs/incoreRC1.3.7/lib/python3.9/site-packages/geopandas/io/file.py:259, in _read_file(filename, bbox, mask, rows, engine, **kwargs)
    256     path_or_bytes = filename
    258 if engine == "fiona":
--> 259     return _read_file_fiona(
    260         path_or_bytes, from_bytes, bbox=bbox, mask=mask, rows=rows, **kwargs
    261     )
    262 elif engine == "pyogrio":
    263     return _read_file_pyogrio(
    264         path_or_bytes, bbox=bbox, mask=mask, rows=rows, **kwargs
    265     )

File ~/opt/miniconda3/envs/incoreRC1.3.7/lib/python3.9/site-packages/geopandas/io/file.py:303, in _read_file_fiona(path_or_bytes, from_bytes, bbox, mask, rows, where, **kwargs)
    300     reader = fiona.open
    302 with fiona_env():
--> 303     with reader(path_or_bytes, **kwargs) as features:
    304         crs = features.crs_wkt
    305         # attempt to get EPSG code

File ~/opt/miniconda3/envs/incoreRC1.3.7/lib/python3.9/site-packages/fiona/env.py:408, in ensure_env_with_credentials.<locals>.wrapper(*args, **kwargs)
    405 @wraps(f)
    406 def wrapper(*args, **kwargs):
    407     if local._env:
--> 408         return f(*args, **kwargs)
    409     else:
    410         if isinstance(args[0], str):

File ~/opt/miniconda3/envs/incoreRC1.3.7/lib/python3.9/site-packages/fiona/__init__.py:264, in open(fp, mode, driver, schema, crs, encoding, layer, vfs, enabled_drivers, crs_wkt, **kwargs)
    261     path = parse_path(fp)
    263 if mode in ('a', 'r'):
--> 264     c = Collection(path, mode, driver=driver, encoding=encoding,
    265                    layer=layer, enabled_drivers=enabled_drivers, **kwargs)
    266 elif mode == 'w':
    267     if schema:
    268         # Make an ordered dict of schema properties.

File ~/opt/miniconda3/envs/incoreRC1.3.7/lib/python3.9/site-packages/fiona/collection.py:162, in Collection.__init__(self, path, mode, driver, schema, crs, encoding, layer, vsi, archive, enabled_drivers, crs_wkt, ignore_fields, ignore_geometry, **kwargs)
    160 if self.mode == 'r':
    161     self.session = Session()
--> 162     self.session.start(self, **kwargs)
    163 elif self.mode in ('a', 'w'):
    164     self.session = WritingSession()

File fiona/ogrext.pyx:540, in fiona.ogrext.Session.start()

File fiona/_shim.pyx:90, in fiona._shim.gdal_open_vector()

DriverError: shapefiles/Mem_power_link5_node.shp: No such file or directory

@navarroc
Copy link
Member

I got an error

---------------------------------------------------------------------------
CPLE_OpenFailedError                      Traceback (most recent call last)
File fiona/_shim.pyx:83, in fiona._shim.gdal_open_vector()

File fiona/_err.pyx:291, in fiona._err.exc_wrap_pointer()

CPLE_OpenFailedError: shapefiles/Mem_power_link5_node.shp: No such file or directory

During handling of the above exception, another exception occurred:

DriverError                               Traceback (most recent call last)
Cell In [6], line 2
      1 ### Read EPN node and link inventory data
----> 2 df_EPNnodes  = gpd.read_file("shapefiles/Mem_power_link5_node.shp")
      3 df_EPNlinks  = gpd.read_file("shapefiles/Mem_power_link5.shp")
      5 ### Plot EPN shapefiles

File ~/opt/miniconda3/envs/incoreRC1.3.7/lib/python3.9/site-packages/geopandas/io/file.py:259, in _read_file(filename, bbox, mask, rows, engine, **kwargs)
    256     path_or_bytes = filename
    258 if engine == "fiona":
--> 259     return _read_file_fiona(
    260         path_or_bytes, from_bytes, bbox=bbox, mask=mask, rows=rows, **kwargs
    261     )
    262 elif engine == "pyogrio":
    263     return _read_file_pyogrio(
    264         path_or_bytes, bbox=bbox, mask=mask, rows=rows, **kwargs
    265     )

File ~/opt/miniconda3/envs/incoreRC1.3.7/lib/python3.9/site-packages/geopandas/io/file.py:303, in _read_file_fiona(path_or_bytes, from_bytes, bbox, mask, rows, where, **kwargs)
    300     reader = fiona.open
    302 with fiona_env():
--> 303     with reader(path_or_bytes, **kwargs) as features:
    304         crs = features.crs_wkt
    305         # attempt to get EPSG code

File ~/opt/miniconda3/envs/incoreRC1.3.7/lib/python3.9/site-packages/fiona/env.py:408, in ensure_env_with_credentials.<locals>.wrapper(*args, **kwargs)
    405 @wraps(f)
    406 def wrapper(*args, **kwargs):
    407     if local._env:
--> 408         return f(*args, **kwargs)
    409     else:
    410         if isinstance(args[0], str):

File ~/opt/miniconda3/envs/incoreRC1.3.7/lib/python3.9/site-packages/fiona/__init__.py:264, in open(fp, mode, driver, schema, crs, encoding, layer, vfs, enabled_drivers, crs_wkt, **kwargs)
    261     path = parse_path(fp)
    263 if mode in ('a', 'r'):
--> 264     c = Collection(path, mode, driver=driver, encoding=encoding,
    265                    layer=layer, enabled_drivers=enabled_drivers, **kwargs)
    266 elif mode == 'w':
    267     if schema:
    268         # Make an ordered dict of schema properties.

File ~/opt/miniconda3/envs/incoreRC1.3.7/lib/python3.9/site-packages/fiona/collection.py:162, in Collection.__init__(self, path, mode, driver, schema, crs, encoding, layer, vsi, archive, enabled_drivers, crs_wkt, ignore_fields, ignore_geometry, **kwargs)
    160 if self.mode == 'r':
    161     self.session = Session()
--> 162     self.session.start(self, **kwargs)
    163 elif self.mode in ('a', 'w'):
    164     self.session = WritingSession()

File fiona/ogrext.pyx:540, in fiona.ogrext.Session.start()

File fiona/_shim.pyx:90, in fiona._shim.gdal_open_vector()

DriverError: shapefiles/Mem_power_link5_node.shp: No such file or directory

You need to use the zip file that is in the notebooks folder in the root of incore-docs. The notebook that is in manual_jb/content/notebook is just so it renders the ran notebook.

@ywkim312
Copy link
Member Author

ywkim312 commented Mar 10, 2023

This is what I asked to @navarroc . I had the same error and Chris mentioned to use the zip file. @longshuicy To avoid the above error, you have to unzip and use the notebook in there.

@navarroc
Copy link
Member

@ywkim312 When we switch this to reading from a dataset, will we be able to remove the conda import? Users will need to install conda into their environment since it won't be there. Just asking so maybe that will increase the urgency of fixing this next release if we can remove that temp fix.

@ywkim312
Copy link
Member Author

ywkim312 commented Mar 10, 2023

@ywkim312 When we switch this to reading from a dataset, will we be able to remove the conda import? Users will need to install conda into their environment since it won't be there. Just asking so maybe that will increase the urgency of fixing this next release if we can remove that temp fix.

That is a good question. However, if they want to use the pyincore, shouldn't they need to have conda environment? Because pip pyincore is incomplete one, the users might need to have conda one for the running their analysis and others. So basic assumption is that, to use pyincore, the users should have their own conda virtual env with pyincore installed, and if so, import conda should work all the time? But I agree that we might not have to release this PR for this release

@navarroc
Copy link
Member

@ywkim312 When we switch this to reading from a dataset, will we be able to remove the conda import? Users will need to install conda into their environment since it won't be there. Just asking so maybe that will increase the urgency of fixing this next release if we can remove that temp fix.

That is a good question. However, if they want to use the pyincore, shouldn't they need to have conda environment? Because pip pyincore is incomplete one, the users might need to have conda one for the running their analysis and others. So basic assumption is that, to use pyincore, the users should have their own conda virtual env with pyincore installed, and if so, import conda should work all the time? But I agree that we might not have to release this PR for this release

I was using a conda environment. It failed to import conda until I manually did a conda install conda. Maybe @longshuicy can confirm if she had to do the same or if it's just me.

@navarroc
Copy link
Member

I still see the same error. Is there anything additional I need to install?

@ywkim312
Copy link
Member Author

I still see the same error. Is there anything additional I need to install?

It worked for me and incore-lab. But can you try install conda like conda install -y conda If this is the case, we might need to add conda into pyincore's requirements

@longshuicy
Copy link
Member

i have to do conda install -y conda to make it work. Maybe just add that as the comment or markdown in the notebook for now?

@longshuicy
Copy link
Member

The zip file only has the restoration notebook, but shouldn't there also be the repair notebook?
image

image

@longshuicy
Copy link
Member

i see this error

 File ~/opt/miniconda3/envs/incoreRC1.3.7/lib/python3.9/site-packages/geopandas/array.py:1413, in _get_common_crs(arr_seq)
   1406         warnings.warn(
   1407             "CRS not set for some of the concatenation inputs. "
   1408             f"Setting output's CRS as {names[0]} "
   1409             "(the single non-null crs provided)."
   1410         )
   1411     return crs_not_none[0]
-> 1413 raise ValueError(
   1414     f"Cannot determine common CRS for concatenation inputs, got {names}. "
   1415     "Use `to_crs()` to transform geometries to the same CRS before merging."
   1416 )

ValueError: Cannot determine common CRS for concatenation inputs, got ['WGS 84', 'WGS 84']. Use `to_crs()` to transform geometries to the same CRS before merging.

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

Successfully merging this pull request may close these issues.

Fix CRS error in Milad's MMSA notebook
3 participants