vels = np.arange(start_vel.value, end_vel.value + del_vel.value,
                 del_vel.value) * u.km / u.s

# Get the radius array so we can cut to where the CO data is valid
radii = gal.radius(header=hi_cube[0].header)
max_radius = 6.0 * u.kpc

all_dists = []
all_radii = []
all_vals_hi = []
all_vals_co = []
edge_masks = []
skeletons = []

hi_beam = average_beams(hi_cube.beams)

# Estimate the noise level in an equivalent slab
hi_mom0 = hi_cube.spectral_slab(-180 * u.km / u.s, -183 * u.km / u.s).moment0()
sigma = sig_clip(hi_mom0.value, nsig=10) * \
    hi_beam.jtok(hi_freq).value

for i, (end, start) in enumerate(ProgressBar(zip(vels[1:], vels[:-1]))):

    hi_slab = hi_cube.spectral_slab(start, end)
    hi_mom0 = hi_slab.moment0() * hi_beam.jtok(hi_freq) / u.Jy

    # Make the CO slab, then reproject onto the HI grid
    co_mom0 = co_cube.spectral_slab(start, end).moment0()
    co_mom0_reproj = reproject_interp(co_mom0.hdu, hi_mom0.header)[0]
    co_mom0 = Projection(co_mom0_reproj, wcs=hi_mom0.wcs)
'''

cube_file = fourteenB_HI_data_path(rotsub_cube_name)

cube = SpectralCube.read(cube_file)

# Begin channel map code here

# integrate over velocities to make channel maps of a set width
vstart = 308  # channels
vend = 788
vstep = 10
all_slabs = np.arange(vstart, vend + vstep, vstep, dtype=int)

# Define the average beam
beam = average_beams(cube.beams)

layers = \
    [cube[start:end].moment0().value *
     beam.jtok(hi_freq) / 1000. * u.km / u.s
     for start, end in zip(all_slabs[:-1], all_slabs[1:])]

# Scale all to the maximum
mx = np.max([np.nanmax(x).value for x in layers])

spec_axis = cube.spectral_axis.to(u.km / u.s).value

center_vels = [(spec_axis[start] + spec_axis[end]) / 2. for start, end in
               zip(all_slabs[:-1], all_slabs[1:])]

pb = ProgressBar(len(center_vels))
# p.plot(rs_n.value, sd_n.value, "bD-", label="North")
# p.plot(rs_s.value, sd_s.value, "go-", label="South")
p.ylabel(r"log $\Sigma$ (M$_{\odot}$ pc$^{-2}$)")
p.xlabel(r"R (kpc)")
p.legend(loc='best')
p.grid("on")

p.savefig(paper1_figures_path("M33_Sigma_profile_co21_N_S_dr_{}pc.pdf".format(dr.value)))
p.savefig(paper1_figures_path("M33_Sigma_profile_co21_N_S_dr_{}pc.png".format(dr.value)))
p.close()

# p.show()

# Now get the HI profile on the same scales
proj = Projection(mom0_hi.data * u.Jy * u.m / u.s, meta={'beam': average_beams(hi_cube.beams)},
                  wcs=WCS(cube[0].header))
rs_hi, sd_hi, sd_sigma_hi = surfdens_radial_profile(gal, cube=hi_cube,
                                                    mom0=proj,
                                                    max_rad=6 * u.kpc, dr=dr,
                                                    beam=average_beams(hi_cube.beams))
# Apply scaling factor
# sd_hi /= 1.45
# sd_sigma_hi /= 1.45

# Overplot these two.
p.errorbar(rs.value, np.log10(sd.value),
           yerr=0.434 * sd_sigma.value / sd.value, fmt="-", color="b",
           label=r"H$_2$", drawstyle='steps-mid')
p.errorbar(rs_hi.value, np.log10(sd_hi.value),
           yerr=0.434 * sd_sigma_hi.value / sd_hi.value, fmt="--", color="g",
Exemple #4
0
    # raw_input("Next plot?")
    p.clf()

# Zoom in on the interesting portion of the spectrum
spectral_cuts = np.array([[-72, -180], [-200, -280], [-220, -315]]) * \
    u.km / u.s

# Now save spectra going through the interesting regions:
for posns, cuts, name in zip(spec_posns, spectral_cuts, names):

    num_posns = len(posns)
    fig, axes = p.subplots(num_posns, 1, sharey=True, sharex=False,
                           figsize=(6, 10))
    for i, (posn, ax) in enumerate(zip(posns, axes)):
        spec = cube.spectral_slab(cuts[0], cuts[1])[:, posn[0], posn[1]]
        spec = spec.to(u.K, equivalencies=average_beams(cube.beams).jtok_equiv(hi_freq))
        velocities = cube.spectral_slab(cuts[0], cuts[1]).spectral_axis.to(u.km / u.s).value
        ax.plot(velocities, spec.value, 'b-', drawstyle='steps-mid')
        if i < num_posns - 1:
            ax.set_xticklabels([])
        else:
            ax.set_xlabel("Velocity (km/s)")
            for label in ax.get_xticklabels()[1::2]:
                label.set_visible(False)

    for i, ax in enumerate(axes):
        if i == 0:
            for label in ax.get_yticklabels()[1::2]:
                label.set_visible(False)
        else:
            for label in ax.get_yticklabels():
Exemple #5
0
    bad_posns = \
        list(set(np.arange(cube.shape[0])) - set(list(chain(*sequences))))

    mask[:, i, j][bad_posns] = False

    if verbose:
        p.plot(spectrum)
        p.plot(smoothed)
        p.vlines(np.where(mask[:, i, j])[0][-1], 0, np.nanmax(spectrum))
        p.vlines(np.where(mask[:, i, j])[0][0], 0, np.nanmax(spectrum))
        p.plot(smoothed * mask[:, i, j], 'bD')
        p.draw()
        raw_input("Next spectrum?")

kernel = average_beams(cube.beams).as_tophat_kernel(pixscale)
kernel_pix = (kernel.array > 0).sum()

for i in ProgressBar(mask.shape[0]):
    mask[i] = nd.binary_opening(mask[i], kernel)
    mask[i] = nd.binary_closing(mask[i], kernel)
    mask[i] = mo.remove_small_objects(mask[i], min_size=kernel_pix,
                                      connectivity=2)


new_header = cube.header.copy()
new_header["BUNIT"] = ""
new_header["BITPIX"] = 8

mask_hdu = fits.PrimaryHDU(mask.astype('>i2'), header=new_header)
mask_hdu.writeto(fourteenB_HI_data_path(mask_name, no_check=True),