예제 #1
0
def get_info_kernel(nrad):
    hpbw = 0.5  # arcsec
    pix_size = 0.11  # arcsec
    beam_sigma_pix = hpbw / FWHM / pix_size
    k_arr = nf.get_indep_info_kernel(beam_sigma_pix, nrad=nrad)
    k_arr = nf.apply_circular_mask(k_arr, radius=nrad // 2)
    post_kernel = convolution.CustomKernel(k_arr)
    return post_kernel
예제 #2
0
def test_smooth_custom_kernel(simulated_spectra):
    """
    Test CustomKernel smoothing with correct parmaeters.
    """

    # Create the original spectrum
    spec1 = simulated_spectra.s1_um_mJy_e1
    flux_original = spec1.flux

    # Create a custom kernel (some weird asymmetric-ness)
    numpy_kernel = np.array([0.5, 1, 2, 0.5, 0.2])
    numpy_kernel = numpy_kernel / np.sum(numpy_kernel)

    custom_kernel = convolution.CustomKernel(numpy_kernel)
    flux_smoothed_astropy = convolution.convolve(flux_original, custom_kernel)

    # Calculate the custom smoothed
    spec1_smoothed = convolution_smooth(spec1, custom_kernel)
    compare_flux(spec1_smoothed.flux.value, flux_smoothed_astropy, flux_original.value)
예제 #3
0
def test_smooth_custom_kernel_uncertainty(simulated_spectra):
    """
    Test CustomKernel smoothing with correct parmaeters.
    """

    np.random.seed(42)

    # Create a custom kernel (some weird asymmetric-ness)
    numpy_kernel = np.array([0.5, 1, 2, 0.5, 0.2])
    numpy_kernel = numpy_kernel / np.sum(numpy_kernel)
    custom_kernel = convolution.CustomKernel(numpy_kernel)

    spec1 = simulated_spectra.s1_um_mJy_e1
    uncertainty = np.abs(np.random.random(spec1.flux.shape))

    # Test StdDevUncertainty
    spec1.uncertainty = StdDevUncertainty(uncertainty)

    spec1_smoothed = convolution_smooth(spec1, custom_kernel)
    tt = convolution.convolve(1 / (spec1.uncertainty.array**2), custom_kernel)
    uncertainty_smoothed_astropy = 1 / np.sqrt(tt)

    assert np.allclose(spec1_smoothed.uncertainty.array,
                       uncertainty_smoothed_astropy)

    # Test VarianceUncertainty
    spec1.uncertainty = VarianceUncertainty(uncertainty)

    spec1_smoothed = convolution_smooth(spec1, custom_kernel)
    uncertainty_smoothed_astropy = 1 / convolution.convolve(
        1 / spec1.uncertainty.array, custom_kernel)
    assert np.allclose(spec1_smoothed.uncertainty.array,
                       uncertainty_smoothed_astropy)

    # Test InverseVariance
    spec1.uncertainty = InverseVariance(uncertainty)

    spec1_smoothed = convolution_smooth(spec1, custom_kernel)
    uncertainty_smoothed_astropy = convolution.convolve(
        spec1.uncertainty.array, custom_kernel)
    assert np.allclose(spec1_smoothed.uncertainty.array,
                       uncertainty_smoothed_astropy)
def postprocess_run(target, store_prefix):
    evid_kernel = convolution.Gaussian2DKernel(1.5)  # std-dev in pixels
    s2 = np.sqrt(2) / 2
    k_arr = np.array([
        [s2**2, s2**1, s2**2],
        [s2**1, s2**0, s2**1],
        [s2**2, s2**1, s2**2],
    ])
    post_kernel = convolution.CustomKernel(k_arr)
    utrans = get_irdc_priors(vsys=VELOS[target])
    par_bins = get_bins(VELOS[target])
    store_name = f'data/run/{store_prefix}_{target}'
    store = nf.HdfStore(store_name)
    stack = get_cubestack(target)
    runner = get_runner(stack, utrans, ncomp=1)
    # begin post-processing steps
    nf.aggregate_run_attributes(store)
    nf.convolve_evidence(store, evid_kernel)
    nf.aggregate_run_products(store)
    nf.aggregate_run_pdfs(store, par_bins=par_bins)
    nf.convolve_post_pdfs(store, post_kernel, evid_weight=False)
    nf.quantize_conv_marginals(store)
    nf.deblend_hf_intensity(store, stack, runner)
    store.close()