示例#1
0
def do_it_all( table, sid_list, name_list, path='', 
               option=['lc','tables','phase'] ):
    """ 
    Does some stuff. Not sure exactly what yet, but I'll 
    want it to make tons of plots and tables for a list of 
    SOURCEIDs and their corresponding data.
    
    Parameters
    ----------
    table : atpy.Table 
        The WFCAM time-series data to be extracted
    sid_list : (list or array) of int
        SOURCEIDs of stars to be analyzed
    name_list : list of str
        Names that correspond to each SOURCEID: will be used in
        the filename and title section of each plot, and in the tables
    path : str
        The parent file path to save the output to. 
        Please make sure it has a "/" at the end of it.
    option : list of str, optional
        Which sub-components of this function you'd like to actually
        call. Default is all (lc, tables, phase).

    Returns
    -------
    I don't know yet. Probably nothing.
    Produces a bunch of files, though!

    
    Notes:
    The input data must already be cleaned via some other method.
    
    """

    if path=='' or type(path) is not str:
        print "`path` must be a string. Exiting without action."
        return
    
    # Force `path` to have a trailing forward slash
    path = path.rstrip('/')+'/'
    
    ## First, make directories for everything (or try, at least).

    # Structure of directories:
    #  path/lc
    #  path/phase
    #  path/tables
    # within each of those (now it's a *),
    #  path/*/(s1 | s2 | s3 | s123)
    # Within lc/s*, we put the files directly in.
    # Within phase/s*, we do
    #  path/phase/s*/(h_fx2 | h_lsp | j_fx2 | j_lsp | k_fx2 | k_lsp | lsp_power)
    # Within tables/s*, we put the files directly in.

    mkdir_p(path+"lc/")
    mkdir_p(path+"phase/")
    mkdir_p(path+"tables/")

    ss = ['s1', 's2', 's3', 's123']
    types = ['h_fx2', 'h_lsp', 'j_fx2', 'j_lsp', 'k_fx2', 'k_lsp', 'lsp_power']

    for s in ss:
        mkdir_p(path+"lc/"+s)
        mkdir_p(path+"tables/"+s)
        for t in types:
            mkdir_p("%sphase/%s/%s"%(path,s,t))
            
    # We should now be done making directories. Let's test this.
    # Tested! Woo.

    ## Second, let's make tables.

    if 'tables' in option:

        tables = path+"tables/"

        # Make a lookup table. It should have a column with the `name_list`
        # parameter we fed into this function, as well as a column with the 
        # SOURCEIDs.
        # They should be named "SOURCEID" and "Designation", respectively.
    
        lookup = atpy.Table()
        lookup.add_column("SOURCEID", sid_list)
        lookup.add_column("Designation", name_list)
        
        for season, s in zip([1,2,3,123], ss):
            
            # Write the spreadsheet and save it to the relevant directory.
            spread3.spreadsheet_write(table, lookup, season, 
                                          tables+s+'/spreadsheet.fits', 
                                          flags=256, per=True)
            

    # What command do we want to make plots?
    # Probably plot3.lc and plot3.phase, which are going to be almost 
    # identical to plot2 equivalents except that they can handle missing data 
    # and flags and stuff.

    ## Third, make lightcurves.
    # And put the gorram Stetson index in the title!

        
    for season, s in zip([1,2,3,123], ss):

        s_stats = atpy.Table(tables+s+'/spreadsheet.fits')

        for name, sid in zip(name_list, sid_list):
            # The specific plot command we use here depends a lot
            # on what functions are available.
            tplot.lc(table, sid, season=season, name=name, #flags=16,
                     outfile=path+"lc/"+s+"/"+name, png_too=True) #png, eps, pdf




        # A bunch of the following code will be substantially rewritten
        # once "spread3" is functional.

        # Well... spread3 is now functional!
            for t in types:
                if t == 'lsp_power':
                    tplot.lsp_power(table, sid, season=season, name=name,
                                    outfile=path+"phase/"+s+"/lsp_power/"+name, 
                                    png_too=True) 

                else:
                    per = s_stats.data[t+"_per"][s_stats.SOURCEID == sid]
                    tplot.phase(table, sid, period=per, season=season, 
                                name=name,
                                outfile=path+"phase/"+s+"/"+t+"/"+name, 
                                png_too=True) 

                # elif t == 'k_fx2':
                #     tplot.phase(table, sid, season=season, name=name,
                #                 outfile=path+"phase/"+s+"/k_fx2/"+name, 
                #                 png_too=True) 
                # elif t == 'k_lsp':
                #     tplot.phase(table, sid, season=season, name=name,
                #                 period='lsp',
                #                 outfile=path+"phase/"+s+"/k_lsp/"+name, 
                #                 png_too=True) 

                # else:
                #     pass


    return
