Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Sebastian Heimann
grond
Commits
60746551
Commit
60746551
authored
Nov 21, 2017
by
Marius Isken
Browse files
wip python3
parent
40d9046c
Changes
7
Hide whitespace changes
Inline
Side-by-side
setup.py
View file @
60746551
...
...
@@ -17,6 +17,7 @@ setup(
author_email
=
'sebastian.heimann@gfz-potsdam.de'
,
packages
=
[
'grond'
,
'grond.baraddur'
,
'grond.problems'
,
'grond.solvers'
,
'grond.analysers'
,
'grond.listeners'
,
'grond.targets'
],
python_requires
=
'>=3.5'
,
scripts
=
[
'apps/grond'
],
package_dir
=
{
'grond'
:
'src'
},
package_data
=
{
'grond'
:
[
'baraddur/templates/*.html'
,
...
...
src/core.py
View file @
60746551
from
__future__
import
print_function
import
os
import
sys
import
logging
...
...
@@ -269,7 +271,7 @@ def bootstrap_outliers(problem, misfits, std_factor=1.0):
gms
=
problem
.
global_misfits
(
misfits
)
ibests
=
[]
for
ibootstrap
in
x
range
(
problem
.
nbootstrap
):
for
ibootstrap
in
range
(
problem
.
nbootstrap
):
bms
=
problem
.
bootstrap_misfits
(
misfits
,
ibootstrap
)
ibests
.
append
(
num
.
argmin
(
bms
))
...
...
@@ -366,7 +368,7 @@ def harvest(rundir, problem=None, nbest=10, force=False, weed=0):
ibests_list
.
append
(
isort
[:
nbest
])
if
weed
!=
3
:
for
ibootstrap
in
x
range
(
config
.
solver_config
.
nbootstrap
):
for
ibootstrap
in
range
(
config
.
solver_config
.
nbootstrap
):
bms
=
problem
.
bootstrap_misfits
(
misfits
,
ibootstrap
)
isort
=
num
.
argsort
(
bms
)
ibests_list
.
append
(
isort
[:
nbest
])
...
...
@@ -453,7 +455,7 @@ def check(
results_list
.
append
(
results
)
else
:
for
i
in
x
range
(
n_random_synthetics
):
for
i
in
range
(
n_random_synthetics
):
x
=
problem
.
random_uniform
(
xbounds
)
sources
.
append
(
problem
.
get_source
(
x
))
ms
,
ns
,
results
=
problem
.
evaluate
(
x
,
result_mode
=
'full'
)
...
...
@@ -519,7 +521,7 @@ def check(
backazimuth
=
target
.
get_backazimuth_for_waveform
(),
debug
=
True
)
except
NotFound
,
e
:
except
NotFound
as
e
:
logger
.
warn
(
str
(
e
))
continue
...
...
@@ -643,7 +645,7 @@ def check(
logger
.
info
(
'%-40s %s'
%
(
(
target
.
string_id
()
+
':'
,
sok
)))
except
GrondError
,
e
:
except
GrondError
as
e
:
logger
.
error
(
'event %i, %s: %s'
%
(
ievent
,
event
.
name
or
util
.
time_to_str
(
event
.
time
),
...
...
@@ -666,7 +668,7 @@ def go(config, event_names=None, force=False, nparallel=1, status=('state',)):
for
x
in
parimap
.
parimap
(
process_event
,
x
range
(
nevents
),
range
(
nevents
),
[
id
(
g_data
)]
*
nevents
,
nprocs
=
nparallel
):
...
...
@@ -856,13 +858,13 @@ def export(what, rundirs, type=None, pnames=None, filename=None):
type
=
'event'
if
shortform
:
print
>>
out
,
'#'
,
' '
.
join
(
'%16s'
%
x
for
x
in
pnames
)
print
(
'#'
,
' '
.
join
(
[
'%16s'
%
x
for
x
in
pnames
]),
file
=
out
)
def
dump
(
x
,
gm
,
indices
):
if
type
==
'vector'
:
print
>>
out
,
' '
,
' '
.
join
(
'%16.7g'
%
problem
.
extract
(
x
,
i
)
for
i
in
indices
),
\
'%16.7g'
%
gm
print
(
' '
,
' '
.
join
(
'%16.7g'
%
problem
.
extract
(
x
,
i
)
for
i
in
indices
),
'%16.7g'
%
gm
,
file
=
out
)
elif
type
==
'source'
:
source
=
problem
.
get_source
(
x
)
...
...
@@ -896,7 +898,7 @@ def export(what, rundirs, type=None, pnames=None, filename=None):
'%16s'
%
x
for
x
in
pnames_take
+
extra
)
if
type
==
'vector'
and
header
!=
new_header
:
print
>>
out
,
new_header
print
(
new_header
,
file
=
out
)
header
=
new_header
else
:
...
...
@@ -919,9 +921,9 @@ def export(what, rundirs, type=None, pnames=None, filename=None):
elif
what
==
'stats'
:
rs
=
make_stats
(
problem
,
xs
,
misfits
,
pnames_clean
)
if
shortform
:
print
>>
out
,
' '
,
format_stats
(
rs
,
pnames
)
print
(
' '
,
format_stats
(
rs
,
pnames
)
,
file
=
out
)
else
:
print
>>
out
,
rs
print
(
rs
,
file
=
out
)
else
:
raise
GrondError
(
'invalid argument: what=%s'
%
repr
(
what
))
...
...
src/dataset.py
View file @
60746551
...
...
@@ -172,7 +172,7 @@ class Dataset(object):
clippings
[
nsl
].
append
(
marker
.
tmin
)
clippings
[
nslc
].
append
(
marker
.
tmin
)
for
k
,
times
in
clippings
.
iter
items
():
for
k
,
times
in
clippings
.
items
():
atimes
=
num
.
array
(
times
,
dtype
=
num
.
float
)
if
k
not
in
self
.
clippings
:
self
.
clippings
[
k
]
=
atimes
...
...
@@ -188,7 +188,7 @@ class Dataset(object):
blacklist
.
extend
(
s
.
strip
()
for
s
in
f
.
read
().
splitlines
())
for
x
in
blacklist
:
if
isinstance
(
x
,
basestring
):
if
isinstance
(
x
,
str
):
x
=
tuple
(
x
.
split
(
'.'
))
self
.
blacklist
.
add
(
x
)
...
...
@@ -206,7 +206,7 @@ class Dataset(object):
self
.
whitelist_nsl_xx
=
set
()
for
x
in
whitelist
:
if
isinstance
(
x
,
basestring
):
if
isinstance
(
x
,
str
):
x
=
tuple
(
x
.
split
(
'.'
))
assert
len
(
x
)
in
(
3
,
4
)
if
len
(
x
)
==
4
:
...
...
@@ -388,7 +388,7 @@ class Dataset(object):
timespan
=
(
tmin
,
tmax
),
fake_input_units
=
'M'
))
except
fs
.
NoResponseInformation
,
fs
.
MultipleResponseInformation
:
except
(
fs
.
NoResponseInformation
,
fs
.
MultipleResponseInformation
)
:
pass
if
len
(
candidates
)
==
1
:
...
...
@@ -689,7 +689,7 @@ class Dataset(object):
raise
NotFound
(
'waveform not available'
,
station
.
nsl
()
+
(
channel
,))
except
NotFound
,
e
:
except
NotFound
as
e
:
if
cache
is
not
None
:
cache
[
nslc
,
tmin
,
tmax
]
=
e
raise
...
...
src/meta.py
View file @
60746551
...
...
@@ -73,13 +73,13 @@ class Parameter(Object):
Object
.
__init__
(
self
,
**
kwargs
)
def
get_label
(
self
,
with_unit
=
True
):
l
=
[
self
.
label
or
self
.
name
]
l
bl
=
[
self
.
label
or
self
.
name
]
if
with_unit
:
unit
=
self
.
get_unit_label
()
if
unit
:
l
.
append
(
'[%s]'
%
unit
)
lb
l
.
append
(
'[%s]'
%
unit
)
return
' '
.
join
(
l
)
return
' '
.
join
(
l
bl
)
def
set_groups
(
self
,
groups
):
if
not
isinstance
(
groups
,
list
):
...
...
@@ -176,7 +176,7 @@ class HasPaths(Object):
if
path
is
None
:
return
None
elif
isinstance
(
path
,
basestring
):
elif
isinstance
(
path
,
str
):
return
extra
(
op
.
normpath
(
xjoin
(
self
.
_basepath
,
xjoin
(
path_prefix
,
path
))))
else
:
...
...
src/plot.py
View file @
60746551
...
...
@@ -87,7 +87,7 @@ def scale_axes(ax, scale):
@
staticmethod
def
__call__
(
value
,
pos
):
return
u
'%d'
%
(
value
*
scale
)
return
'%d'
%
(
value
*
scale
)
ax
.
get_xaxis
().
set_major_formatter
(
FormatScaled
())
ax
.
get_yaxis
().
set_major_formatter
(
FormatScaled
())
...
...
@@ -252,7 +252,7 @@ def draw_sequence_figures(model, plt, misfit_cutoff=None, sort_by='misfit'):
figs
=
[]
fig
=
None
alpha
=
0.5
for
ipar
in
x
range
(
npar
):
for
ipar
in
range
(
npar
):
impl
=
ipar
%
(
nfx
*
nfy
)
+
1
if
impl
==
1
:
...
...
@@ -280,7 +280,7 @@ def draw_sequence_figures(model, plt, misfit_cutoff=None, sort_by='misfit'):
axes
.
axhline
(
par
.
scaled
(
xref
[
ipar
]),
color
=
'black'
,
alpha
=
0.3
)
for
idep
in
x
range
(
ndep
):
for
idep
in
range
(
ndep
):
# ifz, ify, ifx = num.unravel_index(ipar, (nfz, nfy, nfx))
impl
=
(
npar
+
idep
)
%
(
nfx
*
nfy
)
+
1
...
...
@@ -363,7 +363,7 @@ def draw_jointpar_figures(
xs
=
model
.
xs
bounds
=
problem
.
get_parameter_bounds
()
+
problem
.
get_dependant_bounds
()
for
ipar
in
x
range
(
problem
.
ncombined
):
for
ipar
in
range
(
problem
.
ncombined
):
par
=
problem
.
combined
[
ipar
]
lo
,
hi
=
bounds
[
ipar
]
if
lo
==
hi
:
...
...
@@ -407,7 +407,7 @@ def draw_jointpar_figures(
smap
=
{}
iselected
=
0
for
ipar
in
x
range
(
problem
.
ncombined
):
for
ipar
in
range
(
problem
.
ncombined
):
par
=
problem
.
combined
[
ipar
]
if
exclude
and
par
.
name
in
exclude
or
\
include
and
par
.
name
not
in
include
:
...
...
@@ -426,9 +426,9 @@ def draw_jointpar_figures(
nfig
=
(
nselected
-
2
)
/
neach
+
1
figs
=
[]
for
ifig
in
x
range
(
nfig
):
for
ifig
in
range
(
nfig
):
figs_row
=
[]
for
jfig
in
x
range
(
nfig
):
for
jfig
in
range
(
nfig
):
if
ifig
>=
jfig
:
figs_row
.
append
(
plt
.
figure
(
figsize
=
figsize
))
else
:
...
...
@@ -436,10 +436,10 @@ def draw_jointpar_figures(
figs
.
append
(
figs_row
)
for
iselected
in
x
range
(
nselected
):
for
iselected
in
range
(
nselected
):
ipar
=
smap
[
iselected
]
ypar
=
problem
.
combined
[
ipar
]
for
jselected
in
x
range
(
iselected
):
for
jselected
in
range
(
iselected
):
jpar
=
smap
[
jselected
]
xpar
=
problem
.
combined
[
jpar
]
...
...
@@ -819,7 +819,7 @@ def draw_bootstrap_figure(model, plt):
gms_softclip
=
num
.
where
(
gms
>
1.0
,
0.1
*
num
.
log10
(
gms
)
+
1.0
,
gms
)
ibests
=
[]
for
ibootstrap
in
x
range
(
problem
.
nbootstrap
):
for
ibootstrap
in
range
(
problem
.
nbootstrap
):
bms
=
problem
.
bootstrap_misfits
(
model
.
misfits
,
ibootstrap
)
isort_bms
=
num
.
argsort
(
bms
)[::
-
1
]
...
...
@@ -862,7 +862,7 @@ def gather(l, key, sort=None, filter=None):
d
[
k
].
append
(
x
)
if
sort
is
not
None
:
for
v
in
d
.
iter
values
():
for
v
in
d
.
values
():
v
.
sort
(
key
=
sort
)
return
d
...
...
@@ -1266,8 +1266,8 @@ def draw_fits_figures(ds, model, plt):
frame_to_target
[
iy
,
ix
]
=
target
figures
=
{}
for
iy
in
x
range
(
ny
):
for
ix
in
x
range
(
nx
):
for
iy
in
range
(
ny
):
for
ix
in
range
(
nx
):
if
(
iy
,
ix
)
not
in
frame_to_target
:
continue
...
...
@@ -1457,7 +1457,7 @@ def draw_fits_figures(ds, model, plt):
dist
=
source
.
distance_to
(
target
)
azi
=
source
.
azibazi_to
(
target
)[
0
]
infos
.
append
(
str_dist
(
dist
))
infos
.
append
(
u
'%.0f
\u00B0
'
%
azi
)
infos
.
append
(
'%.0f
\u00B0
'
%
azi
)
infos
.
append
(
'%.3g'
%
ws
[
itarget
])
infos
.
append
(
'%.3g'
%
gcms
[
itarget
])
axes2
.
annotate
(
...
...
@@ -1471,7 +1471,7 @@ def draw_fits_figures(ds, model, plt):
fontsize
=
fontsize
,
fontstyle
=
'normal'
)
for
(
iyy
,
ixx
),
fig
in
figures
.
iter
items
():
for
(
iyy
,
ixx
),
fig
in
figures
.
items
():
title
=
'.'
.
join
(
x
for
x
in
cg
if
x
)
if
len
(
figures
)
>
1
:
title
+=
' (%i/%i, %i/%i)'
%
(
iyy
+
1
,
nyy
,
ixx
+
1
,
nxx
)
...
...
@@ -1724,7 +1724,7 @@ def available_plotnames():
def
plot_result
(
dirname
,
plotnames_want
,
save
=
False
,
formats
=
(
'pdf'
,),
dpi
=
None
):
if
isinstance
(
formats
,
basestring
):
if
isinstance
(
formats
,
str
):
formats
=
formats
.
split
(
','
)
plotnames_want
=
set
(
plotnames_want
)
...
...
@@ -1910,7 +1910,7 @@ class SolverPlot(object):
p
=
num
.
zeros
((
ny
,
nx
))
for
j
in
[
jchoice
]:
#
x
range(self.problem.nbootstrap+1):
for
j
in
[
jchoice
]:
# range(self.problem.nbootstrap+1):
ps
=
core
.
excentricity_compensated_probabilities
(
xhist
[
chains_i
[
j
,
:],
:],
local_sxs
[
jchoice
],
2.
)
...
...
@@ -1922,7 +1922,7 @@ class SolverPlot(object):
y
=
num
.
linspace
(
bounds
[
self
.
iypar
][
0
],
bounds
[
self
.
iypar
][
1
],
ny
)
for
ichoice
in
x
range
(
chains_i
.
shape
[
1
]):
for
ichoice
in
range
(
chains_i
.
shape
[
1
]):
iiter
=
chains_i
[
j
,
ichoice
]
vx
=
xhist
[
iiter
,
self
.
ixpar
]
vy
=
xhist
[
iiter
,
self
.
iypar
]
...
...
@@ -1946,7 +1946,7 @@ class SolverPlot(object):
color
=
'black'
,
s
=
msize
*
0.15
,
alpha
=
0.2
,
edgecolors
=
'none'
)
for
ibootstrap
in
x
range
(
self
.
problem
.
nbootstrap
+
1
):
for
ibootstrap
in
range
(
self
.
problem
.
nbootstrap
+
1
):
iiters
=
chains_i
[
ibootstrap
,
:]
fx
=
self
.
problem
.
extract
(
xhist
[
iiters
,
:],
self
.
ixpar
)
...
...
src/qc.py
View file @
60746551
...
...
@@ -108,7 +108,7 @@ def polarization(
trs
.
extend
(
trs_projected
)
except
dataset
.
NotFound
,
e
:
except
dataset
.
NotFound
as
e
:
logger
.
warn
(
str
(
e
))
continue
...
...
src/targets/gnss.py
0 → 100644
View file @
60746551
import
logging
from
pyrocko
import
gf
from
.base
import
MisfitTarget
,
MisfitConfig
,
MisfitResult
,
TargetGroup
guts_prefix
=
'grond'
logger
=
logging
.
getLogger
(
'grond.target'
).
getChild
(
'gnss'
)
class
GNSSTargetGroup
(
TargetGroup
):
pass
class
GNSSMisfitResult
(
MisfitResult
):
pass
class
GNSSMisfitConfig
(
MisfitConfig
):
pass
class
GNSSMisfitTarget
(
gf
.
StaticTarget
,
MisfitTarget
):
pass
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment