Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
546 changes: 546 additions & 0 deletions packages/map2loop/CHANGELOG.md

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions packages/map2loop/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020-2021 The Loop Project

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
124 changes: 124 additions & 0 deletions packages/map2loop/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
![GitHub Release](https://img.shields.io/github/v/release/loop3d/map2loop)
[![DOI](https://img.shields.io/static/v1?label=DOI&message=10.5194/gmd-14-5063-2021&color=blue)](https://doi.org/10.5194/gmd-14-5063-2021)
![License](https://img.shields.io/github/license/loop3d/map2loop)
![PyPI - Downloads](https://img.shields.io/pypi/dm/map2loop?label=pip%20downloads)
![Conda Downloads](https://img.shields.io/conda/dn/loop3d/map2loop?label=Conda%20downloads)
[![Testing](https://github.com/Loop3D/map2loop/actions/workflows/linting_and_testing.yml/badge.svg)](https://github.com/Loop3D/map2loop/actions/workflows/linting_and_testing.yml)
[![Build and Deploy Documentation](https://github.com/Loop3D/map2loop/actions/workflows/documentation.yml/badge.svg)](https://github.com/Loop3D/map2loop/actions/workflows/documentation.yml)


# Map2Loop 3.2

Generate 3D geological model inputs from geological maps — a high-level implementation and extension of the original map2loop code developed by Prof. Mark Jessell at UWA. To see an example interactive model built with map2loop and LoopStructural, follow this link:

<a href="http://tectonique.net/models/brockman_syncline.html">3D Model from the Hamersley region, Western Australia</a>

## Install

#### Option 1: Install with Anaconda

This is the simplest and recommended installation process, with:

```bash
conda install -c loop3d -c conda-forge map2loop
```

#### Option 2: Install with pip
Installation with pip will require that GDAL is installed on your system prior to map2loop installation.
This is because GDAL cannot be installed <a href='https://hackernoon.com/hn-images/1*m4cnTYJWM7Rmpsju8dSHmQ.jpeg'>via pip</a> (at least not with one line of code), and the GDAL installation process will vary depending on your OS.

For more information on installing gdal, see <a href="https://pypi.org/project/GDAL/">GDAL's Pypi</a> page.

Once GDAL is available on your system, map2loop can be installed with:
```bash
pip install map2loop
```

#### Option 3: From source

```bash
git clone https://github.com/Loop3D/map2loop.git

cd map2loop

conda install gdal

conda install -c loop3d -c conda-forge --file dependencies.txt

pip install .
```

#### Option 4: From source & developer mode:
```bash
git clone https://github.com/Loop3D/map2loop.git

cd map2loop

conda install gdal

conda install -c loop3d -c conda-forge --file dependencies.txt

pip install -e .
```

### Documentation

Map2loop's documentation is available <a href="https://loop3d.org/map2loop/">here</a>


## Usage

Our notebooks cover use cases in more detail, but here is an example of processing Loop's South Australia remote geospatial data in just 20 lines of Python.

First, let's import map2loop and define a bounding box. You can use GIS software to find one or use [Loop's Graphical User Interface](https://loop3d.github.io/downloads.html) for the best experience and complete toolset. Remember what projection your coordinates are in!

```python
from map2loop.project import Project
from map2loop.m2l_enums import VerboseLevel

# Note that this region is defined in the EPSG 28354 projection and
# x and y represent easting and northing respectively
bbox_3d = {
'minx': 250805.1529856466,
'miny': 6405084.328058686,
'maxx': 336682.921539395,
'maxy': 6458336.085975628,
'base': -3200,
'top': 1200
}
```

Then, specify: the state, directory for the output, the bounding box and projection from above - and hit go! That's it.

```python
proj = Project(use_australian_state_data = "SA",
working_projection = 'EPSG:28354',
bounding_box = bbox_3d,
loop_project_filename = "output.loop3d"
)

proj.run_all()
```

This is a minimal example and a small part of Loop.

Our _documentation and other resources outline how to extend map2loop and port to the LoopStructural modelling engine. We are working to incorporate geophysical tools and best provide visualisation and workflow consolidation in the GUI._

_Loop is led by Laurent Ailleres (Monash University) with a team of Work Package leaders from:_

- _Monash University: Roy Thomson, Lachlan Grose and Robin Armit_
- _University of Western Australia: Mark Jessell, Jeremie Giraud, Mark Lindsay and Guillaume Pirot_
- _Geological Survey of Canada: Boyan Brodaric and Eric de Kemp_

---

### Known Issues and FAQs

- Developing with docker on Windows means you won't have GPU passthrough and can’t use a discrete graphics card in the container even if you have one.
- If Jupyter links require a token or password, it may mean port 8888 is already in use. To fix, either make docker map to another port on the host ie -p 8889:8888 or stop any other instances on 8888.

### Links

[https://loop3d.github.io/](https://loop3d.github.io/)

[https://github.com/Loop3D/LoopStructural](https://github.com/Loop3D/LoopStructural)
58 changes: 58 additions & 0 deletions packages/map2loop/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "map2loop"
description = "Generate 3D model data from 2D maps."
version = "3.3.1"
requires-python = ">=3.8"
authors = [{ name = "Loop team" }]
readme = "README.md"
license = { text = "MIT" }
keywords = [
"earth sciences",
"geology",
"3-D modelling",
"structural geology",
"uncertainty",
]
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Science/Research",
"Natural Language :: English",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: GIS",
]
dependencies = [
"numpy",
"scipy",
"pandas",
"geopandas",
"shapely>=2",
"networkx",
"owslib",
"loopprojectfile==0.2.2",
"beartype",
"scikit-learn",
"packaging",
]

[project.urls]
Documentation = "https://Loop3d.org/map2loop/"
"Bug Tracker" = "https://github.com/Loop3D/map2loop/issues"
"Source Code" = "https://github.com/Loop3D/map2loop"

[project.optional-dependencies]
tests = ["pytest"]

[tool.setuptools.packages.find]
where = ["src"]
include = ["map2loop", "map2loop.*"]

[tool.setuptools.package-data]
map2loop = ["_datasets/geodata_files/hamersley/*"]
11 changes: 11 additions & 0 deletions packages/map2loop/src/dependencies.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
numpy
scipy
pandas
geopandas
shapely>=2
networkx
owslib
loopprojectfile==0.2.2
beartype
scikit-learn
packaging
118 changes: 118 additions & 0 deletions packages/map2loop/src/map2loop/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import logging
from map2loop.logging import loggers, ch

from .project import Project
from .version import __version__

import warnings # TODO: convert warnings to logging
from packaging import (
version as pkg_version,
) # used instead of importlib.version because adheres to PEP 440 using pkg_version.parse
import pathlib
import re
from importlib.metadata import version as get_installed_version, PackageNotFoundError


class DependencyChecker:
'''
A class to check installation and version compatibility of each package in dependencies.txt

Attributes:
package_name (str): Name of the package
dependency_file (str): path to dependencies.txt
required_version (str or None): required version of the package as in dependencies.txt
installed_version (str or None): installed version of the package in the current environment
'''

def __init__(self, package_name, dependency_file="dependencies.txt"):
self.package_name = package_name
self.dependency_file = pathlib.Path(__file__).parent.parent / dependency_file
self.required_version = self.get_required_version()
self.installed_version = self.get_installed_version()

def get_required_version(self):
'''
Get the required package version for each package from dependencies.txt;

Returns:
str or None: The required version of the package (if specified), otherwise None.
'''
try:
with self.dependency_file.open("r") as file:
for line in file:
if line.startswith(f"{self.package_name}=="):
match = re.match(rf"^{self.package_name}==([\d\.]+)", line.strip())
if match:
return match.group(1)
elif line.strip() == self.package_name:
return None
print(f"{self.package_name} version not found in {self.dependency_file}.")
except FileNotFoundError:
warnings.warn(
f"{self.dependency_file} not found. Unable to check {self.package_name} version compatibility.",
UserWarning,
)
return None

def get_installed_version(self):
'''
Get the installed version of the package.

Returns:
str: The installed version of the package.
'''
try:
# Use importlib.metadata to get the installed version of the package
return get_installed_version(self.package_name)
except PackageNotFoundError:
raise ImportError(
f"{self.package_name} is not installed. Please install {self.package_name}."
)

def check_version(self):
'''
Checks if the installed version of the package matches the required version in the dependencies.txt file.
'''
if self.required_version is None:
if self.installed_version is None:
raise ImportError(
f"{self.package_name} is not installed. Please install {self.package_name} before using map2loop."
)
else:
if self.installed_version is None or pkg_version.parse(
self.installed_version
) != pkg_version.parse(self.required_version):
raise ImportError(
f"Installed version of {self.package_name}=={self.installed_version} does not match required version=={self.required_version}. "
f"Please install the correct version of {self.package_name}."
)


def check_all_dependencies(dependency_file="dependencies.txt"):
dependencies_path = pathlib.Path(__file__).parent.parent / dependency_file
try:
with dependencies_path.open("r") as file:
for line in file:
line = line.strip()
if line.startswith("gdal"):
continue
if line:
if "==" in line:
package_name, _ = line.split("==")
elif ">=" in line:
package_name, _ = line.split(">=")
else:
package_name = line

checker = DependencyChecker(package_name, dependency_file=dependency_file)
checker.check_version()

except FileNotFoundError:
warnings.warn(
f"{dependency_file} not found. No dependencies checked for map2loop.",
UserWarning
)


# Run check for all dependencies listed in dependencies.txt
check_all_dependencies()
Loading