Beispiel #1
0
    def _get_synthetic_data(self):
        lon = num.linspace(10.5, 13.5, 100)
        lat = num.linspace(44.0, 46.0, 100)

        Lon, Lat = num.meshgrid(lon, lat)
        reference = ReferenceLocation(lon=5., lat=45.)

        self.lons = Lon.flatten()
        self.lats = Lat.flatten()
        self.reference = reference
Beispiel #2
0
class SeismicGFConfig(NonlinearGFConfig):
    """
    Seismic GF parameters for Layered Halfspace.
    """
    reference_location = ReferenceLocation.T(
        default=None,
        help="Reference location for the midpoint of the Green's Function "
        "grid.",
        optional=True)
    code = String.T(default='qssp',
                    help='Modeling code to use. (qssp, qseis, comming soon: '
                    'qseis2d)')
    sample_rate = Float.T(default=2.,
                          help='Sample rate for the Greens Functions.')
    rm_gfs = Bool.T(default=True,
                    help='Flag for removing modeling module GF files after'
                    ' completion.')
Beispiel #3
0
class SeismicLinearGFConfig(LinearGFConfig):
    """
    Config for seismic linear GreensFunction calculation parameters.
    """
    reference_location = ReferenceLocation.T(
        default=None,
        help="Reference location for the midpoint of the Green's Function "
        "grid.",
        optional=True)
    duration_sampling = Float.T(
        default=1.,
        help="Calculate Green's Functions for varying Source Time Function"
        " durations determined by prior bounds. Discretization between"
        " is determined by duration sampling.")
    starttime_sampling = Float.T(
        default=1.,
        help="Calculate Green's Functions for varying rupture onset times."
        "These are determined by the (rupture) velocity prior bounds "
        "and the hypocenter location.")
Beispiel #4
0
def init_config(name,
                date=None,
                min_magnitude=6.0,
                main_path='./',
                datatypes=['geodetic'],
                mode='geometry',
                source_type='RectangularSource',
                n_sources=1,
                waveforms=['any_P'],
                sampler='SMC',
                hyper_sampler='Metropolis',
                use_custom=False,
                individual_gfs=False):
    """
    Initialise BEATconfig File and write it main_path/name .
    Fine parameters have to be edited in the config file .yaml manually.

    Parameters
    ----------
    name : str
        Name of the event
    date : str
        'YYYY-MM-DD', date of the event
    min_magnitude : scalar, float
        approximate minimum Mw of the event
    datatypes : List of strings
        data sets to include in the optimization: either 'geodetic' and/or
        'seismic'
    mode : str
        type of optimization problem: 'Geometry' / 'Static'/ 'Kinematic'
    n_sources : int
        number of sources to solve for / discretize depending on mode parameter
    waveforms : list
        of strings of waveforms to include into the misfit function and
        GF calculation
    sampler : str
        Optimization algorithm to use to sample the solution space
        Options: 'SMC', 'Metropolis'
    use_custom : boolean
        Flag to setup manually a custom velocity model.
    individual_gfs : boolean
        Flag to use individual Green's Functions for each specific station.
        If false a reference location will be initialised in the config file.
        If true the reference locations will be taken from the imported station
        objects.

    Returns
    -------
    :class:`BEATconfig`
    """

    c = BEATconfig(name=name, date=date)
    c.project_dir = os.path.join(os.path.abspath(main_path), name)

    if mode == 'geometry' or mode == 'interseismic':
        if date is not None and not mode == 'interseismic':
            c.event = utility.search_catalog(date=date,
                                             min_magnitude=min_magnitude)

        elif mode == 'interseismic':
            c.event = model.Event(lat=10., lon=10., depth=0.)
            c.date = 'dummy'
            logger.info('Interseismic mode! Using event as reference for the'
                        ' stable block! Please update coordinates!')
        else:
            logger.warn('No given date! Using dummy event!'
                        ' Updating reference coordinates (spatial & temporal)'
                        ' necessary!')
            c.event = model.Event(duration=1.)
            c.date = 'dummy'

        if 'geodetic' in datatypes:
            c.geodetic_config = GeodeticConfig()
            if use_custom:
                logger.info('use_custom flag set! The velocity model in the'
                            ' geodetic GF configuration has to be updated!')
                c.geodetic_config.gf_config.custom_velocity_model = \
                    load_model().extract(depth_max=100. * km)
                c.geodetic_config.gf_config.use_crust2 = False
                c.geodetic_config.gf_config.replace_water = False
        else:
            c.geodetic_config = None

        if 'seismic' in datatypes:
            c.seismic_config = SeismicConfig()
            c.seismic_config.init_waveforms(waveforms)

            if not individual_gfs:
                c.seismic_config.gf_config.reference_location = \
                    ReferenceLocation(lat=10.0, lon=10.0)
            else:
                c.seismic_config.gf_config.reference_location = None

            if use_custom:
                logger.info('use_custom flag set! The velocity model in the'
                            ' seismic GF configuration has to be updated!')
                c.seismic_config.gf_config.custom_velocity_model = \
                    load_model().extract(depth_max=100. * km)
                c.seismic_config.gf_config.use_crust2 = False
                c.seismic_config.gf_config.replace_water = False
        else:
            c.seismic_config = None

    elif mode == 'ffi':

        if source_type != 'RectangularSource':
            raise TypeError('Static distributed slip is so far only supported'
                            ' for RectangularSource(s)')

        gmc = load_config(c.project_dir, 'geometry')

        if gmc is not None:
            logger.info('Taking information from geometry_config ...')
            if source_type != gmc.problem_config.source_type:
                raise ValueError(
                    'Specified reference source: "%s" differs from the'
                    ' source that has been used previously in'
                    ' "geometry" mode: "%s"!' %
                    (source_type, gmc.problem_config.source_type))

            n_sources = gmc.problem_config.n_sources
            point = {
                k: v.testvalue
                for k, v in gmc.problem_config.priors.iteritems()
            }
            point = utility.adjust_point_units(point)
            source_points = utility.split_point(point)

            reference_sources = init_reference_sources(
                source_points, n_sources, gmc.problem_config.source_type,
                gmc.problem_config.stf_type)

            c.date = gmc.date
            c.event = gmc.event

            if 'geodetic' in datatypes:
                gc = gmc.geodetic_config
                if gc is None:
                    logger.warning(
                        'Asked for "geodetic" datatype but geometry config '
                        'has no such datatype! Initialising default "geodetic"'
                        ' linear config!')
                    gc = GeodeticConfig()
                    lgf_config = GeodeticLinearGFConfig()
                else:
                    lgf_config = GeodeticLinearGFConfig(
                        earth_model_name=gc.gf_config.earth_model_name,
                        store_superdir=gc.gf_config.store_superdir,
                        n_variations=gc.gf_config.n_variations,
                        reference_sources=reference_sources,
                        sample_rate=gc.gf_config.sample_rate)

                c.geodetic_config = gc
                c.geodetic_config.gf_config = lgf_config

            elif 'seismic' in datatypes:
                sc = gmc.seismic_config
                if sc is None:
                    logger.warning(
                        'Asked for "seismic" datatype but geometry config '
                        'has no such datatype! Initialising default "seismic"'
                        ' linear config!')
                    sc = SeismicConfig()
                    lgf_config = SeismicLinearGFConfig()
                else:
                    lgf_config = SeismicLinearGFConfig(
                        earth_model_name=sc.gf_config.earth_model_name,
                        sample_rate=sc.gf_config.sample_rate,
                        reference_location=sc.gf_config.reference_location,
                        store_superdir=sc.gf_config.store_superdir,
                        n_variations=sc.gf_config.n_variations,
                        reference_sources=reference_sources)
                c.seismic_config = sc
                c.seismic_config.gf_config = lgf_config
        else:
            logger.warning('Found no geometry setup, ...')
            raise ImportError(
                'No geometry configuration file existing! Please initialise'
                ' a "geometry" configuration ("beat init command"), update'
                ' the Greens Function information and create GreensFunction'
                ' stores for the non-linear problem.')

    c.problem_config = ProblemConfig(n_sources=n_sources,
                                     datatypes=datatypes,
                                     mode=mode,
                                     source_type=source_type)
    c.problem_config.init_vars()
    c.problem_config.set_decimation_factor()

    c.sampler_config = SamplerConfig(name=sampler)
    c.sampler_config.set_parameters(update_covariances=False)

    c.hyper_sampler_config = SamplerConfig(name=hyper_sampler)
    c.hyper_sampler_config.set_parameters(update_covariances=None)

    c.update_hypers()
    c.problem_config.validate_priors()

    c.regularize()
    c.validate()

    logger.info('Project_directory: %s \n' % c.project_dir)
    util.ensuredir(c.project_dir)

    dump_config(c)
    return c
