Skip to content
Snippets Groups Projects
Commit 83c15d29 authored by Cain, Payton David's avatar Cain, Payton David
Browse files

WIP: Fix data type/mathematical errors

parent 8a4d3c65
No related branches found
No related tags found
No related merge requests found
...@@ -23,11 +23,15 @@ def calculate_I(measurements, ordinates, metadata): ...@@ -23,11 +23,15 @@ def calculate_I(measurements, ordinates, metadata):
northdown_ordinate = average_ordinate(ordinates, "NorthDown") northdown_ordinate = average_ordinate(ordinates, "NorthDown")
northup_ordinate = average_ordinate(ordinates, "NorthUp") northup_ordinate = average_ordinate(ordinates, "NorthUp")
southup_ordinate = average_ordinate(ordinates, "SouthUp") southup_ordinate = average_ordinate(ordinates, "SouthUp")
total_ordinate = Ordinate() # gather ordinates into array
total_ordinate.h, total_ordinate.z, total_ordinate.e, total_ordinate.f = np.average( ordinates = [
[southdown_ordinate, southup_ordinate, northdown_ordinate, northup_ordinate], southdown_ordinate,
axis=1, northdown_ordinate,
) northup_ordinate,
southup_ordinate,
]
total_ordinate = average_ordinate(ordinates, None)
# calculate f for each measurement type # calculate f for each measurement type
southdown_f = calculate_f(southdown_ordinate, total_ordinate, Iprime) southdown_f = calculate_f(southdown_ordinate, total_ordinate, Iprime)
southup_f = calculate_f(southup_ordinate, total_ordinate, Iprime) southup_f = calculate_f(southup_ordinate, total_ordinate, Iprime)
...@@ -90,7 +94,7 @@ def calculate_scale(f, measurements, I, pier_correction): ...@@ -90,7 +94,7 @@ def calculate_scale(f, measurements, I, pier_correction):
time_delta = np.diff([m.time for m in measurements]) time_delta = np.diff([m.time for m in measurements])
delta_b = delta_f + time_delta delta_b = delta_f + (time_delta / 60.0)
scale_value = f * np.deg2rad(delta_b / detla_r) scale_value = f * np.deg2rad(delta_b / detla_r)
...@@ -100,26 +104,32 @@ def calculate_scale(f, measurements, I, pier_correction): ...@@ -100,26 +104,32 @@ def calculate_scale(f, measurements, I, pier_correction):
def average_angle(measurements, type): def average_angle(measurements, type):
if type == "NorthDown": if type == "NorthDown":
# exclude final measurement, which is only used for scaling # exclude final measurement, which is only used for scaling
measurements = measurements[:-1] measurements = measurements[type][:-1]
return np.average([m.angle for m in measurements[type]]) else:
measurements = measurements[type]
return np.average([m.angle for m in measurements])
def average_residual(measurements, type): def average_residual(measurements, type):
if type == "NorthDown": if type == "NorthDown":
# exclude final measurement, which is only used for scaling # exclude final measurement, which is only used for scaling
measurements = measurements[:-1] measurements = measurements[type][:-1]
return np.average([m.residual for m in measurements[type]]) else:
measurements = measurements[type]
return np.average([m.residual for m in measurements])
def average_ordinate(ordinates, type): def average_ordinate(ordinates, type):
ordinates = ordinates
if type == "NorthDown": if type == "NorthDown":
# exclude final measurement, which is only used for scaling # exclude final measurement, which is only used for scaling
ordinates = ordinates[:-1] ordinates = ordinates[type][:-1]
ordinate = Ordinate() elif type is not None:
ordinate.h, ordinate.e, ordinate.z, ordinate.f = np.average( ordinates = ordinates[type]
[o for o in ordinates[type]], axis=1 o = Ordinate(measurement_type=type)
) avgs = np.average([[o.h, o.e, o.z, o.f] for o in ordinates], axis=0)
return ordinate o.h, o.e, o.z, o.f = avgs
return o
def calculate_f(ordinate, total_ordinate, I): def calculate_f(ordinate, total_ordinate, I):
......
...@@ -43,8 +43,8 @@ class Reading(BaseModel): ...@@ -43,8 +43,8 @@ class Reading(BaseModel):
def calculate(self): def calculate(self):
# gather class object to perform calculations # gather class object to perform calculations
metadata = self.metadata metadata = self.metadata
ordinates = self.ordinate_index ordinates = self.ordinate_index()
measurements = self.measurement_index measurements = self.measurement_index()
# calculate inclination # calculate inclination
inclination, f, ordinate = calculate_I(measurements, ordinates, metadata) inclination, f, ordinate = calculate_I(measurements, ordinates, metadata)
# calculate absolutes # calculate absolutes
...@@ -54,7 +54,9 @@ class Reading(BaseModel): ...@@ -54,7 +54,9 @@ class Reading(BaseModel):
# calculate baselines # calculate baselines
Hb, Zb = calculate_baselines(Habs, Zabs, ordinate) Hb, Zb = calculate_baselines(Habs, Zabs, ordinate)
# calculate scale value for declination # calculate scale value for declination
calculate_scale(f, measurements, inclination, metadata["pier_correction"]) calculate_scale(
f, measurements["NorthDown"], inclination, metadata["pier_correction"]
)
def measurement_index(self) -> Dict[MeasurementType, List[Measurement]]: def measurement_index(self) -> Dict[MeasurementType, List[Measurement]]:
"""Generate index of measurements keyed by MeasurementType. """Generate index of measurements keyed by MeasurementType.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment