Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
geomag-algorithms
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ghsc
National Geomagnetism Program
geomag-algorithms
Commits
83c15d29
Commit
83c15d29
authored
5 years ago
by
Cain, Payton David
Browse files
Options
Downloads
Patches
Plain Diff
WIP: Fix data type/mathematical errors
parent
8a4d3c65
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
geomagio/residual/Calculation.py
+26
-16
26 additions, 16 deletions
geomagio/residual/Calculation.py
geomagio/residual/Reading.py
+5
-3
5 additions, 3 deletions
geomagio/residual/Reading.py
with
31 additions
and
19 deletions
geomagio/residual/Calculation.py
+
26
−
16
View file @
83c15d29
...
@@ -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
):
...
...
This diff is collapsed.
Click to expand it.
geomagio/residual/Reading.py
+
5
−
3
View file @
83c15d29
...
@@ -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.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment