Skip to content

Commit

Permalink
Add essential scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
e-koch committed Feb 7, 2019
1 parent e97329b commit 37298df
Show file tree
Hide file tree
Showing 5 changed files with 254 additions and 0 deletions.
59 changes: 59 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover

# Translations
*.mo
*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/

*.DS_Store
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

This repository contains the analysis scripts for Koch et al. (2019). We compare the HI and CO spectral properties in M33.

HI data products are available [here](https://doi.org/10.11570/18.0003). Use of these data should cite [Koch et al. (2018)](https://ui.adsabs.harvard.edu/#abs/2018MNRAS.479.2505K/abstract).

The CO data is hosted by IRAM [here](http://www.iram-institute.org/EN/content-page-329-7-158-240-329-0.html). The link refers to the papers that should be cited when using these data.

Scripts to reproduce the HI reduction and imaging can be found [here](https://github.com/e-koch/VLA_Lband).

These analyses scripts are setup to run from this directory and rely on paths to the data defined in `paths.py`. The disc parameters (inclination, position angle, etc) are required for some script and are loaded through the `galaxy_params.py` script. The file that is loaded in this script is available from the HI data link above (`DR1/HI/rotation_curve/rad.out.params.csv`).

These scripts rely on two personal python packages that require installing from the source code:

* [galaxies](https://github.com/low-sky/galaxies)
* [CubeAnalysis](https://github.com/e-koch/CubeAnalysis)

31 changes: 31 additions & 0 deletions constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

'''
Define HI frequency once.
'''

import astropy.units as u

distance = 840 * u.kpc


def ang_to_phys(ang_size, distance=distance):
'''
Convert from angular to physical scales
'''
return (ang_size.to(u.rad).value * distance).to(u.pc)


hi_freq = 1.42040575177 * u.GHz

pb_lim = 0.5

co21_mass_conversion = 6.7 * (u.Msun / u.pc ** 2) / (u.K * u.km / u.s)
beam_eff_30m_druard = 56 / 92.

# Note that the top two conversions contain a 1.4x correction for He.
# So they will give the atomic mass, not the HI mass!
hi_mass_conversion = 0.019 * (u.M_sun / u.pc ** 2) / (u.K * u.km / u.s)
hi_mass_conversion_Jy = 2.36e5 * 1.4 * (u.M_sun / u.Mpc ** 2) / (u.Jy * u.km / u.s)

# This does not have the He correction
hi_coldens_Kkms = 1.82e18 * u.cm**-2 / (u.K * u.km / u.s)
43 changes: 43 additions & 0 deletions galaxy_params.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

'''
Use parameters from Diskfit in the Galaxy class
'''

from galaxies import Galaxy
from astropy.table import Table
import astropy.units as u

from cube_analysis.rotation_curves import update_galaxy_params

from paths import fourteenB_HI_data_path, fourteenB_HI_data_wGBT_path

# The models from the peak velocity aren't as biased, based on comparing
# the VLA and VLA+GBT velocity curves. Using these as the defaults

folder_name = "diskfit_peakvels_noasymm_noradial_nowarp_output"

param_name = \
fourteenB_HI_data_path("{}/rad.out.params.csv".format(folder_name))

param_table = Table.read(param_name)

gal = Galaxy("M33")

update_galaxy_params(gal, param_table)

# Load in the model from the feathered data as well.
folder_name = "diskfit_peakvels_noasymm_noradial_nowarp_output"

param_name = \
fourteenB_HI_data_wGBT_path("{}/rad.out.params.csv".format(folder_name))

param_table = Table.read(param_name)

gal_feath = Galaxy("M33")

update_galaxy_params(gal_feath, param_table)

# Force 840 kpc for the distance

gal.distance = 840 * u.kpc
gal_feath.distance = 840 * u.kpc
105 changes: 105 additions & 0 deletions plotting_styles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@

import seaborn as sb

'''
Set style for figures.
'''


def default_figure(font_scale=1.0):
sb.set(font='Times New Roman', style='ticks',
rc={'text.usetex': True})
sb.set_context("poster", font_scale=font_scale)
sb.set_palette("colorblind")


def twocolumn_figure(fig_ratio=None, font_scale=1.25):
default_figure()

width = 8.4
# Keep the default ratio used in seaborn. This can get overwritten.
height = (4.4 / 6.4) * width

figsize = (width, height)

if fig_ratio is not None:
figsize = (width, width * fig_ratio)

sb.set_context("paper", font_scale=font_scale,
rc={"figure.figsize": figsize})
sb.set_palette("colorblind")


def twocolumn_twopanel_figure(fig_ratio=None, **kwargs):

# Use half the ratio of a one column figure.
if fig_ratio is None:
fig_ratio = (4.4 / 6.4) / 2

twocolumn_figure(fig_ratio=fig_ratio, **kwargs)


def onecolumn_figure(fig_ratio=None, font_scale=1.2):
'''
fig_ratio is width / height.
'''
default_figure()

# About the width (in inches) of a column
width = 4.2
# Keep the default ratio used in seaborn. This can get overwritten.
height = (4.4 / 6.4) * width

figsize = (width, height)

if fig_ratio is not None:
figsize = (width, width * fig_ratio)

sb.set_context("paper", font_scale=font_scale,
rc={"figure.figsize": figsize})
sb.set_palette("colorblind")


def onecolumn_Npanel_figure(N, font_scale=1.2):

width = 4.2

height = (4.4 / 6.4) * N * width

onecolumn_figure(fig_ratio=height / width, font_scale=font_scale)


def onecolumn_twopanel_figure(font_scale=1.2):

onecolumn_Npanel_figure(N=2, font_scale=font_scale)


def image_shape_ratio(shape):
'''
Return the width / height for adjusting figure sizes.
'''

return shape[0] / float(shape[1])


def align_yaxis(ax1, v1, ax2, v2):
"""adjust ax2 ylimit so that v2 in ax2 is aligned to v1 in ax1"""
_, y1 = ax1.transData.transform((0, v1))
_, y2 = ax2.transData.transform((0, v2))
adjust_yaxis(ax2, (y1 - y2) / 2, v2)
adjust_yaxis(ax1, (y2 - y1) / 2, v1)


def adjust_yaxis(ax, ydif, v):
"""shift axis ax by ydiff, maintaining point v at the same location"""
inv = ax.transData.inverted()
_, dy = inv.transform((0, 0)) - inv.transform((0, ydif))
miny, maxy = ax.get_ylim()
miny, maxy = miny - v, maxy - v
if -miny > maxy or (-miny == maxy and dy > 0):
nminy = miny
nmaxy = miny * (maxy + dy) / (miny + dy)
else:
nmaxy = maxy
nminy = maxy * (miny + dy) / (maxy + dy)
ax.set_ylim(nminy + v, nmaxy + v)

0 comments on commit 37298df

Please sign in to comment.