def feed_chip_four ( table, sid ): ''' Gets a star's chip intelligently based on its SOURCEID and table. Checks to see if the star is on multiple chips. Inputs: table -- an ATpy table with time-series data and positions. sid -- a 13-digit WFCAM source ID. Calls get_chip. A convenience function. Uses default get_chip keywords. Looks up a star's chip for its first four detections, to see if the star is on multiple chips. SEE ALSO: feed_chip_one for less. I'll have to think carefully about what to return here. (or whether this is even useful or necessary) ''' s_table = season_cut(table, sid, 123) date = s_table.MEANMJDOBS RA = np.degrees(s_table.RA) DEC= np.degrees(s_table.DEC) chips = [ get_chip( date[x], RA[x], DEC[x] ) for x in range(4) ] # chips = [ get_chip( date[0], RA[0], DEC[0] ), # get_chip( date[1], RA[1], DEC[1] ), # get_chip( date[2], RA[2], DEC[2] ), # get_chip( date[3], RA[3], DEC[3] ) ] # For now I'll just return the four chips in a list, rather than some kind # of flag indicating whether the star was on multiple chips. This seems the # most naive way to handle it. return chips
def phase_trajectory (table, sid, period='auto', outfile='', season=123, offset=0): """ Does just the trajectory window from earlier. """ # Loading up the relevant datapoints to plot (note I set flags to 0) s_table = season_cut(table, sid, season, flags=0) if len(s_table) == 0: print "no data here" return date = s_table.MEANMJDOBS - 54579 jcol = s_table.JAPERMAG3 hcol = s_table.HAPERMAG3 kcol = s_table.KAPERMAG3 jmh = s_table.JMHPNT hmk = s_table.HMKPNT jerr = s_table.JAPERMAG3ERR herr = s_table.HAPERMAG3ERR kerr = s_table.KAPERMAG3ERR jmherr=s_table.JMHPNTERR hmkerr=s_table.HMKPNTERR # Let's figure out the period. if period == 'auto': period = 1./test_analyze(date, jcol, jerr) print period elif period == 'lsp': lomb = lsp(date,jcol,6.,6.) lsp_freq = lomb[0] lsp_power= lomb[1] Jmax = lsp_mask( lsp_freq, lsp_power) lsp_per = 1./ lomb[0][Jmax] period = lsp_per print period if period < 1: period_string = "%f hours" % (period*24) print period_string else: period_string = "%f days" % period phase = ((date % period) / period + offset) % 1. fig = plt.figure(figsize = (10, 6), dpi=80, facecolor='w', edgecolor='k') ax_jhk = plt.subplot(1,1,1) plot_trajectory_core( ax_jhk, hmk, jmh, phase , label='Phase') ax_jhk.set_xlabel( "H-K" ) ax_jhk.set_ylabel( "J-H")#, {'rotation':'horizontal'}) return period
def plot_jhmk(table, sid, outfile="", sup="", box=True, bands="jhk", season=123, text=True): """ Plots J and H-K lightcurves in 3 seasons (separated) over time. """ s_table = season_cut(table, sid, 123) date = s_table.MEANMJDOBS - 54579 jcol = s_table.JAPERMAG3 hmkcol = s_table.HMKPNT jerr = s_table.JAPERMAG3ERR hmkerr = s_table.HMKPNTERR plt.clf() ax1 = plt.subplot(2, 3, 1) ax2 = plt.subplot(2, 3, 2, sharey=ax1) ax3 = plt.subplot(2, 3, 3, sharey=ax1) sx1 = plt.subplot(2, 3, 4, sharex=ax1) sx2 = plt.subplot(2, 3, 5, sharex=ax2) sx3 = plt.subplot(2, 3, 6, sharex=ax3) for ax in (ax1, ax2, ax3): ax plt.errorbar(date, jcol, yerr=jerr, fmt="k-o", ecolor="k") for sx in (sx1, sx2, sx3): sx plt.errorbar(date, hmkcol, yerr=hmkerr, fmt="k-o", ecolor="k") ax1 plt.gca().invert_yaxis() plt.ylabel("WFCAM J Magnitude") sx1 d = 54579 plt.xlim(d, d + 100) plt.xlabel("Season 1") sx2 plt.xlim(d + 100, d + 300) plt.xlabel("Season 2") sx3 plt.xlim(d + 300, d + 600) plt.xlabel("Season 3") plt.show() return True
def feed_chip_one ( table, sid ): ''' Gets a star's chip intelligently based on its SOURCEID and table. Inputs: table -- an ATpy table with time-series data and positions. sid -- a 13-digit WFCAM source ID. Calls get_chip. A convenience function. Uses default get_chip keywords. Only looks up a single event's chip. SEE ALSO: feed_chip_four if you want more. ''' s_table = season_cut(table, sid, 123) date = s_table.MEANMJDOBS RA = np.degrees(s_table.RA) DEC= np.degrees(s_table.DEC) return get_chip( date[0], RA[0], DEC[0] )
def S_sid (table, sid, season=123, flags=0) : """ Calculates the Stetson J index for a given source. Inputs: table -- an atpy table with time-series photometry sid -- a Source ID from WFCAM (13 digits) season -- Which observing season of our dataset (1,2, 3, or all) """ from tr_helpers import season_cut s_table = season_cut(table, sid, season, flags=flags) jcol = s_table.JAPERMAG3 hcol = s_table.HAPERMAG3 kcol = s_table.KAPERMAG3 jerr = s_table.JAPERMAG3ERR herr = s_table.HAPERMAG3ERR kerr = s_table.KAPERMAG3ERR return S (jcol, jerr, hcol, herr, kcol, kerr)
def plot_phase(table, sid, period, band="j", outfile="", season=123, offset=0, clear=True): """ Plots magnitude as a function of phase for one source in one band. """ # Yo! This needs one more argument! A constant term to shift over by... # I'll make it scaled to phase (i.e. between 0 and 1) if band.lower() not in ["j", "h", "k", "jmh", "hmk"]: print "Error: keyword 'band' must be 'j','h', 'k', 'jmh', or 'hmk'." print "Keyword 'band' defaulting to 'j'." band = "j" if "m" in band.lower(): bandname = band.upper() + "PNT" thing = "color" else: bandname = band.upper() + "APERMAG3" thing = "magnitude" # w = numpy.where( table.SOURCEID == sid ) s_table = season_cut(table, sid, season) # ra1, ra2 = 314.36, 315.77 # dec1,dec2= 52.02, 52.92 # rabox = [ra1, ra1, ra2, ra2, ra1] # decbox= [dec1,dec2,dec2,dec1,dec1] # sra, sdec = table.RA[w][0], table.DEC[w][0] date = s_table.MEANMJDOBS # - 54579 phase = ((date % period) / period + offset) % 1.0 mag = s_table.data[bandname] err = s_table.data[bandname + "ERR"] if clear: plt.clf() ax = plt.gca() plt.errorbar(phase, mag, yerr=err, fmt="ko") # ,ecolor='k') # plt.errorbar(phase-1,mag,yerr=err,fmt='ko',ecolor='0.7', alpha=0.3) plt.errorbar(phase - 1, mag, yerr=err, fmt="o", mfc="0.7", mec="0.7", ecolor="0.7") plt.errorbar(phase + 1, mag, yerr=err, fmt="o", mfc="0.7", mec="0.7", ecolor="0.7") # plt.errorbar(phase+1,mag,yerr=err,fmt='ko',ecolor='0.7', alpha=0.3) plt.xticks([0, 0.5, 1]) ax.set_xticks(np.arange(-0.5, 1.5, 0.1), minor=True) plt.xlim(-0.25, 1.25) if len(band) == 1: plt.gca().invert_yaxis() plt.ylabel("WFCAM %s %s" % (band.upper(), thing)) plt.xlabel("Phase") if period < 1: period_string = "%f hours" % (period * 24) print period_string else: period_string = "%f days" % period plt.title("Phase-folded lightcurve. Source ID %d. Period: %s." % (sid, period_string)) if outfile == "": plt.show() else: plt.savefig(outfile) return
def plot_lc(table, sid, outfile="", sup="", box=True, bands="jhk", season=123, text=True): """ Plots J,H,K lightcurves WITH ERRORBARS for a given input source. Written with WFCAM columns in mind, specifically like from WSERV1. """ # w = numpy.where( table.SOURCEID == sid ) s_table = season_cut(table, sid, season) ra1, ra2 = 314.36, 315.77 dec1, dec2 = 52.02, 52.92 rabox = [ra1, ra1, ra2, ra2, ra1] decbox = [dec1, dec2, dec2, dec1, dec1] # print w # print table.RA[w] ## print s_table.RA # sra, sdec = table.RA[w][0], table.DEC[w][0] sra, sdec = s_table.RA[0], s_table.DEC[0] date = s_table.MEANMJDOBS - 54579 jcol = s_table.JAPERMAG3 hcol = s_table.HAPERMAG3 kcol = s_table.KAPERMAG3 jerr = s_table.JAPERMAG3ERR herr = s_table.HAPERMAG3ERR kerr = s_table.KAPERMAG3ERR plt.clf() # This is the size of the lightcurve box if box: plt.axes([0.05, 0.1, 0.7, 0.8]) if "j" in bands: plt.errorbar(date, jcol, yerr=jerr, fmt="b-o", ecolor="k", label="J-band, RMS: %f" % jcol.std()) if "h" in bands: plt.errorbar(date, hcol, yerr=herr, fmt="g-o", ecolor="k", label="H-band, RMS: %f" % hcol.std()) if "k" in bands: plt.errorbar(date, kcol, yerr=kerr, fmt="r-o", ecolor="k", label="K-band, RMS: %f" % kcol.std()) plt.gca().invert_yaxis() if text: plt.legend() """ if 'j' in bands: plt.text(20,jcol.max()+.1,"J-band RMS: %f" % jcol.std()) if 'h' in bands: plt.text(20,hcol.max()+.1,"H-band RMS: %f" % hcol.std()) if 'k' in bands: plt.text(20,kcol.max()+.1,"K-band RMS: %f" % kcol.std()) """ plt.ylabel("WFCAM magnitude") plt.xlabel("Julian days since 04/23/2008") plt.title("J, H, K with errorbars. Source ID %d." % sid) plt.suptitle(sup) # This is the size of the position box if box: plt.axes([0.775, 0.55, 0.2, 0.35]) plt.plot(rabox, decbox) plt.plot(np.degrees(sra), np.degrees(sdec), "rD") dx = 1 / 8.0 * (ra2 - ra1) dy = 1 / 8.0 * (dec2 - dec1) arrx = ra1 + 2 * dx arry = dec1 + 6 * dy plt.arrow(arrx, arry, dx, 0) plt.arrow(arrx, arry, 0, dy) plt.gca().invert_xaxis() plt.ylabel("Dec, degrees") plt.xlabel("RA, degrees") plt.axis("off") if outfile == "": plt.show() else: plt.savefig(outfile) return
def plot_5(table, sid, outfile="", name="?", season=123, png_too=False): """ Plots all five lightcurves of one star: J, H, K, J-H, H-K, on one page, for one season. Inputs: table -- atpy table with time series photometry sid -- WFCAM source ID of star to plot Optional inputs: outfile -- a place to save the file name -- a short string to display as a name atop the plot season -- the usual png_too -- if True, saves both a PDF and a PNG of the outfile (note - iff True, don't give a filename extension) Note: heavy edits have made that not strictly true. """ # Loading up the relevant datapoints to plot (note I set flags to 0) s_table = season_cut(table, sid, season, flags=0) if len(s_table) == 0: print "no data here" return date = s_table.MEANMJDOBS - 54579 jcol = s_table.JAPERMAG3 hcol = s_table.HAPERMAG3 kcol = s_table.KAPERMAG3 jmh = s_table.JMHPNT hmk = s_table.HMKPNT jerr = s_table.JAPERMAG3ERR herr = s_table.HAPERMAG3ERR kerr = s_table.KAPERMAG3ERR jmherr = s_table.JMHPNTERR hmkerr = s_table.HMKPNTERR kdex = 1.71 * hmk - jmh kdexerr = np.sqrt(jerr ** 2 + herr ** 2 + kerr ** 2) # Done loading up data. # Let's create that plot. fig = plt.figure(num=None, figsize=(8.5, 11), dpi=80, facecolor="w", edgecolor="k") left = 0.125 # don't touch width = 0.775 # these two. height = 0.8 / 5 bottom = np.arange(0.1, 0.9, height) tri_height = 0.8 / 10 tri_bottom = np.arange(0.1, 0.9, tri_height) ks = 0.05 # this is the size of the kdex box ax_hmk = fig.add_axes([left, bottom[0], width, tri_height]) ax_kdex = fig.add_axes([left, tri_bottom[1], width, tri_height], sharex=ax_hmk) # ax_jmh = fig.add_axes( [left, tri_bottom[2], width, tri_height] # ,sharex=ax_hmk) ax_k = fig.add_axes([left, bottom[1], width, height], sharex=ax_hmk) ax_h = fig.add_axes([left, bottom[2], width, height], sharex=ax_hmk) ax_j = fig.add_axes([left, bottom[3], width, height], sharex=ax_hmk) ax_traj = fig.add_subplot(5, 2, 1) ax_small_traj = fig.add_subplot(5, 2, 2) # ax_thumb= fig.add_subplot(6,3,3) # Plot J-band: ax_j.errorbar(date, jcol, yerr=jerr, fmt="b-o", ecolor="k") ax_j.invert_yaxis() # ax_j.set_xticklabels([]) # Plot H-band: ax_h.errorbar(date, hcol, yerr=herr, fmt="g-o", ecolor="k") ax_h.invert_yaxis() # Plot K-band: ax_k.errorbar(date, kcol, yerr=kerr, fmt="r-o", ecolor="k") ax_k.invert_yaxis() # Plot J-H color: # ax_jmh.errorbar( date, jmh, yerr=jmherr, fmt='k-o', ecolor='k' ) # Plot K dex: ax_kdex.errorbar(date, kdex, yerr=kdexerr, fmt="k-o", ecolor="k") # plot a dotted line: xs = [date.min(), date.max()] ys = [0.1, 0.1] ax_kdex.plot(xs, ys, "r--") # plot red dots on disky nights: disk = np.where(kdex > 0.1) ax_kdex.plot(date[disk], kdex[disk], "ro") # Plot H-K color: ax_hmk.errorbar(date, hmk, yerr=hmkerr, fmt="k-o", ecolor="k") # Plot the trajectory thingy! plot_trajectory_core(ax_traj, hmk, jmh, date) plot_trajectory_core(ax_small_traj, hmk, jmh, date, ms=False) # Done plotting. plt.setp(ax_j.get_xticklabels(), visible=False) plt.setp(ax_h.get_xticklabels(), visible=False) plt.setp(ax_k.get_xticklabels(), visible=False) # plt.setp(ax_jmh.get_xticklabels(), visible=False) plt.setp(ax_kdex.get_xticklabels(), visible=False) # Now let's create labelling information! ax_hmk.set_xlabel("Time (JD since 04/23/2008)") ax_j.set_ylabel("J mag") ax_h.set_ylabel("H mag") ax_k.set_ylabel("K mag") # ax_jmh.set_ylabel( "J-H color" ) ax_hmk.set_ylabel("H-K color") ax_kdex.set_ylabel("K excess") jmean = jcol.mean() hmean = hcol.mean() kmean = kcol.mean() jrms, hrms, krms = jcol.std(), hcol.std(), kcol.std() sra, sdec = s_table.RA[0], s_table.DEC[0] sPosition = coords.Position((sra, sdec), units="rad") sPositionString = sPosition.hmsdms() # i am aware that the following line is SUCH A MESS big_title = ( ("Object %s.\t" % name) + (r"$J_{mean} =$ %.2f, $H_{mean} =$ %.2f, $K_{mean} =$ %.2f, " % (jmean, hmean, kmean)) + "\nSeason %d \t" % season + r"$J_{RMS} =$ %.3f, $H_{RMS} =$ %.3f, $K_{RMS} =$ %.3f" % (jrms, hrms, krms) ) ax_j.annotate( big_title, xy=(0.5, 0.955), fontsize=15, xycoords="figure fraction", horizontalalignment="center", verticalalignment="top", ) plt.suptitle("Position: %s, Source ID %d." % (sPositionString, sid)) if outfile == "": plt.show() else: if png_too: plt.savefig(outfile + ".pdf") plt.savefig(outfile + ".png") plt.close() else: plt.savefig(outfile) plt.close()
def plot_page_periods(table, sid, outfile="", name="?", season=123, png_too=False): """ Plot one comprehensive page of periodicity information for one source in WFCAM time-series JHK data. INPUTS: table: An atpy table with WFCAM time-series photometry sid: A 13-digit WFCAM source ID OPTIONAL INPUTS: outfile: an output filename, including path and filetype extension, to save plot to (rather than plot interactively) name: a nickname/designation for your source season: which season to plot? 1, 2, 3, or all OUTPUTS: Returns nothing; optionally saves an output plot. PROCEDURE: This function calls the Lomb Scargle period-finding algorithm and the Palmer fast chi-square minimization period-finding algorithm to search for periods in the source, in each band. Then it plots the periodogram and the lightcurve folded by the two best periods (lomb period and palmer period). """ # 1. Loading up the relevant datapoints to plot (note I set flags to 0) s_table = season_cut(table, sid, season, flags=0) if len(s_table) < 2: print "no data here" return date = s_table.MEANMJDOBS - 54579 class Band: pass j = Band() h = Band() k = Band() jmh = Band() hmk = Band() kdex = Band() bands = [j, h, k, jmh, kdex, hmk] j.col = s_table.JAPERMAG3 h.col = s_table.HAPERMAG3 k.col = s_table.KAPERMAG3 jmh.col = s_table.JMHPNT hmk.col = s_table.HMKPNT j.err = s_table.JAPERMAG3ERR h.err = s_table.HAPERMAG3ERR k.err = s_table.KAPERMAG3ERR jmh.err = s_table.JMHPNTERR hmk.err = s_table.HMKPNTERR kdex.col = 1.71 * hmk.col - jmh.col kdex.err = np.sqrt(j.err ** 2 + h.err ** 2 + k.err ** 2) # Done loading up data. # 2. Compute periods and basic statistics # a. Overall stetson variability stet = stetson.S(j.col, j.err, h.col, h.err, k.col, k.err) for b in bands: # b. Lomb-scargle periodogram for each band b.lsp = lsp(date, b.col, 6.0, 6.0) b.lsp_freq = b.lsp[0] b.lsp_power = b.lsp[1] Jmax = lsp_mask(b.lsp_freq, b.lsp_power) b.lsp_per = 1.0 / b.lsp[0][Jmax] print "actually using timing 2" print b.lsp_per # deprecated: # b.lsp_per = 1./ b.lsp[0][b.lsp[3]] # c. Fast Chi-squared period for each band b.fx2_per = 1.0 / test_analyze(date, b.col, b.err) # confirmed syntax # ok, now as a test let's print these quantities that we just calculated # print "Stetson index: " + str(stet) # for b, n in zip(bands, ('j','h','k', 'j-h','h-k','kdex')): # print n.upper() + " band LSP period: " + str(b.lsp_per) # print n.upper() + " band fx2 period: " + str(b.fx2_per) # I gotta silence the output of chi whatever. This may involve some serious popen whatever shit. (or just removing a print statement somewhere...) # 3. Create the canvas fig = plt.figure(num=None, figsize=(8.5, 11), dpi=80, facecolor="w", edgecolor="k") # My first approach: using subplots rather than custom coding qs = 3 * np.arange(6) for b, q in zip(bands, qs): # qs: something about dimension parameters: # b.ax1 = fig.add_axes b.ax1 = fig.add_subplot(6, 3, q + 1) b.ax2 = fig.add_subplot(6, 3, q + 2) b.ax3 = fig.add_subplot(6, 3, q + 3) b.ax1.plot(1.0 / b.lsp_freq, b.lsp_power) b.ax1.set_xscale("log") colors = ("b", "g", "r") for b, c in zip((j, h, k), colors): plot_phase_core(b.ax2, date, b.col, b.err, b.lsp_per, color=c) plot_phase_core(b.ax3, date, b.col, b.err, b.fx2_per, color=c) b.ax2.invert_yaxis() b.ax3.invert_yaxis() for b in (jmh, kdex, hmk): plot_phase_core(b.ax2, date, b.col, b.err, b.lsp_per) plot_phase_core(b.ax3, date, b.col, b.err, b.fx2_per) if b is kdex: # plot a dotted line: xs = [-0.25, 1.25] ys = [0.1, 0.1] b.ax2.plot(xs, ys, "r--") b.ax3.plot(xs, ys, "r--") # plot red dots on disky nights: disk = np.where(kdex.col > 0.1) if date[disk].size > 0: plot_phase_core(b.ax2, date[disk], b.col[disk], b.err[disk], b.lsp_per, color="r") plot_phase_core(b.ax3, date[disk], b.col[disk], b.err[disk], b.fx2_per, color="r") jmean = j.col.mean() hmean = h.col.mean() kmean = k.col.mean() jrms, hrms, krms = j.col.std(), h.col.std(), k.col.std() sra, sdec = s_table.RA[0], s_table.DEC[0] sPosition = coords.Position((sra, sdec), units="rad") sPositionString = sPosition.hmsdms() # I'm testing an invisible big axes thing for my title # bigAxes = plt.axes(frameon=False) # plt.xticks([]) # plt.yticks([]) big_title = ( ("Object %s.\t" % name) + (r"$J_{mean} =$ %.2f, $H_{mean} =$ %.2f, $K_{mean} =$ %.2f, " % (jmean, hmean, kmean)) + "\nSeason %d \t" % season + r"$J_{RMS} =$ %.3f, $H_{RMS} =$ %.3f, $K_{RMS} =$ %.3f" % (jrms, hrms, krms) ) mean_per = np.mean([j.lsp_per, h.lsp_per, k.lsp_per, j.fx2_per, h.fx2_per, k.fx2_per]) second_title = ("Stetson Index: %.1f \n" % stet) + ("Average Period: %.2f days\n" % mean_per) # plt.title(big_title) j.ax1.annotate( big_title, xy=(0.025, 0.965), xycoords="figure fraction", horizontalalignment="left", verticalalignment="top" ) j.ax3.annotate( second_title, xy=(0.925, 0.965), xycoords="figure fraction", horizontalalignment="right", verticalalignment="top", ) # Use text and bbox to draw the fitted periods for b in bands: if b.lsp_per > 0.9: b.lsp_per_str = "period: %.2f days" % b.lsp_per else: b.lsp_per_str = "period: %.2f hours" % (b.lsp_per * 24) if b.fx2_per > 0.9: b.fx2_per_str = "period: %.2f days" % b.fx2_per else: b.fx2_per_str = "period: %.2f hours" % (b.fx2_per * 24) plt.text( 0.05, 0.05, b.lsp_per_str, horizontalalignment="left", verticalalignment="bottom", bbox=dict(facecolor="white"), transform=b.ax2.transAxes, ) plt.text( 0.05, 0.05, b.fx2_per_str, horizontalalignment="left", verticalalignment="bottom", bbox=dict(facecolor="white", alpha=0.3), transform=b.ax3.transAxes, ) plt.suptitle("Position: %s, Source ID %d." % (sPositionString, sid)) j.ax1.set_title("Lomb-Scargle Periodogram", fontsize=10) j.ax2.set_title("Best LSP period", fontsize=10) j.ax3.set_title("Best fX2 period", fontsize=10) hmk.ax1.set_xlabel("Period (days)") hmk.ax2.set_xlabel("Phase") hmk.ax3.set_xlabel("Phase") if outfile == "": plt.show() else: if png_too: plt.savefig(outfile + ".pdf") plt.savefig(outfile + ".png") plt.close() else: plt.savefig(outfile) plt.close() return
def lsp_power (table, sid, outfile='', name='', season=123, png_too=False): """ Plots J, H, K periodograms for one star. Inputs: table -- atpy table with time series photometry sid -- WFCAM source ID of star to plot Optional inputs: outfile -- a place to save the file name -- a short string to display as a name atop the plot season -- the usual png_too -- if True, saves both a PDF and a PNG of the outfile (note - iff True, don't give a filename extension) """ # Loading up the relevant datapoints to plot (note I set flags to 0) s_table = season_cut(table, sid, season, flags=0) if len(s_table) < 2: print "no data here" return date = s_table.MEANMJDOBS - 54579 jcol = s_table.JAPERMAG3 hcol = s_table.HAPERMAG3 kcol = s_table.KAPERMAG3 # jmh = s_table.JMHPNT # hmk = s_table.HMKPNT # jerr = s_table.JAPERMAG3ERR # herr = s_table.HAPERMAG3ERR # kerr = s_table.KAPERMAG3ERR # jmherr=s_table.JMHPNTERR # hmkerr=s_table.HMKPNTERR jlsp = lsp(date, jcol, 6., 6.) hlsp = lsp(date, hcol, 6., 6.) klsp = lsp(date, kcol, 6., 6.) j_lsp_freq = jlsp[0] h_lsp_freq = hlsp[0] k_lsp_freq = klsp[0] j_lsp_power = jlsp[1] h_lsp_power = hlsp[1] k_lsp_power = klsp[1] # best periods, filtered by the lsp_mask j_lsp_per = 1./ j_lsp_freq[ lsp_mask( j_lsp_freq, j_lsp_power) ] h_lsp_per = 1./ h_lsp_freq[ lsp_mask( h_lsp_freq, h_lsp_power) ] k_lsp_per = 1./ k_lsp_freq[ lsp_mask( k_lsp_freq, k_lsp_power) ] fig = plt.figure(figsize = (10, 6), dpi=80, facecolor='w', edgecolor='k') ax_j = fig.add_subplot(3,1,1) ax_h = fig.add_subplot(3,1,2, sharex=ax_j) ax_k = fig.add_subplot(3,1,3, sharex=ax_j) ax_j.plot(1./j_lsp_freq, j_lsp_power, 'b') ax_h.plot(1./h_lsp_freq, h_lsp_power, 'g') ax_k.plot(1./k_lsp_freq, k_lsp_power, 'r') ax_j.set_xscale('log') ax_h.set_xscale('log') ax_k.set_xscale('log') ax_j.set_title(name) ax_k.set_xlabel("Period (days)") ax_h.set_ylabel("Periodogram Power") # bottom = 0.1 # height = .25 # left = 0.075 # width = 0.5 # ax_k = fig.add_axes( (left, bottom, width, height) ) # ax_h = fig.add_axes( (left, bottom+.3, width, height), sharex=ax_k ) # ax_j = fig.add_axes( (left, bottom+.6, width, height), sharex=ax_k ) # ax_jhk = fig.add_axes( (.65, bottom, .3, .375) ) # ax_khk = fig.add_axes( (.65, bottom+.475, .3, .375) ) # # Plot J-band: # ax_j.errorbar( date, jcol, yerr=jerr, fmt='bo', ecolor='k') # ax_j.invert_yaxis() # # Plot H-band: # ax_h.errorbar( date, hcol, yerr=herr, fmt='go', ecolor='k' ) # ax_h.invert_yaxis() # # Plot K-band: # ax_k.errorbar( date, kcol, yerr=kerr, fmt='ro', ecolor='k' ) # ax_k.invert_yaxis() # # Plot J-H vs H-K # plot_trajectory_core( ax_jhk, hmk, jmh, date ) # # Plot K vs H-K # plot_trajectory_core( ax_khk, hmk, kcol, date , ms=False, ctts=False) # gonna update this so that it properly uses K-band main sequence line # ax_khk.invert_yaxis() # # Hide the bad labels... # plt.setp(ax_j.get_xticklabels(), visible=False) # plt.setp(ax_h.get_xticklabels(), visible=False) # # Label stuff # ax_k.set_xlabel( "Time (JD since 04/23/2008)" ) # ax_j.set_ylabel( "J",{'rotation':'horizontal', 'fontsize':'large'} ) # ax_h.set_ylabel( "H",{'rotation':'horizontal', 'fontsize':'large'} ) # ax_k.set_ylabel( "K",{'rotation':'horizontal', 'fontsize':'large'} ) # ax_jhk.set_xlabel( "H-K" ) # ax_jhk.set_ylabel( "J-H")#, {'rotation':'horizontal'}) # ax_khk.set_xlabel( "H-K" ) # ax_khk.set_ylabel( "K")#, {'rotation':'horizontal'}) if outfile == '': plt.show() else: if png_too: plt.savefig(outfile+".pdf") plt.savefig(outfile+".png") plt.close() else: plt.savefig(outfile) plt.close()
def phase (table, sid, period='auto', outfile='', season=123, offset=0, flags=0, png_too=False): """ Plots J, H, K lightcurves, as well as JHK color-color and color-mag trajectories, for one star. Inputs: table -- atpy table with time series photometry sid -- WFCAM source ID of star to plot Optional inputs: outfile -- a place to save the file name -- a short string to display as a name atop the plot season -- the usual png_too -- if True, saves both a PDF and a PNG of the outfile (note - iff True, don't give a filename extension) flags -- whether to remove bad observations from plotting, and where to draw the cutoff. """ # Loading up the relevant datapoints to plot # (note I set 'flags' as a keyword) s_table = season_cut(table, sid, season, flags=flags) if len(s_table) == 0: print "no data here" return date = s_table.MEANMJDOBS - 54579 jcol = s_table.JAPERMAG3 hcol = s_table.HAPERMAG3 kcol = s_table.KAPERMAG3 jmh = s_table.JMHPNT hmk = s_table.HMKPNT jerr = s_table.JAPERMAG3ERR herr = s_table.HAPERMAG3ERR kerr = s_table.KAPERMAG3ERR jmherr=s_table.JMHPNTERR hmkerr=s_table.HMKPNTERR # Let's figure out the period. if period == 'auto': period = 1./test_analyze(date, jcol, jerr) print period elif period == 'lsp': lomb = lsp(date,jcol,6.,6.) lsp_freq = lomb[0] lsp_power= lomb[1] Jmax = lsp_mask( lsp_freq, lsp_power) lsp_per = 1./ lomb[0][Jmax] period = lsp_per print period if period < 1: period_string = "%f hours" % (period*24) print period_string else: period_string = "%f days" % period phase = ((date % period) / period + offset) % 1. fig = plt.figure(figsize = (10, 6), dpi=80, facecolor='w', edgecolor='k') bottom = 0.1 height = .25 left = 0.075 width = 0.5 ax_k = fig.add_axes( (left, bottom, width, height) ) ax_h = fig.add_axes( (left, bottom+.3, width, height), sharex=ax_k ) ax_j = fig.add_axes( (left, bottom+.6, width, height), sharex=ax_k ) ax_jhk = fig.add_axes( (.65, bottom, .3, .375) ) ax_khk = fig.add_axes( (.65, bottom+.475, .3, .375) ) # Plot J-band: plot_phase_core( ax_j, date, jcol, jerr, period, offset=offset, color='b') # ax_j.errorbar( date, jcol, yerr=jerr, fmt='bo', ecolor='k') ax_j.invert_yaxis() # Plot H-band: plot_phase_core( ax_h, date, hcol, herr, period, offset=offset, color='g') # ax_h.errorbar( date, hcol, yerr=herr, fmt='go', ecolor='k' ) ax_h.invert_yaxis() # Plot K-band: plot_phase_core( ax_k, date, kcol, kerr, period, offset=offset, color='r') # ax_k.errorbar( date, kcol, yerr=kerr, fmt='ro', ecolor='k' ) ax_k.invert_yaxis() # Plot J-H vs H-K plot_trajectory_core( ax_jhk, hmk, jmh, phase , label='Phase') # Plot K vs H-K plot_trajectory_core( ax_khk, hmk, kcol, phase, label='Phase', ms=False, ctts=False) # gonna update this so that it properly uses K-band main sequence line ax_khk.invert_yaxis() # Hide the bad labels... plt.setp(ax_j.get_xticklabels(), visible=False) plt.setp(ax_h.get_xticklabels(), visible=False) # Label stuff ax_k.set_xlabel( "Phase (Period = %s)" % period_string ) ax_j.set_ylabel( "J",{'rotation':'horizontal', 'fontsize':'large'} ) ax_h.set_ylabel( "H",{'rotation':'horizontal', 'fontsize':'large'} ) ax_k.set_ylabel( "K",{'rotation':'horizontal', 'fontsize':'large'} ) ax_jhk.set_xlabel( "H-K" ) ax_jhk.set_ylabel( "J-H")#, {'rotation':'horizontal'}) ax_khk.set_xlabel( "H-K" ) ax_khk.set_ylabel( "K")#, {'rotation':'horizontal'}) if outfile == '': plt.show() else: if png_too: plt.savefig(outfile+".pdf") plt.savefig(outfile+".png") plt.savefig(outfile+".eps") plt.close() else: plt.savefig(outfile) plt.close() return period
def lc (table, sid, outfile='', name='?', season=123, png_too=False, flags=0): """ Plots J, H, K lightcurves, as well as JHK color-color and color-mag trajectories, for one star. Inputs: table -- atpy table with time series photometry sid -- WFCAM source ID of star to plot Optional inputs: outfile -- a place to save the file name -- a short string to display as a name atop the plot season -- the usual png_too -- if True, saves both a PDF and a PNG of the outfile (note - iff True, don't give a filename extension) flags -- whether to remove bad observations from plotting, and where to draw the cutoff. """ # Loading up the relevant datapoints to plot # (note I set 'flags' as a keyword) s_table = season_cut(table, sid, season, flags=flags) if len(s_table) == 0: print "no data here" return date = s_table.MEANMJDOBS - 54579 jcol = s_table.JAPERMAG3 hcol = s_table.HAPERMAG3 kcol = s_table.KAPERMAG3 jmh = s_table.JMHPNT hmk = s_table.HMKPNT jerr = s_table.JAPERMAG3ERR herr = s_table.HAPERMAG3ERR kerr = s_table.KAPERMAG3ERR jmherr=s_table.JMHPNTERR hmkerr=s_table.HMKPNTERR fig = plt.figure(figsize = (10, 6), dpi=80, facecolor='w', edgecolor='k') bottom = 0.1 height = .25 left = 0.075 width = 0.5 ax_k = fig.add_axes( (left, bottom, width, height) ) ax_h = fig.add_axes( (left, bottom+.3, width, height), sharex=ax_k ) ax_j = fig.add_axes( (left, bottom+.6, width, height), sharex=ax_k ) ax_jhk = fig.add_axes( (.65, bottom, .3, .375) ) ax_khk = fig.add_axes( (.65, bottom+.475, .3, .375) ) # Plot J-band: ax_j.errorbar( date, jcol, yerr=jerr, fmt='bo', ecolor='k') ax_j.invert_yaxis() # Plot H-band: ax_h.errorbar( date, hcol, yerr=herr, fmt='go', ecolor='k' ) ax_h.invert_yaxis() # Plot K-band: ax_k.errorbar( date, kcol, yerr=kerr, fmt='ro', ecolor='k' ) ax_k.invert_yaxis() # Plot J-H vs H-K plot_trajectory_core( ax_jhk, hmk, jmh, date ) # Plot K vs H-K plot_trajectory_core( ax_khk, hmk, kcol, date , ms=False, ctts=False) # gonna update this so that it properly uses K-band main sequence line ax_khk.invert_yaxis() # Hide the bad labels... plt.setp(ax_j.get_xticklabels(), visible=False) plt.setp(ax_h.get_xticklabels(), visible=False) # Label stuff ax_k.set_xlabel( "Time (JD since 04/23/2008)" ) ax_j.set_ylabel( "J",{'rotation':'horizontal', 'fontsize':'large'} ) ax_h.set_ylabel( "H",{'rotation':'horizontal', 'fontsize':'large'} ) ax_k.set_ylabel( "K",{'rotation':'horizontal', 'fontsize':'large'} ) ax_jhk.set_xlabel( "H-K" ) ax_jhk.set_ylabel( "J-H")#, {'rotation':'horizontal'}) ax_khk.set_xlabel( "H-K" ) ax_khk.set_ylabel( "K")#, {'rotation':'horizontal'}) if outfile == '': plt.show() else: if png_too: plt.savefig(outfile+".pdf") plt.savefig(outfile+".png") plt.savefig(outfile+".eps") plt.close() else: plt.savefig(outfile) plt.close()
def make_corrections_table ( constants, table ): ''' Creates a table of photometric corrections per chip per night. Inputs: constants -- an ATpy table which gives 10 constant stars per chip. Columns: "SOURCEID" (13-digit int), "chip" (1-16 int) table -- an ATpy table with time-series photometry Returns: an ATpy table with the following format: THE CORRECTIONS TABLE: night chip correction_J corr_H corr_K '54582.6251067' 3 +0.13 +0.07 -0.03 ''' # rb.meanr(x) is the robust mean # First - let's compute every constant star's robust mean in each band. # And keep track of them. j_meanr = np.zeros(constants.SOURCEID.size) * 1. h_meanr = np.zeros(constants.SOURCEID.size) * 1. k_meanr = np.zeros(constants.SOURCEID.size) * 1. for sid, i in zip(constants.SOURCEID, range(constants.SOURCEID.size)): stable = season_cut(table, sid, 123, flags=0) j_meanr[i] = rb.meanr( stable.JAPERMAG3 ) h_meanr[i] = rb.meanr( stable.HAPERMAG3 ) k_meanr[i] = rb.meanr( stable.KAPERMAG3 ) del stable try: constants.add_column('j_meanr', j_meanr) constants.add_column('h_meanr', h_meanr) constants.add_column('k_meanr', k_meanr) print "computed robust-mean magnitude for each constant star" except: print "looks like you already computed robust-mean magnitudes" # Second - Calculate mean(r) deviations for each chip for each night chip_list = list( set( constants.chip ) ) corrections_list = [] # add tables to this list, join them up at the end for chip in chip_list: local_network = constants.where(constants.chip == chip) # so I'm taking all of the local stars, and for every night... # do i calculate it by each star first, or each night first? # each night first I think would work better. #let's grab a slice of the big table corresponding only to our # favorite sources' photometry. # by joining together the season_cuts from all 10 sources! # no that's stupid. Use an "or |" operator! this is gonna be painful cids= local_network.SOURCEID ids = table.SOURCEID #local_table = season_cut( table, local_network[0], 123 ) local_table = data_cut( table, cids, 123, flags=0 ) # aww yeah # local_table = table.where( ( (ids == cids[0]) | # I really, really wish # (ids == cids[1]) | # I knew how to make # (ids == cids[2]) | # this more elegant. # (ids == cids[3]) | # (ids == cids[4]) | # (ids == cids[5]) | # (ids == cids[6]) | # (ids == cids[7]) | # (ids == cids[8]) | # (ids == cids[9]) ) & # (table.JPPERRBITS <= 0) & # (table.HPPERRBITS <= 0) & # (table.KPPERRBITS <= 0) ) # okay, now that i've got the local table... let's get each night's # meanr deviation. # first, let's make some dates to iterate through date_list = list( set( local_table.MEANMJDOBS ) ) # at some point i need to make a structure to save the corrections to ld = len(date_list) date_arr = np.zeros(ld) j_correction = np.zeros(ld) h_correction = np.zeros(ld) k_correction = np.zeros(ld) chip_arr = chip * np.ones(ld, dtype=int) # get each night's correction! for date, j in zip( date_list, range(ld) ): # a temporary place to keep the individual deviations j_deviation = np.zeros_like(cids) * 1. h_deviation = np.zeros_like(cids) * 1. k_deviation = np.zeros_like(cids) * 1. for star, i in zip(cids, range(cids.size) ): star_night_row = local_table.where( (local_table.SOURCEID == star) & (local_table.MEANMJDOBS == date) ) # deviation: the meanr minus that night's magnitude. j_deviation[i] = (constants.j_meanr[constants.SOURCEID==star]- star_night_row.JAPERMAG3 ) h_deviation[i] = (constants.h_meanr[constants.SOURCEID==star]- star_night_row.HAPERMAG3 ) k_deviation[i] = (constants.k_meanr[constants.SOURCEID==star]- star_night_row.KAPERMAG3 ) date_arr[j] = date j_correction[j] = -rb.meanr(j_deviation) h_correction[j] = -rb.meanr(h_deviation) k_correction[j] = -rb.meanr(k_deviation) # make a table for each chip, and (at the end) # add it to the corrections_list. We'll join them up at the end. correction_subtable = atpy.Table(name="The Corrections Table") # add_column( 'name', data ) correction_subtable.add_column('date', date_arr) correction_subtable.add_column('chip', chip_arr) correction_subtable.add_column('j_correction', j_correction) correction_subtable.add_column('h_correction', h_correction) correction_subtable.add_column('k_correction', k_correction) corrections_list.append( correction_subtable ) #whoo, finally! correction_table = corrections_list[0] for subtable in corrections_list[1:] : correction_table.append( subtable ) return correction_table '''