Skip to content

Commit

Permalink
fix: add thickness fields to proj and thickness_calculators
Browse files Browse the repository at this point in the history
  • Loading branch information
AngRodrigues committed May 8, 2024
1 parent 085d4eb commit f6ec60f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
11 changes: 7 additions & 4 deletions map2loop/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,10 +607,13 @@ def save_into_projectfile(self):
stratigraphic_data["name"] = self.stratigraphic_column.stratigraphicUnits["name"]
stratigraphic_data["group"] = self.stratigraphic_column.stratigraphicUnits["group"]
stratigraphic_data["enabled"] = 1
stratigraphic_data["thickness"] = self.stratigraphic_column.stratigraphicUnits[
"ThicknessMedian"
]

# stratigraphic_data["thickness"] = self.stratigraphic_column.stratigraphicUnits[
# "ThicknessMedian"
# ]
stratigraphic_data["ThicknessMean"] = self.stratigraphic_column.stratigraphicUnits['ThicknessMean']
stratigraphic_data['ThicknessMedian'] = self.stratigraphic_column.stratigraphicUnits['ThicknessMedian']
stratigraphic_data["ThicknessStdDev"] = self.stratigraphic_column.stratigraphicUnits['ThicknessStdDev']

stratigraphic_data["colour1Red"] = [
int(a[1:3], 16) for a in self.stratigraphic_column.stratigraphicUnits["colour"]
]
Expand Down
11 changes: 10 additions & 1 deletion map2loop/thickness_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ def compute(
# Set default value
# thicknesses["ThicknessMedian"] is the median thickness of the unit
thicknesses["ThicknessMedian"] = -1.0
thicknesses['ThicknessMean'] = -1.0
# thicknesses["ThicknessStdDev"] is the standard deviation of the thickness of the unit
thicknesses["ThicknessStdDev"] = 0
thicknesses['ThicknessStdDev'] = thicknesses['ThicknessStdDev'].astype('float64')
Expand Down Expand Up @@ -355,13 +356,16 @@ def compute(
_thickness = numpy.asarray(_thickness, dtype=numpy.float64)

median = numpy.nanmedian(_thickness)
mean = numpy.nanmean(_thickness)
std_dev = numpy.nanstd(_thickness, dtype=numpy.float64)

idx = thicknesses.index[
thicknesses["name"] == stratigraphic_order[i + 1]
].tolist()[0]
thicknesses.loc[idx, "ThicknessMean"] = mean
thicknesses.loc[idx, "ThicknessMedian"] = median
thicknesses.loc[idx, "ThicknessStdDev"] = std_dev

else:
print(
f"Cannot calculate thickness between {stratigraphic_order[i]} and {stratigraphic_order[i + 1]}"
Expand Down Expand Up @@ -564,12 +568,13 @@ def compute(

# create a DataFrame of the thicknesses median and standard deviation by lithology
result = pandas.DataFrame({'unit': lis, 'thickness': thicknesses})
result = result.groupby('unit')['thickness'].agg(['median', 'std']).reset_index()
result = result.groupby('unit')['thickness'].agg(['median', 'mean', 'std']).reset_index()
result.rename(columns={'thickness': 'ThicknessMedian'}, inplace=True)

output_units = units.copy()
# remove the old thickness column
output_units['ThicknessMedian'] = numpy.empty((len(output_units)))
output_units['ThicknessMean'] = numpy.empty((len(output_units)))
output_units['ThicknessStdDev'] = numpy.empty((len(output_units)))

# find which units have no thickness calculated
Expand All @@ -579,6 +584,7 @@ def compute(
for _, unit in result.iterrows():
idx = units.index[units['name'] == unit['unit']].tolist()[0]
output_units.loc[idx, 'ThicknessMedian'] = unit['median']
output_units.loc[idx, 'ThicknessMean'] = unit['mean']
output_units.loc[idx, 'ThicknessStdDev'] = unit['std']

# handle the units that have no thickness
Expand All @@ -601,10 +607,13 @@ def compute(
)
# assign -1 as thickness
output_units.loc[output_units["name"] == unit, "ThicknessMedian"] = -1
output_units.loc[output_units["name"] == unit, "ThicknessMean"] = -1
output_units.loc[output_units["name"] == unit, "ThicknessStdDev"] = -1

# if top//bottom unit assign -1
if unit == stratigraphic_order[-1] or unit == stratigraphic_order[0]:
output_units.loc[output_units["name"] == unit, "ThicknessMedian"] = -1
output_units.loc[output_units["name"] == unit, "ThicknessMean"] = -1
output_units.loc[output_units["name"] == unit, "ThicknessStdDev"] = -1

return output_units

0 comments on commit f6ec60f

Please sign in to comment.