Browse Source

Added GNSSCampaign Target

whitelist
miili 2 years ago
parent
commit
1c85947849
9 changed files with 185 additions and 33 deletions
  1. +1
    -0
      setup.py
  2. +23
    -1
      src/dataset.py
  3. +2
    -0
      src/targets/__init__.py
  4. +7
    -0
      src/targets/base.py
  5. +1
    -0
      src/targets/gnss_campaign/__init__.py
  6. +145
    -0
      src/targets/gnss_campaign/base.py
  7. +0
    -25
      src/targets/gnss_campaign/target.py
  8. +3
    -4
      src/targets/satellite/base.py
  9. +3
    -3
      src/targets/waveform/base.py

+ 1
- 0
setup.py View File

@ -22,6 +22,7 @@ setup(
'grond.targets',
'grond.targets.waveform',
'grond.targets.satellite',
'grond.targets.gnss_campaign',
'grond.problems',
'grond.problems.cmt',
'grond.problems.double_dc',


+ 23
- 1
src/dataset.py View File

@ -83,6 +83,7 @@ class Dataset(object):
self.extend_incomplete = False
self.clip_handling = 'by_nsl'
self.kite_scenes = []
self.gnss_campaigns = []
self.synthetic_test = None
self._picks = None
self._cache = {}
@ -225,6 +226,17 @@ class Dataset(object):
self._picks = None
def add_gnss_campaign(self, filename):
try:
from pyrocko.model import gnss # noqa
except ImportError:
raise ImportError('Module pyrocko.model.gnss not found,'
' please upgrade pyrocko!')
logger.debug('Loading GNSS campaign from %s' % filename)
campaign = load_all(filename=filename)
self.gnss_campaigns.append(campaign[0])
def add_kite_scene(self, filename):
try:
from kite import Scene
@ -349,6 +361,15 @@ class Dataset(object):
return scene
raise NotFound('No kite scene with id %s defined' % scene_id)
def get_gnss_campaigns(self):
return self.gnss_campaigns
def get_gnss_campaign(self, name):
for camp in self.gnss_campaigns:
if camp.name == name:
return camp
raise NotFound('GNSS campaign %s not found!' % name)
def get_response(self, obj, quantity='displacement'):
if (self.responses is None or len(self.responses) == 0) \
and (self.responses_stationxml is None
@ -862,7 +883,7 @@ class DatasetConfig(HasPaths):
optional=True)
gnss_campaign_paths = List.T(
Path.T(),
Path.T(),
optional=True)
def __init__(self, *args, **kwargs):
@ -912,6 +933,7 @@ class DatasetConfig(HasPaths):
logger.warning('Could not find any kite scenes at %s' %
self.kite_scene_paths)
print(self.gnss_campaign_paths)
if self.gnss_campaign_paths:
logger.info('Loading GNSS campaigns...')
for path in self.gnss_campaign_paths:


+ 2
- 0
src/targets/__init__.py View File

@ -1,3 +1,5 @@
from .waveform import * # noqa
from .satellite import * # noqa
from .gnss_campaign import * # noqa
from .base import * # noqa

+ 7
- 0
src/targets/base.py View File

@ -35,6 +35,10 @@ class MisfitResult(Object):
dtype=num.float)
class MisfitConfig(Object):
pass
class MisfitTarget(Object):
manual_weight = Float.T(
@ -47,6 +51,9 @@ class MisfitTarget(Object):
help='Normalisation family of this misfit target')
path = gf.StringID.T(
help='A path identifier used for plotting')
misfit_config = MisfitConfig.T(
default=MisfitConfig.D(),
help='Misfit configuration')
def __init__(self, **kwargs):
Object.__init__(self, **kwargs)


+ 1
- 0
src/targets/gnss_campaign/__init__.py View File

@ -0,0 +1 @@
from .base import * #noqa

+ 145
- 0
src/targets/gnss_campaign/base.py View File

@ -0,0 +1,145 @@
import logging
import numpy as num
from pyrocko import gf
from pyrocko.guts import String, Dict, List
from ..base import MisfitConfig, MisfitTarget, MisfitResult, TargetGroup
guts_prefix = 'grond'
logger = logging.getLogger('grond.target').getChild('gnss_campaign')
class GNSSCampaignMisfitResult(MisfitResult):
statics_syn = Dict.T(optional=True)
statics_obs = Dict.T(optional=True)
class GNSSCampaignMisfitConfig(MisfitConfig):
pass
class GNSSCampaignTargetGroup(TargetGroup):
gnss_campaigns = List.T(optional=True)
misfit_config = GNSSCampaignMisfitConfig.T()
def get_targets(self, ds, event, default_path):
logger.debug('Selecting GNSS targets...')
targets = []
for camp in ds.get_gnss_campaigns():
if camp.name not in self.gnss_campaigns and\
'*all' not in self.gnss_campaigns:
continue
if not isinstance(self.misfit_config,
GNSSCampaignMisfitConfig):
raise AttributeError('misfit_config must be of type'
' GNSSCampaignMisfitConfig')
lats = num.array([s.lat for s in camp.stations])
lons = num.array([s.lon for s in camp.stations])
north_shifts = num.array([s.north_shift for s in camp.stations])
east_shifts = num.array([s.east_shift for s in camp.stations])
gnss_target = GNSSCampaignMisfitTarget(
quantity='displacement',
campaign_name=camp.name,
lats=lats,
lons=lons,
east_shifts=east_shifts,
north_shifts=north_shifts,
tsnapshot=None,
interpolation=self.interpolation,
store_id=self.store_id,
normalisation_family=self.normalisation_family,
path=self.path or default_path,
misfit_config=self.misfit_config)
gnss_target.set_dataset(ds)
targets.append(gnss_target)
return targets
class GNSSCampaignMisfitTarget(gf.GNSSCampaignTarget, MisfitTarget):
campaign_name = String.T()
misfit_config = GNSSCampaignMisfitConfig.T()
def __init__(self, **kwargs):
gf.GNSSCampaignTarget.__init__(self, **kwargs)
MisfitTarget.__init__(self, **kwargs)
self._obs_data = None
self._sigma = None
self._weights = None
@property
def id(self):
return self.campaign_name
def set_dataset(self, ds):
MisfitTarget.set_dataset(self, ds)
@property
def campaign(self):
return self._ds.get_gnss_campaign(self.campaign_name)
@property
def obs_data(self):
if self._obs_data is None:
self._obs_data = num.array([
[s.north.shift for s in self.campaign.stations],
[s.east.shift for s in self.campaign.stations],
[s.up.shift for s in self.campaign.stations]])
return self._obs_data
@property
def obs_sigma(self):
if self._sigma is None:
self._sigma = num.array([
[s.north.sigma for s in self.campaign.stations],
[s.east.sigma for s in self.campaign.stations],
[s.up.sigma for s in self.campaign.stations]])
return self._obs_data
@property
def weights(self):
if self._weights is None:
self._weights = 1./self.obs_sigma
self._weights[self._weights == num.inf] = 1.
return self._weights
def post_process(self, engine, source, statics):
obs = self.obs_data
weights = self.weights
syn = num.array([statics['displacement.n'],
statics['displacement.e'],
-statics['displacement.d']])
res = obs - syn
misfit_value = num.sqrt(
num.sum((res * weights)**2))
misfit_norm = num.sqrt(
num.sum((obs * weights)**2))
result = GNSSCampaignMisfitResult(
misfits=num.array([misfit_value, misfit_norm],
dtype=num.float))
if self._result_mode == 'full':
result.statics_syn = statics
result.statics_obs = obs
return result
def get_combined_weight(self, apply_balancing_weights=False):
return num.array([self.manual_weight])
def prepare_modelling(self, engine, source):
return [self]
def finalize_modelling(
self, engine, source, modelling_targets, modelling_results):
return modelling_results[0]

+ 0
- 25
src/targets/gnss_campaign/target.py View File

@ -1,25 +0,0 @@
import logging
from pyrocko import gf
from pyrocko.guts import Object
from ..base import MisfitTarget, MisfitResult, TargetGroup
guts_prefix = 'grond'
logger = logging.getLogger('grond.targets.gnss.target')
class GNSSTargetGroup(TargetGroup):
pass
class GNSSMisfitResult(MisfitResult):
pass
class GNSSMisfitConfig(Object):
pass
class GNSSMisfitTarget(gf.StaticTarget, MisfitTarget):
pass

+ 3
- 4
src/targets/satellite/base.py View File

@ -2,17 +2,16 @@ import logging
import numpy as num
from pyrocko import gf
from pyrocko.guts import String, Bool, Dict, List, Object
from pyrocko.guts import String, Bool, Dict, List
from grond.meta import Parameter
from ..base import MisfitTarget, MisfitResult, TargetGroup
from ..base import MisfitConfig, MisfitTarget, MisfitResult, TargetGroup
guts_prefix = 'grond'
logger = logging.getLogger('grond.targets.satellite.target')
class SatelliteMisfitConfig(Object):
class SatelliteMisfitConfig(MisfitConfig):
use_weight_focal = Bool.T(default=False)
optimize_orbital_ramp = Bool.T(default=True)
ranges = Dict.T(String.T(), gf.Range.T(),


+ 3
- 3
src/targets/waveform/base.py View File

@ -9,8 +9,8 @@ from pyrocko.guts_array import Array
from grond.dataset import NotFound
from ..base import (
MisfitTarget, TargetGroup, MisfitResult, TargetAnalysisResult)
from ..base import (MisfitConfig, MisfitTarget, MisfitResult,
TargetGroup, TargetAnalysisResult)
guts_prefix = 'grond'
logger = logging.getLogger('grond.targets.waveform.target')
@ -29,7 +29,7 @@ class Trace(Object):
pass
class WaveformMisfitConfig(Object):
class WaveformMisfitConfig(MisfitConfig):
fmin = Float.T()
fmax = Float.T()
ffactor = Float.T(default=1.5)


Loading…
Cancel
Save