gecos-lab / FracAbility

Python toolbox to analyse fracture networks for digitalized rock outcrops.
https://fracability.readthedocs.io/
GNU Affero General Public License v3.0
5 stars 1 forks source link

Unable to save the results in shp files #13

Closed Cylv1 closed 5 days ago

Cylv1 commented 2 weeks ago

Describe the bug, what's wrong, and what you expected.

The following error message appears with FractureNetwork.save_shp() instruction.


ValueError Traceback (most recent call last) File ~\test_script_bahrija.py:47 41 fitter.plot_summary(sort_by='Mean_rank') 43 # ~ fitter.fit_result_to_excel(set_path_excel) 44 45 46 # ~ fracture_net.save_csv(path=path_fn) ---> 47 fracture_net.save_shp(path=path_fn)

File ~\anaconda3\Lib\site-packages\fracability\Entities.py:1431, in FractureNetwork.save_shp(self, path) 1424 """ 1425 Save the entity df as shp 1426 :param path: 1427 :return: 1428 """ 1430 if self.nodes is not None: -> 1431 self.nodes.save_shp(path) 1433 if self.fractures is not None: 1434 self.fractures.save_shp(path)

File ~\anaconda3\Lib\site-packages\fracability\AbstractClasses.py:311, in BaseEntity.save_shp(self, path) 309 final_path = os.path.join(output_path, f'{self.name}.shp') 310 entity_df = self.entity_df --> 311 entity_df.to_file(final_path, crs=self.crs) 313 qgis_style_paths = QgisStyle().available_paths 315 for qgis_path in qgis_style_paths:

File ~\anaconda3\Lib\site-packages\geopandas\geodataframe.py:1536, in GeoDataFrame.to_file(self, filename, driver, schema, index, kwargs) 1441 """Write the GeoDataFrame to a file. 1442 1443 By default, an ESRI shapefile is written, but any OGR data source (...) 1532 1533 """ 1534 from geopandas.io.file import _to_file -> 1536 _to_file(self, filename, driver, schema, index, kwargs)

File ~\anaconda3\Lib\site-packages\geopandas\io\file.py:686, in _to_file(df, filename, driver, schema, index, mode, crs, engine, metadata, kwargs) 683 raise ValueError(f"'mode' should be one of 'w' or 'a', got '{mode}' instead") 685 if engine == "pyogrio": --> 686 _to_file_pyogrio(df, filename, driver, schema, crs, mode, metadata, kwargs) 687 elif engine == "fiona": 688 _to_file_fiona(df, filename, driver, schema, crs, mode, metadata, **kwargs)

File ~\anaconda3\Lib\site-packages\geopandas\io\file.py:742, in _to_file_pyogrio(df, filename, driver, schema, crs, mode, metadata, **kwargs) 739 kwargs["append"] = True 741 if crs is not None: --> 742 raise ValueError("Passing 'crs' is not supported with the 'pyogrio' engine.") 744 # for the fiona engine, this check is done in gdf.iterfeatures() 745 if not df.columns.is_unique:

ValueError: Passing 'crs' is not supported with the 'pyogrio' engine.

Steps to reproduce the bug.

set_path='path' set_path_boundary='path' path_fn = 'path'

set_a = Entities.Fractures(shp=set_path, set_n=1)

boundary = Entities.Boundary(shp=set_path_boundary, group_n=1)

fracture_net = Entities.FractureNetwork()

fracture_net.add_fractures(set_a) fracture_net.add_boundaries(boundary)

fracture_net.calculate_topology()

fitter = Statistics.NetworkFitter(fracture_net)

fitter.fit('lognorm') fitter.fit('expon') fitter.fit('norm') fitter.fit('gengamma') fitter.fit('powerlaw') fitter.fit('weibull_min')

fitter.fit_records(sort_by='Akaike').iloc[:,:-1]

fracture_net.save_shp(path=path_fn)

System Information

Date: Mon Aug 26 18:35:34 2024 Paris, Madrid (heure d’été)

                OS : Windows (10 10.0.19045 SP0 Multiprocessor Free)
            CPU(s) : 4
           Machine : AMD64
      Architecture : 64bit
               RAM : 15.9 GiB
       Environment : Jupyter

  Python 3.12.4 | packaged by Anaconda, Inc. | (main, Jun 18 2024, 15:03:56)
  [MSC v.1929 64 bit (AMD64)]

       fracability : 1.5.0
           pyvista : 0.44.1
               vtk : 9.3.1
             numpy : 1.26.4
         geopandas : 1.0.1
           shapely : 2.0.5
             scipy : 1.13.1
           IPython : 8.25.0
        matplotlib : 3.8.4
            scooby : 0.10.0

  Intel(R) oneAPI Math Kernel Library Version 2023.1-Product Build 20230303
  for Intel(R) 64 architecture applications
--------------------------------------------------------------------------------
Report copied to clipboard

Screenshots and/or videos

No response

Datasets

gbene commented 2 weeks ago

Hi! So it seems a problem related to the version 1.0.1 of geopandas that uses the pyogyro backend to read and write. For a quick fix you can run the following:

python -m pip install geopandas==0.14

in your terminal (if you have anaconda then in the conda terminal once you have activated the environment)!

gbene commented 5 days ago

This is now solved in version 1.5.1. To upgrade run the following:

python -m pip install fracability --upgrade