Skip to content

Commit

Permalink
style: style fixes by ruff and autoformatting by black
Browse files Browse the repository at this point in the history
  • Loading branch information
rabii-chaarani authored and github-actions[bot] committed Aug 23, 2024
1 parent af0b3bb commit 94482a1
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 44 deletions.
2 changes: 1 addition & 1 deletion LoopDataConverter/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .converters import LoopConverter
from .input import InputData
from .datatypes import SurveyName, Datatype
from .datatypes import SurveyName, Datatype
4 changes: 2 additions & 2 deletions LoopDataConverter/converters/loop_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def __init__(self, survey_name: SurveyName, data: InputData, layer: str = None):
The `data` parameter in the `__init__` method is of type `InputData`. It seems to represent the
data that will be used in the survey.
layer : str
The `layer` parameter is a string that represents a specific layer within a .GPKG file.
It is an optional parameter with a default value of `None`, which means it can be omitted
The `layer` parameter is a string that represents a specific layer within a .GPKG file.
It is an optional parameter with a default value of `None`, which means it can be omitted
when creating an instance of the class. If provided, it specifies the layer to
'''
Expand Down
59 changes: 26 additions & 33 deletions LoopDataConverter/converters/ntgs_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

# external imports
import pandas
import numpy


class NTGSConverter(BaseConverter):
Expand All @@ -31,49 +30,46 @@ def type(self):
'''
return self._type_label

def update_empty_rows(self):
'''
The function `update_empty_rows` updates empty rows in the DataFrame with NaN values.
Parameters
----------
None
This method operates on the DataFrames stored in the class and replaces all empty values
This method operates on the DataFrames stored in the class and replaces all empty values
(e.g., empty strings, None, NaN) with NaN across the specified tables.
'''

# List of tables (DataFrames) to update
tables_to_update = [Datatype.FOLD,
Datatype.FAULT,
Datatype.STRUCTURE]

tables_to_update = [Datatype.FOLD, Datatype.FAULT, Datatype.STRUCTURE]

for table in tables_to_update:
# Replace empty strings, None, or NaN with np.nan in the entire table
self.raw_data[table] = self.raw_data[table].map(
lambda x: "NaN" if pandas.isna(x) or x == "" or x is None else x
)


def convert_fold_map(self):
'''
The function `convert_fold_map` converts dip direction, dip, and tightness terms in the raw data
to degrees.
'''
# convert dip direction terms to degrees
self.raw_data[Datatype.FOLD]["AxPlaneDD"] = self.raw_data[Datatype.FOLD][
"AxPlaneDD"
].apply(lambda x: convert_dipdir_terms(x))
self.raw_data[Datatype.FOLD]["AxPlaneDD"] = self.raw_data[Datatype.FOLD]["AxPlaneDD"].apply(
lambda x: convert_dipdir_terms(x)
)
# convert dip terms to degrees
self.raw_data[Datatype.FOLD]["AxPlaneDip"] = self.raw_data[Datatype.FOLD][
"AxPlaneDip"
].apply(lambda x: convert_dip_terms(x, type="fold"))
# convert tightness terms to degrees
self.raw_data[Datatype.FOLD]["Interlimb"] = self.raw_data[Datatype.FOLD][
"Interlimb"
].apply(lambda x: convert_tightness_terms(x))
self.raw_data[Datatype.FOLD]["Interlimb"] = self.raw_data[Datatype.FOLD]["Interlimb"].apply(
lambda x: convert_tightness_terms(x)
)

def convert_fault_map(self):
'''
Expand All @@ -83,18 +79,18 @@ def convert_fault_map(self):
'''

# convert dip direction terms to degrees

self.raw_data[Datatype.FAULT]["DipDirectn"] = self.raw_data[Datatype.FAULT][
"DipDirectn"
].apply(lambda x: convert_dipdir_terms(x))
"DipDirectn"
].apply(lambda x: convert_dipdir_terms(x))
# convert dip terms to degrees
self.raw_data[Datatype.FAULT]["Dip"] = self.raw_data[Datatype.FAULT]["Dip"].apply(
lambda x: convert_dip_terms(x, type="fault")
)
lambda x: convert_dip_terms(x, type="fault")
)
# convert displacement terms to meters
self.raw_data[Datatype.FAULT]["Displace"] = self.raw_data[Datatype.FAULT][
"Displace"
].apply(lambda x: convert_displacement_terms(x))
self.raw_data[Datatype.FAULT]["Displace"] = self.raw_data[Datatype.FAULT]["Displace"].apply(
lambda x: convert_displacement_terms(x)
)

def convert_structure_map(self):
'''
Expand All @@ -106,22 +102,19 @@ def convert_structure_map(self):
condition = (self.raw_data[Datatype.STRUCTURE]["Dip"] == -99) & (
self.raw_data[Datatype.STRUCTURE]["DipEstimte"] != "NaN"
)

# convert dip estimate to float (average of the range)
self.raw_data[Datatype.STRUCTURE].loc[condition, "Dip"] = (
self.raw_data[Datatype.STRUCTURE]
.loc[condition, "DipEstimte"]
.apply(lambda x: convert_dip_terms(x, type="structure"))
self.raw_data[Datatype.STRUCTURE]
.loc[condition, "DipEstimte"]
.apply(lambda x: convert_dip_terms(x, type="structure"))
)

# discard any rows that has a dip value of -99 and does not have any estimated dip value
condition = (self.raw_data[Datatype.STRUCTURE]["Dip"] == -99) & (
self.raw_data[Datatype.STRUCTURE]["DipEstimte"] == "NaN"
)
self.raw_data[Datatype.STRUCTURE] = self.raw_data[Datatype.STRUCTURE][
~condition
]

self.raw_data[Datatype.STRUCTURE] = self.raw_data[Datatype.STRUCTURE][~condition]

def convert(self):
'''
Expand Down
9 changes: 4 additions & 5 deletions LoopDataConverter/file_readers/_file_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import os
import validators

#TODO: add a metaclass for methods that are repetitive
# TODO: add a metaclass for methods that are repetitive


class BaseFileReader(ABC):
def __init__(self):
Expand All @@ -22,7 +23,6 @@ def check_source_type(self, file_source: str):
file_source
), "Invalid file source, must be a valid URL or file path"


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


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

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

# 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]
Expand All @@ -86,7 +85,7 @@ def get_file(self, file_source: str, layer: str = None):

elif file_extension == ".gpkg":
assert layer is False, "Layer name must be provided for GeoPackage files"

return geopandas.read_file(file_source, layer=layer)

else:
Expand Down
4 changes: 2 additions & 2 deletions LoopDataConverter/input/input_data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from dataclasses import dataclass
from ..datatypes import Datatype


@dataclass
class InputData:
"""Class to store input data for the loop data converter
Expand All @@ -11,7 +12,7 @@ class InputData:
fault: Optional[Datatype] = None
fold: Optional[Datatype] = None
"""

GEOLOGY: Datatype.GEOLOGY = None
STRUCTURE: Datatype.STRUCTURE = None
FAULT: Datatype.FAULT = None
Expand All @@ -35,7 +36,6 @@ def __getitem__(self, datatype: str):
raise KeyError(f"Datatype {datatype.name} not found in InputData")



# @dataclass
# class InputData:
# """Class to store input data for the loop data converter
Expand Down
1 change: 0 additions & 1 deletion LoopDataConverter/utils/conversion.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import numpy



def convert_dipdir_terms(cardinal: str):
"""
Convert cardinal directions to degrees.
Expand Down

0 comments on commit 94482a1

Please sign in to comment.