Ejemplo n.º 1
0
def calculate_stuff(splits=10, start=0):
    ''' 
    Runs the spreadsheet, first splitting it into `splits` 
    spreadsheets and then joining them. 
    
    '''

    if type(splits) is not int or type(start) is not int:
        raise TypeError


# We are going to split this into 10 smaller pieces through the magic of mod operations! woo.

    split_data = []
    spreadsheets = []

    for i in range(start, splits):
        data_i = data.where(data.SOURCEID % splits == i)

        split_data.append(data_i)

        lookup_i = sp.base_lookup(data_i)

        # The parameter "-1" is the season that tells data_cut not to make
        # any cuts on the data.
        sp_i = sp.spreadsheet_write(data_i,
                                    lookup_i,
                                    -1,
                                    path2 + 'sp%d.fits' % i,
                                    flags=256,
                                    per=True,
                                    graded=False,
                                    rob=True,
                                    colorslope=True)
        # EEEEE this is a flag to come and find this section of code

        try:
            now = datetime.datetime.strftime(datetime.datetime.now(),
                                             "%Y-%m-%d %H:%M:%S")
        except:
            now = 'sometime'
        print "finished chunk %d at %s" % (i, now)
def calculate_stuff( splits = 10, start=0 ):
    ''' 
    Runs the spreadsheet, first splitting it into `splits` 
    spreadsheets and then joining them. 
    
    '''
    
    if type(splits) is not int or type(start) is not int:
        raise TypeError

# We are going to split this into 10 smaller pieces through the magic of mod operations! woo.
    
    split_data = []
    spreadsheets = []

    for i in range(start, splits):
        data_i = data.where(data.SOURCEID % splits == i)
        
        split_data.append(data_i)
        
        lookup_i = sp.base_lookup(data_i)
        
        # The parameter "-1" is the season that tells data_cut not to make 
        # any cuts on the data.
        sp_i = sp.spreadsheet_write(data_i, lookup_i, -1, 
                                    path2+'sp%d.fits'%i, flags=256,
                                    per=True, graded=False, rob=True,
                                    colorslope=True)
        # EEEEE this is a flag to come and find this section of code
        
        try:
            now = datetime.datetime.strftime(datetime.datetime.now(),
                                             "%Y-%m-%d %H:%M:%S")
        except:
            now = 'sometime'
        print "finished chunk %d at %s" % (i, now)
def tables():
    """
    Creates spreadsheets for Wise, Aspin, wise_trans, wise_extras, 
    and rwa_sources that include color-slope terms and robust stats.

    """

    # wise disks
    
    wise_disks_lookup = atpy.Table()
    wise_disks_lookup.add_column("SOURCEID", wise_disks[rwd])
    wise_disks_lookup.add_column("Designation", wise_disks_names[rwd])

    spread3.spreadsheet_write(
        watso, wise_disks_lookup, 0, 
        path2+"Wise/spreadsheet_withcolors.fits",
        flags=256, rob=True, colorslope=True, per=True)

    # wise special case
    wise_v_lookup = atpy.Table()
    wise_v_lookup.add_column("SOURCEID", wise_v)
    wise_v_lookup.add_column("Designation", wise_v_names)

    spread3.spreadsheet_write(
        data, wise_v_lookup, 0, 
        path2+"Wise/spreadsheet_withcolors_wise29434.fits",
        flags=256, rob=True, colorslope=True, per=True)
    
    # aspins
    
    aspin_sources_lookup = atpy.Table()
    aspin_sources_lookup.add_column("SOURCEID", aspin_sources[ras])
    aspin_sources_lookup.add_column("Designation", aspin_sources_names[ras])

    spread3.spreadsheet_write(
        watso, aspin_sources_lookup, 0, 
        path2+"Aspin/spreadsheet_withcolors.fits",
        flags=256, rob=True, colorslope=True, per=True)
    
    # wise trans

    wise_trans_lookup = atpy.Table()
    wise_trans_lookup.add_column("SOURCEID", wise_trans[rwt])
    wise_trans_lookup.add_column("Designation", wise_trans_names[rwt])

    spread3.spreadsheet_write(
        watso, wise_trans_lookup, 0,
        path2+"transition/spreadsheet_withcolors.fits",
        flags=256, rob=True, colorslope=True, per=True)

    # wise extras

    wise_extras_lookup = atpy.Table()
    wise_extras_lookup.add_column("SOURCEID", wise_extras[rwe])
    wise_extras_lookup.add_column("Designation", wise_extras_names[rwe])

    spread3.spreadsheet_write(
        data, wise_extras_lookup, 0,
        path2+"Wise_extras/spreadsheet_withcolors.fits",
        flags=256, rob=True, colorslope=True)

    # special case of whatevers - this is gonna be annoying to disentangle.
    # I'll have to see what the error behavior of statcruncher is when
    # there's no data for a star. Hopefully null values and no crashing.

    welo_lookup = atpy.Table()
    welo_lookup.add_column("SOURCEID", welo_sources)
    welo_lookup.add_column("Designation", welo_names)
    
    spread3.spreadsheet_write(
        welo, welo_lookup, 0,
        path2+"Wise_extras/spreadsheet_withcolors_lonely.fits",
        flags=256, rob=True, colorslope=True)
    
    # rwa dudes

    rwa_lookup = atpy.Table()
    rwa_lookup.add_column("SOURCEID", rwa_sources)
    rwa_lookup.add_column("Designation", rwa_names)

    spread3.spreadsheet_write(
        rwa_data, rwa_lookup, 0,
        path2+"RWA_sources/spreadsheet_withcolors.fits",
        flags=256, rob=True, colorslope=True, per=True)
    
    print "Did the spreadsheets!"
Ejemplo n.º 4
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.
    
    """

    # until we figure out orion seasons...
    season = 0

    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/")
    mkdir_p(path+"tables/")
    for t in types:
        mkdir_p("%sphase/%s"%(path,t))
            
    # We should now be done making directories. Let's test this.
    # Tested! Woo.

    ## Second, let's make tables.

    tables = path+"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+'/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.
        if 'lc' in option:
            tplot.graded_lc(table, sid, season=0, name=name, #flags=16,
                            outfile=path+"lc/"+name, png_too=True,
                            abridged=True, color_slope=True) 
#png, eps, pdf




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

        # Well... spread3 is now functional!
        if 'phase' in option:
            for t in types:
                if t == 'lsp_power':
                    tplot.lsp_power(table, sid, season=0, name=name,
                                    outfile=path+"phase/lsp_power/"+name, 
                                    png_too=True) 
                    
                else:
                    per = s_stats.data[t+"_per"][s_stats.SOURCEID == sid]
                    tplot.graded_phase(table, sid, period=per, season=0, 
                                       name=name, color_slope=True,
                                       outfile=path+"phase/"+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