Skip to content

Commit

Permalink
fix: converts correctly shapefiles
Browse files Browse the repository at this point in the history
  • Loading branch information
rabii-chaarani committed Aug 23, 2024
1 parent 0e8dfa7 commit 1f1fa45
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 33 deletions.
Binary file not shown.
Binary file not shown.
19 changes: 11 additions & 8 deletions LoopDataConverter/converters/loop_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ 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 in the `__init__` method is a string that represents a specific layer
within the data. 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
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
'''
self._fileData = data
Expand All @@ -43,13 +43,15 @@ def __init__(self, survey_name: SurveyName, data: InputData, layer: str = None):
SurveyName.GSNSW: "",
SurveyName.MRT: "",
}
self._used_converter = None

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

def get_converter(self):
'''
Expand All @@ -70,6 +72,7 @@ def convert(self):
'''
data = self.read_file()
converter = self.get_converter()
converter(data)
self.data = converter._data
self._used_converter = self.get_converter()
self._used_converter = self._used_converter(data)
self._used_converter.convert()
self.data = self._used_converter._data
82 changes: 57 additions & 25 deletions LoopDataConverter/converters/ntgs_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ 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.update_empty_rows()
self._type_label = "NTGSConverter"
self._data = None

Expand All @@ -30,6 +31,30 @@ 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
(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]

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):
'''
Expand All @@ -38,16 +63,16 @@ def convert_fold_map(self):
'''
# convert dip direction terms to degrees
self.raw_data[Datatype.FOLD]["AxialPlaneDipDir"] = self.raw_data[Datatype.FOLD][
"AxialPlaneDipDir"
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]["AxialPlaneDip"] = self.raw_data[Datatype.FOLD][
"AxialPlaneDip"
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]["InterlimbAngle"] = self.raw_data[Datatype.FOLD][
"InterlimbAngle"
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 @@ -58,38 +83,45 @@ def convert_fault_map(self):
'''

# convert dip direction terms to degrees
self.raw_data[Datatype.FAULT]["DipDirection"] = self.raw_data[Datatype.FAULT][
"DipDirection"
].apply(lambda x: convert_dipdir_terms(x))

self.raw_data[Datatype.FAULT]["DipDirectn"] = self.raw_data[Datatype.FAULT][
"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")
)
self.raw_data[Datatype.FAULT]["Displacement"] = self.raw_data[Datatype.FAULT][
"Displacement"
].apply(lambda x: convert_displacement_terms(x))
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))

def convert_structure_map(self):
'''
This function filters out rows with a dip value of -99 and no estimated dip value, then converts
dip estimates to floats by averaging the range.
'''
# 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]["DipEstimate"] != numpy.nan
# select any rows that has a dip value of -99 and have any estimated dip value
condition = (self.raw_data[Datatype.STRUCTURE]["Dip"] == -99) & (
self.raw_data[Datatype.STRUCTURE]["DipEstimte"] != "NaN"
)
self.raw_data = self.raw_data[Datatype.STRUCTURE][condition]

# convert dip estimate to float (average of the range)
condition = self.raw_data[Datatype.STRUCTURE]["Dip"] == -99
self.raw_data[Datatype.STRUCTURE].loc[condition, "DipEstimate"] = (
self.raw_data[Datatype.STRUCTURE]
.loc[condition, "DipEstimate"]
.apply(lambda x: sum(map(float, x.split("-"))) / 2)
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"))
)

# 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][condition, "Dip"] = self.raw_data[Datatype.STRUCTURE][
condition, "DipEstimate"
self.raw_data[Datatype.STRUCTURE] = self.raw_data[Datatype.STRUCTURE][
~condition
]


def convert(self):
'''
Expand Down

0 comments on commit 1f1fa45

Please sign in to comment.