def analyse_noise(self, tpoint=None, chop_bounds=['b', 'c']): """ Analyse seismic noise in datatraces and set data-covariance matrixes accordingly. """ if self.config.noise_estimator.structure == 'non-toeplitz': results = self.assemble_results(tpoint, order='wmap', chop_bounds=chop_bounds) else: results = [None] * len(self.wavemaps) for wmap, wmap_results in zip(self.wavemaps, results): logger.info( 'Retrieving seismic data-covariances with structure "%s" ' 'for %s ...' % (self.config.noise_estimator.structure, wmap._mapid)) cov_ds_seismic = self.noise_analyser.get_data_covariances( wmap=wmap, results=wmap_results, sample_rate=self.config.gf_config.sample_rate, chop_bounds=chop_bounds) for j, trc in enumerate(wmap.datasets): if trc.covariance is None: trc.covariance = heart.Covariance(data=cov_ds_seismic[j]) else: trc.covariance.data = cov_ds_seismic[j] if int(trc.covariance.data.sum()) == trc.data_len(): logger.warning('Data covariance is identity matrix!' ' Please double check!!!')
def load_SAR_data(datadir, tracks): ''' Load SAR data in given directory and tracks. Returns Diff_IFG objects. ''' DIFFGs = [] for k in tracks: # open matlab.mat files data = scipy.io.loadmat(datadir + 'quad_' + k + '.mat', squeeze_me=True, struct_as_record=False) covs = scipy.io.loadmat(datadir + 'CovMatrix_' + k + '.mat', squeeze_me=True, struct_as_record=False) utmx = data['cfoc'][:, 0] utmy = data['cfoc'][:, 1] lons, lats = utility.utm_to_lonlat(utmx, utmy, 36) Lv = data['lvQT'] covariance = heart.Covariance(data=covs['Cov']) DIFFGs.append( heart.DiffIFG(track=k, displacement=data['sqval'], utme=utmx, utmn=utmy, lons=lons, lats=lats, covariance=covariance, incidence=Lv.inci, heading=Lv.head, odw=data['ODW_sub'])) return DIFFGs
def load_SAR_data(datadir, names): """ Load SAR data in given directory and filenames. Returns Diff_IFG objects. """ diffgs = [] tobeloaded_names = set(copy.deepcopy(names)) for k in names: # open matlab.mat files data = load_matfile(datadir + 'quad_' + k + '.mat', squeeze_me=True, struct_as_record=False) covs = load_matfile(datadir + 'CovMatrix_' + k + '.mat', squeeze_me=True, struct_as_record=False) if data is not None and covs is not None: utmx = data['cfoc'][:, 0] utmy = data['cfoc'][:, 1] lons, lats = utility.utm_to_lonlat(utmx, utmy, 36) Lv = data['lvQT'] covariance = heart.Covariance(data=covs['Cov']) diffgs.append( heart.DiffIFG(name=k, displacement=data['sqval'], utme=utmx, utmn=utmy, lons=lons, lats=lats, covariance=covariance, incidence=Lv.inci, heading=Lv.head, odw=data['ODW_sub'])) tobeloaded_names.discard(k) else: logger.info('File %s was no SAR data?!' % datadir) names = list(tobeloaded_names) return diffgs
def __init__(self, sc, event, project_dir, hypers=False): super(SeismicComposite, self).__init__() logger.debug('Setting up seismic structure ...\n') self.name = 'seismic' self._like_name = 'seis_like' self.correction_name = 'time_shift' self.event = event self.engine = LocalEngine( store_superdirs=[sc.gf_config.store_superdir]) seismic_data_path = os.path.join(project_dir, bconfig.seismic_data_name) self.datahandler = heart.init_datahandler( seismic_config=sc, seismic_data_path=seismic_data_path) self.wavemaps = [] for wc in sc.waveforms: if wc.include: wmap = heart.init_wavemap(waveformfit_config=wc, datahandler=self.datahandler, event=event) if sc.calc_data_cov: logger.info('Estimating seismic data-covariances ' 'for %s ...\n' % wmap.name) cov_ds_seismic = cov.seismic_data_covariance( data_traces=wmap.datasets, filterer=wc.filterer, sample_rate=sc.gf_config.sample_rate, arrival_taper=wc.arrival_taper, engine=self.engine, event=self.event, targets=wmap.targets) else: logger.info('No data-covariance estimation, using imported' ' covariances...\n') cov_ds_seismic = [] at = wc.arrival_taper n_samples = int( num.ceil(at.duration * sc.gf_config.sample_rate)) for trc in wmap.datasets: if trc.covariance is None: logger.warn('No data covariance given/estimated! ' 'Setting default: eye') cov_ds_seismic.append(num.eye(n_samples)) else: data_cov = trc.covariance.data if data_cov.shape[0] != n_samples: raise ValueError( 'Imported covariance %i does not agree ' ' with taper duration %i!' % (data_cov.shape[0], n_samples)) cov_ds_seismic.append(data_cov) weights = [] for t, trc in enumerate(wmap.datasets): trc.covariance = heart.Covariance(data=cov_ds_seismic[t]) if int(trc.covariance.data.sum()) == trc.data_len(): logger.warn('Data covariance is identity matrix!' ' Please double check!!!') icov = trc.covariance.chol_inverse weights.append( shared(icov, name='seis_%s_weight_%i' % (wc.name, t), borrow=True)) wmap.add_weights(weights) self.wavemaps.append(wmap) else: logger.info('The waveform defined in "%s" config is not ' 'included in the optimization!' % wc.name) if hypers: self._llks = [] for t in range(self.n_t): self._llks.append( shared(num.array([1.]), name='seis_llk_%i' % t, borrow=True))