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

GemGIS 1.1.1 #299

Merged
merged 18 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/pypi_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
pip install -r requirements.txt
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERS }}
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ Furthermore, many [example models](https://gemgis.readthedocs.io/en/latest/getti
<a name="installation"></a>
## Installation
It is recommended to use GemGIS with **python">=3.10"** in a separated environment. The main packages and its dependencies can be installed via the conda-forge channel. GemGIS is then available through PyPi or Conda.
1) `conda install -c conda-forge geopandas">=0.12.2" rasterio">=1.3.4"`
2) `conda install -c conda-forge pyvista">=0.37.0"`
1) `conda install -c conda-forge geopandas">=0.13.2" rasterio">=1.3.8"`
2) `conda install -c conda-forge pyvista">=0.42.1"`
3) `pip install gemgis` / `conda install -c conda-forge gemgis`

Check out the [Installation Page](https://gemgis.readthedocs.io/en/latest/getting_started/installation.html) for more detailed instructions.
Expand Down
Binary file added docs/getting_started/images/tutorial70_cover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions docs/getting_started/installation.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.. _installation_ref:

Installation (Tested 2023-01-01)
Installation (Tested 2023-09-01)
===========================================================

GemGIS is supported on Python version 3.10. Previous versions are officially not supported.
Expand Down Expand Up @@ -96,15 +96,15 @@ Installing GemGIS's dependencies manually

Two of the main packages that GemGIS is dependent on are `rasterio <https://rasterio.readthedocs.io/en/latest/>`_ and `GeoPandas <https://geopandas.org/>`_. It is recommended to install these packages separately as they both depend on the `GDAL <https://gdal.org/>`_ translator library for raster and vector geospatial data. In addition, many smaller libraries like shaply or fiona will also be installed properly.

Install the latest versions of GeoPandas and Rasterio (as of 2023-01-01). Please mind the quotation marks that are necessary when specifying the version numbers.::
Install the latest versions of GeoPandas and Rasterio (as of 2023-09-01). Please mind the quotation marks that are necessary when specifying the version numbers.::

conda install -c conda-forge geopandas">=0.12.2" rasterio">=1.3.4"
conda install -c conda-forge geopandas">=0.13.2" rasterio">=1.3.8"

.. image:: images/cmd6.png

In order to visualize and work with meshes, the `PyVista <https://docs.pyvista.org/>`_ package is being installed::

conda install -c conda-forge pyvista">=0.37.0"
conda install -c conda-forge pyvista">=0.42."


Installing GemGIS via PyPi
Expand Down
1,403 changes: 1,403 additions & 0 deletions docs/getting_started/tutorial/70_Reprojecting_Seismic_Data.ipynb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "86f44ca3",
"metadata": {},
"source": [
"# 71 Opening Rasters from OpenFileGDB\n",
"\n",
"This notebook illustrates how to open rasters that are stored in OpenFileGDBs. Currently, QGIS can open rasters from OpenFileGDBs since version 3.32. GeoPandas and the underlying fiona package are capable of opening vector files from OpenFileGDBs. It is not planned to support raster files (https://github.com/geopandas/geopandas/issues/2793). It is not planned to implement that feature into rasterio either (https://github.com/rasterio/rasterio/discussions/2914). Therefore, the decision was made to implement the functionality to open rasters from OpenFileGDBs directly using the `gdal` package. "
]
},
{
"cell_type": "markdown",
"id": "e7147456",
"metadata": {},
"source": [
"## Set File Paths and download Tutorial Data\n",
"\n",
"If you downloaded the latest `GemGIS` version from the Github repository, append the path so that the package can be imported successfully. Otherwise, it is recommended to install `GemGIS` via `pip install gemgis` and import `GemGIS` using `import gemgis as gg`. In addition, the file path to the folder where the data is being stored is set. The tutorial data is downloaded using Pooch (https://www.fatiando.org/pooch/latest/index.html) and stored in the specified folder. Use `pip install pooch` if Pooch is not installed on your system yet."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "eb8af06a",
"metadata": {},
"outputs": [],
"source": [
"import warnings\n",
"warnings.filterwarnings(\"ignore\")\n",
"\n",
"import gemgis as gg"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "a4128de8",
"metadata": {},
"outputs": [],
"source": [
"file_path ='data/71_Opening_Rasters_From_OpenFileGDB/'"
]
},
{
"cell_type": "markdown",
"id": "fb73e2b2-98ab-472d-bb33-e12d82240790",
"metadata": {},
"source": [
"## Opening OpenFileGDB\n",
"\n",
"The OpenFileGDB can be opened using the GemGIS function `gg.raster.read_raster_gdb(...)`. It will automatically save all included rasters to file. If there is no projection included in the OpenFileGDB, a `crs` must be provided manually."
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "fdbd8040-ba16-4047-881d-59358d2289c8",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"RasterCenoman_Turon_top.tif successfully saved to file\n",
"RasterCenoman_Turon_m.tif successfully saved to file\n",
"RasterDevon_MK_m.tif successfully saved to file\n",
"RasterDevon_MK_top.tif successfully saved to file\n",
"RasterUKarb_m.tif successfully saved to file\n",
"RasterUKarb_top.tif successfully saved to file\n",
"RasterDGM.tif successfully saved to file\n"
]
}
],
"source": [
"gg.raster.read_raster_gdb(file_path + 'OpenFileGDB.gdb', \n",
" crs='EPSG:25832')"
]
},
{
"cell_type": "markdown",
"id": "1d9f4836-6af6-40e6-a882-c6f63d0321e0",
"metadata": {},
"source": [
"## Opening Rasters using Rasterio\n",
"\n",
"The downloaded rasters can be opened using the rasterio package as any other raster. "
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
4 changes: 3 additions & 1 deletion docs/getting_started/tutorial/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,6 @@ Each set of functions of GemGIS is collected in a different module. The function
65_displaying_seismic_horizons_and_faults
66_generating_voronoi_polygons
67_rotating_gempy_input_data
68_Creating_Finite_Faults_with_GemGIS
68_Creating_Finite_Faults_with_GemGIS
70_Reprojecting_Seismic_Data
71_Opening_Rasters_From_OpenFileGDB
18 changes: 4 additions & 14 deletions gemgis/postprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1074,21 +1074,11 @@ def clip_fault_of_gempy_model(geo_model,
raise ValueError('Fault is not part of the GemPy geo_model')

# Getting the fault DataFrames
fault_df_interfaces = gp.get_data(geo_model, 'surface_points')[
gp.get_data(geo_model,
'surface_points')['surface'] == fault].reset_index(drop=True)
fault_df_interfaces = geo_model.surface_points.df[
geo_model.surface_points.df['surface'] == fault].reset_index(drop=True)

fault_df_orientations1 = gp.get_data(geo_model,
'orientations',
numeric=False)
fault_df_orientations2 = gp.get_data(geo_model,
'orientations',
numeric=True)

fault_df_orientations = fault_df_orientations1.merge(fault_df_orientations2,
how='inner')

fault_df_orientations = fault_df_orientations[fault_df_orientations['surface'] == fault].reset_index(drop=True)
fault_df_orientations = geo_model.orientations.df[
geo_model.orientations.df['surface'] == fault].reset_index(drop=True)

# Checking that the parameter which is of type string or list of strings
if not isinstance(which, str):
Expand Down
71 changes: 71 additions & 0 deletions gemgis/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -2711,3 +2711,74 @@ def extract_contour_lines_from_raster(raster: Union[rasterio.io.DatasetReader, n
gdf_lines['Z'] = values

return gdf_lines


def read_raster_gdb(path: str,
crs: Union[str,
pyproj.crs.crs.CRS,
rasterio.crs.CRS] = None):
"""Read Raster from OpenFileGDB.

Parameters
__________
path : str
Path to the OpenFileGDB.
crs : str, pyproj.crs.crs.CRS, rasterio.crs.CRS
Coordinate Reference System of the dataset.

.. versionadded:: 1.1.1

"""
# Trying to import osgeo but returning error if tqdm is not installed
try:
from osgeo import gdal, osr
except ModuleNotFoundError:
raise ModuleNotFoundError('osgeo package is not installed')

# Checking that the path is of type string
if not isinstance(path, str):
raise TypeError('Path to the OpenFileGDB must be provided as string')

# Opening Database
ds = gdal.Open(path)

# Getting the length of the subsets
len_subdatasets = len(ds.GetSubDatasets())

# Performing workflow for every dataset
for i in range(len_subdatasets):
# Getting the name of the layer
layer = ds.GetSubDatasets()[i][0]
# Opening the raster layer
dataset = gdal.Open(layer)
# Getting the first raster band
raster_band = dataset.GetRasterBand(1)
# Getting raster values as array
raster = raster_band.ReadAsArray()

# Creating CRS from projection or manually
if dataset.GetProjection():
proj = osr.SpatialReference(wkt=dataset.GetProjection())
epsg = proj.GetAttrValue('AUTHORITY', 1)
crs = 'EPSG:' + epsg
else:
if not crs:
raise ValueError(
'Raster does not have a projection, please provide a valid coordinate reference system')

# Saving raster to file
with rasterio.open(
ds.GetSubDatasets()[i][1].replace(' ', '') + '.tif',
'w',
driver='GTiff',
height=raster.shape[0],
width=raster.shape[1],
count=1,
dtype=raster.dtype,
crs=crs,
transform=affine.Affine.from_gdal(*dataset.GetGeoTransform()),
nodata=raster_band.GetNoDataValue()
) as dst:
dst.write(raster, 1)

print(ds.GetSubDatasets()[i][1].replace(' ', '') + '.tif successfully saved to file')
Loading
Loading