Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
rabii-chaarani committed Jul 15, 2024
2 parents ee1f699 + c1e2457 commit 05c8d64
Show file tree
Hide file tree
Showing 45 changed files with 1,164 additions and 3 deletions.
154 changes: 154 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
on: [push, pull_request]
name: release-please
jobs:
linting:
name: Linting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install black ruff
- name: Autoformat with black
run: |
black .
- name: Lint with ruff
run: |
ruff check LoopDataConverter --fix
- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "style: style fixes by ruff and autoformatting by black"

continuous-integration:
name: Continuous integration ${{ matrix.os }} python ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: ${{ fromJSON(vars.BUILD_OS)}}
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- uses: conda-incubator/setup-miniconda@v3

with:
python-version: ${{ matrix.python-version }}
- name: Installing dependencies
shell: bash -l {0}
run: |
conda install -c conda-forge numpy scipy pytest dill beartype pandas geopandas shapely validators sqlite -y
- name: Building and install
shell: bash -l {0}
run: |
pip install . --user
- name: Testing
shell: bash -l {0}
run: |
pytest
release-please:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/dev'
steps:
- uses: GoogleCloudPlatform/release-please-action@v4
id: release
with:
release-type: python
package-name: LoopDataConverter
version-file: LoopDataConverter/version.py
outputs:
release_created: ${{ steps.release.outputs.release_created }}
# if a release is created then run the deploy scripts for github.io, conda, pypi and docker

conda-deploy:
name: Building conda package for python ${{ matrix.os }})
needs: "continuous-integration"
runs-on: ${{matrix.os}}
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
python-version: ${{ matrix.python-version }}

- uses: actions/checkout@v4
- name: update submodules
# shell: bash -l {0}
run: |
git submodule update --init --recursive
- name: Conda build
env:
ANACONDA_API_TOKEN: ${{ secrets.ANACONDA_TOKEN }}
shell: bash -l {0}
run: |
conda install -c conda-forge conda-build pytest numpy scipy pandas geopandas sqlite shapely validators anaconda-client -y
conda build -c anaconda -c conda-forge --output-folder conda conda
conda convert -p all conda/linux-64/*.tar.bz2 -f -o conda
conda install anaconda-client -y
- name: upload artifacts
uses: actions/upload-artifact@v4
with:
name: conda-${{ matrix.os }}-${{ matrix.python-version }}
path: conda

make_sdist:
needs: "continuous-integration"
name: Make SDist
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Build SDist
run: |
pip install build
python -m build
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist/

upload_to_conda:
needs: ["release-please", "conda-deploy"]
runs-on: ${{matrix.os}}
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
if: ${{ needs.release-please.outputs.release_created }}
steps:
- uses: actions/download-artifact@v4
with:
name: conda-${{ matrix.os }}-${{ matrix.python-version }}
path: conda
- uses: conda-incubator/setup-miniconda@v3
- name: upload all files to conda-forge
shell: bash -l {0}
env:
ANACONDA_API_TOKEN: ${{ secrets.ANACONDA_TOKEN }}
run: |
conda install -c anaconda anaconda-client -y
anaconda upload --label main conda/*/*.tar.bz2
upload_to_pypi:
needs: ["release-please", "conda-deploy"]
runs-on: "ubuntu-latest"

if: ${{ needs.release-please.outputs.release_created }}
steps:
- uses: actions/download-artifact@v4
with:
name: dist
path: dist
- uses: pypa/gh-action-pypi-publish@release/v1
with:
skip_existing: true
verbose: true
user: ${{ secrets.PYPI_USERNAME }}
password: ${{ secrets.PYPI_API_TOKEN }}
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
LoopDataConverter.egg-info/dependency_links.txt
LoopDataConverter.egg-info/PKG-INFO
LoopDataConverter.egg-info/top_level.txt
LoopDataConverter.egg-info/requires.txt
LoopDataConverter.egg-info/SOURCES.txt
LoopDataConverter.egg-info/top_level.txt
LoopDataConverter.egg-info/PKG-INFO
LoopDataConverter.egg-info/dependency_links.txt
Empty file added LoopDataConverter/__init__.py
Empty file.
Binary file not shown.
14 changes: 14 additions & 0 deletions LoopDataConverter/converters/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from .base_converter import BaseConverter
from .ntgs_converter import NTGSConverter
from ..datatypes import SurveyName

converter_map = {
SurveyName.NTGS: NTGSConverter,
SurveyName.GA: "",
SurveyName.GSQ: "",
SurveyName.GSWA: "",
SurveyName.GSSA: "",
SurveyName.GSV: "",
SurveyName.MRT: "",
SurveyName.GSNSW: "",
}
26 changes: 26 additions & 0 deletions LoopDataConverter/converters/base_converter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from abc import ABC, abstractmethod


class BaseConverter(ABC):

def __init__(self):
self._type_label = "BaseTypeConverter"

def type(self):
return self._type_label

@abstractmethod
def convert_fold_map(self):
pass

@abstractmethod
def convert_fault_map(self):
pass

@abstractmethod
def convert_structure_map(self):
pass

@abstractmethod
def convert(self):
pass
44 changes: 44 additions & 0 deletions LoopDataConverter/converters/conversion_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from .ntgs_converter import NTGSConverter
from ..datatypes import SurveyName
from ..file_readers import LoopGisReader
from ..input import InputData


class LoopConverter:
"""
LoopConverter class use the LoopGisReader to look up the correct file
reader for the input file type and then converting the data to
Map2Loop or LoopStrucural formats using the adequate converter
"""

def __init__(self, survey_name: SurveyName, data: InputData, layer: str = None):
self._fileData = data
self._layer = layer
self._survey_name = survey_name
self._converters = {
SurveyName.NTGS: NTGSConverter,
SurveyName.GA: "",
SurveyName.GSQ: "",
SurveyName.GSWA: "",
SurveyName.GSSA: "",
SurveyName.GSV: "",
SurveyName.GSNSW: "",
SurveyName.MRT: "",
}

def read_file(self):
"""
read the file using the correct file reader
"""
file_reader = LoopGisReader(self._fileData)
file_reader.read(self._fileData, self._layer)
return file_reader.data

def get_converter(self):
return self._converters[self._survey_name]

def convert(self):
data = self.read_file()
converter = self.get_converter()
converter(data)
self.data = converter._data
68 changes: 68 additions & 0 deletions LoopDataConverter/converters/ntgs_converter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# internal imports
from .base_converter import BaseConverter
from ..utils import (
convert_dipdir_terms,
convert_dip_terms,
convert_tightness_terms,
convert_displacement_terms,
)

# external imports
import pandas
import numpy


class NTGSConverter(BaseConverter):
# TODO: modify class to take fold, fault, and structure layers as arguments
def __init__(self, data: pandas.DataFrame):
self.raw_data = data.copy()
self._type_label = "NTGSConverter"
self._data = None

def type(self):
return self._type_label

def convert_fold_map(self):
# convert dip direction terms to degrees
self.raw_data["AxialPlaneDipDir"] = self.raw_data["AxialPlaneDipDir"].apply(
lambda x: convert_dipdir_terms(x)
)
# convert dip terms to degrees
self.raw_data["AxialPlaneDip"] = self.raw_data["AxialPlaneDip"].apply(
lambda x: convert_dip_terms(x, type="fold")
)
# convert tightness terms to degrees
self.raw_data["InterlimbAngle"] = self.raw_data["InterlimbAngle"].apply(
lambda x: convert_tightness_terms(x)
)

def convert_fault_map(self):
# convert dip direction terms to degrees
self.raw_data["DipDirection"] = self.raw_data["DipDirection"].apply(
lambda x: convert_dipdir_terms(x)
)
# convert dip terms to degrees
self.raw_data["Dip"] = self.raw_data["Dip"].apply(
lambda x: convert_dip_terms(x, type="fault")
)
self.raw_data["Displacement"] = self.raw_data["Displacement"].apply(
lambda x: convert_displacement_terms(x)
)

def convert_structure_map(self):
# discard any rows that has a dip value of -99 and does not have any esimated dip value
condition = (self.raw_data["Dip"] != -99) & (self.raw_data["DipEstimate"] != numpy.nan)
self.raw_data = self.raw_data[condition]
# convert dip estimate to float (average of the range)
condition = self.raw_data["Dip"] == -99
self.raw_data.loc[condition, "DipEstimate"] = self.raw_data.loc[
condition, "DipEstimate"
].apply(lambda x: sum(map(float, x.split("-"))) / 2)
self.raw_data[condition, "Dip"] = self.raw_data[condition, "DipEstimate"]

def convert(self):
self.convert_fold_map()
self.convert_fault_map()
self.convert_structure_map()

self._data = self.raw_data.copy()
1 change: 1 addition & 0 deletions LoopDataConverter/datatypes/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .enums import Datatype, SurveyName, Filetype
Binary file not shown.
Binary file not shown.
31 changes: 31 additions & 0 deletions LoopDataConverter/datatypes/enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from enum import IntEnum


class Datatype(IntEnum):
GEOLOGY = 0
STRUCTURE = 1
FAULT = 2
FOLD = 3
DTM = 4
FAULT_ORIENTATION = 5


class SurveyName(IntEnum):

GA = 0
NTGS = 1
GSQ = 2
GSWA = 3
GSSA = 4
GSV = 5
MRT = 6
GSNSW = 7


class Filetype(IntEnum):

CSV = 0
GEOJSON = 1
SHP = 2
GPKG = 3
ZIP = 4
Empty file.
1 change: 1 addition & 0 deletions LoopDataConverter/fields/_ntgs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from ._ntgs_config import NtgsConfig
Loading

0 comments on commit 05c8d64

Please sign in to comment.