Exemplo n.º 1
0
    def testIOEvent(self):
        tempdir = tempfile.mkdtemp(prefix='pyrocko-model')
        fn = pjoin(tempdir, 'event.txt')
        e1 = model.Event(
            10., 20., 1234567890., 'bubu', region='taka tuka land',
            moment_tensor=moment_tensor.MomentTensor(strike=45., dip=90),
            magnitude=5.1, magnitude_type='Mw')
        guts.dump(e1, filename=fn)
        e2 = guts.load(filename=fn)
        assert e1.region == e2.region
        assert e1.name == e2.name
        assert e1.lat == e2.lat
        assert e1.lon == e2.lon
        assert e1.time == e2.time
        assert e1.region == e2.region
        assert e1.magnitude == e2.magnitude
        assert e1.magnitude_type == e2.magnitude_type
        assert e1.get_hash() == e2.get_hash()

        fn2 = pjoin(tempdir, 'events.txt')
        guts.dump_all([e1, e2], filename=fn2)

        with self.assertRaises(model.OneEventRequired):
            model.load_one_event(fn2)

        shutil.rmtree(tempdir)
Exemplo n.º 2
0
    def testIOEvent(self):
        tempdir = tempfile.mkdtemp(prefix='pyrocko-model')
        fn = pjoin(tempdir, 'event.txt')
        e1 = model.Event(10.,
                         20.,
                         1234567890.,
                         'bubu',
                         depth=10.,
                         region='taka tuka land',
                         moment_tensor=moment_tensor.MomentTensor(strike=45.,
                                                                  dip=90),
                         magnitude=5.1,
                         magnitude_type='Mw',
                         tags=['cluster:-1', 'custom_magnitude:2.5'])

        guts.dump(e1, filename=fn)
        e2 = guts.load(filename=fn)
        assert e1.region == e2.region
        assert e1.name == e2.name
        assert e1.lat == e2.lat
        assert e1.lon == e2.lon
        assert e1.time == e2.time
        assert e1.region == e2.region
        assert e1.magnitude == e2.magnitude
        assert e1.magnitude_type == e2.magnitude_type
        assert e1.get_hash() == e2.get_hash()
        assert e1.tags == e2.tags

        fn2 = pjoin(tempdir, 'events.txt')
        guts.dump_all([e1, e2], filename=fn2)

        with self.assertRaises(model.OneEventRequired):
            model.load_one_event(fn2)

        shutil.rmtree(tempdir)
Exemplo n.º 3
0
    def get_template_origin(self):

        event = model.load_one_event(self.expand_path(
            self.template_event_path))

        origin = geo.Point(
            lat=event.lat,
            lon=event.lon,
            z=event.depth)

        return origin
