From 42b142dfafbe1c79f0a9dd9c4acc012aafebaf44 Mon Sep 17 00:00:00 2001 From: smknaake Date: Wed, 16 Oct 2024 10:30:48 +0200 Subject: [PATCH] Bump version; change WindowsPath to Path --- geost/__init__.py | 2 +- geost/base.py | 86 ++++++++++++++++----------------- geost/bro/bro_models.py | 6 +-- geost/io/gef.py | 8 +-- geost/io/parsers/gef_parsers.py | 6 +-- geost/io/parsers/xml_parsers.py | 6 +-- geost/mixins.py | 30 ++++++------ geost/models/basemodels.py | 8 ++- geost/read.py | 40 +++++++-------- geost/spatial.py | 42 ++++++++-------- geost/utils.py | 16 +++--- tutorials/basics.ipynb | 4 +- 12 files changed, 126 insertions(+), 128 deletions(-) diff --git a/geost/__init__.py b/geost/__init__.py index 36cc17f..ad07a11 100644 --- a/geost/__init__.py +++ b/geost/__init__.py @@ -15,4 +15,4 @@ # read_xml_soil_cores, from geost.utils import csv_to_parquet, excel_to_parquet -__version__ = "0.2.4" +__version__ = "0.2.5" diff --git a/geost/base.py b/geost/base.py index 1482430..fac1cdf 100644 --- a/geost/base.py +++ b/geost/base.py @@ -1,5 +1,5 @@ import pickle -from pathlib import WindowsPath +from pathlib import Path from typing import Any, Iterable, List import geopandas as gpd @@ -237,7 +237,7 @@ def select_within_bbox( def select_with_points( self, - points: str | WindowsPath | gpd.GeoDataFrame, + points: str | Path | gpd.GeoDataFrame, buffer: float | int, invert: bool = False, ): @@ -246,7 +246,7 @@ def select_with_points( Parameters ---------- - points : str | WindowsPath | gpd.GeoDataFrame + points : str | Path | gpd.GeoDataFrame Geodataframe (or file that can be parsed to a geodataframe) to select with. buffer : float | int Buffer distance for selection geometries. @@ -266,7 +266,7 @@ def select_with_points( def select_with_lines( self, - lines: str | WindowsPath | gpd.GeoDataFrame, + lines: str | Path | gpd.GeoDataFrame, buffer: float | int, invert: bool = False, ): @@ -275,7 +275,7 @@ def select_with_lines( Parameters ---------- - lines : str | WindowsPath | gpd.GeoDataFrame + lines : str | Path | gpd.GeoDataFrame Geodataframe (or file that can be parsed to a geodataframe) to select with. buffer : float | int Buffer distance for selection geometries. @@ -295,7 +295,7 @@ def select_with_lines( def select_within_polygons( self, - polygons: str | WindowsPath | gpd.GeoDataFrame, + polygons: str | Path | gpd.GeoDataFrame, buffer: float | int = 0, invert: bool = False, ): @@ -304,7 +304,7 @@ def select_within_polygons( Parameters ---------- - polygons : str | WindowsPath | gpd.GeoDataFrame + polygons : str | Path | gpd.GeoDataFrame Geodataframe (or file that can be parsed to a geodataframe) to select with. buffer : float | int, optional Optional buffer distance around the polygon selection geometries, by default @@ -397,7 +397,7 @@ def select_by_length(self, min_length: float = None, max_length: float = None): def get_area_labels( self, - polygon_gdf: str | WindowsPath | gpd.GeoDataFrame, + polygon_gdf: str | Path | gpd.GeoDataFrame, column_name: str, include_in_header=False, ) -> pd.DataFrame: @@ -407,7 +407,7 @@ def get_area_labels( Parameters ---------- - polygon_gdf : str | WindowsPath | gpd.GeoDataFrame + polygon_gdf : str | Path | gpd.GeoDataFrame GeoDataFrame with polygons. column_name : str The column name to find the labels in. @@ -968,7 +968,7 @@ def to_multiblock( def to_vtm( self, - outfile: str | WindowsPath, + outfile: str | Path, data_columns: str | List[str], radius: float = 1, vertical_factor: float = 1.0, @@ -981,7 +981,7 @@ def to_vtm( Parameters ---------- - outfile : str | WindowsPath + outfile : str | Path Path to vtm file to be written. data_columns : str | List[str] Name or names of data columns to include for visualisation. Can be columns that @@ -1014,7 +1014,7 @@ def to_vtm( def to_datafusiontools( self, columns: List[str], - outfile: str | WindowsPath = None, + outfile: str | Path = None, encode: bool = False, relative_to_vertical_reference: bool = True, ): @@ -1032,7 +1032,7 @@ def to_datafusiontools( columns : List[str] Which columns in the data to include for the export. These will become variables in the DataFusionTools "Data" class. - outfile : str | WindowsPath, optional + outfile : str | Path, optional If a path to outfile is given, the data is written to a pickle file. encode : bool, default True If True, categorical data columns are encoded to additional binary columns @@ -1136,7 +1136,7 @@ def _create_geodataframe_3d( def to_qgis3d( self, - outfile: str | WindowsPath, + outfile: str | Path, relative_to_vertical_reference: bool = True, crs: str | int | CRS = None, **kwargs, @@ -1147,7 +1147,7 @@ def to_qgis3d( Parameters ---------- - outfile : str | WindowsPath + outfile : str | Path Path to geopackage file to be written. relative_to_vertical_reference : bool, optional If True, the depth of all data objects will converted to a depth with @@ -1167,7 +1167,7 @@ def to_qgis3d( def to_kingdom( self, - outfile: str | WindowsPath, + outfile: str | Path, tdstart: int = 1, vw: float = 1500.0, vs: float = 1600.0, @@ -1178,7 +1178,7 @@ def to_kingdom( Parameters ---------- - outfile : str | WindowsPath + outfile : str | Path Path to csv file to be written. tdstart : int startindex for TDchart, default is 1 @@ -1693,7 +1693,7 @@ def select_within_bbox( def select_with_points( self, - points: str | WindowsPath | gpd.GeoDataFrame, + points: str | Path | gpd.GeoDataFrame, buffer: float | int, invert: bool = False, ): @@ -1702,7 +1702,7 @@ def select_with_points( Parameters ---------- - points : str | WindowsPath | gpd.GeoDataFrame + points : str | Path | gpd.GeoDataFrame Geodataframe (or file that can be parsed to a geodataframe) to select with. buffer : float | int Buffer distance for selection geometries. @@ -1722,7 +1722,7 @@ def select_with_points( def select_with_lines( self, - lines: str | WindowsPath | gpd.GeoDataFrame, + lines: str | Path | gpd.GeoDataFrame, buffer: float | int, invert: bool = False, ): @@ -1731,7 +1731,7 @@ def select_with_lines( Parameters ---------- - lines : str | WindowsPath | gpd.GeoDataFrame + lines : str | Path | gpd.GeoDataFrame Geodataframe (or file that can be parsed to a geodataframe) to select with. buffer : float | int Buffer distance for selection geometries. @@ -1751,7 +1751,7 @@ def select_with_lines( def select_within_polygons( self, - polygons: str | WindowsPath | gpd.GeoDataFrame, + polygons: str | Path | gpd.GeoDataFrame, buffer: float | int = 0, invert: bool = False, ): @@ -1760,7 +1760,7 @@ def select_within_polygons( Parameters ---------- - polygons : str | WindowsPath | gpd.GeoDataFrame + polygons : str | Path | gpd.GeoDataFrame Geodataframe (or file that can be parsed to a geodataframe) to select with. buffer : float | int, optional Optional buffer distance around the polygon selection geometries, by default @@ -2028,7 +2028,7 @@ def select_by_condition(self, condition: Any, invert: bool = False): def get_area_labels( self, - polygon_gdf: str | WindowsPath | gpd.GeoDataFrame, + polygon_gdf: str | Path | gpd.GeoDataFrame, column_name: str, include_in_header=False, ) -> pd.DataFrame: @@ -2038,7 +2038,7 @@ def get_area_labels( Parameters ---------- - polygon_gdf : str | WindowsPath | gpd.GeoDataFrame + polygon_gdf : str | Path | gpd.GeoDataFrame GeoDataFrame with polygons. column_name : str The column name to find the labels in. @@ -2057,7 +2057,7 @@ def get_area_labels( ) return result - def to_geoparquet(self, outfile: str | WindowsPath, **kwargs): + def to_geoparquet(self, outfile: str | Path, **kwargs): """ Write header data to geoparquet. You can use the resulting file to display borehole locations in GIS for instance. Please note that Geoparquet is supported @@ -2065,7 +2065,7 @@ def to_geoparquet(self, outfile: str | WindowsPath, **kwargs): Parameters ---------- - file : str | WindowsPath + file : str | Path Path to shapefile to be written. **kwargs gpd.GeoDataFrame.to_parquet kwargs. See relevant Pandas documentation. @@ -2073,14 +2073,14 @@ def to_geoparquet(self, outfile: str | WindowsPath, **kwargs): """ self.header.to_geoparquet(outfile, **kwargs) - def to_shape(self, outfile: str | WindowsPath, **kwargs): + def to_shape(self, outfile: str | Path, **kwargs): """ Write header data to shapefile. You can use the resulting file to display borehole locations in GIS for instance. Parameters ---------- - file : str | WindowsPath + file : str | Path Path to shapefile to be written. **kwargs gpd.GeoDataFrame.to_file kwargs. See relevant GeoPandas documentation. @@ -2088,14 +2088,14 @@ def to_shape(self, outfile: str | WindowsPath, **kwargs): """ self.header.to_shape(outfile, **kwargs) - def to_geopackage(self, outfile: str | WindowsPath, **kwargs): + def to_geopackage(self, outfile: str | Path, **kwargs): """ Write header data to geopackage. You can use the resulting file to display borehole locations in GIS for instance. Parameters ---------- - file : str | WindowsPath + file : str | Path Path to geopackage to be written. **kwargs gpd.GeoDataFrame.to_file kwargs. See relevant GeoPandas documentation. @@ -2103,14 +2103,14 @@ def to_geopackage(self, outfile: str | WindowsPath, **kwargs): """ self.header.to_geopackage(outfile, **kwargs) - def to_parquet(self, outfile: str | WindowsPath, data_table: bool = True, **kwargs): + def to_parquet(self, outfile: str | Path, data_table: bool = True, **kwargs): """ Export the data or header table to a parquet file. By default the data table is exported. Parameters ---------- - file : str | WindowsPath + file : str | Path Path to parquet file to be written. data_table : bool, optional If True, the data table is exported. If False, the header table is exported. @@ -2131,14 +2131,14 @@ def to_parquet(self, outfile: str | WindowsPath, data_table: bool = True, **kwar else: self.header.to_parquet(outfile, **kwargs) - def to_csv(self, outfile: str | WindowsPath, data_table: bool = True, **kwargs): + def to_csv(self, outfile: str | Path, data_table: bool = True, **kwargs): """ Export the data or header table to a csv file. By default the data table is exported. Parameters ---------- - file : str | WindowsPath + file : str | Path Path to csv file to be written. data_table : bool, optional If True, the data table is exported. If False, the header table is exported. @@ -2199,7 +2199,7 @@ def to_multiblock( def to_vtm( self, - outfile: str | WindowsPath, + outfile: str | Path, data_columns: str | List[str], radius: float = 1, vertical_factor: float = 1.0, @@ -2212,7 +2212,7 @@ def to_vtm( Parameters ---------- - outfile : str | WindowsPath + outfile : str | Path Path to vtm file to be written. data_columns : str | List[str] Name or names of data columns to include for visualisation. Can be columns that @@ -2244,7 +2244,7 @@ def to_vtm( def to_datafusiontools( self, columns: List[str], - outfile: str | WindowsPath = None, + outfile: str | Path = None, encode: bool = False, relative_to_vertical_reference: bool = True, ): @@ -2262,7 +2262,7 @@ def to_datafusiontools( columns : List[str] Which columns in the data to include for the export. These will become variables in the DataFusionTools "Data" class. - outfile : str | WindowsPath, optional + outfile : str | Path, optional If a path to outfile is given, the data is written to a pickle file. encode : bool, default True If True, categorical data columns are encoded to additional binary columns @@ -2409,7 +2409,7 @@ def get_layer_top( def to_qgis3d( self, - outfile: str | WindowsPath, + outfile: str | Path, relative_to_vertical_reference: bool = True, **kwargs, ): @@ -2419,7 +2419,7 @@ def to_qgis3d( Parameters ---------- - outfile : str | WindowsPath + outfile : str | Path Path to geopackage file to be written. relative_to_vertical_reference : bool, optional If True, the depth of all data objects will converted to a depth with respect to @@ -2440,7 +2440,7 @@ def to_qgis3d( def to_kingdom( self, - outfile: str | WindowsPath, + outfile: str | Path, tdstart: int = 1, vw: float = 1500.0, vs: float = 1600.0, @@ -2451,7 +2451,7 @@ def to_kingdom( Parameters ---------- - out_file : str | WindowsPath + out_file : str | Path Path to csv file to be written. tdstart : int startindex for TDchart, default is 1 diff --git a/geost/bro/bro_models.py b/geost/bro/bro_models.py index f007757..0259714 100644 --- a/geost/bro/bro_models.py +++ b/geost/bro/bro_models.py @@ -1,4 +1,4 @@ -from pathlib import WindowsPath +from pathlib import Path from typing import List import rioxarray as rio @@ -13,7 +13,7 @@ class GeoTop(VoxelModel): @classmethod def from_netcdf( cls, - nc_path: str | WindowsPath, + nc_path: str | Path, data_vars: List[str] = None, bbox: tuple[float, float, float, float] = None, lazy: bool = True, @@ -26,7 +26,7 @@ def from_netcdf( Parameters ---------- - nc_path : str | WindowsPath + nc_path : str | Path Path to the netcdf file of GeoTop. data_vars : ArrayLike List or array-like object specifying which data variables to return. diff --git a/geost/io/gef.py b/geost/io/gef.py index 902afe5..ecf6bb7 100644 --- a/geost/io/gef.py +++ b/geost/io/gef.py @@ -1,19 +1,19 @@ # import numpy as np # import pandas as pd -from pathlib import Path, WindowsPath +from pathlib import Path from typing import Iterable, Union from geost.io.parsers.gef_parsers import CptGefFile from geost.utils import get_path_iterable -def _parse_cpt_gef_files(file_or_folder: Union[str, WindowsPath]): +def _parse_cpt_gef_files(file_or_folder: Union[str, Path]): """ Parse gef files from CPT data into Pandas DataFrames. Parameters ---------- - file_or_folder : Union[str, WindowsPath] + file_or_folder : Union[str, Path] Gef file or folder with gef files to parse. Yields @@ -22,7 +22,7 @@ def _parse_cpt_gef_files(file_or_folder: Union[str, WindowsPath]): Pandas DataFrame per gef file. """ - if isinstance(file_or_folder, (str, WindowsPath)): + if isinstance(file_or_folder, (str, Path)): files = get_path_iterable(Path(file_or_folder), wildcard="*.gef") elif isinstance(file_or_folder, Iterable): diff --git a/geost/io/parsers/gef_parsers.py b/geost/io/parsers/gef_parsers.py index bc6de3c..77a6fa7 100644 --- a/geost/io/parsers/gef_parsers.py +++ b/geost/io/parsers/gef_parsers.py @@ -1,6 +1,6 @@ import logging import re -from pathlib import WindowsPath +from pathlib import Path from typing import NamedTuple, Union import numpy as np @@ -136,7 +136,7 @@ class CptGefFile: # TODO: Break parser down in HeaderParser and DataParser and Parameters ---------- - path : str, WindowsPath, optional + path : str, Path, optional Path to the gef file to parse. If None, an empty class instance is returned. sep : str, optional Column separator character of the gef file to use when the separator is not @@ -144,7 +144,7 @@ class CptGefFile: # TODO: Break parser down in HeaderParser and DataParser and """ - def __init__(self, path: str | WindowsPath = None, sep: str = " "): + def __init__(self, path: str | Path = None, sep: str = " "): self.path = path self._header = None self._data = None diff --git a/geost/io/parsers/xml_parsers.py b/geost/io/parsers/xml_parsers.py index 0d4015f..554d241 100644 --- a/geost/io/parsers/xml_parsers.py +++ b/geost/io/parsers/xml_parsers.py @@ -1,5 +1,5 @@ import re -from pathlib import Path, WindowsPath +from pathlib import Path from typing import NamedTuple, Union import pandas as pd @@ -23,8 +23,8 @@ class LayerSoilCore(NamedTuple): class SoilCore: - def __init__(self, xml: Union[str, WindowsPath, etree._Element]): - if isinstance(xml, (str, WindowsPath)): + def __init__(self, xml: Union[str, Path, etree._Element]): + if isinstance(xml, (str, Path)): self.root = etree.parse(xml).getroot() elif isinstance(xml, etree._Element): self.root = xml diff --git a/geost/mixins.py b/geost/mixins.py index 2399a23..eadb413 100644 --- a/geost/mixins.py +++ b/geost/mixins.py @@ -1,30 +1,30 @@ -from pathlib import WindowsPath +from pathlib import Path import geopandas as gpd import pandas as pd class PandasExportMixin: - def to_csv(self, file: str | WindowsPath, **kwargs): + def to_csv(self, file: str | Path, **kwargs): """ Write data to csv file. Parameters ---------- - file : str | WindowsPath + file : str | Path Path to csv file to be written. **kwargs pd.DataFrame.to_csv kwargs. See relevant Pandas documentation. """ self.df.to_csv(file, **kwargs) - def to_parquet(self, file: str | WindowsPath, **kwargs): + def to_parquet(self, file: str | Path, **kwargs): """ Write data to parquet file. Parameters ---------- - file : str | WindowsPath + file : str | Path Path to parquet file to be written. **kwargs pd.DataFrame.to_parquet kwargs. See relevant Pandas documentation. @@ -33,13 +33,13 @@ def to_parquet(self, file: str | WindowsPath, **kwargs): class GeopandasExportMixin: - def to_csv(self, file: str | WindowsPath, **kwargs): + def to_csv(self, file: str | Path, **kwargs): """ Write header to csv file as plain table (no geometries). Parameters ---------- - file : str | WindowsPath + file : str | Path Path to csv file to be written. **kwargs pd.DataFrame.to_csv kwargs. See relevant Pandas documentation. @@ -47,13 +47,13 @@ def to_csv(self, file: str | WindowsPath, **kwargs): df = pd.DataFrame(self.gdf.drop(columns="geometry")) df.to_csv(file, **kwargs) - def to_parquet(self, file: str | WindowsPath, **kwargs): + def to_parquet(self, file: str | Path, **kwargs): """ Write header to parquet file as plain table (no geometries). Parameters ---------- - file : str | WindowsPath + file : str | Path Path to parquet file to be written. **kwargs pd.DataFrame.to_parquet kwargs. See relevant Pandas documentation. @@ -61,35 +61,35 @@ def to_parquet(self, file: str | WindowsPath, **kwargs): df = pd.DataFrame(self.gdf.drop(columns="geometry")) df.to_parquet(file, **kwargs) - def to_shape(self, file: str | WindowsPath, **kwargs): + def to_shape(self, file: str | Path, **kwargs): """ Write header data to shapefile. You can use the resulting file to display borehole locations in GIS for instance. Parameters ---------- - file : str | WindowsPath + file : str | Path Path to shapefile to be written. **kwargs gpd.GeoDataFrame.to_file kwargs. See relevant GeoPandas documentation. """ self.gdf.to_file(file, **kwargs) - def to_geopackage(self, file: str | WindowsPath, **kwargs): + def to_geopackage(self, file: str | Path, **kwargs): """ Write header data to geopackage. You can use the resulting file to display borehole locations in GIS for instance. Parameters ---------- - file : str | WindowsPath + file : str | Path Path to geopackage to be written. **kwargs gpd.GeoDataFrame.to_file kwargs. See relevant GeoPandas documentation. """ self.gdf.to_file(file, **kwargs) - def to_geoparquet(self, file: str | WindowsPath, **kwargs): + def to_geoparquet(self, file: str | Path, **kwargs): """ Write header data to geoparquet. You can use the resulting file to display borehole locations in GIS for instance. Please note that Geoparquet is supported @@ -97,7 +97,7 @@ def to_geoparquet(self, file: str | WindowsPath, **kwargs): Parameters ---------- - file : str | WindowsPath + file : str | Path Path to shapefile to be written. **kwargs gpd.GeoDataFrame.to_parquet kwargs. See relevant Pandas documentation. diff --git a/geost/models/basemodels.py b/geost/models/basemodels.py index ed066d0..985409c 100644 --- a/geost/models/basemodels.py +++ b/geost/models/basemodels.py @@ -1,5 +1,5 @@ from abc import ABC, abstractmethod -from pathlib import WindowsPath +from pathlib import Path import geopandas as gpd import numpy as np @@ -233,15 +233,13 @@ def select_index(self, **xr_kwargs): selected = self.ds.isel(**xr_kwargs) return self.__class__(selected) - def select_with_points( - self, points: str | WindowsPath | gpd.GeoDataFrame - ) -> xr.Dataset: + def select_with_points(self, points: str | Path | gpd.GeoDataFrame) -> xr.Dataset: """ Select voxel columns at the locations of point geometries. Parameters ---------- - points : str | WindowsPath | gpd.GeoDataFrame + points : str | Path | gpd.GeoDataFrame Geodataframe (or file that can be parsed to a geodataframe) to select with. Returns diff --git a/geost/read.py b/geost/read.py index 98b66b3..7aacfd3 100644 --- a/geost/read.py +++ b/geost/read.py @@ -1,4 +1,4 @@ -from pathlib import Path, WindowsPath +from pathlib import Path from typing import Union import geopandas as gpd @@ -49,13 +49,13 @@ } -def __read_file(file: str | WindowsPath, **kwargs) -> pd.DataFrame: +def __read_file(file: str | Path, **kwargs) -> pd.DataFrame: """ Read parquet file. Parameters ---------- - file : WindowsPath + file : Path Path to file to be read. kwargs : optional Kwargs to pass to the read function @@ -144,7 +144,7 @@ def _check_mandatory_column_presence( def read_borehole_table( - file: str | WindowsPath, + file: str | Path, horizontal_reference: str | int | CRS = 28992, vertical_reference: str | int | CRS = 5709, has_inclined: bool = False, @@ -176,7 +176,7 @@ def read_borehole_table( Parameters ---------- - file : str | WindowsPath + file : str | Path Path to file to be read. Depending on the file extension, the corresponding Pandas read function will be called. This can be either pandas.read_parquet, pandas.read_csv or pandas.read_excel. The **kwargs that can be given to this @@ -244,7 +244,7 @@ def read_borehole_table( def read_cpt_table( - file: str | WindowsPath, + file: str | Path, horizontal_reference: str | int | CRS = 28992, vertical_reference: str | int | CRS = 5709, as_collection: bool = True, @@ -265,7 +265,7 @@ def read_cpt_table( Parameters ---------- - file : str | WindowsPath + file : str | Path File with the CPT information to read. horizontal_reference : str | int | CRS, optional EPSG of the data's horizontal reference. Takes anything that can be interpreted @@ -308,7 +308,7 @@ def read_cpt_table( return cpts -def read_nlog_cores(file: str | WindowsPath) -> BoreholeCollection: +def read_nlog_cores(file: str | Path) -> BoreholeCollection: """ Read NLog boreholes from the 'nlog_stratstelsel' Excel file. You can find this distribution of borehole data here: https://www.nlog.nl/boringen @@ -319,7 +319,7 @@ def read_nlog_cores(file: str | WindowsPath) -> BoreholeCollection: Parameters ---------- - file : str | WindowsPath + file : str | Path Path to nlog_stratstelsel.xlsx or .parquet Returns @@ -383,7 +383,7 @@ def read_nlog_cores(file: str | WindowsPath) -> BoreholeCollection: def read_xml_geotechnical_cores( - file_or_folder: str | WindowsPath, + file_or_folder: str | Path, ) -> BoreholeCollection: """ NOTIMPLEMENTED @@ -394,7 +394,7 @@ def read_xml_geotechnical_cores( pass -def read_xml_soil_cores(file_or_folder: str | WindowsPath) -> BoreholeCollection: +def read_xml_soil_cores(file_or_folder: str | Path) -> BoreholeCollection: """ NOTIMPLEMENTED Read xml files of BRO soil boreholes (IMBRO or IMBRO/A quality). @@ -403,7 +403,7 @@ def read_xml_soil_cores(file_or_folder: str | WindowsPath) -> BoreholeCollection pass -def read_xml_geological_cores(file_or_folder: str | WindowsPath) -> BoreholeCollection: +def read_xml_geological_cores(file_or_folder: str | Path) -> BoreholeCollection: """ NOTIMPLEMENTED Read xml files of DINO geological boreholes. @@ -412,7 +412,7 @@ def read_xml_geological_cores(file_or_folder: str | WindowsPath) -> BoreholeColl pass -def read_gef_cores(file_or_folder: str | WindowsPath) -> BoreholeCollection: +def read_gef_cores(file_or_folder: str | Path) -> BoreholeCollection: """ NOTIMPLEMENTED Read gef files of boreholes. @@ -421,13 +421,13 @@ def read_gef_cores(file_or_folder: str | WindowsPath) -> BoreholeCollection: pass -def read_gef_cpts(file_or_folder: str | WindowsPath) -> CptCollection: +def read_gef_cpts(file_or_folder: str | Path) -> CptCollection: """ Read one or more GEF files of CPT data into a geost CptCollection. Parameters ---------- - file_or_folder : str | WindowsPath + file_or_folder : str | Path GEF files to read. Returns @@ -442,7 +442,7 @@ def read_gef_cpts(file_or_folder: str | WindowsPath) -> CptCollection: return DiscreteData(df).to_collection() -def read_xml_cpts(file_or_folder: str | WindowsPath) -> CptCollection: +def read_xml_cpts(file_or_folder: str | Path) -> CptCollection: """ NOTIMPLEMENTED Read xml files of cpts. @@ -598,8 +598,8 @@ def get_bro_objects_from_geometry( def read_uullg_tables( - header_table: str | WindowsPath, - data_table: str | WindowsPath, + header_table: str | Path, + data_table: str | Path, horizontal_reference: str | int | CRS = 28992, vertical_reference: str | int | CRS = 5709, **kwargs, @@ -613,9 +613,9 @@ def read_uullg_tables( Parameters ---------- - header_table : str | WindowsPath + header_table : str | Path Path to file of the UU-LLG header table. - data_table : str | WindowsPath + data_table : str | Path Path to file of the UU-LLG data table. horizontal_reference : str | int | CRS, optional EPSG of the data's horizontal reference. Takes anything that can be interpreted diff --git a/geost/spatial.py b/geost/spatial.py index d774e94..528d008 100644 --- a/geost/spatial.py +++ b/geost/spatial.py @@ -1,4 +1,4 @@ -from pathlib import Path, WindowsPath +from pathlib import Path import geopandas as gpd import numpy as np @@ -13,7 +13,7 @@ def check_gdf_instance( - gdf_or_path: str | WindowsPath | gpd.GeoDataFrame, + gdf_or_path: str | Path | gpd.GeoDataFrame, ) -> gpd.GeoDataFrame: """ Check if the argument is already a geodataframe or pointing to a file @@ -21,7 +21,7 @@ def check_gdf_instance( Parameters ---------- - gdf_or_path : str | WindowsPath | gpd.GeoDataFrame + gdf_or_path : str | Path | gpd.GeoDataFrame The geodataframe or file that can be read and parsed to a geodataframe Returns @@ -29,7 +29,7 @@ def check_gdf_instance( gpd.GeoDataFrame An instance of a geopandas geodataframe """ - if isinstance(gdf_or_path, str | WindowsPath): + if isinstance(gdf_or_path, str | Path): gdf_or_path = Path(gdf_or_path) filetype = gdf_or_path.suffix if filetype in (".parquet", ".geoparquet"): @@ -85,7 +85,7 @@ def check_and_coerce_crs(gdf: gpd.GeoDataFrame, to_crs: int): def select_points_within_bbox( - gdf: str | WindowsPath | gpd.GeoDataFrame, + gdf: str | Path | gpd.GeoDataFrame, xmin: float | int, ymin: float | int, xmax: float | int, @@ -97,7 +97,7 @@ def select_points_within_bbox( Parameters ---------- - gdf : str | WindowsPath | gpd.GeoDataFrame + gdf : str | Path | gpd.GeoDataFrame Geodataframe (or file that can be parsed to a geodataframe) to select from. xmin : float | int Minimum x-coordinate of the bounding box. @@ -130,8 +130,8 @@ def select_points_within_bbox( def select_points_near_points( - gdf: str | WindowsPath | gpd.GeoDataFrame, - point_gdf: str | WindowsPath | gpd.GeoDataFrame, + gdf: str | Path | gpd.GeoDataFrame, + point_gdf: str | Path | gpd.GeoDataFrame, buffer: float | int, invert: bool = False, ) -> gpd.GeoDataFrame: @@ -140,9 +140,9 @@ def select_points_near_points( Parameters ---------- - gdf : str | WindowsPath | gpd.GeoDataFrame + gdf : str | Path | gpd.GeoDataFrame Geodataframe (or file that can be parsed to a geodataframe) to select from. - point_gdf : str | WindowsPath | gpd.GeoDataFrame + point_gdf : str | Path | gpd.GeoDataFrame Geodataframe (or file that can be parsed to a geodataframe) to select with. buffer : float | int Buffer distance for selection geometries. @@ -178,8 +178,8 @@ def select_points_near_points( def select_points_near_lines( - gdf: str | WindowsPath | gpd.GeoDataFrame, - line_gdf: str | WindowsPath | gpd.GeoDataFrame, + gdf: str | Path | gpd.GeoDataFrame, + line_gdf: str | Path | gpd.GeoDataFrame, buffer: float | int, invert: bool = False, ) -> gpd.GeoDataFrame: @@ -188,9 +188,9 @@ def select_points_near_lines( Parameters ---------- - gdf : str | WindowsPath | gpd.GeoDataFrame + gdf : str | Path | gpd.GeoDataFrame Geodataframe (or file that can be parsed to a geodataframe) to select from. - line_gdf : str | WindowsPath | gpd.GeoDataFrame + line_gdf : str | Path | gpd.GeoDataFrame Geodataframe (or file that can be parsed to a geodataframe) to select with. buffer : float | int Buffer distance for selection geometries. @@ -216,8 +216,8 @@ def select_points_near_lines( def select_points_within_polygons( - gdf: str | WindowsPath | gpd.GeoDataFrame, - polygon_gdf: str | WindowsPath | gpd.GeoDataFrame, + gdf: str | Path | gpd.GeoDataFrame, + polygon_gdf: str | Path | gpd.GeoDataFrame, buffer: float | int = 0, invert: bool = False, ) -> gpd.GeoDataFrame: @@ -227,9 +227,9 @@ def select_points_within_polygons( Parameters ---------- - gdf : str | WindowsPath | gpd.GeoDataFrame + gdf : str | Path | gpd.GeoDataFrame Geodataframe (or file that can be parsed to a geodataframe) to select from. - polygon_gdf : str | WindowsPath | gpd.GeoDataFrame + polygon_gdf : str | Path | gpd.GeoDataFrame Geodataframe (or file that can be parsed to a geodataframe) to select with. buffer : float | int, optional Optional buffer distance around the polygon selection geometries, by default 0. @@ -291,7 +291,7 @@ def find_area_labels( def get_raster_values( - x: np.ndarray, y: np.ndarray, raster_to_read: str | WindowsPath | xr.DataArray + x: np.ndarray, y: np.ndarray, raster_to_read: str | Path | xr.DataArray ) -> np.ndarray: """ Return sampled values from a raster at the given (x, y) locations. @@ -302,7 +302,7 @@ def get_raster_values( 1D array of x-coordinates, same length as 'y'. y : np.ndarray 1D array of y-coordinates, same length as 'x'. - raster_to_read : str | WindowsPath | xr.DataArray + raster_to_read : str | Path | xr.DataArray Location of a raster file or an xr.DataArray with dimensions 'x' and 'y'. This raster is used to sample values from at all (x, y) locations. @@ -311,7 +311,7 @@ def get_raster_values( np.ndarray 1D array of sampled values """ - if isinstance(raster_to_read, (str, WindowsPath)): + if isinstance(raster_to_read, (str, Path)): raster_to_read = rioxarray.open_rasterio(raster_to_read).squeeze() if set(raster_to_read.dims) != set(("y", "x")): diff --git a/geost/utils.py b/geost/utils.py index 84baa92..44e4307 100644 --- a/geost/utils.py +++ b/geost/utils.py @@ -1,5 +1,5 @@ import operator -from pathlib import Path, WindowsPath +from pathlib import Path from typing import Union import geopandas as gpd @@ -23,16 +23,16 @@ def csv_to_parquet( - file: Union[str, WindowsPath], out_file: Union[str, WindowsPath] = None, **kwargs + file: Union[str, Path], out_file: Union[str, Path] = None, **kwargs ) -> None: """ Convert csv table to parquet. Parameters ---------- - file : Union[str, WindowsPath] + file : Union[str, Path] Path to csv file to convert. - out_file : Union[str, WindowsPath], optional + out_file : Union[str, Path], optional Path to parquet file to be written. If not provided it will use the path of 'file'. **kwargs @@ -55,16 +55,16 @@ def csv_to_parquet( def excel_to_parquet( - file: Union[str, WindowsPath], out_file: Union[str, WindowsPath] = None, **kwargs + file: Union[str, Path], out_file: Union[str, Path] = None, **kwargs ) -> None: """ Convert excel table to parquet. Parameters ---------- - file : Union[str, WindowsPath] + file : Union[str, Path] Path to excel file to convert. - out_file : Union[str, WindowsPath], optional + out_file : Union[str, Path], optional Path to parquet file to be written. If not provided it will use the path of 'file'. **kwargs @@ -88,7 +88,7 @@ def excel_to_parquet( df.to_parquet(out_file) -def get_path_iterable(path: WindowsPath, wildcard: str = "*"): +def get_path_iterable(path: Path, wildcard: str = "*"): if path.is_file(): return [path] elif path.is_dir(): diff --git a/tutorials/basics.ipynb b/tutorials/basics.ipynb index 0c8f983..06c14c7 100644 --- a/tutorials/basics.ipynb +++ b/tutorials/basics.ipynb @@ -626,7 +626,7 @@ ], "metadata": { "kernelspec": { - "display_name": "geost_env", + "display_name": "default", "language": "python", "name": "python3" }, @@ -640,7 +640,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.4" + "version": "3.12.5" }, "orig_nbformat": 4 },