def do_it_all_cygob7(lc=True, phase=True):
    """
    Creates Lightcurve plots for WISE, Aspin, and RWA sources.

    For each (season), (period-type), (subcategory of stars), do stuff!
    
    """

    # Preliminary stuff
    ## First, make directories for everything (or try, at least).

    # Structure of directories:
    #  lc_path/lc
    #  lc_path/phase
    #  lc_path/tables
    # within each of those (now it's a *),
    #  lc_path/*/(s1 | s2 | s3 | s123)
    # Within lc/s*, we put the files directly in.
    # Within phase/s*, we do
    #  lc_path/phase/s*/(h_fx2 | h_lsp | j_fx2 | j_lsp | k_fx2 | k_lsp | lsp_power)
    # Within tables/s*, we put the files directly in.

    # mkdir_p(lc_path+"lc/")
    # mkdir_p(lc_path+"phase/")
    # mkdir_p(lc_path+"tables/")

    ss = ["s1", "s2", "s3", "s123"]
    # types = ['h_fx2', 'h_lsp', 'j_fx2', 'j_lsp', 'k_fx2', 'k_lsp', 'lsp_power']
    groups = ["Wise", "Aspin", "transition", "Wise_extras", "RWA_sources"]

    # for s in ss:
    #     mkdir_p(lc_path+"lc/"+s)
    #     mkdir_p(lc_path+"tables/"+s)
    #     for t in types:
    #         mkdir_p("%sphase/%s/%s"%(lc_path,s,t))

    for g in groups:
        for s in ss:
            mkdir_p(lc_path + g + "/lc/" + s)

    # We should now be done making directories. Let's test this.
    # tested!

    # First: do all the straight lightcurves

    if lc:
        for season, s_name in zip([1, 2, 3, 123], ss):

            print season, "is the current season"

            # wise disks
            for s, n in zip(wise_disks[rwd], wise_disks_names[rwd]):
                fig = plot3.lc(
                    watso,
                    s,
                    season=season,
                    name=str(n),
                    color_slope=True,
                    date_offset=54579,
                    custom_xlabel="Time (JD since 04/23/2008)",
                    plot_warn=False,
                    outfile=lc_path + "Wise/lc/" + s_name + "/" + str(n) + ".eps",
                    png_too=False,
                )

                if fig == None:
                    print "dude %s failed to plot right" % str(s)

            # wise special case
            for s, n in zip(wise_v, wise_v_names):
                fig = plot3.lc(
                    data,
                    s,
                    season=season,
                    name=str(n),
                    color_slope=True,
                    date_offset=54579,
                    custom_xlabel="Time (JD since 04/23/2008)",
                    outfile=lc_path + "Wise/lc/" + s_name + "/" + str(n) + ".eps",
                    png_too=False,
                )

            # aspins
            for s, n in zip(aspin_sources[ras], aspin_sources_names[ras]):
                fig = plot3.lc(
                    watso,
                    s,
                    season=season,
                    name=str(n),
                    color_slope=True,
                    date_offset=54579,
                    custom_xlabel="Time (JD since 04/23/2008)",
                    outfile=lc_path + "Aspin/lc/" + s_name + "/" + str(n) + ".eps",
                    png_too=False,
                )

                if fig == None:
                    print "dude %s failed to plot right" % str(s)

            # wise trans
            for s, n in zip(wise_trans[rwt], wise_trans_names[rwt]):
                fig = plot3.lc(
                    watso,
                    s,
                    season=season,
                    name=str(n),
                    color_slope=True,
                    date_offset=54579,
                    custom_xlabel="Time (JD since 04/23/2008)",
                    outfile=lc_path + "transition/lc/" + s_name + "/" + str(n) + ".eps",
                    png_too=False,
                )

                if fig == None:
                    print "dude %s failed to plot right" % str(s)

            # wise extras
            for s, n in zip(wise_extras[rwe], wise_extras_names[rwe]):
                fig = plot3.lc(
                    data,
                    s,
                    season=season,
                    name=str(n),
                    color_slope=True,
                    date_offset=54579,
                    custom_xlabel="Time (JD since 04/23/2008)",
                    outfile=lc_path + "Wise_extras/lc/" + s_name + "/" + str(n) + ".eps",
                    png_too=False,
                )

                if fig == None:
                    fig2 = plot3.lc(
                        welo,
                        s,
                        season=season,
                        name=str(n),
                        color_slope=True,
                        date_offset=54579,
                        custom_xlabel="Time (JD since 04/23/2008)",
                        outfile=lc_path + "Wise_extras/lc/" + s_name + "/" + str(n) + ".eps",
                        png_too=False,
                    )
                    if fig2 == None:
                        print "dude %s failed to plot right" % str(s)

            print "Now for RWA sources:"

            for s, n in zip(rwa_sources, rwa_names):
                fig = plot3.lc(
                    rwa_data,
                    s,
                    season=season,
                    name=str(n),
                    color_slope=True,
                    date_offset=54579,
                    custom_xlabel="Time (JD since 04/23/2008)",
                    outfile=lc_path + "RWA_sources/lc/" + s_name + "/" + str(n) + ".eps",
                    png_too=False,
                )

                if fig == None:
                    print "dude %s failed to plot right" % str(s)

        print "did that."

    if phase:
        # We're making lightcurves for TEN specific stars.

        # eight RWA stars:
        rwa_phase_list = [
            {"name": "RWA 1", "season": 123, "per": 9.114109},
            {"name": "RWA 3", "season": 123, "per": 17.87},
            {"name": "RWA 4", "season": 3, "per": 6.337136},
            {"name": "RWA 13", "season": 3, "per": 9.372071},
            {"name": "RWA 21", "season": 123, "per": 3.724390},
            {"name": "RWA 23", "season": 123, "per": 2.806367},
            {"name": "RWA 26", "season": 123, "per": 5.800502},
            {"name": "RWA 28", "season": 123, "per": 4.810614},
        ]

        # one each WISE and Aspin
        wise_phase = {"name": 31848, "season": 123, "per": 39.556962}

        aspin_phase = {"name": "aspin Cyg 19", "season": 123, "per": 9.521996}

        for d in rwa_phase_list:
            s = rwa_sources[d["name"] == np.array(rwa_names)][0]
            print d["name"], s
            fig = plot3.phase(
                rwa_data,
                s,
                season=d["season"],
                name=d["name"],
                period=d["per"],
                color_slope=True,
                outfile=fig6path + d["name"] + ".eps",
                plot_warn=False,
                period_decimal_places=2,
            )

        for d in [wise_phase]:
            s = wise_disks[d["name"] == wise_disks_names][0]
            fig = plot3.phase(
                watso,
                s,
                season=d["season"],
                name=d["name"],
                period=d["per"],
                color_slope=True,
                outfile=fig6path + "WISE " + str(d["name"]) + ".eps",
                plot_warn=False,
                period_decimal_places=2,
            )

        for d in [aspin_phase]:
            s = aspin_sources[d["name"] == aspin_sources_names][0]
            fig = plot3.phase(
                watso,
                s,
                season=d["season"],
                name=d["name"],
                period=d["per"],
                color_slope=True,
                outfile=fig6path + d["name"] + ".eps",
                plot_warn=False,
                period_decimal_places=2,
            )