Browse Source

new grond init

priors
miili 2 years ago
parent
commit
2b38cd7b4c
9 changed files with 203 additions and 37 deletions
  1. +2
    -1
      setup.py
  2. +1
    -1
      src/analysers/noise_analyser/analyser.py
  3. +53
    -15
      src/apps/cmd_init.py
  4. +70
    -9
      src/apps/grond.py
  5. +46
    -0
      src/data/init/README_example.md
  6. +0
    -8
      src/data/init/event_myanmar_2011.txt
  7. +1
    -2
      src/data/init/example_insar_rectangular.gronf
  8. +1
    -1
      src/data/init/example_wphase_cmt.gronf
  9. +29
    -0
      src/data/init/section_noise_analyser.gronf

+ 2
- 1
setup.py View File

@ -136,7 +136,8 @@ setup(
'report/app/js/*.js',
'data/init/*.gronf',
'data/init/*.txt'
'data/init/*.txt',
'data/init/*.md'
]},
data_files=[],


+ 1
- 1
src/analysers/noise_analyser/analyser.py View File

@ -296,7 +296,7 @@ class NoiseAnalyserConfig(AnalyserConfig):
check_events = Bool.T(
default=False,
help='check the gCMT global catalogue for M>5 earthquakes'
help='check the GlobalCMT for M>5 earthquakes'
' that produce phase arrivals'
' contaminating and affecting the noise analysis')


+ 53
- 15
src/apps/cmd_init.py View File

@ -1,7 +1,9 @@
import logging
import glob
import shutil
import os.path as op
from pyrocko import util
logger = logging.getLogger('grond.init')
km = 1e3
@ -14,19 +16,17 @@ class GrondInit(object):
def __init__(self):
pass
def available_inits(self):
def get_examples(self):
return {
'examples': tuple((self.filename_to_abbrv(fn),
self._get_description(fn))
for fn in self.example_files),
'events': tuple((self.filename_to_abbrv(fn),
self._get_description(fn))
for fn in self.event_files),
self.filename_to_abbrv(fn): self._get_description(fn)
for fn in self.example_files
}
@staticmethod
def filename_to_abbrv(filename):
return op.basename(filename).split('.')[0]
def get_sections(self):
return {
self.filename_to_abbrv(fn): self._get_description(fn)
for fn in self.section_files
}
@property
def example_files(self):
@ -40,16 +40,54 @@ class GrondInit(object):
def snippet_files(self):
return self._get_files('snippet_*.gronf')
@property
def event_files(self):
return self._get_files('event_*.txt')
def _get_files(self, name):
return glob.glob(op.join(self.folder, name))
def _get_description(self, filename):
@staticmethod
def _get_description(filename):
with open(filename, 'rt') as f:
for ln in f.readlines():
if ln.startswith('#'):
return ln.split(':')[-1].strip('# \n')
return 'No description!'
@staticmethod
def filename_to_abbrv(filename):
return op.basename(filename).split('.')[0]
def init_example(self, abbrv, path, force=False):
path = op.abspath(path)
if op.exists(path) and not force:
raise OSError('Directory already exists: %s' % op.basename(path))
logger.info('Initialising example configuration for %s...' % abbrv)
sub_dirs = ['config', 'gf_stores', 'data']
for d in sub_dirs:
p = op.join(path, d + '/')
logger.debug('Creating directory: %s' % p)
util.ensuredirs(p)
fn = self.abbrv_to_filename(abbrv)
logger.debug('Copying config file: %s' % fn)
shutil.copyfile(fn, op.join(path, 'config', op.basename(fn)))
logger.debug('Copying README.md: %s' % fn)
shutil.copyfile(op.join(self.folder, 'README_example.md'),
op.join(path, 'README.md'))
def abbrv_to_filename(self, abbrv):
ext = '.gronf'
fn = op.join(self.folder, abbrv + ext)
if fn not in self._get_files('*.gronf'):
raise OSError('File not found: %s' % fn)
return fn
def get_content(self, abbrv):
try:
fn = self.abbrv_to_filename(abbrv)
except OSError:
return False
with open(fn, 'r') as f:
return f.read()

+ 70
- 9
src/apps/grond.py View File

