Beispiel #1
0
def build_rotation_curve_3cube(l_inds, b_inds, d_inds, meshed=False, 
                               with_elliptical=False, d_samp=3):
    wcs = wcs_defs.get_ppdv_wcs()

    if meshed:
        l_g = l_inds
        b_g = b_inds
        d_g = d_inds
    else:
        l_g, b_g, d_g = np.meshgrid(l_inds, b_inds, d_inds, indexing='ij')

    l_vals, b_vals, mu_vals, _ = wcs.wcs_pix2world(l_g, b_g, d_g, 0,
                                                   wcs_defs.origin)

    mu_edges = edges_from_centers(np.unique(mu_vals))
    rotation_curve_3cube = np.zeros(l_g.shape)
    #d_vals = distmod_to_distance(mu_vals)
    N_d = rotation_curve_3cube.shape[-1]

    l_samps = np.zeros([l_vals.shape[0], l_vals.shape[1], d_samp])
    l_samps[:, :, :] = l_vals[:, :, 0, None]
    b_samps = np.zeros([b_vals.shape[0], b_vals.shape[1], d_samp])
    b_samps[:, :, :] = b_vals[:, :, 0, None]

    for d_i in range(N_d):
        d_samps = np.linspace(mu_edges[d_i], mu_edges[d_i+1], d_samp)
        d_samps = distmod_to_distance(d_samps)
        v_r_samps = rotation_curve(l_samps,
                                   b_samps,
                                   d_samps,
                                   with_elliptical= with_elliptical)
        rotation_curve_3cube[:, :, d_i] = np.average(v_r_samps, axis=-1)
    return rotation_curve_3cube
Beispiel #2
0
def build_velocity_moment_3cube(full_4cube, v_inds):
    ppdv_wcs = wcs_defs.get_ppdv_wcs()
    _, _, _, v_vals = ppdv_wcs.wcs_pix2world(0, 0, 0, 
                                             v_inds, wcs_defs.origin)
    moment_3cube = np.zeros(full_4cube.shape[0:3])
    moment_3cube = (full_4cube * v_vals).sum(axis=3)
    collapsed_4cube = full_4cube.sum(axis=3)
    moment_3cube /= collapsed_4cube
    moment_3cube = np.ma.masked_where(collapsed_4cube==0, moment_3cube)
    return moment_3cube
Beispiel #3
0
def build_clemens_rotation_curve_3cube(l_inds, b_inds, d_inds):
    wcs = wcs_defs.get_ppdv_wcs()

    l_g, b_g, d_g = np.meshgrid(l_inds, b_inds, d_inds, indexing='ij')

    l_vals, b_vals, mu_vals, _ = wcs.wcs_pix2world(l_g, b_g, d_g, 0,
                                                   wcs_defs.origin)
    d_vals = distmod_to_distance(mu_vals)
    clemens_rotation_curve_3cube = clemens_rotation_curve(l_vals, b_vals, d_vals)
    return clemens_rotation_curve_3cube
Beispiel #4
0
def extract_profile(cube, l_value, b_value, 
                  l_inds, b_inds):
    ppdv_wcs = wcs_defs.get_ppdv_wcs()
    l_ind, b_ind, d_ind, _ = ppdv_wcs.wcs_world2pix(l_value, 
                                                    b_value, 
                                                    0,
                                                    0, 
                                                    wcs_defs.origin)
    l_ind = np.round(l_ind).astype('int')
    b_ind = np.round(b_ind).astype('int')
    if (l_ind in l_inds) & (b_ind in b_inds):
        l_ind -= l_inds.min()
        b_ind -= b_inds.min()
        value = cube[l_ind, b_ind, :]
    else:
        value = np.nan
    return value
