diff --git a/LoopDataConverter/converters/__pycache__/loop_converter.cpython-311.pyc b/LoopDataConverter/converters/__pycache__/loop_converter.cpython-311.pyc index e8ba4dd..6b79a1b 100644 Binary files a/LoopDataConverter/converters/__pycache__/loop_converter.cpython-311.pyc and b/LoopDataConverter/converters/__pycache__/loop_converter.cpython-311.pyc differ diff --git a/LoopDataConverter/converters/__pycache__/ntgs_converter.cpython-311.pyc b/LoopDataConverter/converters/__pycache__/ntgs_converter.cpython-311.pyc index afdbba7..322399e 100644 Binary files a/LoopDataConverter/converters/__pycache__/ntgs_converter.cpython-311.pyc and b/LoopDataConverter/converters/__pycache__/ntgs_converter.cpython-311.pyc differ diff --git a/LoopDataConverter/converters/loop_converter.py b/LoopDataConverter/converters/loop_converter.py index fae1c0f..52f0ba2 100644 --- a/LoopDataConverter/converters/loop_converter.py +++ b/LoopDataConverter/converters/loop_converter.py @@ -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 @@ -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): ''' @@ -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 diff --git a/LoopDataConverter/converters/ntgs_converter.py b/LoopDataConverter/converters/ntgs_converter.py index 071def6..0e84cfb 100644 --- a/LoopDataConverter/converters/ntgs_converter.py +++ b/LoopDataConverter/converters/ntgs_converter.py @@ -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 @@ -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): ''' @@ -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): @@ -58,16 +83,18 @@ 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): ''' @@ -75,21 +102,26 @@ def convert_structure_map(self): 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): '''