@ -15,6 +15,19 @@ logger = logging.getLogger('grond.main')
km = 1e3
class Color:
PURPLE = '\033[95m'
CYAN = '\033[96m'
DARKCYAN = '\033[36m'
BLUE = '\033[94m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
END = '\033[0m'
def d2u(d):
if isinstance(d, dict):
return dict((k.replace('-', '_'), v) for (k, v) in d.items())
@ -448,24 +461,72 @@ def command_init(args):
grond_init = GrondInit()
def print_section(entries):
if len(entries) == 0:
return '\tNone available.'
padding = max([len(n) for n in entries.keys()])
rstr = []
for name, desc in entries.items():
rstr.append(' {c.BOLD}{name:<{padding}}{c.END} : {desc}'.format(
name=name, desc=desc, padding=padding, c=Color))
return '\n'.join(rstr)
help_text = '''Available configuration examples for grond.
{c.BOLD}Example Projects{c.END}
Deploy a full project structure into a directory.
usage: grond init example_regional_cmt example-project/
{examples_list}
{c.BOLD}Config Sections{c.END}
Print out configuration snippets for various components.
usage: grond init section_noise_analyser
{sections_list}
'''.format(c=Color,
examples_list=print_section(grond_init.get_examples()),
sections_list=print_section(grond_init.get_sections()))
def setup(parser):
parser.add_option(
'--force', dest='force', action='store_true')
parser, options, args = cl_parse('init', args, setup)
parser, options, args = cl_parse(
'init', args, setup,
'Use grond init list to show available initialisations')
if len(args) not in (1, 2):
help_and_die(parser, '1 or 2 arguments required')
if args[0] == 'list':
print('List of available configuration examples for grond:')
for section, entries in grond_init.available_inits().items():
padding = max([len(n) for n, _ in entries])
print('\n{title}:'.format(title=section.title()))
for name, desc in entries:
print(' {name:<{padding}}: {desc}'.format(
name=name, desc=desc, padding=padding))
print(help_text)
elif args[0].startswith('section_'):
sec = grond_init.get_content(args[0])
if not sec:
help_and_die(parser, 'Unknown section: %s' % args)
sys.stdout.write(sec)
elif args[0].startswith('example_'):
if len(args) == 1:
help_and_die(parser, 'Not project directory given!' % args)
if op.exists(op.abspath(args[1])) and not options.force:
help_and_die(
parser,
'Directory %s already exists! Use --force to overwrite.'
% args[1])
try:
grond_init.init_example(args[0], args[1], force=options.force)
except OSError as e:
print(str(e))
else:
help_and_die(parser, 'Unknown init: %s' % args)
def command_init_old(args):


+ 46
- 0
src/data/init/README_example.md View File

@ -0,0 +1,46 @@
Grond Project Layout
====================
For detailed instructions see the documentation https://pyrocko.org/grond/current.
Folder Layout
-------------
```
├── config
│ ├── laquila2009_joint.gronf
│ ├── ...
│ :
├── data
│ └── events # several events could be set up here
│ ├── laquila2009
│ │ ├── event.txt
│ │ ├── insar
│ │ │ ├── dsc_insar.npz
│ │ │ ├── dsc_insar.yml
│ │ │ :
│ │ │
│ │ ├── waveforms
│ │ │ ├── raw # contains Mini-SEED files
│ │ │ │ ├── trace_BK-CMB--BHE_2009-04-06_00-38-31.mseed
│ │ │ │ ├── trace_BK-CMB--BHN_2009-04-06_00-38-31.mseed
│ │ │ │ :
│ │ │ └── stations.xml
│ │ │
│ │ └── gnss
│ │ └── gnss.yml
│ :
├── gf_stores # contains Green's functions
│ ├── Abruzzo_Ameri_nearfield # static near-field GF store
│ │ └── ...
│ ├── global_2s_25km # dynamic far-field GF store
│ │ └── ...
│ :
├── runs # created at runtime, contains individual optimisation results
│ └── ...
└── reports
└── ...
```

+ 0
- 8
src/data/init/event_myanmar_2011.txt View File

@ -1,8 +0,0 @@
name = myanmar_2011
time = 2011-03-24 13:55:12.010
latitude = 20.687
longitude = 99.822
magnitude = 6.9
moment = 1.9228e+19
depth = 8000
region = Myanmar

+ 1
- 2
src/data/init/example_insar_rectangular.gronf View File

@ -1,6 +1,5 @@
%YAML 1.1
# Example: Inversion of planar RectangularSource from local InSAR Observations
# Example: Inversion of planar RectangularSource from local InSAR Observations.
--- !grond.Config
# All file paths referenced below are treated relative to the location of this


+ 1
- 1
src/data/init/example_wphase_cmt.gronf View File

@ -1,5 +1,5 @@
%YAML 1.1
# Example: Inversion of W-Phase from teleseismic observations
# Example: Inversion of W-Phase from teleseismic observations.
--- !grond.Config
# All file paths referenced below are treated relative to the location of this


+ 29
- 0
src/data/init/section_noise_analyser.gronf View File

@ -0,0 +1,29 @@
%YAML 1.1
# Section: Seismic noise analyser to weigh stations by SNR.
analyser_configs:
- !grond.NoiseAnalyserConfig
# Number of windows for trace splitting
nwindows: 1
# Total length of noise trace in the analysis
pre_event_noise_duration: 500.
# Check for events from the GlobalCMT catalog with M>5
check_events: False
# Onset of phase_def used for upper limit of window:
# P or S (see pyrocko.cake)
phase_def: P
# Set weight to inverse of noise variance (var) or standard deviation (std).
statistic: var
# Generate weights based on inverse of noise measure (weighting),
# or discrete on/off style in combination with cutoff value
# (weeding, see cutoff).
mode: weighting
# Set weight to zero, when noise level exceeds median by the given cutoff factor.
cutoff: 0.

Loading…
Cancel
Save