Beispiel #5
0
def extract_spline_value(cube, l_value, b_value, d_value,
                  l_inds, b_inds, d_vals):
    ppdv_wcs = wcs_defs.get_ppdv_wcs()
    l_ind, b_ind, d_ind, _ = ppdv_wcs.wcs_world2pix(l_value, 
                                                    b_value, 
                                                    0,
                                                    0, 
                                                    wcs_defs.origin)
    l_ind = np.round(l_ind).astype('int')
    b_ind = np.round(b_ind).astype('int')
    if (l_ind in l_inds) & (b_ind in b_inds):
        l_ind -= l_inds.min()
        b_ind -= b_inds.min()
        value = interpolate.spline(d_vals, cube[l_ind, b_ind, :], d_value,
                                   order=1)
    else:
        value = np.nan
    return value
Beispiel #6
0
def extract_value(cube, l_value, b_value, d_value, 
                  l_inds, b_inds, d_inds):
    ppdv_wcs = wcs_defs.get_ppdv_wcs()
    mu_value = distance_to_distmod(d_value)
    l_ind, b_ind, d_ind, _ = ppdv_wcs.wcs_world2pix(l_value, 
                                                    b_value, 
                                                    mu_value, 
                                                    0, 
                                                    wcs_defs.origin)
    l_ind = np.round(l_ind).astype('int')
    b_ind = np.round(b_ind).astype('int')
    d_ind = np.round(d_ind).astype('int')
    if (l_ind in l_inds) & (b_ind in b_inds) & (d_ind in d_inds):
        l_ind -= l_inds.min()
        b_ind -= b_inds.min()
        d_ind -= d_inds.min()
        value = cube[l_ind, b_ind, d_ind]
    else:
        value = np.nan
    return value
Beispiel #7
0
def build_velocity_moment_3cube_from_components(U, spatial_shape, 
                                                V, veldist_shape,
                                                v_inds):
    N_x, N_y = spatial_shape
    N_d, N_v = veldist_shape
    N_k = V.shape[1]
    ppdv_wcs = wcs_defs.get_ppdv_wcs()
    _, _, _, v_vals = ppdv_wcs.wcs_pix2world(0, 0, 0, 
                                             v_inds, wcs_defs.origin)
    v_vals = np.asarray(v_vals).ravel()

    V_ur = V.reshape([N_d, N_v, N_k])
    comp_moments = np.sum(V_ur * v_vals[None, :, None], axis=1)
    moment_3cube = np.dot(U, comp_moments.T)
    moment_3cube /= np.dot(U, V_ur.sum(axis=1).T)
    moment_3cube = np.nan_to_num(moment_3cube)

    moment_3cube = moment_3cube.reshape([N_x, N_y, N_d])
    moment_3cube = moment_3cube.swapaxes(0,1)
    return moment_3cube
Beispiel #8
0
        N_k = 10
        stuff = load_band(step_kind, N_k, v_pad=20)
        ppd, lsr_moment_cube, flat_rotation_cube, clemens_rotation_cube, position_grids = stuff
        l_g, d_g, b_vals, v_vals = position_grids

        b_min = -20
        b_max = 20

    l_inds, b_inds, d_inds, v_inds = get_field_inds('band')
    b_inds = b_inds#[65:95]
    #b_inds = b_inds[70:91] #(narrow)
    #b_inds = b_inds[50:111] #(medium)
    #l_inds = l_inds[1050:1350]
    l_inds = l_inds[:-1]
    d_inds = d_inds[:]
    ppdv_wcs = wcs_defs.get_ppdv_wcs()
    l_g, b_g, d_g = np.meshgrid(l_inds, b_inds, d_inds, indexing='ij')
    l_g, b_g, d_g, _ = ppdv_wcs.wcs_pix2world(l_g, b_g, d_g, 0, 
                                            wcs_defs.origin)
    d_g = distmod_to_distance(d_g)
    _, b_vals, _, _ = ppdv_wcs.wcs_pix2world(0, b_inds, 0, 0, 
                                             wcs_defs.origin)

    b_min = -1.5
    b_max = 1.5

    if False:
        fname = solution_location + 'moment_cube_vrot_220_dmax_15_vpad_30_narrow.fits'
    else:
        fname = solution_location + 'gd_band_smooth2_moment.fits'
    with fits.open(fname) as hdu: