-
Notifications
You must be signed in to change notification settings - Fork 0
/
sensitivityrun.py
180 lines (135 loc) · 7.26 KB
/
sensitivityrun.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
from regionlib import brasil
import os, gsw
import pickle
import graph, nstools, interptools, inverttools
from functools import partial
import parametertools as ptools
import numpy as np
import matplotlib.pyplot as plt
import pdb
from scipy.io import savemat
switch = { "reflevel":False,
"H_0":False,
"no mix":False,
"bounds":False,
"column weighting":False,
"gaussian noise": False,
"reference station":True
}
if switch["reflevel"]:
################################
### REFERENCE LEVEL TESTING
################################
with open('data/withparams.pickle', 'rb') as outfile:
[surfaces,neighbors,distances] = pickle.load(outfile)
reflevels = surfaces.keys()
for k in reflevels:
if int(k) >1200 and int(k) < 4000:
with open('data/run0/withparams.pickle', 'rb') as outfile:
[surfaces,neighbors,distances] = pickle.load(outfile)
params = {"reflevel":int(k),"upperbound":1000,"lowerbound":4000,\
"mixs":{"kvo":True,"kvb":True,"kh":True},"debug":False,\
"3point":True,"edgeguard":True,"H_0":1000}
out= inverttools.invert("coupled",surfaces,neighbors,distances,params=params)
inv = out["surfaces"]
inv = nstools.streamFuncToUV(inv,neighbors,distances)
with open('sens/reflevel/{}.pickle'.format(k), 'wb') as outfile:
pickle.dump([out,neighbors,distances],outfile)
if switch["H_0"]:
######################
###### H_0 Testing
######################
for H_0 in [200,500,1000,1500,2000]:
with open('data/run0/interpedbrasil.pickle', 'rb') as outfile:
[surfaces,neighbors,distances] = pickle.load(outfile)
surfaces, neighbors, distances = nstools.addParametersToSurfaces(brasil,surfaces,neighbors,distances,H_0=H_0)
params = {"reflevel":2000,"upperbound":1000,"lowerbound":4000,\
"mixs":{"kvo":True,"kvb":True,"kh":True},"debug":False,\
"3point":True,"edgeguard":True,"H_0":H_0
}
out= inverttools.invert("coupled",surfaces,neighbors,distances,params=params)
with open('sens/H_0/{}.pickle'.format(H_0), 'wb') as outfile:
pickle.dump([out,neighbors,distances],outfile)
if switch["no mix"]:
######################
###### No Mixing
######################
with open('data/run0/withparams.pickle', 'rb') as outfile:
[surfaces,neighbors,distances] = pickle.load(outfile)
params = {"reflevel":2000,"upperbound":1000,"lowerbound":4000,\
"mixs":{"kvo":False,"kvb":False,"kh":False},"debug":False,\
"3point":True,"edgeguard":True,"H_0":1000}
out= inverttools.invert("coupled",surfaces,neighbors,distances,params=params)
with open('sens/nomix.pickle'.format(k), 'wb') as outfile:
pickle.dump([out,neighbors,distances],outfile)
if switch["bounds"]:
######################
###### Change upper and lower bound of inversion
######################
for delta in range(1,4):
newupperbound = 1000+delta*200
newlowerbound = 4000-delta*200
with open('data/run0/withparams.pickle', 'rb') as outfile:
[surfaces,neighbors,distances] = pickle.load(outfile)
params = {"reflevel":2000,"upperbound":newupperbound,"lowerbound":newlowerbound,\
"mixs":{"kvo":True,"kvb":True,"kh":True},"debug":False,\
"3point":True,"edgeguard":True,"H_0":1000}
out= inverttools.invert("coupled",surfaces,neighbors,distances,params=params)
with open('sens/bounds{}-{}.pickle'.format(newlowerbound,newupperbound), 'wb') as outfile:
pickle.dump([out,neighbors,distances],outfile)
if switch["column weighting"]:
######################
###### Change column weighting by a factor of magnitude
######################
for delta in ((1,0,0),(0,1,0),(0,0,1),(-1,0,0),(0,-1,0),(0,0,-1)):
with open('data/run0/withparams.pickle', 'rb') as outfile:
[surfaces,neighbors,distances] = pickle.load(outfile)
params = {"reflevel":2000,"upperbound":1000,"lowerbound":4000,\
"mixs":{"kvo":True,"kvb":True,"kh":True},"debug":False,\
"3point":True,"edgeguard":True,"H_0":1000,
"scalecoeffs":{"Ar":0.05,"kvo":5*10**(-6+delta[0]),"kvb":5*10**(-4+delta[1]),"kh":5*10**(2+delta[2])}}
out= inverttools.invert("coupled",surfaces,neighbors,distances,params=params)
with open('sens/columnweighting-{}-{}-{}.pickle'.format(delta[0],delta[1],delta[2]), 'wb') as outfile:
pickle.dump([out,neighbors,distances],outfile)
if switch["gaussian noise"]:
######################
###### Add Gaussian noise to neutral surface determination
######################
for noise in range(1,4):
with open('data/run0/annotatedbrasilargowoce.pickle', 'rb') as outfile:
preinterpsurfaces,profiles = pickle.load(outfile)
preinterpsurfaces = nstools.addDataToSurfaces(brasil,profiles,preinterpsurfaces,noise=noise*15)
surfaces,neighbors,distances = \
interptools.interpolateSurfaces(brasil,preinterpsurfaces,\
interpmethod="gam",smart=False,coord="latlon")
surfaces, neighbors, distances = nstools.addParametersToSurfaces(brasil,surfaces,neighbors,distances,H_0=1000)
params = {"reflevel":2000,"upperbound":1000,"lowerbound":4000,\
"mixs":{"kvo":True,"kvb":True,"kh":True},"debug":False,\
"3point":True,"edgeguard":True,"H_0":1000
}
out= inverttools.invert("coupled",surfaces,neighbors,distances,params=params)
with open('sens/noise-{}.pickle'.format(noise*30), 'wb') as outfile:
pickle.dump([out,neighbors,distances], outfile)
if switch["reference station"]:
######################
###### Choosing a different reference station
######################
with open('data/run0/argoandwoce.pickle', 'rb') as outfile:
profiles = pickle.load(outfile)
## profilechoice = nstools.profileInBox(profiles,-40,-20,-31,-28,5000)
## #profilechoice = nstools.profileInBox(profiles,-45,-20,-40,-31,5000)
profilechoice = nstools.profileInBox(profiles,-25,-20,-25,-20,4500)
profilechoice = profilechoice[0]
preinterpsurfaces = nstools.runPeerSearch(profiles,range(200,5000,200),profilechoice,False,10**10)
preinterpsurfaces = nstools.addDataToSurfaces(brasil,profiles,preinterpsurfaces,noise=0)
surfaces,neighbors,distances = \
interptools.interpolateSurfaces(brasil,preinterpsurfaces,\
interpmethod="gam",smart=False,coord="latlon")
surfaces, neighbors, distances = nstools.addParametersToSurfaces(brasil,surfaces,neighbors,distances,H_0=1000)
params = {"reflevel":2000,"upperbound":1000,"lowerbound":4000,\
"mixs":{"kvo":True,"kvb":True,"kh":True},"debug":False,\
"3point":True,"edgeguard":True,"H_0":1000
}
out= inverttools.invert("coupled",surfaces,neighbors,distances,params=params)
with open('data/sens/differentref-{}-{}.pickle'.format(profilechoice.lon,profilechoice.lat), 'wb') as outfile:
pickle.dump([out,neighbors,distances], outfile)