Skip to content

Commit

Permalink
major refactoring! Removed match, resolvedstellarpops, trilegal code …
Browse files Browse the repository at this point in the history
…dependencies
  • Loading branch information
philrosenfield committed Feb 13, 2017
1 parent 31d8f2e commit a145ce2
Show file tree
Hide file tree
Showing 49 changed files with 9,655 additions and 288 deletions.
26 changes: 19 additions & 7 deletions TPAGBparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#EXT = '.png'
EXT = '.pdf'
if hostname.endswith('astro.washington.edu'):
print 'better edit TPAGBparams.py...'
print('better edit TPAGBparams.py...')
else:
if 'Linux' in os.uname():
# linux laptop
Expand All @@ -17,16 +17,28 @@
mpl.use('Agg')
else:
# mac
#research_path = '/Users/rosenfield/research/'
research_path = '/Volumes/tehom/research'
# research_path = '/Users/rosenfield/research/'
# research_path = '/Volumes/tehom/research'
research_path = '/Users/rosenfield/Desktop/'

tpcalib_dir = os.path.join(research_path, 'TP-AGBcalib')
snap_src = os.path.join(tpcalib_dir, 'SNAP')
phat_src = os.path.join(tpcalib_dir, 'PHAT')
# phat_src = os.path.join(tpcalib_dir, 'PHAT')
phat_src = research_path

matchfake_loc = os.path.join(snap_src, 'data', 'galaxies')
data_loc = os.path.join(snap_src, 'data', 'opt_ir_matched_v2')
project = 'PHAT'
# project = 'SNAP'
if project == 'PHAT':
data_loc = os.path.join(phat_src, 'lowav', 'phot')
match_run_loc = os.path.join(phat_src, 'lowav', 'fake')
matchfake_loc = os.path.join(phat_src, 'lowav', 'fake')
else:
matchfake_loc = os.path.join(snap_src, 'data', 'galaxies')
data_loc = os.path.join(snap_src, 'data', 'opt_ir_matched_v2')
data_loc = os.path.join(snap_src, 'data', 'galaxies')
match_run_loc = os.path.join(snap_src, 'match')

dirs = [tpcalib_dir, snap_src, phat_src]
dirs = [tpcalib_dir, data_loc, matchfake_loc]
for d in dirs:
if not os.path.isdir(d):
#print 'Warning. Can not find %s.' % d
Expand Down
16 changes: 9 additions & 7 deletions analysis/add_asts.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import os
import sys

import ResolvedStellarPops as rsp

