Skip to content

Commit

Permalink
test: added NTGS test data and example of use
Browse files Browse the repository at this point in the history
  • Loading branch information
rabii-chaarani committed Aug 19, 2024
1 parent 7f1661d commit 59628d7
Show file tree
Hide file tree
Showing 45 changed files with 330 additions and 37 deletions.
2 changes: 2 additions & 0 deletions LoopDataConverter/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from .converters import LoopConverter
from .input import InputData
from .datatypes import SurveyName
Binary file modified LoopDataConverter/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file not shown.
3 changes: 1 addition & 2 deletions LoopDataConverter/converters/loop_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ def read_file(self):
"""
read the file using the correct file reader
"""
file_reader = LoopGisReader(self._fileData)
file_reader.read(self._fileData, self._layer)
file_reader = LoopGisReader(self._fileData)()
return file_reader.data

def get_converter(self):
Expand Down
Binary file not shown.
26 changes: 9 additions & 17 deletions LoopDataConverter/file_readers/_file_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def check_source_type(self, file_source: str):
file_source
), "Invalid file source, must be a valid URL or file path"

@beartype.beartype

@abstractmethod
def get_file(self, file_source: str, layer: str = None):
pass
Expand Down Expand Up @@ -49,7 +49,7 @@ def type(self):
def check_source_type(self, file_source: str):
super().check_source_type(file_source)

@beartype.beartype

def get_file(self, file_source: str, layer: str = None):
return pandas.read_csv(file_source)

Expand All @@ -67,7 +67,6 @@ def read(self, file_source: str):
class GeoDataFileReader(BaseFileReader):
def __init__(self):
self.file_reader_label = "GeoDataFileReader"
self.file = None
self.data = None

def type(self):
Expand All @@ -76,9 +75,10 @@ def type(self):
@beartype.beartype
def check_source_type(self, file_source: str):
super().check_source_type(file_source)

@beartype.beartype
def get_file(self, file_source: str, layer: str = None):

# TODO: add general check for variable types
def get_file(self, file_source: str,
layer: str = None):
file_extension = os.path.splitext(file_source)[1]

if file_extension in [".shp", ".geojson"]:
Expand Down Expand Up @@ -137,7 +137,9 @@ def assign_reader(self, file_source):
raise ValueError(f"Unsupported file format: {file_extension}")

def read(self, datatype: Datatype):
self._reader.read(self._fileData[Datatype.GEOLOGY], self._layer)
self._reader[datatype] = self.assign_reader(self._fileData[datatype])
self.file_reader_label[datatype] = self._reader[datatype].type()
self._reader[datatype].get_file(self._fileData[datatype], self._layer)

return self._reader.data

Expand All @@ -147,25 +149,15 @@ def __call__(self):
"""

if self._fileData[Datatype.GEOLOGY] is not None:
self._reader[Datatype.GEOLOGY] = self.assign_reader(self._fileData[Datatype.GEOLOGY])
self.file_reader_label[Datatype.GEOLOGY] = self._reader[Datatype.GEOLOGY].type()
self._data[Datatype.GEOLOGY] = self.read(Datatype.GEOLOGY)

if self._fileData[Datatype.STRUCTURE] is not None:
self._reader[Datatype.STRUCTURE] = self.assign_reader(
self._fileData[Datatype.STRUCTURE]
)
self.file_reader_label[Datatype.STRUCTURE] = self._reader[Datatype.STRUCTURE].type()
self._data[Datatype.STRUCTURE] = self.read(Datatype.STRUCTURE)

if self._fileData[Datatype.FAULT] is not None:
self._reader[Datatype.FAULT] = self.assign_reader(self._fileData[Datatype.FAULT])
self.file_reader_label[Datatype.FAULT] = self._reader[Datatype.FAULT].type()
self._data[Datatype.FAULT] = self.read(Datatype.FAULT)

if self._fileData[Datatype.FOLD] is not None:
self._reader[Datatype.FOLD] = self.assign_reader(self._fileData[Datatype.FOLD])
self.file_reader_label[Datatype.FOLD] = self._reader[Datatype.FOLD].type()
self._data[Datatype.FOLD] = self.read(Datatype.FOLD)

def save(self, file_path, file_extension=None):
Expand Down
Binary file modified LoopDataConverter/input/__pycache__/input_data.cpython-311.pyc
Binary file not shown.
67 changes: 52 additions & 15 deletions LoopDataConverter/input/input_data.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,72 @@
from dataclasses import dataclass
from ..datatypes import Datatype


@dataclass
class InputData:
"""Class to store input data for the loop data converter
Attributes:
geology: Datatype.GEOLOGY = None
structure: Datatype.STRUCTURE = None
fault: Datatype.FAULT = None
fold: Datatype.FOLD = None
geology: Optional[Datatype] = None
structure: Optional[Datatype] = None
fault: Optional[Datatype] = None
fold: Optional[Datatype] = None
"""

GEOLOGY: Datatype.GEOLOGY = None
STRUCTURE: Datatype.STRUCTURE = None
FAULT: Datatype.FAULT = None
FOLD: Datatype.FOLD = None

geology: Datatype.GEOLOGY = None
structure: Datatype.STRUCTURE = None
fault: Datatype.FAULT = None
fold: Datatype.FOLD = None

def __getitem__(self, datatype: Datatype):
"""Method to get the the file directory of a datatype
def __getitem__(self, datatype: str):
"""Method to get the file directory of a datatype
Parameters:
datatype (Datatype): The datatype to get the file directory of
datatype (str): The datatype to get the file directory of
Returns:
The file directory of the datatype
Raises:
KeyError: If the datatype is not found in InputData
"""
try:
return getattr(self, datatype.name)
except AttributeError:
raise KeyError(f"Datatype {datatype.name} not found in InputData")



# @dataclass
# class InputData:
# """Class to store input data for the loop data converter

# Attributes:
# geology: Datatype.GEOLOGY = None
# structure: Datatype.STRUCTURE = None
# fault: Datatype.FAULT = None
# fold: Datatype.FOLD = None

# """

# geology: Datatype.GEOLOGY = None
# structure: Datatype.STRUCTURE = None
# fault: Datatype.FAULT = None
# fold: Datatype.FOLD = None

# def __getitem__(self, datatype: Datatype):
# """Method to get the the file directory of a datatype

# Parameters:
# datatype (Datatype): The datatype to get the file directory of

# Returns:
# The file directory of the datatype
# """

return self.__dict__[datatype]
# try:
# return self.__dict__[datatype]
# except KeyError:
# raise KeyError(f"Datatype {datatype} not found in InputData")


@dataclass
Expand Down
Loading

0 comments on commit 59628d7

Please sign in to comment.