import numpy as np
import matplotlib.pyplot as plt
from corner import hist2d, corner
import seaborn as sb
import emcee
from scipy.stats import binned_statistic
from scipy import stats

from paths import (fourteenB_HI_data_wGBT_path, fourteenB_wGBT_HI_file_dict,
                   allfigs_path, iram_co21_14B088_data_path)
from plotting_styles import (default_figure, onecolumn_figure,
                             twocolumn_twopanel_figure, twocolumn_figure)
from constants import co21_mass_conversion, hi_mass_conversion
from galaxy_params import gal_feath as gal

fig_path = allfigs_path("co_vs_hi")
if not os.path.exists(fig_path):
    os.mkdir(fig_path)

inc = np.cos(gal.inclination)

# Start with checking the column densities from the fitting.

tab = Table.read(
    fourteenB_HI_data_wGBT_path(
        "tables/hi_co_gaussfit_column_densities_perpix.fits"))

# Don't consider the "bad fits" that are probably due to multiple components
good_pts = np.logical_and(~tab['multicomp_flag_HI'], ~tab['multicomp_flag_CO'])

# Our flagging didn't pick up some bad HI fits that are supremely narrow
Exemplo n.º 2
0
import os
import numpy as np
from spectral_cube import SpectralCube
import astropy.units as u
import scipy.ndimage as nd
from uvcombine.scale_factor import find_scale_factor
from scipy.stats import theilslopes
import matplotlib.pyplot as plt

from paths import iram_matched_data_path, noema_data_path, allfigs_path
from constants import co21_freq
from plotting_styles import onecolumn_figure

from cube_analysis.feather_cubes import feather_compare_cube

figure_folder = allfigs_path("Imaging")
if not os.path.exists(figure_folder):
    os.mkdir(figure_folder)

noema_cube = SpectralCube.read(
    noema_data_path('M33-ARM05_yclean.tc_final.image.pbcor.K.26regrid.fits'))

iram_cube = SpectralCube.read(
    iram_matched_data_path("m33.co21_iram.noema_regrid.spatial.fits"))

# Also need the pb map. It is constant across the channels so grab the first
# channel
noema_pb = SpectralCube.read(
    noema_data_path('yclean_05/M33-ARM05_yclean.tc_final.pb.fits'))[0]

# Define a mask that will be used to smoothly taper the IRAM data near the
df_hi = DataFrame(hi_mod_vals, index=parnames_hwhm)
# df_hi.to_latex(alltables_path("hi_totalprof_hwhm_lossample_stacking.tex"))
df_hi.to_csv(
    fourteenB_HI_data_wGBT_path(
        "tables/hi_totalprof_hwhm_lossample_stacking.csv", no_check=True))

df_co = DataFrame(co_mod_vals, index=parnames_hwhm)
# df_co.to_latex(alltables_path("co_totalprof_hwhm_lossample_stacking.tex"))
df_co.to_csv(
    iram_co21_14B088_data_path(
        "tables/co_totalprof_hwhm_lossample_stacking.csv", no_check=True))

# Compare the different stacking approaches

figure_folder = allfigs_path("stacked_profiles")
if not os.path.exists(figure_folder):
    os.mkdir(figure_folder)

# onecolumn_figure()
default_figure()

val_names = [
    'model_COmodelvels',
    'model_HImodelvels',
    'spec_HImodelvels',
    # 'spec_HImodelvels_fullsamp',
    'spec_HIpeakvels',
    'spec_HIpeakvels_fullsamp'
]
# 30 m beam efficiency
beam_eff = beam_eff_30m_druard

# Roughly constant for all pixels
hi_err = 2.8 * u.K

# Pixels to save plots of as examples
# Order: simple both, multi-comp CO, both multi-comp,
# HI good fit w/ multi-comp, Bad HI multi-comp,
# HI w/ and w/o HWHM mask
example_pix = [(454, 924), (788, 576), (954, 438), (938, 681), (774, 680),
               (984, 523)]
example_params = []

# Make a new figures folder for these
figure_folder = allfigs_path("co_vs_hi/example_spectra/")
if not os.path.exists(allfigs_path(figure_folder)):
    os.mkdir(allfigs_path(figure_folder))

# rand_ord = np.random.choice(np.arange(len(yposns)), size=len(yposns),
#                             replace=False)

# for i, (y, x) in enumerate(ProgressBar(zip(yposns[rand_ord],
#                                            xposns[rand_ord]))):
for i, (y, x) in enumerate(ProgressBar(zip(yposns, xposns))):

    co_spectrum = co_cube[:, y, x]

    # The CO error can vary. Pull from the RMS map
    co_err = co_rms.data[y, x] * u.K
Exemplo n.º 5
0
ax1.errorbar(bin_centers,
             co_tab_5beam['peaksub_sigma'],
             yerr=co_tab_5beam['peaksub_sigma_low_lim'],
             label='95"',
             drawstyle='steps-mid',
             linestyle=':')
ax1.set_ylabel(r"$\sigma_{\rm CO}$ (km/s)")

ax1.grid()

ax1.set_xlabel("Radius (kpc)")

plt.tight_layout()

plt.savefig(
    allfigs_path(
        "stacked_profiles/total_profile_radial_widths_HI_CO21_varyres.pdf"))
plt.savefig(
    allfigs_path(
        "stacked_profiles/total_profile_radial_widths_HI_CO21_varyres.png"))
plt.close()

ratio = co_tab['peaksub_sigma'] / hi_tab['peaksub_sigma']
ratio_err = ratio * np.sqrt(
    (co_tab['peaksub_sigma_low_lim'] / co_tab['peaksub_sigma'])**2 +
    (hi_tab['peaksub_sigma_low_lim'] / hi_tab['peaksub_sigma'])**2)

ratio_2beam = co_tab_2beam['peaksub_sigma'] / hi_tab_2beam['peaksub_sigma']
ratio_2beam_err = ratio_2beam * \
    np.sqrt((co_tab_2beam['peaksub_sigma_low_lim'] / co_tab_2beam['peaksub_sigma'])**2 +
            (hi_tab_2beam['peaksub_sigma_low_lim'] / hi_tab_2beam['peaksub_sigma'])**2)
Exemplo n.º 6
0
ax.contour(np.isfinite(co_moment0.data[zoom_slice]).astype(float),
           levels=[0.5],
           colors=sb.color_palette('viridis')[:1],
           alpha=0.75)
ax.contour(co_moment0.data[zoom_slice],
           levels=[900, 1400, 1900, 2400],
           cmap='viridis',
           alpha=0.75)

# CO levels at: 877,  1370,  1862,  2354 K m/s
# <Quantity [  5.8759,  9.179 , 12.4754, 15.7718] solMass / pc2>

cbar = plt.colorbar(im)
cbar.set_label(r"HI Column Density (cm$^{-2}$)")

plt.savefig(allfigs_path("HI_maps/coldens_map_14B088_w_CO21.pdf"))
plt.savefig(allfigs_path("HI_maps/coldens_map_14B088_w_CO21.png"))

plt.close()

ax = plt.subplot(111, projection=moment0_wcs)
im = ax.imshow(
    moment0_coldens,
    cmap='binary',
    origin='lower',
    interpolation='nearest',
    alpha=0.85,
)
# norm=ImageNormalize(vmin=-0.001,
#                     vmax=np.nanmax(moment0_coldens),
#                     stretch=AsinhStretch()))
Exemplo n.º 7
0
phys_bins = ang_to_phys(0.5 * (bins[1:] + bins[:-1]) * u.deg).to(u.kpc)

test, test_err = bootstrap_two_point(data.T, bins, Nbootstrap=2000)

onecolumn_figure()

plt.errorbar(phys_bins.value, test, yerr=test_err, drawstyle='steps-mid')
plt.axhline(0., linestyle='--', color='k')
plt.grid()
plt.xlabel("Separation (kpc)")
plt.ylabel("Correlation")

plt.tight_layout()

plt.savefig(allfigs_path("CO21_properties/corbelli_cloudloc_2ptcorr.pdf"))
plt.savefig(allfigs_path("CO21_properties/corbelli_cloudloc_2ptcorr.png"))
plt.close()

# Run one more with the Landy-Szalay estimator against a random sample

# radeg_R = np.random.uniform(low=tab['RAdeg'].min(), high=tab['RAdeg'].max())
# decdeg_R = np.random.uniform(low=tab['DEdeg'].min(), high=tab['DEdeg'].max())

# data_R = np.vstack([radeg_R, decdeg_R])

test_ls, test_err_ls = bootstrap_two_point(data.T,
                                           bins,
                                           Nbootstrap=2000,
                                           method='landy-szalay')
Exemplo n.º 8
0
from os.path import join, exists
import os

from paths import (fourteenB_wGBT_HI_file_dict, fourteenB_HI_data_wGBT_path,
                   iram_co21_14B088_data_path, allfigs_path)
from plotting_styles import (onecolumn_figure, default_figure,
                             twocolumn_figure)
from constants import hi_freq
'''
Is bright CO better correlated w/ the HI velocity?

Compare the peak temp of CO between the CO and HI velocities.

'''

fig_path = join(allfigs_path(""), "co_vs_hi")
if not exists(fig_path):
    os.mkdir(fig_path)

cpal = sb.color_palette()

hi_mom1 = fits.open(fourteenB_wGBT_HI_file_dict['Moment1'])[0].data / 1000.
hi_peakvels = fits.open(
    fourteenB_wGBT_HI_file_dict['PeakVels'])[0].data / 1000.
hi_peaktemp = fits.open(fourteenB_wGBT_HI_file_dict['PeakTemp'])[0].data

co_mom1 = fits.open(
    iram_co21_14B088_data_path(
        "m33.co21_iram.14B-088_HI.mom1.fits"))[0].data / 1000.
co_peakvels = fits.open(
    iram_co21_14B088_data_path(