示例#1
0
def locate_mcmc(x, y, spec_index, snr_centre_on_axis, nchan, band=(400., 800.), nsample=100000, burn=10000, add_error=False, x_lims=(-beam_sep, beam_sep), y_lims=(-beam_sep, beam_sep), spec_index_lims=(-10., 10.)):
    if _np.abs(x) > 0.5*beam_sep or _np.abs(y) > 0.5*beam_sep:
        print "WARNING: You are considering an event location outside the centre beam,"              " which will give results that might not make sense."
    
    chans = get_chan_centres(nchan, band)
    
    mcmc_inputs = {}
    mcmc_inputs['x'] = _pymc.Uniform('x', x_lims[0], x_lims[1], value=0.)
    mcmc_inputs['y'] = _pymc.Uniform('y', y_lims[0], y_lims[1], value=0.)
    mcmc_inputs['spec_index'] = _pymc.Uniform('spec_index', spec_index_lims[0], spec_index_lims[1], value=0.)

    @_pymc.deterministic(plot=False)
    def _pymc_observed_relative_signals(x=mcmc_inputs['x'], y=mcmc_inputs['y'], spec_index=mcmc_inputs['spec_index'], chans=chans):
        return observed_relative_signals(x, y, spec_index, chans)
    
    # this is my "observed signal"
    sig = observed_relative_signals(x, y, spec_index, chans)
    
    off_axis_snr_scale = (_np.squeeze(beam_signal(x, y, chans))) * snr_centre_on_axis / _np.sqrt(nchan)
    err = 1./ (off_axis_snr_scale.sum(0) / _np.sqrt(nchan))
    
    if add_error:
        error = _np.random.normal(scale=err, size=sig.shape)
        sig += error
        
    mcmc_inputs['signals'] = _pymc.Normal('signals', mu=_pymc_observed_relative_signals, tau=1./err**2, value=sig, observed=True)
    
    R = _pymc.MCMC(input=mcmc_inputs)
    R.use_step_method(_pymc.AdaptiveMetropolis, [R.x, R.y, R.spec_index])
    R.sample(nsample, burn=burn)
    
    return R
示例#2
0
def all_beam_signals(x, y, freq=400.):
    return _np.squeeze(beam_signal(_np.array(x)[..., _np.newaxis]-offsets[:,0][_np.newaxis, ...],
                                  _np.array(y)[..., _np.newaxis]-offsets[:,1][_np.newaxis, ...],
                                  _np.squeeze(_np.array([freq]))))