Beispiel #5
0
def init_config(name,
                date=None,
                min_magnitude=6.0,
                main_path='./',
                datatypes=['geodetic'],
                mode='geometry',
                source_type='RectangularSource',
                n_sources=1,
                waveforms=['any_P'],
                sampler='SMC',
                hyper_sampler='Metropolis',
                use_custom=False,
                individual_gfs=False):
    """
    Initialise BEATconfig File and write it main_path/name .
    Fine parameters have to be edited in the config file .yaml manually.

    Parameters
    ----------
    name : str
        Name of the event
    date : str
        'YYYY-MM-DD', date of the event
    min_magnitude : scalar, float
        approximate minimum Mw of the event
    datatypes : List of strings
        data sets to include in the optimization: either 'geodetic' and/or
        'seismic'
    mode : str
        type of optimization problem: 'Geometry' / 'Static'/ 'Kinematic'
    n_sources : int
        number of sources to solve for / discretize depending on mode parameter
    waveforms : list
        of strings of waveforms to include into the misfit function and
        GF calculation
    sampler : str
        Optimization algorithm to use to sample the solution space
        Options: 'SMC', 'Metropolis'
    use_custom : boolean
        Flag to setup manually a custom velocity model.
    individual_gfs : boolean
        Flag to use individual Green's Functions for each specific station.
        If false a reference location will be initialised in the config file.
        If true the reference locations will be taken from the imported station
        objects.

    Returns
    -------
    :class:`BEATconfig`
    """

    c = BEATconfig(name=name, date=date)
    c.project_dir = os.path.join(os.path.abspath(main_path), name)

    if mode == 'geometry' or mode == 'interseismic':
        if date is not None and not mode == 'interseismic':
            c.event = utility.search_catalog(date=date,
                                             min_magnitude=min_magnitude)

        elif mode == 'interseismic':
            c.event = model.Event(lat=10., lon=10., depth=0.)
            c.date = 'dummy'
            logger.info('Interseismic mode! Using event as reference for the'
                        ' stable block! Please update coordinates!')
        else:
            logger.warn('No given date! Using dummy event!'
                        ' Updating reference coordinates (spatial & temporal)'
                        ' necessary!')
            c.event = model.Event(duration=1.)
            c.date = 'dummy'

        if 'geodetic' in datatypes:
            c.geodetic_config = GeodeticConfig()
            if use_custom:
                logger.info('use_custom flag set! The velocity model in the'
                            ' geodetic GF configuration has to be updated!')
                c.geodetic_config.gf_config.custom_velocity_model = \
                    load_model().extract(depth_max=100. * km)
                c.geodetic_config.gf_config.use_crust2 = False
                c.geodetic_config.gf_config.replace_water = False
        else:
            c.geodetic_config = None

        if 'seismic' in datatypes:
            c.seismic_config = SeismicConfig()
            c.seismic_config.init_waveforms(waveforms)

            if not individual_gfs:
                c.seismic_config.gf_config.reference_location = \
                    ReferenceLocation(lat=10.0, lon=10.0)
            else:
                c.seismic_config.gf_config.reference_location = None

            if use_custom:
                logger.info('use_custom flag set! The velocity model in the'
                            ' seismic GF configuration has to be updated!')
                c.seismic_config.gf_config.custom_velocity_model = \
                    load_model().extract(depth_max=100. * km)
                c.seismic_config.gf_config.use_crust2 = False
                c.seismic_config.gf_config.replace_water = False
        else:
            c.seismic_config = None

    elif mode == 'static':

        if source_type != 'RectangularSource':
            raise TypeError('Static distributed slip is so far only supported'
                            ' for RectangularSource(s)')

        gc = load_config(c.project_dir, 'geometry')

        if gc is not None:
            logger.info('Taking information from geometry_config ...')
            n_sources = gc.problem_config.n_sources
            point = {
                k: v.testvalue
                for k, v in gc.problem_config.priors.iteritems()
            }
            source_points = utility.split_point(point)
            reference_sources = [
                RectangularSource(**source_points[i]) for i in range(n_sources)
            ]

            c.date = gc.date
            c.event = gc.event
            c.geodetic_config = gc.geodetic_config
            c.geodetic_config.gf_config = LinearGFConfig(
                store_superdir=gc.geodetic_config.gf_config.store_superdir,
                n_variations=gc.geodetic_config.gf_config.n_variations,
                reference_sources=reference_sources)
        else:
            logger.info('Found no geometry setup, init blank ...')
            c.geodetic_config = GeodeticConfig(gf_config=LinearGFConfig())
            c.date = 'dummy'
        logger.info(
            'Problem config has to be updated. After deciding on the patch'
            ' dimensions and extension factors please run: import')

    c.problem_config = ProblemConfig(n_sources=n_sources,
                                     datatypes=datatypes,
                                     mode=mode,
                                     source_type=source_type)
    c.problem_config.init_vars()
    c.problem_config.set_decimation_factor()

    c.sampler_config = SamplerConfig(name=sampler)
    c.sampler_config.set_parameters(update_covariances=False)

    c.hyper_sampler_config = SamplerConfig(name=hyper_sampler)
    c.hyper_sampler_config.set_parameters(update_covariances=None)

    c.update_hypers()
    c.problem_config.validate_priors()

    c.regularize()
    c.validate()

    logger.info('Project_directory: %s \n' % c.project_dir)
    util.ensuredir(c.project_dir)

    dump_config(c)
    return c