コード例 #1
0
ファイル: BayWatch.py プロジェクト: kuanyuke/BayHunter
    def __init__(self,
                 configfile,
                 capacity=100,
                 address='127.0.0.1',
                 port=5556,
                 save_plots=None):
        # set up socket
        sock_addr = 'tcp://%s:%d' % (address, port)
        logger.info('Connecting to %s' % sock_addr)
        context = SerializingContext()
        self.socket = context.socket(zmq.SUB)
        self.socket.connect(sock_addr)
        self.socket.setsockopt_string(zmq.SUBSCRIBE, u'')
        if save_plots and not op.exists(op.dirname(save_plots)):
            raise OSError('%s does not exist' % op.dirname(save_plots))
        self.save_plots = save_plots

        data_pars = utils.read_config(configfile)
        defaults = utils.get_path('defaults.ini')
        self.priors, self.initparams = utils.load_params(defaults)
        self.priors.update(data_pars['priors'])
        self.initparams.update(data_pars['initparams'])
        self.nchains = self.initparams['nchains']
        self.refmodel = data_pars.get('refmodel', dict())

        self.capacity = capacity
        self.modellength = int(self.priors['layers'][1] + 1) * 2
        self.vs_step = np.ones((capacity, self.modellength)) * np.nan
        self.dep_step = np.ones((capacity, self.modellength)) * np.nan
        self.likes = np.ones((capacity)) * np.nan
        self.vpvss = np.ones((capacity)) * np.nan
        self.modelmatrix = np.ones((capacity, self.modellength)) * np.nan
        self.mantle = self.priors['mantle']

        # colors only for inversion targets - modeled data
        # self.colors = ['purple', 'green', 'orange' 'red', 'brown', 'blue']
        self.colors = [
            'teal', 'lightcoral', 'saddlebrown', 'magenta', 'royalblue'
        ]

        self.targets = data_pars['targets']
        self.targetrefs = [target.ref for target in self.targets]
        self.ntargets = len(self.targets)

        self.noises = np.ones((self.capacity, self.ntargets * 2)) * np.nan
        self.init_style_dicts()
        self.init_plot()
        self.init_arrays()
        self.breakloop = np.zeros(self.nchains)
コード例 #2
0
    def __init__(self,
                 targets,
                 chainidx=0,
                 initparams={},
                 modelpriors={},
                 sharedmodels=None,
                 sharedmisfits=None,
                 sharedlikes=None,
                 sharednoise=None,
                 sharedvpvs=None,
                 random_seed=None):
        self.chainidx = chainidx
        self.rstate = np.random.RandomState(random_seed)

        defaults = utils.get_path('defaults.ini')
        self.priors, self.initparams = utils.load_params(defaults)
        self.initparams.update(initparams)
        self.priors.update(modelpriors)
        self.dv = (self.priors['vs'][1] - self.priors['vs'][0])

        self.nchains = self.initparams['nchains']
        self.station = self.initparams['station']

        # set targets and inversion specific parameters
        self.targets = targets

        # set parameters
        self.iter_phase1 = int(self.initparams['iter_burnin'])
        self.iter_phase2 = int(self.initparams['iter_main'])
        self.iterations = self.iter_phase1 + self.iter_phase2
        self.iiter = -self.iter_phase1
        self.lastmoditer = self.iiter

        self.propdist = np.array(self.initparams['propdist'])
        self.acceptance = self.initparams['acceptance']
        self.thickmin = self.initparams['thickmin']
        self.maxlayers = int(self.priors['layers'][1]) + 1

        self.lowvelperc = self.initparams['lvz']
        self.highvelperc = self.initparams['hvz']
        self.mantle = self.priors['mantle']

        # chain models
        self._init_chainarrays(sharedmodels, sharedmisfits, sharedlikes,
                               sharednoise, sharedvpvs)

        # init model and values
        self._init_model_and_currentvalues()
コード例 #3
0
    def __init__(self,
                 targets,
                 initparams=dict(),
                 priors=dict(),
                 random_seed=None):
        self.sock_addr = 'tcp://*:5556'
        self.rstate = np.random.RandomState(random_seed)

        defaults = utils.get_path('defaults.ini')
        self.priors, self.initparams = utils.load_params(defaults)
        self.priors.update(priors)
        self.initparams.update(initparams)

        self.station = self.initparams.get('station')

        savepath = op.join(self.initparams['savepath'], 'data')
        if not op.exists(savepath):
            os.makedirs(savepath)

        # save file for offline-plotting
        outfile = op.join(savepath, '%s_config.pkl' % self.station)
        utils.save_config(targets,
                          outfile,
                          priors=self.priors,
                          initparams=self.initparams)

        self.nchains = self.initparams.get('nchains')
        self.ntargets = len(targets.targets)

        self.iter_phase1 = int(self.initparams['iter_burnin'])
        self.iter_phase2 = int(self.initparams['iter_main'])
        self.iterations = self.iter_phase1 + self.iter_phase2

        self.maxlayers = int(self.priors['layers'][1]) + 1
        self.vpvs = self.priors['vpvs']

        # shared data and chains
        self._init_shareddata()

        logger.info('> %d chain(s) are initiated ...' % self.nchains)

        self.chains = []
        for i in np.arange(self.nchains):
            self.chains += [self._init_chain(chainidx=i, targets=targets)]

        self.manager = mp.Manager()
コード例 #4
0
    def __init__(self,
                 configfile,
                 capacity=100,
                 address='127.0.0.1',
                 port=5556):
        # set up socket
        sock_addr = 'tcp://%s:%d' % (address, port)
        logger.info('Connecting to %s' % sock_addr)
        context = SerializingContext()
        self.socket = context.socket(zmq.SUB)
        self.socket.connect(sock_addr)
        self.socket.setsockopt_string(zmq.SUBSCRIBE, u'')

        data_pars = utils.read_config(configfile)
        defaults = utils.get_path('defaults.ini')
        self.priors, self.initparams = utils.load_params(defaults)
        self.priors.update(data_pars['priors'])
        self.initparams.update(data_pars['initparams'])
        self.nchains = self.initparams['nchains']
        self.refmodel = data_pars.get('refmodel', dict())

        self.capacity = capacity
        self.modellength = int(self.priors['layers'][1] + 1) * 2
        self.vs_step = np.ones((capacity, self.modellength)) * np.nan
        self.dep_step = np.ones((capacity, self.modellength)) * np.nan
        self.likes = np.ones((capacity)) * np.nan
        self.modelmatrix = np.ones((capacity, self.modellength)) * np.nan

        # parameters for synthetic computation
        self.vpvs = self.priors['vpvs']

        # colors only for inversion targets - modeled data
        self.colors = ['purple', 'green', 'orange' 'red', 'brown', 'blue']

        self.targets = data_pars['targets']
        self.targetrefs = [target.ref for target in self.targets]
        self.ntargets = len(self.targets)

        self.noises = np.ones((self.capacity, self.ntargets * 2)) * np.nan
        self.init_style_dicts()
        self.init_plot()
        self.init_arrays()
        self.breakloop = np.zeros(self.nchains)
コード例 #5
0
from BayHunter import SynthObs
import logging

#
# console printout formatting
#
formatter = ' %(processName)-12s: %(levelname)-8s |  %(message)s'
logging.basicConfig(format=formatter, level=logging.INFO)
logger = logging.getLogger()

#
# ------------------------------------------------------------  obs SYNTH DATA
#
# Load priors and initparams from config.ini or simply create dictionaries.
initfile = 'config.ini'
priors, initparams = utils.load_params(initfile)

# Load observed data (synthetic test data)
xsw, _ysw = np.loadtxt('observed/st3_rdispph.dat', usecols=[0, 1]).T
xrf, _yrf = np.loadtxt('observed/st3_prf.dat', usecols=[0, 1]).T

# add noise to create observed data
# order of noise values (correlation, amplitude):
# noise = [corr1, sigma1, corr2, sigma2] for 2 targets
noise = [0.0, 0.012, 0.90, 0.005]
ysw_err = SynthObs.compute_expnoise(_ysw, corr=noise[0], sigma=noise[1])
ysw = _ysw + ysw_err
yrf_err = SynthObs.compute_gaussnoise(_yrf, corr=noise[2], sigma=noise[3])
yrf = _yrf + yrf_err

#