From 21c03724fad7b11451587be3f99140a599146b72 Mon Sep 17 00:00:00 2001 From: AlexanderJuestel Date: Sun, 21 Jul 2024 12:02:29 +0200 Subject: [PATCH] Fix #348 --- gemgis/download_gemgis_data.py | 1 - gemgis/gemgis.py | 1 - gemgis/postprocessing.py | 42 +++++++++++++++++----------------- gemgis/raster.py | 3 +-- gemgis/utils.py | 15 ++++++------ gemgis/web.py | 35 ++++------------------------ 6 files changed, 33 insertions(+), 64 deletions(-) diff --git a/gemgis/download_gemgis_data.py b/gemgis/download_gemgis_data.py index a96c4d98..a999445b 100644 --- a/gemgis/download_gemgis_data.py +++ b/gemgis/download_gemgis_data.py @@ -82,7 +82,6 @@ def download_tutorial_data(filename: str, create_pooch : Create pooch class to fetch files from a website. """ try: - import pooch from pooch import HTTPDownloader download = HTTPDownloader(progressbar=False) except ModuleNotFoundError: diff --git a/gemgis/gemgis.py b/gemgis/gemgis.py index ebef8c08..c5d544a6 100644 --- a/gemgis/gemgis.py +++ b/gemgis/gemgis.py @@ -22,7 +22,6 @@ import numpy as np # import scooby import pandas as pd -from pandas.core import frame import rasterio import geopandas as gpd import rasterio.transform diff --git a/gemgis/postprocessing.py b/gemgis/postprocessing.py index 28bc19d2..e0086fbd 100644 --- a/gemgis/postprocessing.py +++ b/gemgis/postprocessing.py @@ -63,12 +63,12 @@ def extract_lithologies(geo_model, raise ModuleNotFoundError( 'Matplotlib package is not installed. Use pip install matplotlib to install the latest version') - # Trying to import gempy but returning error if gempy is not installed - try: - import gempy as gp - except ModuleNotFoundError: - raise ModuleNotFoundError( - 'GemPy package is not installed. Use pip install gempy to install the latest version') + ## Trying to import gempy but returning error if gempy is not installed + #try: + # import gempy as gp + #except ModuleNotFoundError: + # raise ModuleNotFoundError( + # 'GemPy package is not installed. Use pip install gempy to install the latest version') shape = geo_model._grid.topography.values_2d[:, :, 2].shape @@ -502,11 +502,11 @@ def crop_block_to_topography(geo_model) -> pv.core.pointset.UnstructuredGrid: """ # Trying to import GemPy - try: - import gempy as gp - except ModuleNotFoundError: - raise ModuleNotFoundError( - 'GemPy package is not installed. Use pip install gempy to install the latest version') + #try: + # import gempy as gp + #except ModuleNotFoundError: + # raise ModuleNotFoundError( + # 'GemPy package is not installed. Use pip install gempy to install the latest version') # Trying to import PVGeo try: @@ -880,7 +880,7 @@ def save_qgis_qml_file(gdf: gpd.geodataframe.GeoDataFrame, raise TypeError('gdf must be a GeoDataFrame') # Checking that the geometry column is present in the gdf - if not 'geometry' in gdf: + if 'geometry' not in gdf: raise ValueError('geometry column not present in GeoDataFrame') # Checking that all geometries are Polygons @@ -892,7 +892,7 @@ def save_qgis_qml_file(gdf: gpd.geodataframe.GeoDataFrame, raise TypeError('value column name must be of type string') # Checking that the value column is present in the gdf - if not value in gdf: + if value not in gdf: raise ValueError('"%s" not in gdf. Please provide a valid column name.' % value) # Checking that the color column is of type string @@ -900,7 +900,7 @@ def save_qgis_qml_file(gdf: gpd.geodataframe.GeoDataFrame, raise TypeError('color column name must be of type string') # Checking that the value column is present in the gdf - if not color in gdf: + if color not in gdf: raise ValueError('"%s" not in gdf. Please provide a valid column name.' % color) # Creating RGBA column from hex colors @@ -1058,11 +1058,11 @@ def clip_fault_of_gempy_model(geo_model, """ # Trying to import gempy but returning error if gempy is not installed - try: - import gempy as gp - except ModuleNotFoundError: - raise ModuleNotFoundError( - 'GemPy package is not installed. Use pip install gempy to install the latest version') + #try: + # import gempy as gp + #except ModuleNotFoundError: + # raise ModuleNotFoundError( + # 'GemPy package is not installed. Use pip install gempy to install the latest version') # Checking that the fault is provided as string if not isinstance(fault, str): @@ -1070,7 +1070,7 @@ def clip_fault_of_gempy_model(geo_model, # Checking that the fault is a fault of the geo_model if isinstance(fault, str): - if not fault in geo_model.surfaces.df['surface'][geo_model.surfaces.df['isFault'] == True].tolist(): + if fault not in geo_model.surfaces.df['surface'][geo_model.surfaces.df['isFault'] == True].tolist(): raise ValueError('Fault is not part of the GemPy geo_model') # Getting the fault DataFrames @@ -1087,7 +1087,7 @@ def clip_fault_of_gempy_model(geo_model, # Checking that the correct values are provided for the parameter which if isinstance(which, str): - if not which in ['first', 'last', 'both']: + if which not in ['first', 'last', 'both']: raise ValueError('The options for the parameter "which" include "first", "last", or "both"') # Checking that the i size is of type int or float diff --git a/gemgis/raster.py b/gemgis/raster.py index 8f619bec..20ed37cb 100644 --- a/gemgis/raster.py +++ b/gemgis/raster.py @@ -28,8 +28,7 @@ import pandas as pd import geopandas as gpd from typing import Union, List, Sequence, Optional, Iterable, Dict, Tuple -from rasterio.mask import mask -from shapely.geometry import box, Polygon, LineString +from shapely.geometry import Polygon, LineString import shapely from pathlib import Path import affine diff --git a/gemgis/utils.py b/gemgis/utils.py index 596b3e60..5afe457c 100644 --- a/gemgis/utils.py +++ b/gemgis/utils.py @@ -541,11 +541,11 @@ def show_number_of_data_points(geo_model): """ # Trying to import gempy but returning error if gempy is not installed - try: - import gempy as gp - except ModuleNotFoundError: - raise ModuleNotFoundError( - 'GemPy package is not installed. Use pip install gempy to install the latest version') + #try: + # import gempy as gp + #except ModuleNotFoundError: + # raise ModuleNotFoundError( + # 'GemPy package is not installed. Use pip install gempy to install the latest version') # Create empty lists to store values no_int = [] @@ -2405,7 +2405,6 @@ def rotate_gempy_input_data(extent: Union[np.ndarray, shapely.geometry.Polygon, list(extent_polygon.centroid.coords)[0][1])) # Creating Bounding Box - bbox = box(*extent_rotated.bounds) extent = [extent_rotated.bounds[0], extent_rotated.bounds[2], extent_rotated.bounds[1], @@ -2636,7 +2635,7 @@ def get_cdp_linestring_of_seismic_data(path_in: str, """ # Trying to import segysak but returning error if segysak is not installed try: - from segysak.segy import segy_loader, segy_writer + from segysak.segy import segy_loader except ModuleNotFoundError: raise ModuleNotFoundError( 'segysak package is not installed. Use pip install segysak to install the latest version') @@ -2720,7 +2719,7 @@ def get_cdp_points_of_seismic_data(path_in: str, """ # Trying to import segysak but returning error if segysak is not installed try: - from segysak.segy import segy_loader, segy_writer + from segysak.segy import segy_loader except ModuleNotFoundError: raise ModuleNotFoundError( 'segysak package is not installed. Use pip install segysak to install the latest version') diff --git a/gemgis/web.py b/gemgis/web.py index 127dc3b8..e4056526 100644 --- a/gemgis/web.py +++ b/gemgis/web.py @@ -98,8 +98,8 @@ def load_wms(url: str, # Requesting the WMS Service or returning an error if a module may be missing try: - wms = owslib.wms.WebMapService(url, - version=version) + wms = WebMapService(url, + version=version) return wms except requests.exceptions.SSLError: @@ -197,11 +197,7 @@ def load_as_map(url: str, # Trying to import owslib but returning error if owslib is not installed try: - import owslib from owslib import util - from owslib.wms import WebMapService - from owslib.wfs import WebFeatureService - from owslib.wcs import WebCoverageService __all__ = [util] except ModuleNotFoundError: raise ModuleNotFoundError( @@ -404,11 +400,7 @@ def load_as_array(url: str, # Trying to import owslib but returning error if owslib is not installed try: - import owslib from owslib import util - from owslib.wms import WebMapService - from owslib.wfs import WebFeatureService - from owslib.wcs import WebCoverageService __all__ = [util] except ModuleNotFoundError: raise ModuleNotFoundError( @@ -557,9 +549,7 @@ def load_wfs(url: str): # -> owslib.wfs.WebFeatureService: try: import owslib from owslib import util - from owslib.wms import WebMapService from owslib.wfs import WebFeatureService - from owslib.wcs import WebCoverageService __all__ = [util] except ModuleNotFoundError: raise ModuleNotFoundError( @@ -578,7 +568,7 @@ def load_wfs(url: str): # -> owslib.wfs.WebFeatureService: # Requesting the WMS Service or returning an error if a module may be missing try: - wfs = owslib.wfs.WebFeatureService(url) + wfs = WebFeatureService(url) return wfs @@ -634,9 +624,6 @@ def load_as_gpd(url: str, try: import owslib from owslib import util - from owslib.wms import WebMapService - from owslib.wfs import WebFeatureService - from owslib.wcs import WebCoverageService __all__ = [util] except ModuleNotFoundError: raise ModuleNotFoundError( @@ -731,8 +718,6 @@ def load_wcs(url: str): # -> owslib.wcs.WebCoverageService: try: import owslib from owslib import util - from owslib.wms import WebMapService - from owslib.wfs import WebFeatureService from owslib.wcs import WebCoverageService __all__ = [util] except ModuleNotFoundError: @@ -744,7 +729,7 @@ def load_wcs(url: str): # -> owslib.wcs.WebCoverageService: raise TypeError('URL must be of type string') # Loading the WCS Layer - wcs = owslib.wcs.WebCoverageService(url) + wcs = WebCoverageService(url) return wcs @@ -810,11 +795,7 @@ def create_request(wcs_url: str, # Trying to import owslib but returning error if owslib is not installed try: - import owslib from owslib import util - from owslib.wms import WebMapService - from owslib.wfs import WebFeatureService - from owslib.wcs import WebCoverageService __all__ = [util] except ModuleNotFoundError: raise ModuleNotFoundError( @@ -904,11 +885,7 @@ def load_as_file(url: str, # Trying to import owslib but returning error if owslib is not installed try: - import owslib from owslib import util - from owslib.wms import WebMapService - from owslib.wfs import WebFeatureService - from owslib.wcs import WebCoverageService __all__ = [util] except ModuleNotFoundError: raise ModuleNotFoundError( @@ -1018,11 +995,7 @@ def load_as_files(wcs_url: str, # Trying to import owslib but returning error if owslib is not installed try: - import owslib from owslib import util - from owslib.wms import WebMapService - from owslib.wfs import WebFeatureService - from owslib.wcs import WebCoverageService __all__ = [util] except ModuleNotFoundError: raise ModuleNotFoundError(