def make_rrl_finder_chart(target_stem, ra, dec): target_stem = re.sub('\.', '_', target_stem) target_stem = re.sub('-', '', target_stem) target_stem = sgr_setup.get_target_stem(target_stem) coords = str(ra) +' ' +str(dec) ra= SkyCoord(coords, unit=(u.deg, u.deg)).ra dec = SkyCoord(coords, unit=(u.deg, u.deg)).dec fitsfile = target_stem + '_e1_3p6um.fits' print ra, dec inputfile = fitsfile fitsdata = astropy.io.fits.open(fitsfile)[0].data interval = ZScaleInterval() zmin, zmax = interval.get_limits(fitsdata) fig = mp.figure(figsize=(10,10)) mosaic = aplpy.FITSFigure(inputfile, figure = fig) mosaic.show_grayscale(vmin=zmin,vmax=zmax, invert='true') ### manually implimenting zscale mosaic.tick_labels.set_font(size='small') mosaic.tick_labels.set_xformat("hh:mm:ss") mosaic.set_theme('publication') mosaic.show_markers(ra.deg, dec.deg, edgecolor='magenta', facecolor='magenta', marker='o', s=100, alpha=0.3) mosaic.show_markers(ra.deg, dec.deg, edgecolor='magenta', facecolor='magenta', marker='o', s=300, alpha=0.1) #mosaic.save(target_stem + '_location.pdf') mp.show()
def make_rrl_finder_chart(target_stem, ra, dec): target_stem = re.sub('\.', '_', target_stem) target_stem = re.sub('-', '', target_stem) target_stem = sgr_setup.get_target_stem(target_stem) coords = str(ra) + ' ' + str(dec) ra = SkyCoord(coords, unit=(u.deg, u.deg)).ra dec = SkyCoord(coords, unit=(u.deg, u.deg)).dec fitsfile = target_stem + '_e1_3p6um.fits' print ra, dec inputfile = fitsfile fitsdata = astropy.io.fits.open(fitsfile)[0].data interval = ZScaleInterval() zmin, zmax = interval.get_limits(fitsdata) fig = mp.figure(figsize=(10, 10)) mosaic = aplpy.FITSFigure(inputfile, figure=fig) mosaic.show_grayscale(vmin=zmin, vmax=zmax, invert='true') ### manually implimenting zscale mosaic.tick_labels.set_font(size='small') mosaic.tick_labels.set_xformat("hh:mm:ss") mosaic.set_theme('publication') mosaic.show_markers(ra.deg, dec.deg, edgecolor='magenta', facecolor='magenta', marker='o', s=100, alpha=0.3) mosaic.show_markers(ra.deg, dec.deg, edgecolor='magenta', facecolor='magenta', marker='o', s=300, alpha=0.1) #mosaic.save(target_stem + '_location.pdf') mp.show()
target = sys.argv[4] else: target = target_name outname = re.sub(' ', '_', target) is_hrs = re.search(":", coords) if (is_hrs != None): ra = SkyCoord(coords, unit=(u.hourangle, u.deg)).ra dec = SkyCoord(coords, unit=(u.hourangle, u.deg)).dec is_deg = re.search("d", coords) if (is_deg != None): ra = SkyCoord(coords, unit=(u.deg, u.deg)).ra dec = SkyCoord(coords, unit=(u.deg, u.deg)).dec image_stem = sgr_setup.get_target_stem(target) fitsfile = image_stem + '_e1_3p6um.fits' print ra, dec, period fig = aplpy.FITSFigure(fitsfile) rr_x, rr_y = fig.world2pixel(ra, dec) print rr_x, rr_y mch_file = image_stem + '_3p6um_cal.mch' phot_file = image_stem + '_3p6um.cal' num_frames = len(glob.glob('*_dn.cal')) file_list = [] mch_file = open(mch_file, 'r')
def robust_offset_calculator(row): target_stem = row.ix[0, 'survey_ident'] target_stem = re.sub('\.', '_', target_stem) target_stem = re.sub('-', '', target_stem) target_stem = sgr_setup.get_target_stem(target_stem) file_list = glob.glob('*.alf') num_frames = len(file_list) print num_frames ### Reading in the daomaster raw file here if ((num_frames % 6) == 0): n_lines_raw = num_frames / 6.0 + 1.0 else: n_lines_raw = np.ceil(num_frames / 6.0) print n_lines_raw with open(target_stem + '_3p6um_cal.raw') as raw_file: lines = [] ## skip the 3 header lines if they exist firstline = raw_file.readline() isheader = re.search('NL', firstline) if (isheader != None): for count in np.arange(0, 2): raw_file.readline() else: raw_file.seek(0) while True: line = list(itertools.islice(raw_file, n_lines_raw)) if line: lines.append(line) else: break num_stars = len(lines) objects = np.zeros((num_stars, (num_frames * 2) + 3)) for star in np.arange(0, num_stars): data = "".join(lines[star]) data = data.split() objects[star][0] = data[0] ## ID objects[star][1] = data[1] ## XC objects[star][2] = data[2] ## YC for epoch in np.arange(0, (num_frames * 2), 2): objects[star][epoch + 3] = data[epoch + 3] ## mag objects[star][epoch + 4] = data[epoch + 4] ## err epoch1 = objects[:, 3] epoch1_err = objects[:, 4] min_epoch1 = min(epoch1) offsets = np.zeros(num_frames) sdev_offsets = np.zeros(num_frames) for epoch in np.arange( 2, (num_frames * 2), 2): ## starting from 1 because don't match epoch 1 to itself difference = epoch1 - objects[:, epoch + 3] ediff = np.sqrt(epoch1_err**2 + objects[:, epoch + 4]**2) clipped = sigma_clip(difference, sig=4., iters=100) av_diff = np.ma.mean(clipped) sdev_diff = np.ma.std(clipped) offsets[(epoch / 2.)] = av_diff sdev_offsets[(epoch / 2.)] = sdev_diff print "Epoch " + str((epoch / 2.) + 1) + " offset " + str( av_diff) + " sdev " + str(sdev_diff) mp.close('all') axp1 = mp.subplot(111) mp.axis([min_epoch1, min_epoch1 + 8, av_diff - 1, av_diff + 1]) axp1.errorbar(epoch1, clipped, yerr=ediff, color='grey', ls='none') axp1.plot(epoch1, clipped, 'k.', ls='none') axp1.axhline(av_diff, color='r', ls='--') axp1.axhline(av_diff + 2 * sdev_diff, color='b', ls='--') axp1.axhline(av_diff - 2 * sdev_diff, color='b', ls='--') mp.show()
def calibrate_and_plot(row): directory_switcher(row, 0) survey_ident = row['survey_ident'] ra = row['ra'] dec = row['dec'] period = row['period'] target_name = row['target_name'] channel = 1 ### hardwired to channel 1 here if (channel == 1 or channel == '3p6um' or channel == '1'): new_chan = '3p6um' elif (channel == 2 or channel == '4p5um' or channel == '2'): new_chan = '4p5um' else: print 'invalid channel' exit(1) if new_chan == '3p6um': num_chan = 1 if new_chan == '4p5um': num_chan = 2 target_stem = sgr_setup.get_target_stem(survey_ident) dir_name = re.sub('\.', '_', survey_ident) dir_name = re.sub('-', '', dir_name) directory = '/Users/vs522/Dropbox/TRACCS/TRACCS_Output/' + dir_name + '/' + dir_name + '_' + new_chan os.chdir(directory) if (len(glob.glob(target_stem + '*' + new_chan + '*.alf')) == 0): print 'You need to run ALLFRAME before you can calibrate the photometry' print 'This is the CALIBRATION ONLY script' print 'Run ``globular_pipeline_anychannel.py`` to do the combined photometry and calibration script' exit(1) flux_epoch_1 = target_stem + '_e1_' + new_chan aperture_correction_photometry.apcor_photo(flux_epoch_1) apcor, sdev_apcor = calculate_aperture_correction_testing.calc_apcor( flux_epoch_1, 'apcor.raw', 3, target_stem, 0.3) apply_aperture_correction.apply_apcor( target_stem + '_e1_' + new_chan + '_dn.alf', apcor, num_chan) calibrate_all_epochs.calibrate(target_stem + '_' + new_chan + '.mch') all_location_corrections.location_corr(target_stem, new_chan) robust_offset_calculator(row) #make_rrl_finder_chart(target_stem, ra, dec) mch_file = target_stem + '_3p6um_cal.mch' phot_file = target_stem + '_3p6um.cal' make_rrl_finder_chart(survey_ident, ra, dec) mag, err = find_which_star(target_stem, ra, dec) mjds = grab_mjds(mch_file) #plot_a_lc(target_stem, target_name, period, mjds, mag, err) #mosaic.save(target_stem + '_location.pdf') offsets_df = pd.read_csv(target_stem + '_3p6um_cal.off_log', delim_whitespace=True, header=None, names=('obs', 'offset', 'sdev', 'nstars')) mp.close() mp.clf() mp.errorbar(offsets_df.obs, offsets_df.offset, yerr=offsets_df.sdev, color='k', ls='none') mp.plot(offsets_df.obs, offsets_df.offset, 'ko', ls='none') mp.axhline(offsets_df.offset.mean(), color='r', ls='--') mp.axhline(offsets_df.offset.mean() - 2 * offsets_df.offset.std(), color='b', ls='--') mp.show() #plot_existing_lc(row, 1, 1.5/12.) avmag1, sdev1 = plot_new_lc(row, mjds, mag, err, period, target_name, 1, 1.5 / 12.) print avmag1, sdev1 row.av_3p6 = avmag1 row.sdev_3p6 = sdev1 return (row)
import all_location_corrections import os target_name = sys.argv[1] channel = sys.argv[2] if (channel == 1 or channel == '3p6um' or channel == '1'): new_chan = '3p6um' elif (channel == 2 or channel == '4p5um' or channel == '2'): new_chan = '4p5um' else: print 'invalid channel' exit(1) if new_chan == '3p6um': num_chan = 1 if new_chan == '4p5um': num_chan = 2 target_stem = sgr_setup.get_target_stem(target_name) if (len(glob.glob(target_stem + '*' + channel +'*.alf'))==0): print 'You need to run ALLFRAME before you can calibrate the photometry' print 'This is the CALIBRATION ONLY script' print 'Run ``globular_pipeline_anychannel.py`` to do the combined photometry and calibration script' exit(1) ## Convert the images to counts and give them sensible names ## Also cleans up old runs ## for omegaCen only - doesn't apply for Sgr stream, orphan stream etc: ## Aperture correction
def robust_offset_calculator(row): target_stem = row.ix[0, 'survey_ident'] target_stem = re.sub('\.', '_', target_stem) target_stem = re.sub('-', '', target_stem) target_stem = sgr_setup.get_target_stem(target_stem) file_list = glob.glob('*.alf') num_frames = len(file_list) print num_frames ### Reading in the daomaster raw file here if ((num_frames % 6 ) == 0): n_lines_raw = num_frames / 6.0 + 1.0 else: n_lines_raw = np.ceil(num_frames / 6.0) print n_lines_raw with open(target_stem + '_3p6um_cal.raw') as raw_file: lines = [] ## skip the 3 header lines if they exist firstline = raw_file.readline() isheader = re.search('NL', firstline) if (isheader!=None): for count in np.arange(0,2): raw_file.readline() else: raw_file.seek(0) while True: line = list(itertools.islice(raw_file, n_lines_raw)) if line: lines.append(line) else: break num_stars = len(lines) objects = np.zeros((num_stars, (num_frames*2) + 3)) for star in np.arange(0,num_stars): data = "".join(lines[star]) data = data.split() objects[star][0] = data[0] ## ID objects[star][1] = data[1] ## XC objects[star][2] = data[2] ## YC for epoch in np.arange(0,(num_frames*2), 2): objects[star][epoch + 3] = data[epoch + 3] ## mag objects[star][epoch + 4] = data[epoch + 4] ## err epoch1 = objects[:,3] epoch1_err = objects[:,4] min_epoch1 = min(epoch1) offsets = np.zeros(num_frames) sdev_offsets = np.zeros(num_frames) for epoch in np.arange(2, (num_frames*2), 2): ## starting from 1 because don't match epoch 1 to itself difference = epoch1 - objects[ : , epoch + 3] ediff = np.sqrt(epoch1_err**2 + objects[ : , epoch + 4]**2) clipped = sigma_clip(difference, sig = 4., iters=100) av_diff = np.ma.mean(clipped) sdev_diff = np.ma.std(clipped) offsets[(epoch/2.)] = av_diff sdev_offsets[(epoch/2.)] = sdev_diff print "Epoch " + str((epoch/2.)+1) + " offset " +str(av_diff) + " sdev " + str(sdev_diff) mp.close('all') axp1 = mp.subplot(111) mp.axis([min_epoch1, min_epoch1+8, av_diff - 1, av_diff + 1]) axp1.errorbar(epoch1, clipped, yerr = ediff, color='grey', ls='none') axp1.plot(epoch1, clipped, 'k.', ls='none') axp1.axhline(av_diff, color='r', ls='--') axp1.axhline(av_diff+2*sdev_diff, color='b', ls='--') axp1.axhline(av_diff-2*sdev_diff, color='b', ls='--') mp.show()
def calibrate_and_plot(row): directory_switcher(row, 0) survey_ident = row['survey_ident'] ra = row['ra'] dec = row['dec'] period = row['period'] target_name = row['target_name'] channel = 1 ### hardwired to channel 1 here if (channel == 1 or channel == '3p6um' or channel == '1'): new_chan = '3p6um' elif (channel == 2 or channel == '4p5um' or channel == '2'): new_chan = '4p5um' else: print 'invalid channel' exit(1) if new_chan == '3p6um': num_chan = 1 if new_chan == '4p5um': num_chan = 2 target_stem = sgr_setup.get_target_stem(survey_ident) dir_name = re.sub('\.', '_', survey_ident) dir_name = re.sub('-', '', dir_name) directory = '/Users/vs522/Dropbox/TRACCS/TRACCS_Output/' + dir_name + '/' + dir_name + '_' + new_chan os.chdir(directory) if (len(glob.glob(target_stem + '*' + new_chan +'*.alf'))==0): print 'You need to run ALLFRAME before you can calibrate the photometry' print 'This is the CALIBRATION ONLY script' print 'Run ``globular_pipeline_anychannel.py`` to do the combined photometry and calibration script' exit(1) flux_epoch_1 = target_stem + '_e1_' + new_chan aperture_correction_photometry.apcor_photo(flux_epoch_1) apcor, sdev_apcor = calculate_aperture_correction_testing.calc_apcor(flux_epoch_1, 'apcor.raw', 3, target_stem, 0.3) apply_aperture_correction.apply_apcor(target_stem + '_e1_' + new_chan + '_dn.alf', apcor, num_chan) calibrate_all_epochs.calibrate(target_stem + '_' + new_chan + '.mch') all_location_corrections.location_corr(target_stem, new_chan) robust_offset_calculator(row) #make_rrl_finder_chart(target_stem, ra, dec) mch_file = target_stem + '_3p6um_cal.mch' phot_file = target_stem + '_3p6um.cal' make_rrl_finder_chart(survey_ident, ra, dec) mag, err = find_which_star(target_stem, ra, dec) mjds = grab_mjds(mch_file) #plot_a_lc(target_stem, target_name, period, mjds, mag, err) #mosaic.save(target_stem + '_location.pdf') offsets_df = pd.read_csv(target_stem + '_3p6um_cal.off_log', delim_whitespace=True, header=None, names=('obs', 'offset', 'sdev', 'nstars')) mp.close() mp.clf() mp.errorbar(offsets_df.obs, offsets_df.offset, yerr=offsets_df.sdev, color='k', ls='none') mp.plot(offsets_df.obs, offsets_df.offset, 'ko', ls='none') mp.axhline(offsets_df.offset.mean(), color='r', ls='--') mp.axhline(offsets_df.offset.mean()- 2*offsets_df.offset.std(), color='b', ls='--') mp.show() #plot_existing_lc(row, 1, 1.5/12.) avmag1, sdev1 = plot_new_lc(row, mjds, mag, err, period, target_name, 1, 1.5/12.) print avmag1, sdev1 row.av_3p6 = avmag1 row.sdev_3p6 = sdev1 return(row)
import sgr_pre_allframe_matching import traccs_master_image_phot target_name = sys.argv[1] channel = sys.argv[2] if (channel == 1 or channel == '3p6um' or channel == '1'): new_chan = '3p6um' elif (channel == 2 or channel == '4p5um' or channel == '2'): new_chan = '4p5um' else: print 'invalid channel' exit(1) if new_chan == '3p6um': num_chan = 1 if new_chan == '4p5um': num_chan = 2 target_stem = sgr_setup.get_target_stem(target_name) print target_stem ### Checking that you've made a good psf for epoch 1 if ((os.path.isfile(target_stem + '_e1_' + new_chan + '_dn.psf') == False) and os.path.isfile('master_' + new_chan + '.psf') == False): print 'You need to make the master psf first!!' exit(1) ## Now copy the psf to each epoch if (os.path.isfile('master_' + new_chan + '.psf') == False): shutil.copy(target_stem + '_e1_' + new_chan + '_dn.psf', 'master_' + new_chan + '.psf')