Skip to content

Commit

Permalink
fix: initial commit to add list of thickness calculators as a field i…
Browse files Browse the repository at this point in the history
…n the LPF
  • Loading branch information
AngRodrigues committed Oct 2, 2024
1 parent 6a16cf5 commit 6262403
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 12 deletions.
3 changes: 2 additions & 1 deletion LoopProjectFile/DataCollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def CreateObservationGroup(dataCollectionGroup):
obGroup.createDimension("foldObservationIndex", None)
obGroup.createDimension("foliationObservationIndex", None)
obGroup.createDimension("discontinuityObservationIndex", None)
obGroup.createDimension("stratigraphicObservationIndex", None)
obGroup.createDimension("stratigraphicObservationIndex", None)

faultObservationType_t = obGroup.createCompoundType(
LoopProjectFile.faultObservationType, "FaultObservation"
)
Expand Down
37 changes: 34 additions & 3 deletions LoopProjectFile/ExtractedInformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,9 @@ def GetDiscontinuityLog(root, indexList=[], indexRange=(0, 0), verbose=False):
)



# Set stratigraphic log
def SetStratigraphicLog(root, data, append=False, verbose=False):
def SetStratigraphicLog(root, data, thickness_calculator_data=None, append=False, verbose=False):
"""
**SetStratigraphicLog** - Saves a list of strata in (formation,
thickness) format into the netCDF Loop Project File
Expand Down Expand Up @@ -302,26 +303,56 @@ def SetStratigraphicLog(root, data, append=False, verbose=False):
zlib=True,
complevel=9,
)

# Define compound type for thickness calculator (list of length 5)
thicknessCalculatorType_t = siGroup.createCompoundType(
LoopProjectFile.thicknessCalculatorType, "ThicknessCalculator"
)
siGroup.createVariable(
"thicknessCalculator",
thicknessCalculatorType_t,
zlib=True,
complevel=9,
)
else:
siGroup = resp["value"]

if siGroup:
stratigraphicLayersLocation = siGroup.variables["stratigraphicLayers"]
thickness_calculator = siGroup.variables["thicknessCalculator"]

index = 0
if append:
index = siGroup.dimensions["index"].size
for i in data:
stratigraphicLayersLocation[index] = i
index += 1
siGroup.setncattr("index_MaxValid", index)
# Write thickness calculator data (must match expected structure)
if thickness_calculator_data:
# Check that each entry is a tuple/list of length 5
for tc in thickness_calculator_data:
if len(tc) != 5:
errStr = "(ERROR) Each entry of thickness calculator data must be of length 5; this one is of length " + str(len(tc))
if verbose:
print(errStr)
return {"errorFlag": True, "errorString": errStr}
import numpy as np
# Convert the first (and only) tuple to a structured array
structured_data = np.array([thickness_calculator_data[0]], dtype=LoopProjectFile.thicknessCalculatorType)

# Assign only the first structured row
thickness_calculator[:] = structured_data[0]


else:
errStr = "(ERROR) Failed to create stratigraphic log group for strata setting"
if verbose:
print(errStr)
response = {"errorFlag": True, "errorString": errStr}

return response


def GetStratigraphicLog(root, indexList=[], indexRange=(0, 0), verbose=False):
response = {"errorFlag": False}
resp = GetStratigraphicInformationGroup(root)
Expand Down
30 changes: 22 additions & 8 deletions LoopProjectFile/LoopProjectFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ class EventRelationshipType(enum.IntEnum):
FAULT_FAULT_OVERPRINT = 4

class ThickenessCalculatorType(enum.IntEnum):
ALPHA = 0
INTERPOLATED_STRUCTURE = 1
STRUCTURAL_POINT = 2
PLACEHOLDER_1 = 3
PLACEHOLDER_2 = 4
PLACEHOLDER_1 = 0
PLACEHOLDER_2 = 1
PLACEHOLDER_3 = 3
PLACEHOLDER_4 = 4
PLACEHOLDER_5 = 5

# ### External Accessors ### #

Expand Down Expand Up @@ -295,6 +295,15 @@ def Set(filename, element, **kwargs):
response = ExtractedInformation.SetStratigraphicLog(
root, append=True, **kwargs
)


###################################
# ###################################
# elif element == "thicknessCalculator":
# response = ExtractedInformation.SetThicknessCalculator(root, **kwargs)



elif element == "faultLog":
response = ExtractedInformation.SetFaultLog(root, **kwargs)
elif element == "faultLogAppend":
Expand Down Expand Up @@ -739,9 +748,9 @@ def CheckFileValid(filename, verbose=False):
("group", "S120"),
("supergroup", "S120"),
("enabled", "u1"),
("ThicknessMean", "<f8", (len(ThickenessCalculatorType)), ),
("ThicknessMedian", "<f8", (len(ThickenessCalculatorType)), ),
("ThicknessStdDev", "<f8", (len(ThickenessCalculatorType)), ),
# ("ThicknessMean", "<f8", (len(ThickenessCalculatorType)), ),
# ("ThicknessMedian", "<f8", (len(ThickenessCalculatorType)), ),
# ("ThicknessStdDev", "<f8", (len(ThickenessCalculatorType)), ),
("colour1Red", "u1"),
("colour1Green", "u1"),
("colour1Blue", "u1"),
Expand All @@ -751,6 +760,11 @@ def CheckFileValid(filename, verbose=False):
]
)

thicknessCalculatorType = numpy.dtype(
numpy.dtype([("name1", "S120"), ("name2", "S120"), ("name3", "S120"), ("name4", "S120"), ("name5", "S120")]),
"ThicknessCalculator"
)

eventRelationshipType = numpy.dtype(
[
("eventId1", "<u4"),
Expand Down
1 change: 1 addition & 0 deletions LoopProjectFile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
foliationObservationType,
discontinuityObservationType,
stratigraphicLayerType,
thicknessCalculatorType,
stratigraphicObservationType,
contactObservationType,
eventRelationshipType,
Expand Down

0 comments on commit 6262403

Please sign in to comment.