from ..pop_synth.asts import ASTs, ast_correct_starpop
from ..pop_synth import SimGalaxy
from .. import fileio
# where the matchfake files live
from ..TPAGBparams import snap_src
matchfake_loc = os.path.join(snap_src, 'data', 'galaxies')
Expand All @@ -21,7 +23,7 @@ def make_ast_corrections(trilegal_catalogs, target, outfiles='default',
fake=None):
"""
apply ast corrections from fake files found in matchfake_loc/*[target]*
see rsp.ast_correct_starpop
see asts.ast_correct_starpop
"""
if type(outfiles) is str:
outfmt = 'default'
Expand All @@ -32,18 +34,18 @@ def make_ast_corrections(trilegal_catalogs, target, outfiles='default',
# search string for fake files
search_str = '*{}*.matchfake'.format(target.upper())

fakes = rsp.fileio.get_files(matchfake_loc, search_str)
fakes = fileio.get_files(matchfake_loc, search_str)
logger.info('fake files found: {}'.format(fakes))
else:
fakes = [fake]

asts = [rsp.ASTs(f) for f in fakes]
asts = [ASTs(f) for f in fakes]
logger.debug('{}'.format(trilegal_catalogs))

for i, trilegal_catalog in enumerate(trilegal_catalogs):
logger.info('working on {}'.format(trilegal_catalog))

sgal = rsp.SimGalaxy(trilegal_catalog)
sgal = SimGalaxy(trilegal_catalog)
# "overwrite" (append columns) to the existing catalog by default
if outfmt == 'default':
outfile = trilegal_catalog
Expand All @@ -65,7 +67,7 @@ def make_ast_corrections(trilegal_catalogs, target, outfiles='default',
else:
continue

rsp.ast_correct_starpop(sgal, asts_obj=ast, overwrite=overwrite,
ast_correct_starpop(sgal, asts_obj=ast, overwrite=overwrite,
outfile=outfile, diag_plot=diag_plot,
hdf5=hdf5, correct=correct)
return
Expand Down Expand Up @@ -130,7 +132,7 @@ def main(argv):
if args.directory:
if args.name[0].endswith('/'):
args.name[0] = args.name[0][:-1]
tricats = rsp.fileio.get_files(args.name[0], '*_???.dat')
tricats = fileio.get_files(args.name[0], '*_???.dat')
else:
tricats = args.name

Expand Down
10 changes: 5 additions & 5 deletions analysis/agb_flux.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import matplotlib.pyplot as plt
import numpy as np
from ..TPAGBparams import EXT
from ResolvedStellarPops.fileio import readfile, get_files
from ResolvedStellarPops.utils import count_uncert_ratio
from ResolvedStellarPops.galaxies.galaxy import Galaxy
from ..fileio import readfile, get_files
from ..utils import count_uncert_ratio
from ..pop_synth import Galaxy

from dweisz.match.scripts.sfh import SFH as MatchSFH
from ..sfhs.match_sfh import SFH
from ..fileio import load_lf_file, load_observation
from .analyze import get_itpagb

Expand Down Expand Up @@ -80,7 +80,7 @@ def ntpagb_model_data(narratiofile, sfhfile, metafile=None):
mean_nagb = np.mean(ratiodata['nagb'][1:])
agbm2d = mean_nagb / ratiodata['nagb'][0]

sfh = MatchSFH(sfhfile, meta_file=metafile)
sfh = SFH(sfhfile, meta_file=metafile)
massfrac, massfrac_perr, massfrac_merr = sfh.mass_fraction(0, 2e9)

agbm2d_err = count_uncert_ratio(np.mean(ratiodata['nagb'][1:]),
Expand Down
61 changes: 36 additions & 25 deletions analysis/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@
#import matplotlib as mpl
#mpl.use('Agg')
import matplotlib.pylab as plt
import ResolvedStellarPops as rsp

from astropy.io import ascii
from ..pop_synth.stellar_pops import normalize_simulation, rgb_agb_regions, limiting_mag
from ..sfhs.star_formation_histories import StarFormationHistories
from ..fileio import load_obs, find_fakes

from ..fileio import load_obs, find_fakes, get_files
from ..utils import astronomy_utils
#logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)

from ..TPAGBparams import snap_src, matchfake_loc
angst_data = rsp.angst_tables.angst_table.AngstTables()
from .. import angst_tables
angst_data = angst_tables.angst_data

__all__ = ['get_itpagb', 'parse_regions']


def get_trgb(target, filter2='F160W', filter1=None):
import difflib
angst_data = rsp.angst_tables.angst_data
angst_data = angst_tables.angst_data
if 'm31' in target.lower() or 'B' in target:
trgb = 22.
else:
Expand Down Expand Up @@ -67,6 +67,7 @@ def parse_regions(args):
if args.yfilter == 'V':
opt = False

trgb = args.trgb
if args.trgb is None:
try:
trgb = get_trgb(args.target, filter2=filter2, filter1=filter1)
Expand Down Expand Up @@ -95,37 +96,47 @@ def parse_regions(args):
colmax = row['colmax']
else:
if args.colorlimits is not None:
colmin, colmax = map(float, args.colorlimits.split(','))
colmin, colmax = np.array(args.colorlimits.split(','), dtype=float)
if colmax < colmin:
colmax = colmin + colmax
logger.info('colmax was less than colmin, assuming it is dcol, colmax is set to colmin + dcol')

if args.maglimits is not None:
magfaint, magbright = map(float, args.maglimits.split(','))
print magfaint
magfaint, magbright = np.array(args.maglimits.split(','), dtype=float)
msg = 'maglimits'
else:
magbright = trgb + args.trgbexclude
magfaint = trgb + args.trgboffset
msg = 'trgb + offset'

if args.comp_frac is not None:
skip = False
search_str = '*{}*.matchfake'.format(args.target.upper())
fakes = rsp.fileio.get_files(matchfake_loc, search_str)
fakes = fileio.get_files(matchfake_loc, search_str)
logger.info('found fakes {}'.format(fakes))
try:
fake = [f for f in fakes if filter1 in f][0]
except:
fake = [f for f in fakes if filter2 in f][0]
logger.info('using fake: {}'.format(fake))
_, comp_mag2 = limiting_mag(fake, args.comp_frac)
#comp_mag1, comp_mag2 = limiting_mag(args.fake_file,
# args.comp_frac)
if comp_mag2 < trgb + args.trgboffset:
msg = '{} completeness fraction: {}'.format(args.comp_frac,
comp_mag2)
magfaint = comp_mag2

if len(fakes) > 1:
try:
fake = [f for f in fakes if filter1 in f][0]
except:
try:
fake = [f for f in fakes if filter2 in f][0]
except:
logger.warning('uncertain which fake file to to use')
skip = True
else:
logger.info('magfaint: {} comp_mag2: {} using magfaint'.format(magfaint, comp_mag2))
fake, = fake
if not skip:
logger.info('using fake: {}'.format(fake))
_, comp_mag2 = limiting_mag(fake, args.comp_frac)
#comp_mag1, comp_mag2 = limiting_mag(args.fake_file,
# args.comp_frac)
if comp_mag2 < trgb + args.trgboffset:
msg = '{} completeness fraction: {}'.format(args.comp_frac,
comp_mag2)
magfaint = comp_mag2
else:
logger.info('magfaint: {} comp_mag2: {} using magfaint'.format(magfaint, comp_mag2))
logger.info('faint mag limit for rgb norm set to {}'.format(msg))

regions_kw = {'offset': args.trgboffset,
Expand All @@ -137,7 +148,7 @@ def parse_regions(args):
'mag_faint': magfaint}

logger.info('regions: {}'.format(regions_kw))

return regions_kw


Expand Down Expand Up @@ -172,7 +183,7 @@ def get_itpagb(target, color, mag, col, blue_cut=-99, absmag=False,
logger.error('Target not found: get_snap_trgb_av_dmod {}'.format(target))
return [np.nan] * 2
if absmag:
mtrgb = rsp.astronomy_utils.mag2Mag(mtrgb, 'F160W', 'wfc3ir',
mtrgb = astronomy_utils.mag2Mag(mtrgb, 'F160W', 'wfc3ir',
dmod=dmod, Av=Av)
dmod = 0.
Av = 0.
Expand All @@ -186,7 +197,7 @@ def get_itpagb(target, color, mag, col, blue_cut=-99, absmag=False,
mtrgb, Av, dmod = angst_data.get_tab5_trgb_av_dmod(target.upper(),
filters=col)
if absmag:
mtrgb = rsp.astronomy_utils.mag2Mag(mtrgb, col, 'acs_wfc',
mtrgb = astronomy_utils.mag2Mag(mtrgb, col, 'acs_wfc',
dmod=dmod, Av=Av)
redward_of_rheb = np.arange(len(color))
blueward_of_rheb = np.arange(len(color))
Expand Down
Loading

0 comments on commit a145ce2

Please sign in to comment.