Exemplo n.º 4
0
    def __init__(self, config):
        logger.info('... Initialising Geometry Optimizer ... \n')

        pc = config.problem_config

        super(GeometryOptimizer, self).__init__(pc)

        # Load event
        if config.event is None:
            if self._seismic_flag:
                self.event = model.load_one_event(
                    os.path.join(
                        config.seismic_config.datadir, 'event.txt'))
            else:
                logger.warn('Found no event information!')
        else:
            self.event = config.event

        # Init sources
        self.sources = []
        for i in range(pc.n_faults):
            if self.event:
                source = heart.RectangularSource.from_pyrocko_event(self.event)
                # hardcoded inversion for hypocentral time
                source.stf.anchor = -1.
            else:
                source = heart.RectangularSource()

            self.sources.append(source)

        dsources = utility.transform_sources(self.sources, pc.datasets)

        if self._seismic_flag:
            logger.debug('Setting up seismic structure ...\n')
            sc = config.seismic_config
            self.engine = gf.LocalEngine(
                store_superdirs=[sc.gf_config.store_superdir])

            seismic_data_path = os.path.join(
                config.project_dir, bconfig.seismic_data_name)
            stations, data_traces = utility.load_objects(
                seismic_data_path)
            stations = utility.apply_station_blacklist(stations, sc.blacklist)

            self.stations = utility.weed_stations(
                stations, self.event, distances=sc.distances)

            self.data_traces = utility.weed_data_traces(
                data_traces, self.stations)

            target_deltat = 1. / sc.gf_config.sample_rate

            if self.data_traces[0].deltat != target_deltat:
                utility.downsample_traces(
                    self.data_traces, deltat=target_deltat)

            self.stargets = heart.init_targets(
                self.stations,
                channels=sc.channels,
                sample_rate=sc.gf_config.sample_rate,
                crust_inds=[0],  # always reference model
                interpolation='multilinear')

            self.ns_t = len(self.stargets)
            logger.info('Number of seismic datasets: %i ' % self.ns_t)

            if sc.calc_data_cov:
                logger.info('Estimating seismic data-covariances ...\n')
                cov_ds_seismic = cov.get_seismic_data_covariances(
                    data_traces=self.data_traces,
                    filterer=sc.filterer,
                    sample_rate=sc.gf_config.sample_rate,
                    arrival_taper=sc.arrival_taper,
                    engine=self.engine,
                    event=self.event,
                    targets=self.stargets)
            else:
                logger.info('No data-covariance estimation ...\n')
                cov_ds_seismic = []
                at = sc.arrival_taper
                n_samples = int(num.ceil(
                    (num.abs(at.a) + at.d) * sc.gf_config.sample_rate))

                for tr in self.data_traces:
                    cov_ds_seismic.append(
                        num.power(bconfig.default_seis_std, 2) * \
                        num.eye(n_samples))

            self.sweights = []
            for s_t in range(self.ns_t):
                if self.stargets[s_t].covariance.data is None:
                    logger.debug(
                        'No data covariance given. Seting default: sigma2 * I')
                    self.stargets[s_t].covariance.data = cov_ds_seismic[s_t]

                icov = self.stargets[s_t].covariance.inverse
                self.sweights.append(shared(icov))

            # syntetics generation
            logger.debug('Initialising synthetics functions ... \n')
            self.get_seis_synths = theanof.SeisSynthesizer(
                engine=self.engine,
                sources=dsources['seismic'],
                targets=self.stargets,
                event=self.event,
                arrival_taper=sc.arrival_taper,
                filterer=sc.filterer)

            self.chop_traces = theanof.SeisDataChopper(
                sample_rate=sc.gf_config.sample_rate,
                traces=self.data_traces,
                arrival_taper=sc.arrival_taper,
                filterer=sc.filterer)

        if self._geodetic_flag:
            logger.debug('Setting up geodetic structure ...\n')
            gc = config.geodetic_config

            geodetic_data_path = os.path.join(
                config.project_dir, bconfig.geodetic_data_name)
            self.gtargets = utility.load_objects(geodetic_data_path)

            self.ng_t = len(self.gtargets)
            logger.info('Number of geodetic datasets: %i ' % self.ng_t)

            # geodetic data
            _disp_list = [self.gtargets[i].displacement
                 for i in range(self.ng_t)]
            _lons_list = [self.gtargets[i].lons for i in range(self.ng_t)]
            _lats_list = [self.gtargets[i].lats for i in range(self.ng_t)]
            _odws_list = [self.gtargets[i].odw for i in range(self.ng_t)]
            _lv_list = [self.gtargets[i].update_los_vector()
                            for i in range(self.ng_t)]

            if gc.calc_data_cov:
                logger.info('Using data covariance!')
            else:
                logger.info('No data-covariance estimation ...\n')
                for g_t in self.gtargets:
                    g_t.covariance.data = num.power(
                        bconfig.default_geo_std, 2) * \
                        num.eye(g_t.lats.size)

            self.gweights = []
            for g_t in range(self.ng_t):
                icov = self.gtargets[g_t].covariance.inverse
                self.gweights.append(shared(icov))

            # merge geodetic data to call pscmp only once each forward model
            ordering = utility.ListArrayOrdering(_disp_list, intype='numpy')
            self.Bij = utility.ListToArrayBijection(ordering, _disp_list)

            odws = self.Bij.fmap(_odws_list)
            lons = self.Bij.fmap(_lons_list)
            lats = self.Bij.fmap(_lats_list)

            logger.info('Number of geodetic data points: %i ' % lats.shape[0])

            self.wdata = shared(self.Bij.fmap(_disp_list) * odws)
            self.lv = shared(self.Bij.f3map(_lv_list))
            self.odws = shared(odws)

            # syntetics generation
            logger.debug('Initialising synthetics functions ... \n')
            self.get_geo_synths = theanof.GeoLayerSynthesizerStatic(
                lats=lats,
                lons=lons,
                store_superdir=gc.gf_config.store_superdir,
                crust_ind=0,    # always reference model
                sources=dsources['geodetic'])

        self.config = config
Exemplo n.º 5
0
profile = ProfileStats()

km = 1000.

#homedir = '/Users/vasyurhm/Aqaba1995'
#datadir = homedir + '/data/'
#storehomedir = [homedir + '/GF/']
#geo_datadir = '/Users/vasyurhm/SAR_data/Aqaba/'

homedir = '/data3TB/Teleseism'
datadir = homedir + '/autokiwi/events/Aqaba1995/kiwi/data/'
storehomedir = [homedir + '/Greensfunctions/Aqaba1995GFS/']
geo_datadir = '/data/SAR_data/Aqaba1995/subsampled/'

event = model.load_one_event(datadir + 'event.txt')

# load geodetic data
tracks = [
    'A_T114do', 'A_T114up', 'A_T343co', 'A_T343up', 'D_T254co', 'D_T350co'
]
DiffIFGs = inputf.load_SAR_data(geo_datadir, tracks)
image = 2
utmx = []
utmy = []
for ifg in DiffIFGs:
    utmx.append(ifg.utme)
    utmy.append(ifg.utmn)

lons, lats = utility.utm_to_lonlat(num.hstack(utmx), num.hstack(utmy), 36)