def prepare_galaxy_inputfile(inps): """ Make a galaxy input file for trilegal TODO: Better object_mass selection based on target """ # If match was run with setz, this is the logz dispersion. # Only useful for clusters, also it is not saved in the match output files # Only set in the match parameter file. inps.match_zdisp = 0.00 rsp.match.utils.process_match_sfh(inps.sfh_file, outfile=inps.object_sfr_file, zdisp=inps.match_zdisp) gal_dict =\ {'mag_limit_val': limiting_mag(inps.fake_file, 0.1)[1], 'object_av': inps.Av, 'object_dist': 10 ** (inps.dmod/5. + 1.), 'photsys': inps.photsys, 'object_mass': inps.object_mass or load_sim_masses(inps.target), 'object_sfr_file': inps.object_sfr_file, 'file_imf': inps.file_imf or 'tab_imf/imf_salpeter.dat', 'binary_frac': inps.binary_frac or 0., 'object_cutoffmass': inps.object_cutoffmass or 0.8} # filter1 is used here to find the mag depth for trilegal input. gal_dict['filter1'] = inps.filter2 trigal_dict = rsp.trilegal.utils.galaxy_input_dict(**gal_dict) del gal_dict['filter1'] gal_inp = rsp.fileio.InputParameters(default_dict=trigal_dict) gal_inp.write_params(inps.galaxy_input, rsp.trilegal.utils.galaxy_input_fmt()) return gal_dict
def prepare_for_varysfh(inps, outfile): """ Prepare a default varysfh inputfile """ # get completeness mags for mag limits if inps.offset is None: logger.info('finding completeness fraction from fake file') inps.comp_mag1, inps.comp_mag2 = limiting_mag(inps.fake_file, inps.comp_frac) # get Av, dmod, mTRGB, photsys msfh = rsp.match.utils.MatchSFH(inps.sfh_file) inps.Av = msfh.Av inps.dmod = msfh.dmod angst_target = \ difflib.get_close_matches(inps.target.upper(), angst_data.targets)[0].replace('-', '_') try: target_row = angst_data.__getattribute__(angst_target) inps.trgb = target_row['%s,%s' % (inps.filter1, inps.filter2)]['mTRGB'] if inps.photsys is None: inps.photsys = angst_data.get_item(angst_target, 'camera').lower() if inps.photsys == 'acs': inps.photsys = 'acs_wfc' except AttributeError: logger.error('{} not found in angst tables, \ using M=-4 to find mTRGB'.format(angst_target)) inps.trgb = rsp.astronomy_utils.Mag2mag(-4., inps.filter2, inps.photsys, dmod=inps.dmod, Av=inps.Av) # get observered number of RGB and AGB stars mag1, mag2 = np.loadtxt(inps.matchphot, unpack=True) if inps.mag_faint is None: logger.info('assuming faint mag offset of 2') inps.offset = 2. else: inps.offset = inps.trgb - inps.mag_faint rgbs, agbs = rgb_agb_regions(inps.offset, inps.trgb_exclude, inps.trgb, mag2, mag_faint=inps.mag_faint, mag_bright=inps.mag_bright, col_min=inps.col_min, mag1=mag1, col_max=inps.col_max) inps.nrgbs = len(rgbs) inps.nagbs = len(agbs) # convert match SFH to trilegal AMR gal_inp = prepare_galaxy_inputfile(inps) inps.__dict__.update(gal_inp) inps.write_params(outfile)