gmeterpy 0.0.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gmeterpy/__init__.py +5 -0
- gmeterpy/cli/__init__.py +1 -0
- gmeterpy/cli/gabl.py +159 -0
- gmeterpy/cli/gphone.py +41 -0
- gmeterpy/cli/loop.py +217 -0
- gmeterpy/cli/scx2.py +51 -0
- gmeterpy/cli/vgfit.py +60 -0
- gmeterpy/constants.py +63 -0
- gmeterpy/core/__init__.py +0 -0
- gmeterpy/core/adjustment.py +66 -0
- gmeterpy/core/dmatrices.py +242 -0
- gmeterpy/core/gvalues.py +53 -0
- gmeterpy/core/network.py +405 -0
- gmeterpy/core/readings.py +217 -0
- gmeterpy/core/relative.py +382 -0
- gmeterpy/corrections/__init__.py +25 -0
- gmeterpy/corrections/atmosphere.py +91 -0
- gmeterpy/corrections/polar_motion.py +134 -0
- gmeterpy/corrections/tides/__init__.py +0 -0
- gmeterpy/corrections/tides/prolet.py +36 -0
- gmeterpy/corrections/tides/tamura.py +539 -0
- gmeterpy/corrections/vgrad.py +158 -0
- gmeterpy/meters/__init__.py +1 -0
- gmeterpy/meters/freefall/__init__.py +1 -0
- gmeterpy/meters/freefall/drop.py +97 -0
- gmeterpy/meters/freefall/effective_height.py +108 -0
- gmeterpy/meters/freefall/fsol.py +94 -0
- gmeterpy/meters/gabl/__init__.py +0 -0
- gmeterpy/meters/gabl/core.py +506 -0
- gmeterpy/meters/gabl/parser.py +167 -0
- gmeterpy/meters/gphone/__init__.py +0 -0
- gmeterpy/meters/gphone/gphone.py +112 -0
- gmeterpy/meters/scintrex/__init__.py +4 -0
- gmeterpy/meters/scintrex/cg.py +266 -0
- gmeterpy/meters/tsoft.py +76 -0
- gmeterpy/plotting/__init__.py +0 -0
- gmeterpy/plotting/absolute.py +37 -0
- gmeterpy/plotting/relative.py +296 -0
- gmeterpy/plotting/vgfit.py +78 -0
- gmeterpy/stats/__init__.py +12 -0
- gmeterpy/stats/funcs.py +43 -0
- gmeterpy/stats/interpolate.py +13 -0
- gmeterpy/stats/lstsq.py +57 -0
- gmeterpy/units.py +24 -0
- gmeterpy-0.0.3.dist-info/METADATA +123 -0
- gmeterpy-0.0.3.dist-info/RECORD +50 -0
- gmeterpy-0.0.3.dist-info/WHEEL +5 -0
- gmeterpy-0.0.3.dist-info/entry_points.txt +6 -0
- gmeterpy-0.0.3.dist-info/licenses/LICENSE.txt +21 -0
- gmeterpy-0.0.3.dist-info/top_level.txt +1 -0
gmeterpy/__init__.py
ADDED
gmeterpy/cli/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Command-line interfaces for gMeterPy."""
|
gmeterpy/cli/gabl.py
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
"""GABL data processing script."""
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import configparser
|
|
7
|
+
import os
|
|
8
|
+
|
|
9
|
+
from gmeterpy.corrections import get_polar_motion
|
|
10
|
+
from gmeterpy.corrections.tides.prolet import prolet
|
|
11
|
+
from gmeterpy.meters.gabl.core import GABLProject
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def main():
|
|
15
|
+
conf_parser = argparse.ArgumentParser(
|
|
16
|
+
description="Process GABL data",
|
|
17
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
18
|
+
add_help=False,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
conf_parser.add_argument(
|
|
22
|
+
"-c", "--conf_file", help="Specify config file", metavar="FILE"
|
|
23
|
+
)
|
|
24
|
+
args, remaining_argv = conf_parser.parse_known_args()
|
|
25
|
+
|
|
26
|
+
defaults = {
|
|
27
|
+
"station": "",
|
|
28
|
+
"station_id": "0000",
|
|
29
|
+
"lat": None,
|
|
30
|
+
"lon": None,
|
|
31
|
+
"elev": None,
|
|
32
|
+
"timedelta": 0,
|
|
33
|
+
"baro_factor": 0.3,
|
|
34
|
+
"meter_type": "GBL-M",
|
|
35
|
+
"meter_sn": "001",
|
|
36
|
+
"tdb": 0,
|
|
37
|
+
"tda": 0,
|
|
38
|
+
"sigma": 3.0,
|
|
39
|
+
"reject_by": "series",
|
|
40
|
+
"mean_by": "series",
|
|
41
|
+
"drop_model": "OLS",
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if args.conf_file:
|
|
45
|
+
config = configparser.ConfigParser()
|
|
46
|
+
config.read([args.conf_file])
|
|
47
|
+
defaults.update(dict(config.items("ProjectParams")))
|
|
48
|
+
|
|
49
|
+
parser = argparse.ArgumentParser(
|
|
50
|
+
# Inherit options from config_parser
|
|
51
|
+
parents=[conf_parser]
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
parser.set_defaults(**defaults)
|
|
55
|
+
|
|
56
|
+
parser.add_argument("path", help="path to data", action="store")
|
|
57
|
+
|
|
58
|
+
# Station
|
|
59
|
+
parser.add_argument("--station", type=str, help="human-readable station name")
|
|
60
|
+
parser.add_argument("--station-id", type=str, help="computer-readable station id")
|
|
61
|
+
parser.add_argument("--lat", type=float, help="latitude")
|
|
62
|
+
parser.add_argument("--lon", type=float, help="longitude")
|
|
63
|
+
parser.add_argument("--elev", type=float, help="height above sea level")
|
|
64
|
+
parser.add_argument("--timezone", type=float, help="timedelta from UTC in hours")
|
|
65
|
+
parser.add_argument(
|
|
66
|
+
"--baro-factor", type=float, help="barometric admittance factor, default is 0.3"
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
# Instrument
|
|
70
|
+
parser.add_argument("--meter-type", type=str, help="type of the gravimeter")
|
|
71
|
+
parser.add_argument("--meter-sn", type=str, help="s/n of the gravimeter")
|
|
72
|
+
|
|
73
|
+
# Corrections
|
|
74
|
+
parser.add_argument("--tide", type=argparse.FileType("r"), required=True)
|
|
75
|
+
|
|
76
|
+
# Processing
|
|
77
|
+
parser.add_argument("--tdb", type=int, help="truncate drop in the beginning")
|
|
78
|
+
parser.add_argument("--tda", type=int, help="truncate drop in the end")
|
|
79
|
+
parser.add_argument("--sigma", type=float, help="rejection level, default is 3.0")
|
|
80
|
+
parser.add_argument(
|
|
81
|
+
"--reject-by",
|
|
82
|
+
type=str,
|
|
83
|
+
help="reject drops in series, seances or azimuths, default is in series",
|
|
84
|
+
)
|
|
85
|
+
parser.add_argument(
|
|
86
|
+
"--mean-by",
|
|
87
|
+
type=str,
|
|
88
|
+
help="find mean value in series, seances or azimuths, default is in series",
|
|
89
|
+
)
|
|
90
|
+
parser.add_argument(
|
|
91
|
+
"--drop-model", type=str, help="regression model for drop fitting"
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
# Plots
|
|
95
|
+
parser.add_argument("--plot-residuals", action="store_true")
|
|
96
|
+
|
|
97
|
+
args = parser.parse_args(remaining_argv)
|
|
98
|
+
|
|
99
|
+
path = args.path
|
|
100
|
+
ftide = args.tide.name
|
|
101
|
+
|
|
102
|
+
before = args.tdb
|
|
103
|
+
after = args.tda
|
|
104
|
+
|
|
105
|
+
config = {
|
|
106
|
+
"station": args.station,
|
|
107
|
+
"sid": args.station_id,
|
|
108
|
+
"baro_factor": args.baro_factor,
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if args.lat is not None:
|
|
112
|
+
config.update({"lat": float(args.lat)})
|
|
113
|
+
if args.lon is not None:
|
|
114
|
+
config.update({"lon": float(args.lon)})
|
|
115
|
+
if args.elev is not None:
|
|
116
|
+
config.update({"height": float(args.elev)})
|
|
117
|
+
|
|
118
|
+
proj = GABLProject.load(path, add_to_meta=config, timezone=args.timezone)
|
|
119
|
+
|
|
120
|
+
proj.proc_drops(before, after, model=args.drop_model)
|
|
121
|
+
|
|
122
|
+
os.chdir(path)
|
|
123
|
+
|
|
124
|
+
# corrections
|
|
125
|
+
proj.set_correction("c_tide", prolet, fname=ftide, which="solid")
|
|
126
|
+
proj.set_correction("c_ocean", prolet, fname=ftide, which="ocean")
|
|
127
|
+
|
|
128
|
+
# update polar motion coordinates
|
|
129
|
+
xp, yp = get_polar_motion(proj._data.jd.values)
|
|
130
|
+
proj.add_quantity_column("xp", xp)
|
|
131
|
+
proj.add_quantity_column("yp", yp)
|
|
132
|
+
proj._update_g_result()
|
|
133
|
+
|
|
134
|
+
if args.reject_by.lower() == "series":
|
|
135
|
+
by = ["azimuth", "seance", "series"]
|
|
136
|
+
elif args.reject_by.lower() == "seance":
|
|
137
|
+
by = ["azimuth", "seance"]
|
|
138
|
+
elif args.reject_by.lower() == "azimuth":
|
|
139
|
+
by = ["azimuth"]
|
|
140
|
+
|
|
141
|
+
proj = proj.filter(by=by, sigma=args.sigma)
|
|
142
|
+
|
|
143
|
+
if args.mean_by.lower() == "series":
|
|
144
|
+
by = ["azimuth", "seance", "series"]
|
|
145
|
+
elif args.mean_by.lower() == "seance":
|
|
146
|
+
by = ["azimuth", "seance"]
|
|
147
|
+
elif args.mean_by.lower() == "azimuth":
|
|
148
|
+
by = ["azimuth"]
|
|
149
|
+
|
|
150
|
+
proj = proj.mean(by=by)
|
|
151
|
+
proj._set.proc()
|
|
152
|
+
|
|
153
|
+
proj.report()
|
|
154
|
+
|
|
155
|
+
if args.plot_residuals:
|
|
156
|
+
if not os.path.exists("plot"):
|
|
157
|
+
os.makedirs("plot")
|
|
158
|
+
for fig_name, fig in proj.plot_residuals(by=by):
|
|
159
|
+
fig.savefig("plot/" + fig_name + ".png")
|
gmeterpy/cli/gphone.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import os
|
|
5
|
+
|
|
6
|
+
from gmeterpy.meters.gphone.gphone import gPhone
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def main():
|
|
10
|
+
parser = argparse.ArgumentParser(description="Convert and preprocess gPhone data")
|
|
11
|
+
parser.add_argument(
|
|
12
|
+
"infile",
|
|
13
|
+
metavar="INPUT",
|
|
14
|
+
type=argparse.FileType("rt"),
|
|
15
|
+
help="Input gPhone data file",
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
parser.add_argument("--station", type=str, help="human-readable station name")
|
|
19
|
+
parser.add_argument("--station-id", type=str, help="computer-readable station id")
|
|
20
|
+
parser.add_argument("--lat", type=float, help="latitude")
|
|
21
|
+
parser.add_argument("--lon", type=float, help="longitude")
|
|
22
|
+
|
|
23
|
+
args = parser.parse_args()
|
|
24
|
+
|
|
25
|
+
proc_dir = os.path.dirname(os.path.abspath(args.infile.name))
|
|
26
|
+
os.chdir(proc_dir)
|
|
27
|
+
|
|
28
|
+
data = gPhone(args.infile.name)
|
|
29
|
+
|
|
30
|
+
data._data["meter_sn"] = "110"
|
|
31
|
+
data._data["sid"] = "CONT"
|
|
32
|
+
data._data["line"] = 0
|
|
33
|
+
# data._data['dur'] = 1
|
|
34
|
+
data._data["stdev"] = 1
|
|
35
|
+
data._data["rej"] = 0
|
|
36
|
+
|
|
37
|
+
data._data["lon"] = args.lon
|
|
38
|
+
data._data["lat"] = args.lat
|
|
39
|
+
# data._data['elev'] = args.elev
|
|
40
|
+
|
|
41
|
+
data.to_file("readings.txt")
|
gmeterpy/cli/loop.py
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import configparser
|
|
5
|
+
import os
|
|
6
|
+
|
|
7
|
+
import matplotlib.pylab as plt
|
|
8
|
+
import numpy as np
|
|
9
|
+
import pandas as pd
|
|
10
|
+
|
|
11
|
+
from gmeterpy.core.relative import RelativeReadings
|
|
12
|
+
from gmeterpy.corrections.atmosphere import atmospheric_pressure_correction
|
|
13
|
+
from gmeterpy.corrections.tides.prolet import prolet
|
|
14
|
+
from gmeterpy.corrections.tides.tamura import tide
|
|
15
|
+
from gmeterpy.plotting.relative import plot_loop_processing
|
|
16
|
+
from gmeterpy.stats import interpolate
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def main():
|
|
20
|
+
conf_parser = argparse.ArgumentParser(
|
|
21
|
+
description="Process relative measurements",
|
|
22
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
23
|
+
add_help=False,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
conf_parser.add_argument(
|
|
27
|
+
"-c", "--conf_file", help="specify config file", metavar="FILE"
|
|
28
|
+
)
|
|
29
|
+
args, remaining_argv = conf_parser.parse_known_args()
|
|
30
|
+
|
|
31
|
+
defaults = {
|
|
32
|
+
"tide_model": "longman",
|
|
33
|
+
"drift_order": 1,
|
|
34
|
+
"tb": 0,
|
|
35
|
+
"ta": 1,
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if args.conf_file:
|
|
39
|
+
config = configparser.ConfigParser()
|
|
40
|
+
config.read([args.conf_file])
|
|
41
|
+
defaults.update(dict(config.items("ProjectParams")))
|
|
42
|
+
|
|
43
|
+
parser = argparse.ArgumentParser(parents=[conf_parser])
|
|
44
|
+
parser.set_defaults(**defaults)
|
|
45
|
+
|
|
46
|
+
parser.add_argument("file", help="input data file")
|
|
47
|
+
|
|
48
|
+
# parser.add_argument('--merge', action='append', default=[],
|
|
49
|
+
# help='files to merge (stations, level, etc.)')
|
|
50
|
+
|
|
51
|
+
# Merge files
|
|
52
|
+
parser.add_argument(
|
|
53
|
+
"--stations", type=open, help="specify file with station inforamtion"
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
# Processing options
|
|
57
|
+
parser.add_argument(
|
|
58
|
+
"--tb",
|
|
59
|
+
type=int,
|
|
60
|
+
metavar="N",
|
|
61
|
+
help="truncate N readings in the beginning of each setup",
|
|
62
|
+
)
|
|
63
|
+
parser.add_argument(
|
|
64
|
+
"--ta",
|
|
65
|
+
type=int,
|
|
66
|
+
metavar="N",
|
|
67
|
+
help="truncate N readings in the end of each setup",
|
|
68
|
+
)
|
|
69
|
+
parser.add_argument(
|
|
70
|
+
"--drift-order", type=int, help="polynomial order for a drift function"
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
# Corrections
|
|
74
|
+
parser.add_argument(
|
|
75
|
+
"--tide-model", type=str, help="tide model to calculate tide correction"
|
|
76
|
+
)
|
|
77
|
+
parser.add_argument("--tide", type=open, help="file with tides")
|
|
78
|
+
parser.add_argument(
|
|
79
|
+
"--calibration", type=open, help="file with calibration coefficients"
|
|
80
|
+
)
|
|
81
|
+
parser.add_argument("--pressure", type=open, help="file with pressure measurements")
|
|
82
|
+
|
|
83
|
+
# Filter
|
|
84
|
+
# parser.add_argument('--filter', nargs=3,
|
|
85
|
+
# help='filter data by values in columns')
|
|
86
|
+
|
|
87
|
+
# Plots
|
|
88
|
+
parser.add_argument(
|
|
89
|
+
"--plot-tide-diff",
|
|
90
|
+
action="store_true",
|
|
91
|
+
help="plot the difference between the old and the new tide models",
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
args = parser.parse_args(remaining_argv)
|
|
95
|
+
|
|
96
|
+
proc_dir = os.path.dirname(os.path.abspath(args.file))
|
|
97
|
+
os.chdir(proc_dir)
|
|
98
|
+
|
|
99
|
+
readings = RelativeReadings.from_file(args.file, use_drift=True)
|
|
100
|
+
suffix = "_line_" + str(int(readings.data.line.unique()[0]))
|
|
101
|
+
|
|
102
|
+
# if args.auto_sid:
|
|
103
|
+
# readings = readings.auto_sid(2)
|
|
104
|
+
|
|
105
|
+
# merge_files = args.merge
|
|
106
|
+
# for f in merge_files:
|
|
107
|
+
# to_merge = pd.read_csv(f)
|
|
108
|
+
# readings = readings.merge(to_merge)
|
|
109
|
+
|
|
110
|
+
if args.stations is not None:
|
|
111
|
+
to_merge = pd.read_csv(args.stations)
|
|
112
|
+
readings = readings.merge(to_merge)
|
|
113
|
+
else:
|
|
114
|
+
sid = readings.data.sid.values
|
|
115
|
+
name = ["S" + str(x) for x in sid]
|
|
116
|
+
readings._data["name"] = name
|
|
117
|
+
|
|
118
|
+
# apply gravimeter calibration parameter
|
|
119
|
+
if args.calibration is not None:
|
|
120
|
+
cparams = pd.read_csv(args.calibration, delim_whitespace=True).drop(
|
|
121
|
+
"stdev", axis=1
|
|
122
|
+
)
|
|
123
|
+
readings = readings.merge(cparams)
|
|
124
|
+
readings.data["c_calibr"] = readings.data.g * (readings.data.coef - 1)
|
|
125
|
+
readings.set_correction("c_calibr", "c_calibr")
|
|
126
|
+
|
|
127
|
+
# apply tide model
|
|
128
|
+
tide_model = args.tide_model
|
|
129
|
+
# needed only if tide_model is 'atlantida' or 'ts'
|
|
130
|
+
if tide_model in ("atlantida", "ts"):
|
|
131
|
+
if args.tide is not None:
|
|
132
|
+
tide_file = os.path.abspath(args.tide.name)
|
|
133
|
+
else:
|
|
134
|
+
raise Exception("You need to specify filename with tides")
|
|
135
|
+
|
|
136
|
+
# tide correction
|
|
137
|
+
if tide_model in ("tamura", "atlantida", "custom"):
|
|
138
|
+
old = readings.data.c_tide.copy()
|
|
139
|
+
if tide_model == "tamura":
|
|
140
|
+
d, t = readings.data, readings.data.index
|
|
141
|
+
c_tide = list(
|
|
142
|
+
map(
|
|
143
|
+
tide,
|
|
144
|
+
t.year,
|
|
145
|
+
t.month,
|
|
146
|
+
t.day,
|
|
147
|
+
t.hour,
|
|
148
|
+
t.minute,
|
|
149
|
+
t.second,
|
|
150
|
+
d.lon,
|
|
151
|
+
d.lat,
|
|
152
|
+
d.height,
|
|
153
|
+
)
|
|
154
|
+
)
|
|
155
|
+
readings._data["c_tide"] = np.asarray(c_tide) / 1000
|
|
156
|
+
elif tide_model == "atlantida":
|
|
157
|
+
c_tide = prolet(tide_file)
|
|
158
|
+
readings._data["c_tide"] = readings.interpolate_from_ts(c_tide) / 1000
|
|
159
|
+
elif tide_model == "custom":
|
|
160
|
+
tides = pd.read_csv(tide_file, index_col="time", parse_dates=True)
|
|
161
|
+
for name, group in readings.data.groupby("name"):
|
|
162
|
+
c_tide = (
|
|
163
|
+
interpolate(tides[tides.name == name]["tide"], group.index) / 1000
|
|
164
|
+
)
|
|
165
|
+
readings.data.loc[readings.data.name == name, "c_tide"] = c_tide
|
|
166
|
+
if args.plot_tide_diff:
|
|
167
|
+
diff = readings.data.c_tide - old
|
|
168
|
+
(diff - diff.mean()).plot()
|
|
169
|
+
plt.savefig("tide_diff" + suffix + ".png", dpi=600, format="png")
|
|
170
|
+
|
|
171
|
+
readings.set_correction("c_tide", "c_tide")
|
|
172
|
+
|
|
173
|
+
# update polar motion coordinates
|
|
174
|
+
# xp, yp = get_polar_motion(readings._data.jd.values)
|
|
175
|
+
# readings.add_quantity_column('xp', xp)
|
|
176
|
+
# readings.add_quantity_column('yp', yp)
|
|
177
|
+
# readings._update_g_result()
|
|
178
|
+
|
|
179
|
+
# pressure correction
|
|
180
|
+
if args.pressure is not None:
|
|
181
|
+
pres = pd.read_csv(args.pressure, index_col="time", parse_dates=True)
|
|
182
|
+
readings.data["pres"] = interpolate(pres["pres"], readings.data.index)
|
|
183
|
+
readings.data["c_atm"] = (
|
|
184
|
+
atmospheric_pressure_correction(readings.data.height, readings.data["pres"])
|
|
185
|
+
/ 1000
|
|
186
|
+
).round(4)
|
|
187
|
+
readings.set_correction("c_atm", "c_atm")
|
|
188
|
+
readings.data.c_atm.plot()
|
|
189
|
+
|
|
190
|
+
loop = readings.copy().truncate(by="setup", before=args.tb, after=args.ta)
|
|
191
|
+
|
|
192
|
+
# filter
|
|
193
|
+
# loop = loop.filter('tilt_y', -20, 20)
|
|
194
|
+
# loop = loop.filter('tilt_x', -20, 20)
|
|
195
|
+
|
|
196
|
+
dur_med = readings.data.dur.median()
|
|
197
|
+
loop = loop.filter(dur_med, dur_med + 20, column="dur")
|
|
198
|
+
|
|
199
|
+
# loop = loop.filter('setup', 8, 17)
|
|
200
|
+
# loop = loop.filter('stdev', -1, 0.1)
|
|
201
|
+
|
|
202
|
+
# adj = loop.adjust(mask=False, order=args.drift_order)
|
|
203
|
+
|
|
204
|
+
adj = loop.adjust(drift_args={"drift_order": args.drift_order})
|
|
205
|
+
|
|
206
|
+
adj.readings.to_file("readings" + suffix + ".redu")
|
|
207
|
+
|
|
208
|
+
report = adj.report()
|
|
209
|
+
with open("report" + suffix + ".txt", "w") as f:
|
|
210
|
+
f.write(report)
|
|
211
|
+
|
|
212
|
+
ties = adj.ties()
|
|
213
|
+
if not ties._data.empty:
|
|
214
|
+
ties.to_file(fname="ties" + suffix + ".txt")
|
|
215
|
+
|
|
216
|
+
plot_loop_processing(readings, adj)
|
|
217
|
+
plt.savefig("plot" + suffix + ".png", dpi=600, format="png")
|
gmeterpy/cli/scx2.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
"""Convert Scintrex CG-x txt file to table txt"""
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import os
|
|
7
|
+
|
|
8
|
+
from gmeterpy.meters.scintrex import ScintrexCG5, ScintrexCG6
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def main():
|
|
12
|
+
parser = argparse.ArgumentParser(description="Convert Scintrex CG-x file")
|
|
13
|
+
parser.add_argument(
|
|
14
|
+
"infile",
|
|
15
|
+
metavar="INPUT",
|
|
16
|
+
type=argparse.FileType("rt"),
|
|
17
|
+
help="Input Scintrex CG-x data file",
|
|
18
|
+
)
|
|
19
|
+
parser.add_argument(
|
|
20
|
+
"--meter-type",
|
|
21
|
+
default="cg5",
|
|
22
|
+
choices=["cg5", "cg6"],
|
|
23
|
+
help="type of the gravimeter",
|
|
24
|
+
)
|
|
25
|
+
parser.add_argument(
|
|
26
|
+
"--remove-drift",
|
|
27
|
+
action="store_false",
|
|
28
|
+
help="Remove linear drift defined as Drift value in SETUP PARAMETERS",
|
|
29
|
+
)
|
|
30
|
+
args = parser.parse_args()
|
|
31
|
+
|
|
32
|
+
proc_dir = os.path.dirname(os.path.abspath(args.infile.name))
|
|
33
|
+
os.chdir(proc_dir)
|
|
34
|
+
|
|
35
|
+
if args.meter_type.lower() == "cg5":
|
|
36
|
+
survey = ScintrexCG5(args.infile.name, use_drift=args.remove_drift)
|
|
37
|
+
elif args.meter_type.lower() == "cg6":
|
|
38
|
+
survey = ScintrexCG6(args.infile.name, use_drift=args.remove_drift)
|
|
39
|
+
|
|
40
|
+
# show lines info
|
|
41
|
+
for line, data in survey.data.groupby("line"):
|
|
42
|
+
print("line:", line)
|
|
43
|
+
print("\tsid:\t", data.sid.unique())
|
|
44
|
+
print("\tsetup:\t", data.setup.unique())
|
|
45
|
+
|
|
46
|
+
# write lines in separate files
|
|
47
|
+
# lines = survey.lines().copy()
|
|
48
|
+
# for i, line in enumerate(lines):
|
|
49
|
+
# suffix = '_line_' + str(int(line.data.line.unique()[0]))
|
|
50
|
+
# line.to_file('readings' + suffix + '.txt')
|
|
51
|
+
survey.to_file("readings.txt")
|
gmeterpy/cli/vgfit.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
from pandas import read_csv
|
|
7
|
+
|
|
8
|
+
from gmeterpy.corrections.vgrad import fit_floating_gravity, generate_report
|
|
9
|
+
from gmeterpy.plotting.vgfit import plot_fit
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def main():
|
|
13
|
+
parser = argparse.ArgumentParser(
|
|
14
|
+
description="Polynomial fit of the vertical gravity gradients data"
|
|
15
|
+
)
|
|
16
|
+
parser.add_argument(
|
|
17
|
+
"-i",
|
|
18
|
+
"--input",
|
|
19
|
+
type=argparse.FileType("rt"),
|
|
20
|
+
required=True,
|
|
21
|
+
help="Input file",
|
|
22
|
+
metavar="FILE",
|
|
23
|
+
)
|
|
24
|
+
parser.add_argument(
|
|
25
|
+
"-n", "--name", default="", type=str, help="Station name", metavar="STATION"
|
|
26
|
+
)
|
|
27
|
+
parser.add_argument(
|
|
28
|
+
"-d",
|
|
29
|
+
"--degree",
|
|
30
|
+
type=int,
|
|
31
|
+
default=2,
|
|
32
|
+
help="Degree of the polynomial model (default: 2).",
|
|
33
|
+
metavar="DEGREE",
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
args = parser.parse_args()
|
|
37
|
+
|
|
38
|
+
data = read_csv(args.input)
|
|
39
|
+
|
|
40
|
+
df, res = fit_floating_gravity(data, deg=args.degree)
|
|
41
|
+
params = res.params.iloc[-args.degree :]
|
|
42
|
+
cov_params = res.cov_params().iloc[-args.degree :, -args.degree :]
|
|
43
|
+
|
|
44
|
+
df["resid"] = res.resid
|
|
45
|
+
|
|
46
|
+
gp = np.poly1d(np.concatenate([params.values[::-1], np.zeros(1)]), variable="h")
|
|
47
|
+
|
|
48
|
+
make_plot = True
|
|
49
|
+
make_report = True
|
|
50
|
+
|
|
51
|
+
station = args.name
|
|
52
|
+
|
|
53
|
+
if make_plot:
|
|
54
|
+
fig = plot_fit(df, gp, cov_params, station)
|
|
55
|
+
plot_file = station + "_all.png"
|
|
56
|
+
fig.savefig(plot_file)
|
|
57
|
+
|
|
58
|
+
if make_report:
|
|
59
|
+
report_file = "vg_" + station + "_fit_all.txt"
|
|
60
|
+
generate_report(report_file, data, res, gp, station)
|
gmeterpy/constants.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"""Constants for gMeterPy."""
|
|
2
|
+
|
|
3
|
+
from typing import ClassVar
|
|
4
|
+
|
|
5
|
+
from astropy.constants import Constant
|
|
6
|
+
from astropy.constants import c as c
|
|
7
|
+
|
|
8
|
+
omega = Constant(
|
|
9
|
+
abbrev="omega",
|
|
10
|
+
name="Mean angular rotation rate of the Earth",
|
|
11
|
+
value=7292115.0e-11,
|
|
12
|
+
unit="rad / s",
|
|
13
|
+
uncertainty=0.0,
|
|
14
|
+
reference="",
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
atm_sens = Constant(
|
|
18
|
+
abbrev="atm_sens",
|
|
19
|
+
name="Default sensitivity of changes in gravity "
|
|
20
|
+
"with variations in atmospheric pressure.",
|
|
21
|
+
value=0.3,
|
|
22
|
+
unit="uGal / mbar",
|
|
23
|
+
uncertainty=0.0,
|
|
24
|
+
reference="IAG 1983 Resolution no.9",
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# ISO 2533:1975 constants
|
|
29
|
+
class ISA1975(Constant):
|
|
30
|
+
default_reference = "Standard Atmosphere ISO 2533:1975"
|
|
31
|
+
_registry: ClassVar[dict] = {}
|
|
32
|
+
_has_incompatible_units: ClassVar[set] = set()
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
p0 = ISA1975(
|
|
36
|
+
"p0",
|
|
37
|
+
"Standard atmospheric pressure at sea level.",
|
|
38
|
+
101325.0,
|
|
39
|
+
"Pa",
|
|
40
|
+
0.0,
|
|
41
|
+
system="si",
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
L = ISA1975("L", "Temperature lapse rate.", 0.0065, "K / m", 0.0, system="si")
|
|
45
|
+
|
|
46
|
+
Tn = ISA1975(
|
|
47
|
+
"Tn",
|
|
48
|
+
"Standard thermodynamic air temperature at sea level.",
|
|
49
|
+
288.15,
|
|
50
|
+
"K",
|
|
51
|
+
0.0,
|
|
52
|
+
system="si",
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
gn = ISA1975(
|
|
56
|
+
"gn", "Standard acceleration of free-fall.", 9.80665, "m / s**2", 0.0, system="si"
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
M = ISA1975(
|
|
60
|
+
"M", "Air molar mass at sea level.", 0.028964420, "kg / mol", 0.0, system="si"
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
R = ISA1975("R", "Universal gas constant.", 8.31432, "J / (mol * K)", 0.0, system="si")
|
|
File without changes
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
import matplotlib.pylab as plt
|
|
4
|
+
import numpy as np
|
|
5
|
+
import statsmodels.api as sm
|
|
6
|
+
from scipy.stats import chi2
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class AdjustmentResults:
|
|
10
|
+
def __init__(self, model, results):
|
|
11
|
+
|
|
12
|
+
self.model = model
|
|
13
|
+
self.res = results
|
|
14
|
+
|
|
15
|
+
self._s0 = np.sqrt(self.res.scale)
|
|
16
|
+
|
|
17
|
+
@property
|
|
18
|
+
def number_of_observations(self):
|
|
19
|
+
return self.res.nobs
|
|
20
|
+
|
|
21
|
+
@property
|
|
22
|
+
def number_of_unknowns(self):
|
|
23
|
+
return self.res.df_model
|
|
24
|
+
|
|
25
|
+
@property
|
|
26
|
+
def degrees_of_freedom(self):
|
|
27
|
+
return self.res.df_resid
|
|
28
|
+
|
|
29
|
+
@property
|
|
30
|
+
def params(self):
|
|
31
|
+
return self.res.params
|
|
32
|
+
|
|
33
|
+
def _params_contains(self, *args, **kwargs):
|
|
34
|
+
return self.params.index.str.contains(*args, **kwargs)
|
|
35
|
+
|
|
36
|
+
def _params_startswith(self, *args, **kwargs):
|
|
37
|
+
return self.params.index.str.startswith(*args, **kwargs)
|
|
38
|
+
|
|
39
|
+
def _params_endswith(self, *args, **kwargs):
|
|
40
|
+
return self.params.index.str.endswith(*args, **kwargs)
|
|
41
|
+
|
|
42
|
+
def has_params(self, name):
|
|
43
|
+
return np.any(self._params_contains(name))
|
|
44
|
+
|
|
45
|
+
@property
|
|
46
|
+
def sigma(self):
|
|
47
|
+
return self.res.bse
|
|
48
|
+
|
|
49
|
+
@property
|
|
50
|
+
def s0(self):
|
|
51
|
+
return self._s0
|
|
52
|
+
|
|
53
|
+
def chi2(self, alpha=0.95, scale=1.0):
|
|
54
|
+
dof = self.degrees_of_freedom
|
|
55
|
+
lower, upper = np.asarray(chi2.interval(alpha=alpha, df=dof))
|
|
56
|
+
chisq = self.s0**2 / scale**2 * dof
|
|
57
|
+
return chisq, lower, upper
|
|
58
|
+
|
|
59
|
+
def qqplot(self, ax=None, **kwargs):
|
|
60
|
+
"""Q-Q plot of the residuals."""
|
|
61
|
+
if ax is None:
|
|
62
|
+
_fig, ax = plt.subplots(figsize=(4, 3))
|
|
63
|
+
|
|
64
|
+
sm.graphics.qqplot(self.res.resid, fit=True, line="s", ax=ax, **kwargs)
|
|
65
|
+
ax.set_title("Normal Q-Q plot")
|
|
66
|
+
return ax
|