def mConfig(config, runName, dbDir='.', outputDir='Dithers', nside=128, **kwargs):
    """
    A MAF config for analysis of various dithers applied to an opsim run.

    runName must correspond to the name of the opsim output
        (minus '_sqlite.db', although if added this will be stripped off)

    dbDir is the directory containing the sqlite database
    outputDir is the output directory
    """
    config.modules = ['mafContrib']

    # Setup Database access
    config.outputDir = outputDir
    if runName.endswith('_sqlite.db'):
        runName = runName.replace('_sqlite.db', '')
    sqlitefile = os.path.join(dbDir, runName + '_sqlite.db')
    config.dbAddress ={'dbAddress':'sqlite:///'+sqlitefile}
    config.opsimName = runName
    config.figformat = 'pdf'

    # Connect to the database to fetch some values we're using to help configure the driver.
    opsimdb = utils.connectOpsimDb(config.dbAddress)

    # Fetch the proposal ID values from the database
    propids, propTags = opsimdb.fetchPropInfo()
    if 'WFD' not in propTags:
        propTags['WFD'] = []

    # Construct a WFD SQL where clause (handles the case of multiple propIDs mapping into "WFD").
    wfdWhere = utils.createSQLWhere('WFD', propTags)
    print 'WFD "where" clause: %s' %(wfdWhere)

    # Filter list, and map of colors (for plots) to filters.
    filters = ['u','g','r','i','z','y']
    colors={'u':'m','g':'b','r':'g','i':'y','z':'r','y':'k'}
    filtorder = {'u':1,'g':2,'r':3,'i':4,'z':5,'y':6}

    racol = 'ditheredRA'
    deccol = 'ditheredDec'
    filterlist = ['r', 'i']
    slicerList = []
    for f in filterlist:
        sqlconstraint = "filter = '%s'" %(f)
        sqlconstraint += 'and %s' %(wfdWhere)
        # Set up metrics to run for each dither pattern.
        metricList = []
        metricList.append(configureMetric('mafContrib.GalaxyCountsMetric', kwargs={'nside':nside},
                                          displayDict={'group':'Dithers', 'subgroup':'Galaxy Counts',
                                            'order':filtorder[f]}))
        slicer = configureSlicer('HealpixSlicer', kwargs={'nside':nside, 'spatialkey1':racol, 'spatialkey2':deccol},
                                 constraints=[sqlconstraint], metricDict=makeDict(*metricList),
                                 metadata='Default Dither')
        slicerList.append(slicer)

    config.slicers = makeDict(*slicerList)
    return config
def mConfig(config, runName, dbDir='.', outputDir='Out', **kwargs):
    """
    Set up a MAF config for a very simple, example analysis.
    """

    # Setup Database access
    sqlitefile = os.path.join(dbDir, runName + '_sqlite.db')
    config.dbAddress ={'dbAddress':'sqlite:///'+sqlitefile}
    config.opsimName = runName

    # Set the output directory.
    config.outputDir = outputDir

    # Set up slicerList to store slicers.
    slicerList = []
    # Set parameter for healpix slicer resolution.
    nside = 64    

    # Loop over g and r filters.
    filters = ['g','r']
    for f in filters:
        # Set up metrics and slicers.
        m1 = configureMetric('CountMetric', kwargs={'col':'expMJD','metricName':'NVisits'}, 
                            plotDict={'colorMin':0, 'colorMax':200, 'units':'N Visits'},
                           summaryStats={'MedianMetric':{}, 'RobustRmsMetric':{}})
        m2 = configureMetric('Coaddm5Metric', kwargs={'m5Col':'fiveSigmaDepth'}, 
                            plotDict={'percentileClip':95}, summaryStats={'MedianMetric':{}})
        metricDict = makeDict(m1, m2)
        sqlconstraint = 'filter = "%s"' %(f)
        slicer = configureSlicer('HealpixSlicer',
                                  kwargs={'nside':nside, 'spatialkey1':'fieldRA', 'spatialkey2':'fieldDec'},
                                metricDict=metricDict, constraints=[sqlconstraint,])
        config.slicers=makeDict(slicer)
        slicerList.append(slicer)

    # Bundle together slicers and metrics, and pass to config 
    config.slicers=makeDict(*slicerList)
    # Return config (which then is treated like 'root' from the one-off configs in runFlexibleDriver.py)
    return config
# Let's try to connect to fatboy and run some metrics on stripe 82

from lsst.sims.maf.driver.mafConfig import configureSlicer, configureMetric, makeDict, configureStacker


root.dbAddress={'dbAddress':'mssql+pymssql://clue-1:[email protected]:1433', 'dbClass':'SdssDatabase'}

root.outputDir = 'SDSSDir'
root.opsimName = 'stripe82'
root.verbose = True
root.getConfig = False
slicerList = []
nside = 512


m1 = configureMetric('MeanMetric', kwargs={'col':'psfWidth'})
m2 =  configureMetric('MaxMetric', kwargs={'col':'nStars'}, plotDict={'cbarFormat':'%i'})
m3 =  configureMetric('MaxMetric', kwargs={'col':'nGalaxy'}, plotDict={'cbarFormat':'%i'})
m4 = configureMetric('CountMetric', kwargs={'col':'psfWidth'})


metricDict = makeDict(m1,m2,m3,m4)
sqlconstraint = 'filter="r" and nStars > 0 and nGalaxy > 0'
stacker = configureStacker('SdssRADecStacker')
slicer = configureSlicer('HealpixSDSSSlicer',
                            kwargs={'nside':nside,'spatialkey1':'RA1', 'spatialkey2':'Dec1'},
                            metricDict=metricDict, stackerDict=makeDict(stacker), constraints=[sqlconstraint,])

slicerList.append(slicer)

m1 = configureMetric('MinMetric', kwargs={'col':'Dec1'})
Exemple #4
0
root.outputDir = './ChipGap'
root.dbAddress = {'dbAddress':'sqlite:///ops1_1140_sqlite.db'}
root.opsimName = 'ops1_1140'
#root.dbAddress = {'dbAddress':'sqlite:///opsimblitz1_1133_sqlite.db'}
#root.opsimName = 'opsimblitz1_1133'

root.verbose = True

slicerList=[]
constraints = ['filter="r"']
#constraints = ['filter="r" and night < 100']
# How many Healpix sides to use
nside=128

m1 = configureMetric('CountMetric', kwargs={'col':'expMJD'},
                     plotDict={'percentileClip':80., 'units':'#'},
                     summaryStats={'MeanMetric':{},'RmsMetric':{}, 'SumMetric':{}, 'MedianMetric':{}})
m2 = configureMetric('Coaddm5Metric',
                     plotDict={'zp':27., 'percentileClip':95, 'units':'Co-add m5 - %.1f'%27.},
                     summaryStats={'MeanMetric':{},'RmsMetric':{}, 'MedianMetric':{}})
# Combine metrics in a dictionary
metricDict = makeDict(m1,m2)
# Generate the slicer configuration, passing in the metric configurations and SQL constraints
slicer = configureSlicer('HealpixSlicer',
                          kwargs={"nside":nside,'spatialkey1':"fieldRA", 'spatialkey2':"fieldDec"},
                          metricDict=metricDict, constraints=constraints)
# Add the slicer to the list of slicers
slicerList.append(slicer)

# Turn in the camera to calc chip gaps. Increase the radius to get the chips that poke out at the corners.
slicer = configureSlicer('HealpixSlicer',
# Name of the output table in the database
root.opsimName = 'opsimblitz2_1060'

# Make an empty list to hold all the slicer configs
sliceList = []

# Define the filters we want to loop over
filters = ['u','g','r','i','z','y']
# Make a dict of what colors to use for different filters
colors={'u':'m','g':'b','r':'g','i':'y','z':'Orange','y':'r'}

# Look at the single-visit depth and airmass for observations in each filter and merge
# them into a single histogram
for f in filters:
    m1 = configureMetric('CountMetric', kwargs={'col':'fiveSigmaDepth'}, 
                          histMerge={'histNum':1, 'legendloc':'upper right',
                                     'color':colors[f],'label':'%s'%f, 
                                     'ylabel':'Count'} )
    slicer = configureSlicer('OneDSlicer', kwargs={"sliceColName":'fiveSigmaDepth','binsize':0.1,},
                              metricDict=makeDict(m1), constraints=["filter = '%s'"%(f)]) 
    sliceList.append(slicer)
    m1 = configureMetric('CountMetric', kwargs={'col':'airmass'},
                          histMerge={'histNum':2, 'legendloc':'upper right',
                                     'color':colors[f], 'label':'%s'%f} )
    slicer = configureSlicer('OneDSlicer', kwargs={"sliceColName":'airmass','binsize':0.05},
                              metricDict=makeDict(m1), constraints=["filter = '%s'"%(f)])
    sliceList.append(slicer)




root.slicers = makeDict(*sliceList)
# Here is an example of a very very simple MAF configuration driver script
# to run:
# runDriver.py oneMetricOneSlicer.py

# This script uses the LSST pex_config.  This is executed as a python script, but only things that 
#  start with 'root.' are passed on to the driver script.

# Import MAF helper functions 
from lsst.sims.maf.driver.mafConfig import configureSlicer, configureMetric, makeDict

# Set the output directory
root.outputDir = './OneMetric'
# Set the database to use (the example db included in the git repo)
root.dbAddress = {'dbAddress':'sqlite:///opsimblitz2_1060_sqlite.db'}
# Name of this run (filename base)
root.opsimName = 'ob2_1060'

# Configure a metric to run. Compute the mean on the final delivered seeing.
#Once the mean seeing has been computed everywhere on the sky, compute the RMS as a summary statistic.
metric = configureMetric('MeanMetric', kwargs={'col':'finSeeing'},
                          summaryStats={'RmsMetric':{}})

# Configure a slicer.  Use the Healpixslicer to compute the metric at points in the sky.
#Set the constraint as an empty string so all data is returned.
slicer = configureSlicer('HealpixSlicer', metricDict=makeDict(metric),
                          constraints=[''])

root.slicers = makeDict(slicer)

Exemple #7
0
# getConfig copies OpSim configuration parameters into output directory (if True).
root.getConfig = False
# Setup a list to hold all the slicers we want to run
slicerList=[]

# How many Healpix sides to use
nside=128

# List of SQL constraints.
# If multiple constraints are listed in a slicer object, they are looped over and each one is executed individualy.
constraints = ["filter = \'%s\'"%'r', "filter = \'%s\' and night < 730"%'r']

# Configure a Healpix slicer:
# Configure 2 metrics to run on the Healpix slicer.
m1 = configureMetric('CountMetric', kwargs={'col':'expMJD'},
                     plotDict={'percentileClip':80., 'units':'#'},
                     summaryStats={'MeanMetric':{},'RmsMetric':{}})
m2 = configureMetric('Coaddm5Metric',
                     plotDict={'zp':27., 'percentileClip':95, 'units':'Co-add m5 - %.1f'%27.})
# Combine metrics in a dictionary
metricDict = makeDict(m1,m2)
# Generate the slicer configuration, passing in the metric configurations and SQL constraints
slicer = configureSlicer('HealpixSlicer',
                          kwargs={"nside":nside,'spatialkey1':"fieldRA", 'spatialkey2':"fieldDec"},
                          metricDict=metricDict, constraints=constraints)
# Add the slicer to the list of slicers
slicerList.append(slicer)

# Run the same metrics, but now use the hexdither field positions:
# As before, but new spatialkeys and add a metadata keyword so the previous files don't get overwritten
slicer = configureSlicer('HealpixSlicer',
def mConfig(config, runName, dbDir='.', outputDir='VarOut', nside=16, **kwargs):

    # Tell the driver where to get contributed modules
    config.modules = ['mafContrib']
    # Set the output figure format.
    config.figformat = 'pdf'

    # Set the output directory
    config.outputDir = outputDir

    # Setup Database access
    if runName.endswith('_sqlite.db'):
        runName = runName.replace('_sqlite.db', '')
    sqlitefile = os.path.join(dbDir, runName + '_sqlite.db')
    config.dbAddress ={'dbAddress':'sqlite:///'+sqlitefile}
    config.opsimName = runName
    config.figformat = 'pdf'

    config.verbose = True

    # Filter list, and map of colors (for plots) to filters.
    filters = ['u','g','r','i','z','y']
    colors={'u':'m','g':'b','r':'g','i':'y','z':'r','y':'k'}
    filtorder = {'u':1,'g':2,'r':3,'i':4,'z':5,'y':6}

    # Set parameter for healpix resolution.
    nside = nside
    # Set filters to use.
    filterlist = ['r']
    # Set the number of years to use.
    nyears = 3
    nnights = int(nyears * 365)

    for f in filterlist:
        # Set up the sqlconstraint.
        sqlconstraint = 'filter=\'%s\' and night<%d' %(f, nnights)
        metriclist = []

        # Configure the period deviation metric to run. Compute the recovered period for each HEALPIX.
        # Once the period has been computed everywhere on the sky, compute the mean and RMS as a summary statistic.
        mkwargs = {'col':'expMJD', 'periodMin':2, 'periodMax':10., 'nPeriods':5,
                    'metricName':'ShortPeriodDeviations'}
        metriclist.append(configureMetric('mafContrib.PeriodDeviationMetric', kwargs=mkwargs,
                                    summaryStats={'MeanMetric':{}, 'RmsMetric':{}},
                                    displayDict={'group':'Cadence', 'subgroup':'Period Recovery', 'order':filtorder[f]}))
        # Configure an additional version for long period variables.
        mkwargs = {'col':'expMJD', 'periodMin':100, 'periodMax':300., 'nPeriods':5,
                    'metricName':'LongPeriodDeviations'}
        metriclist.append(configureMetric('mafContrib.PeriodDeviationMetric', kwargs=mkwargs,
                                    summaryStats={'MeanMetric':{}, 'RmsMetric':{}},
                                    displayDict={'group':'Cadence', 'subgroup':'Period Recovery', 'order':filtorder[f]}))

        # Configure the phase coverage metric.
        mkwargs = {'col':'expMJD', 'periodMin':2, 'periodMax':10., 'nPeriods':5,
                    'metricName':'ShortPeriod Phase Uniformity'}
        metriclist.append(configureMetric('mafContrib.PhaseUniformityMetric', kwargs=mkwargs,
                                    summaryStats={'MeanMetric':{}, 'RmsMetric':{}},
                                    displayDict={'group':'Cadence', 'subgroup':'Phase Uniformity', 'order':filtorder[f]}))
        # Configure an additional version for long period variables.
        mkwargs = {'col':'expMJD', 'periodMin':100, 'periodMax':300., 'nPeriods':5,
                    'metricName':'LongPeriod Phase Uniformity'}
        metriclist.append(configureMetric('mafContrib.PhaseUniformityMetric', kwargs=mkwargs,
                                    summaryStats={'MeanMetric':{}, 'RmsMetric':{}},
                                    displayDict={'group':'Cadence', 'subgroup':'Phase Uniformity', 'order':filtorder[f]}))

        # Configure a slicer.  Use the Healpixslicer to compute the metric at points in the sky.
        # Set the constraint as an empty string if all data are to be returned.
        slicer = configureSlicer('HealpixSlicer',
                                kwargs={'nside':nside},
                                metricDict=makeDict(**metriclist),
                                constraints=[sqlconstraint])

    config.slicers = makeDict(slicer)

    return config
Exemple #9
0
def mConfig(config, runName, dbDir='.', outputDir='Dithers', nside=128, **kwargs):
    """
    A MAF config for analysis of various dithers applied to an opsim run.

    runName must correspond to the name of the opsim output
        (minus '_sqlite.db', although if added this will be stripped off)

    dbDir is the directory containing the sqlite database
    outputDir is the output directory
    """
    # To use the maf contributed metrics (including galaxy counts metric).
    config.modules = ['mafContrib']

    # Setup Database access
    config.outputDir = outputDir
    if runName.endswith('_sqlite.db'):
        runName = runName.replace('_sqlite.db', '')
    sqlitefile = os.path.join(dbDir, runName + '_sqlite.db')
    config.dbAddress ={'dbAddress':'sqlite:///'+sqlitefile}
    config.opsimName = runName
    config.figformat = 'pdf'

    # Connect to the database to fetch some values we're using to help configure the driver.
    opsimdb = utils.connectOpsimDb(config.dbAddress)

    # Fetch the proposal ID values from the database
    propids, propTags = opsimdb.fetchPropInfo()
    if 'WFD' not in propTags:
        propTags['WFD'] = []

    # Construct a WFD SQL where clause (handles the case of multiple propIDs mapping into "WFD").
    wfdWhere = utils.createSQLWhere('WFD', propTags)
    print 'WFD "where" clause: %s' %(wfdWhere)

    # Filter list, and map of colors (for plots) to filters.
    filters = ['u','g','r','i','z','y']
    colors={'u':'m','g':'b','r':'g','i':'y','z':'r','y':'k'}
    filtorder = {'u':1,'g':2,'r':3,'i':4,'z':5,'y':6}

    summaryStats = {'MeanMetric':{}, 'MedianMetric':{}, 'RmsMetric':{},
                    'PercentileMetric 1':{'metricName':'25th%ile', 'percentile':25},
                    'PercentileMetric 2':{'metricName':'75th%ile', 'percentile':75},
                    'MinMetric':{},
                    'MaxMetric':{},
                    'TotalPowerMetric':{}}

    ditherDict = {}
    ditherDict['NoDither'] = None
    ditherDict['HexDither'] = None
    ditherDict['RandomDither'] = stackers.RandomDitherStacker()
    ditherDict['NightlyRandomDither'] = stackers.NightlyRandomDitherStacker()
    ditherDict['SpiralDither'] = stackers.SpiralDitherStacker()
    ditherDict['NightlySpiralDither'] = stackers.NightlySpiralDitherStacker()
    ditherDict['SequentialHexDither'] = stackers.SequentialHexDitherStacker()
    ditherDict['NightlySequentialHexDither'] = stackers.NightlySequentialHexDitherStacker()
    dithernames = ['NoDither', 'HexDither', 'SequentialHexDither', 'NightlySequentialHexDither',
                   'RandomDither', 'NightlyRandomDither', 'SpiralDither', 'NightlySpiralDither']

    filterlist = ['u', 'g', 'r', 'i', 'z', 'y']

    # Set up sqlconstraint and use this as the outermost loop.
    slicerList = []
    order = 0
    for f in filterlist:
        sqlconstraint = "filter = '%s'" %(f)
        sqlconstraint += ' and %s' %(wfdWhere)
        common_metadata = '%s band WFD' %(f)
        histNum = 0
        # Set up metrics to run for each dither pattern.
        # Set up appropriate slicer and update order/hist label for each ditherpattern, using the same sqlconstraint.
        for i, dithername in enumerate(dithernames):
            if dithername == 'NoDither':
                racol = 'fieldRA'
                deccol = 'fieldDec'
            elif dithername == 'HexDither':
                racol = 'ditheredRA'
                deccol = 'ditheredDec'
            else:
                racol = ditherDict[dithername].colsAdded[0]
                deccol = ditherDict[dithername].colsAdded[1]
            metadata = common_metadata + ' ' + dithername

            metricList = []
            metricList.append(configureMetric('Coaddm5Metric',
                                            plotDict={'units':'Coadded m5'},
                                            summaryStats=summaryStats,
                                            displayDict={'group':'Dithers', 'subgroup':'Coadded Depth',
                                                         'order':i+filtorder[f]*100},
                                            histMerge={'histNum':histNum, 'color':colors[f], 'label':'%s' %(metadata),
                                                         'legendloc':'upper right'}))
            histNum += 1
            metricList.append(configureMetric('CountUniqueMetric', kwargs={'col':'night', 'metricName':'Unique Nights'},
                                               plotDict={'title':'Number of unique nights with observations',
                                                         'cbarFormat':'%d'},
                                                summaryStats=summaryStats,
                                                displayDict={'group':'Dithers', 'subgroup':'Number of nights',
                                                             'order':i+filtorder[f]*100},
                                                histMerge={'histNum':histNum, 'color':colors[f], 'label':'%s' %(metadata),
                                                         'legendloc':'upper right'}))
            histNum += 1
            metricList.append(configureMetric('CountMetric', kwargs={'col':'expMJD',
                                                                 'metricName':'Number of Visits'},
                                          plotDict={'title':'Number of visits',
                                                    'colorMin':0, 'colorMax':300,
                                                    'cbarFormat': '%d'},
                                            summaryStats=summaryStats,
                                            displayDict={'group':'Dithers','subgroup':'Number of visits',
                                                         'order':i+filtorder[f]*100},
                                            histMerge={'histNum':histNum, 'color':colors[f], 'label':'%s' %(metadata),
                                                         'legendloc':'upper right'}))
            histNum += 1
            metricList.append(configureMetric('mafContrib.GalaxyCountsMetric', kwargs={'nside':nside},
                                          summaryStats=summaryStats,
                                            displayDict={'group':'Dithers', 'subgroup':'Galaxy Counts',
                                                              'order':i+filtorder[f]*100},
                                            histMerge={'histNum':histNum, 'color':colors[f], 'label':'%s' %(metadata),
                                                         'legendloc':'upper right'}))
            histNum += 1
            slicer = configureSlicer('HealpixSlicer', kwargs={'nside':nside, 'spatialkey1':racol, 'spatialkey2':deccol},
                                    constraints=[sqlconstraint], metricDict=makeDict(*metricList),
                                    metadata= metadata, metadataVerbatim=True)
            slicerList.append(slicer)

    config.slicers = makeDict(*slicerList)
    return config
# Set output directory.
root.outputDir = 'OutDir'

root.verbose = True

# Set up slicerList to store slicers.
slicerList = []
# Set parameter for healpix slicer resolution.
nside = 64

# Loop over g and r filters, running metrics and slicers in each bandpass.
filters = ['g','r']
for f in filters:
    # Set up metrics and slicers.
    m1 = configureMetric('CountMetric', kwargs={'col':'expMJD','metricName':'NVisits'}, 
                            plotDict={'colorMin':0, 'colorMax':200, 'units':'N Visits',
                                      'xMin':0, 'xMax':200},
                            summaryStats={'MedianMetric':{}, 'RobustRmsMetric':{}})
    m2 = configureMetric('Coaddm5Metric', kwargs={'m5Col':'fiveSigmaDepth'}, 
                            plotDict={'percentileClip':95}, summaryStats={'MedianMetric':{}})
    metricDict = makeDict(m1, m2)
    sqlconstraint = 'filter = "%s"' %(f)
    slicer = configureSlicer('HealpixSlicer',
                            kwargs={'nside':nside, 'spatialkey1':'fieldRA', 'spatialkey2':'fieldDec'},
                            metricDict=metricDict, constraints=[sqlconstraint,])
    slicerList.append(slicer)

# Bundle together metrics and slicers and pass to 'root'
root.slicers=makeDict(*slicerList)
Exemple #11
0
nside = 16

#import healpy
#solidangle = healpy.nside2pixarea(nside, degrees=True)
#import numpy
#solidangle = numpy.asscalar(solidangle)

# supernova light curve
kwargs = {
    'lc.class': 'projects.snlightcurve.SNLightCurve',
    'lc.z': 0.3,
    'lc.source': 'hsiao',
    'lc.tmin': 1e-8,
    'lc.tmax': 10 * (1 + .3),
    'magPrecision': 0.05
}

# Configure a metric to run. Compute the mean on the final delivered seeing.  Once the mean seeing has been computed everywhere on the sky, compute the RMS as a summary statistic.

metric = configureMetric('projects.ctmetric_lsst.ctmetric_lsst',
                         kwargs=kwargs,
                         summaryStats={'RmsMetric': {}})

# Configure a binner.  Use the Healpixbinner to compute the metric at points in the sky.  Set the constraint as an empty string so all data is returned.
binner = configureSlicer('HealpixSlicer',
                         kwargs={"nside": nside},
                         metricDict=makeDict(metric),
                         constraints=[''])

root.slicers = makeDict(binner)
#setenv PYTHONPATH $PYTHONPATH':/some/path/here/'
#or bash:
#export PYTHONPATH=$PYTHONPATH':/some/path/here/'

from lsst.sims.maf.driver.mafConfig import configureMetric, configureSlicer, configureStacker, makeDict


root.outputDir = 'OutDither'
root.dbAddress = {'dbAddress':'sqlite:///opsimblitz2_1060_sqlite.db'}
root.opsimName = 'opsimblitz2_1060'

sliceList = []
nside = 128

# "Normal" configuration of HealpixSlicer
metric = configureMetric('Coaddm5Metric')
slicer = configureSlicer('HealpixSlicer', kwargs={'nside':nside},
                         metricDict=makeDict(metric), constraints=['filter="r"'],
                         metadata='no dither')
sliceList.append(slicer)

# Normal configuration, making defaults explicit
metric = configureMetric('Coaddm5Metric')
slicer = configureSlicer('HealpixSlicer', kwargs={'nside':nside,
                                                  'spatialkey1':'fieldRA',
                                                  'spatialkey2':'fieldDec'},
                         metricDict=makeDict(metric), constraints=['filter="r"'],
                         metadata='no dither')
# (Not going to add this to slicerlist as it's a duplicate of above)

# Configuring HealpixSlicer to use hexdither RA/dec
Exemple #13
0
def mConfig(config, runName, dbDir='.', outputDir='Out', **kwargs):
    """
    Set up a MAF config for Zeljko's requested metrics. (also included in sstarDriver.py now).
    """
    sqlitefile = os.path.join(dbDir, runName + '_sqlite.db')
    config.dbAddress = {'dbAddress':'sqlite:///'+sqlitefile}
    config.opsimName = runName
    config.outputDir = outputDir

    # Connect to the database to fetch some values we're using to help configure the driver.
    opsimdb = utils.connectOpsimDb(config.dbAddress)

    # Fetch the proposal ID values from the database
    propids, WFDpropid, DDpropid = opsimdb.fetchPropIDs()
    
    # Construct a WFD SQL where clause so multiple propIDs can by WFD:
    wfdWhere = ''
    if len(WFDpropid) == 1:
        wfdWhere = "propID = '%s'"%WFDpropid[0]
    else: 
        for i,propid in enumerate(WFDpropid):
            if i == 0:
                wfdWhere = wfdWhere+'('+'propID = %s'%propid
            else:
                wfdWhere = wfdWhere+'or propID = %s'%propid
            wfdWhere = wfdWhere+')'


    # Fetch the total number of visits (to create fraction)
    totalNVisits = opsimdb.fetchNVisits()

    slicerList=[]
    nside = 128

    # fO metrics for all and WFD
    m1 = configureMetric('CountMetric', kwargs={'col':'expMJD', 'metricName':'fO'},
                        plotDict={'units':'Number of Visits', 'xMin':0,
                                    'xMax':1500},
                        summaryStats={'fOArea':{'nside':nside},
                                        'fONv':{'nside':nside}})
    slicer = configureSlicer('fOSlicer', kwargs={'nside':nside},
                            metricDict=makeDict(m1),
                            constraints=['',wfdWhere])
    slicerList.append(slicer)
    
    # Medians in r and i filters
    m1 = configureMetric('MedianMetric', kwargs={'col':'finSeeing'}, summaryStats={'IdentityMetric':{}})
    m2 = configureMetric('MedianMetric', kwargs={'col':'airmass'}, summaryStats={'IdentityMetric':{}})
    m3 = configureMetric('MedianMetric', kwargs={'col':'fiveSigmaDepth'}, summaryStats={'IdentityMetric':{}})
    slicer = configureSlicer('UniSlicer', metricDict=makeDict(m1,m2,m3),
                            constraints=['filter = "r"', 'filter = "i"'])
    slicerList.append(slicer)


    # Number of visits per proposal
    constraints = ["propID = '%s'"%pid for pid in propids ]
    m1 = configureMetric('CountMetric', kwargs={'col':'expMJD', 'metricName':'Number of Visits Per Proposal'},
                            summaryStats={'IdentityMetric':{}, 'NormalizeMetric':{'normVal':totalNVisits}})
    slicer = configureSlicer('UniSlicer', metricDict=makeDict(m1),
                            constraints=constraints)
    slicerList.append(slicer)

    # Mean slew time, total number of visits, total visit exposure time, number of nights of observing
    m1 = configureMetric('MeanMetric', kwargs={'col':'slewTime'}, summaryStats={'IdentityMetric':{}})
    m2 = configureMetric('CountMetric', kwargs={'col':'expMJD', 'metricName':'Total Number of Visits'},
                        summaryStats={'IdentityMetric':{}} )
    m3 = configureMetric('OpenShutterMetric', summaryStats={'IdentityMetric':{}} )
    slicer = configureSlicer('UniSlicer', metricDict=makeDict(m1,m2,m3),
                                constraints=[''])
    slicerList.append(slicer)

    m1 = configureMetric('CountMetric', kwargs={'col':'expMJD', 'metricName':'Number of visits per night'}, 
                        summaryStats={'MeanMetric':{}, 'RmsMetric':{}, 'MedianMetric':{}})
    m2 = configureMetric('OpenShutterFractionMetric',
                         summaryStats={'MeanMetric':{}, 'RmsMetric':{}, 'MedianMetric':{}})
    slicer = configureSlicer('OneDSlicer', kwargs={'sliceColName':'night', 'binsize':1},
                             metricDict=makeDict(m1,m2),
                             constraints=[''])
    slicerList.append(slicer)

    config.slicers = makeDict(*slicerList)
    return config
# Here is an example of a very very simple MAF configuration driver script
# to run:
# runDriver.py oneMetricOneSlicer.py

# This script uses the LSST pex_config.  This is executed as a python script, but only things that
#  start with 'root.' are passed on to the driver script.

# Import MAF helper functions
from lsst.sims.maf.driver.mafConfig import configureSlicer, configureMetric, makeDict

# Set the output directory
root.outputDir = './OneMetric'
# Set the database to use (the example db included in the git repo)
root.dbAddress = {'dbAddress': 'sqlite:///opsimblitz2_1060_sqlite.db'}
# Name of this run (filename base)
root.opsimName = 'ob2_1060'

# Configure a metric to run. Compute the mean on the final delivered seeing.
#Once the mean seeing has been computed everywhere on the sky, compute the RMS as a summary statistic.
metric = configureMetric('MeanMetric',
                         kwargs={'col': 'finSeeing'},
                         summaryStats={'RmsMetric': {}})

# Configure a slicer.  Use the Healpixslicer to compute the metric at points in the sky.
#Set the constraint as an empty string so all data is returned.
slicer = configureSlicer('HealpixSlicer',
                         metricDict=makeDict(metric),
                         constraints=[''])

root.slicers = makeDict(slicer)
Exemple #15
0
#For example for c-shell:
#setenv PYTHONPATH $PYTHONPATH':/some/path/here/'
#or bash:
#export PYTHONPATH=$PYTHONPATH':/some/path/here/'

from lsst.sims.maf.driver.mafConfig import configureMetric, configureSlicer, configureStacker, makeDict

root.outputDir = 'OutDither'
root.dbAddress = {'dbAddress': 'sqlite:///opsimblitz2_1060_sqlite.db'}
root.opsimName = 'opsimblitz2_1060'

sliceList = []
nside = 128

# "Normal" configuration of HealpixSlicer
metric = configureMetric('Coaddm5Metric')
slicer = configureSlicer('HealpixSlicer',
                         kwargs={'nside': nside},
                         metricDict=makeDict(metric),
                         constraints=['filter="r"'],
                         metadata='no dither')
sliceList.append(slicer)

# Normal configuration, making defaults explicit
metric = configureMetric('Coaddm5Metric')
slicer = configureSlicer('HealpixSlicer',
                         kwargs={
                             'nside': nside,
                             'spatialkey1': 'fieldRA',
                             'spatialkey2': 'fieldDec'
                         },
#PYTHONPATH environement variable.  For example:
#setenv PYTHONPATH $PYTHONPATH':/some/path/here/'
#or bash:
#export PYTHONPATH=$PYTHONPATH':/some/path/here/'

from lsst.sims.maf.driver.mafConfig import configureMetric, configureSlicer, makeDict

root.outputDir = 'OutMetrics'
root.dbAddress = {'dbAddress': 'sqlite:///opsimblitz2_1060_sqlite.db'}
root.opsimName = 'opsimblitz2_1060'

root.modules = ['exampleNewMetrics']

sliceList = []

metric = configureMetric('exampleNewMetrics.SimplePercentileMetric',
                         kwargs={'col': 'airmass'})
slicer = configureSlicer('UniSlicer',
                         metricDict=makeDict(metric),
                         constraints=['filter="r"'])
sliceList.append(slicer)

metric = configureMetric('exampleNewMetrics.PercentileMetric',
                         kwargs={
                             'col': 'airmass',
                             'percentile': 75
                         })
slicer = configureSlicer('UniSlicer',
                         metricDict=makeDict(metric),
                         constraints=['filter="r"'])
sliceList.append(slicer)
def mConfig(config, runName, dbDir='.', outputDir='LensedQuasarTimeDelays-dithered', **kwargs):

    config.outputDir = outputDir
    if runName.endswith('_sqlite.db'):
        runName = runName.replace('_sqlite.db', '')
    config.opsimName = runName
    sqlitefile = os.path.join(dbDir, runName + '_sqlite.db')
    config.dbAddress = {'dbAddress':'sqlite:///' + sqlitefile}
    config.figformat = 'pdf'

    config.modules = ['mafContrib']
    
    sliceList = []
    
    for i, expt in enumerate(['u','g','r','i','z','y','multi']):
    
        seasonstyle   = {'title':'%s, dithered, %s-band: Mean Season Length' %(runName, expt), 
                        'xlabel':'Season Length (months)','bins':49,'xMin':0.0, 'xMax':12.0,
                        'colorMin':0.0, 'colorMax':12.0}
        campaignstyle = {'title':'%s, dithered, %s-band: Campaign Length' %(runName, expt),
                        'xlabel':'Campaign Length (seasons)','bins':11,'xMin':0.0, 'xMax':11.0,
                        'colorMin':0.0, 'colorMax':11.0}
        cadencestyle  = {'title':'%s dithered, %s-band: Mean Separation between Nights' %(runName, expt),
                        'xlabel':'Night Separation (days)','bins':41,'xMin':0.0, 'xMax':40.0,
                        'colorMin':0.0, 'colorMax':40.0}

        if expt != 'multi':
            # First look at individual filters, one at a time:
            constraints = ['filter="'+expt+'"']
        else:
            # Now look at all bands together:
            constraints = ['']

        # Configure metrics:
    
        seasonmetric = configureMetric('mafContrib.SeasonLengthMetric', 
                                    kwargs={'seasonCol':'season','expMJDCol':'expMJD'}, 
                                    plotDict=seasonstyle,
                                    displayDict={'group':'Time Delay', 'order':i})
        campaignmetric = configureMetric('mafContrib.CampaignLengthMetric', 
                                        kwargs={'seasonCol':'season'}, plotDict=campaignstyle,
                                        displayDict={'group':'Time Delay', 'order':i})
        cadencemetric = configureMetric('mafContrib.MeanNightSeparationMetric', 
                                        kwargs={'seasonCol':'season','nightCol':'night'}, 
                                        plotDict=cadencestyle,
                                        displayDict={'group':'Time Delay', 'order':i})
    
        # Add a column labelling the seasons:
        stacker = configureStacker('mafContrib.SeasonStacker', kwargs={})

        # Make sky maps, at default resolution for now, and including opsim 
        # hexagonal dither stacker, called implicitly by specifying the 
        # spatialkeys:
    
        slicer = configureSlicer('HealpixSlicer', kwargs={'nside':128,
                                                        'spatialkey1':'ditheredRA',
                                                        'spatialkey2':'ditheredDec'},
                                    metricDict = makeDict(seasonmetric, campaignmetric, cadencemetric, accuracymetric),
                                    constraints=constraints,
                                    stackerDict=makeDict(stacker))
    
        sliceList.append(slicer)
    
    # End of expt loop.

    # Send it all off to root (aka 'config').
    
    config.slicers = makeDict(*sliceList)
    return config
# Example for TripletMetric.py
# Mike Lund - Vanderbilt University
# [email protected]
# Last edited 9/6/2014
from lsst.sims.maf.driver.mafConfig import configureSlicer, configureMetric, makeDict
root.modules = ['mafContrib']

# Set the output directory
root.outputDir = './Triplets'
# Set the database to use (the example db included in the git repo)
root.dbAddress = {'dbAddress':'sqlite:///opsimblitz2_1060_sqlite.db'}
# Name of this run (filename base)
root.opsimName = 'ob2_1060'

plotDict={'colorMin':1, 'logScale':True, 'xlabel':'Number of triplets'}
# Two metrics in TripletMetric. TripletMetric.TripletMetric is irrespective of band, while TripletMetric.TripletBandMetric is restricted to triplets of observations in the same band.

metric = configureMetric('mafContrib.TripletBandMetric',
                         plotDict=plotDict, kwargs={'DelMin':1, 'DelMax':7, 'RatioMax':2, 'RatioMin':1})

# Configure a slicer. Long run times for Healpixslicer
#slicer = configureSlicer('HealpixSlicer', metricDict=makeDict(metric), constraints=[''])
slicer = configureSlicer('OpsimFieldSlicer', metricDict=makeDict(metric), constraints=[''])

root.slicers = makeDict(slicer)
Exemple #19
0
root.verbose = True

# Set up slicerList to store slicers.
slicerList = []
# Set parameter for healpix slicer resolution.
nside = 4

# Loop over g and r filters, running metrics and slicers in each bandpass.
filters = ['u', 'g','r', 'i', 'z', 'y']
colors = {'u':'m','g':'b','r':'g','i':'y','z':'r','y':'k'}

for i, f in enumerate(filters):
    # Set up metrics and slicers.
    m1 = configureMetric('CountMetric', kwargs={'col':'expMJD','metricName':'NVisits'}, 
                            plotDict={'units':'N Visits', 'xMin':0, 'xMax':200},
                            summaryStats={'MedianMetric':{}, 'RobustRmsMetric':{}},
                            histMerge={'histNum':1, 'xMin':0, 'xMax':200, 'color':colors[f]},
                            displayDict={'group':'Basic', 'subgroup':'Nvisits', 'order':i})
    m2 = configureMetric('Coaddm5Metric', kwargs={'m5Col':'fiveSigmaDepth'}, 
                            plotDict={'percentileClip':95}, summaryStats={'MedianMetric':{}},
                            histMerge={'histNum':2, 'color':colors[f]},
                            displayDict={'group':'Basic', 'subgroup':'Coadd', 'order':i, 
                                         'caption':'Coadded m5 limiting magnitude for %s' %(f)})
    metricDict = makeDict(m1, m2)
    sqlconstraint = 'filter = "%s"' %(f)
    slicer = configureSlicer('HealpixSlicer',
                            kwargs={'nside':nside, 'spatialkey1':'fieldRA', 'spatialkey2':'fieldDec'},
                            metricDict=metricDict, constraints=[sqlconstraint,])
    slicerList.append(slicer)

# Bundle together metrics and slicers and pass to 'root'
# Set the output directory
root.outputDir = './ctmetric_lsst_out'
# Set the database to use (the example db included in the git repo)
#root.dbAddress = {'dbAddress':'sqlite:///opsimblitz2_1060_sqlite.db'}
root.dbAddress = {'dbAddress':'sqlite:////Users/akim/Downloads/opsimblitz2_1060_sqlite.db'}
# Name of this run (filename base)
root.opsimName = 'ctmetric_lsst'

root.modules = ['projects.ctmetric_lsst']

nside=16

#import healpy
#solidangle = healpy.nside2pixarea(nside, degrees=True)
#import numpy
#solidangle = numpy.asscalar(solidangle)

# supernova light curve
kwargs = {'lc.class':'projects.snlightcurve.SNLightCurve','lc.z':0.3, 'lc.source': 'hsiao','lc.tmin':1e-8,'lc.tmax':10*(1+.3), 'magPrecision':0.05}

# Configure a metric to run. Compute the mean on the final delivered seeing.  Once the mean seeing has been computed everywhere on the sky, compute the RMS as a summary statistic.

metric = configureMetric('projects.ctmetric_lsst.ctmetric_lsst',kwargs=kwargs,summaryStats={'RmsMetric':{}})

# Configure a binner.  Use the Healpixbinner to compute the metric at points in the sky.  Set the constraint as an empty string so all data is returned.
binner = configureSlicer('HealpixSlicer',kwargs={"nside":nside},  metricDict=makeDict(metric),
                          constraints=[''])

root.slicers = makeDict(binner)
Exemple #21
0
from lsst.sims.maf.driver.mafConfig import configureMetric, configureSlicer, makeDict

root.outputDir = 'BigHist'
root.dbAddress = {'dbAddress':'sqlite:///ops2_1065_sqlite.db'}
root.opsimName = 'ops2_1065'


sliceList = []
binMin = 0.5
binMax = 60
binsize= 1
metric1 = configureMetric('Tgaps',
                         kwargs={'binMin':binMin,
                                 'binMax':binMax, 'binsize':binsize})
metric15 = configureMetric('Tgaps',
                         kwargs={'binMin':0,
                                 'binMax':60, 'binsize':.05, 'metricName':'TgapsFine'})

binMax = 365.25*5

metric2 = configureMetric('Tgaps',
                         kwargs={'metricName':'AllGaps', 'allGaps':True, 'binMin':binMin,
                                 'binMax':binMax, 'binsize':binsize})

metricDict = makeDict(metric1,metric2, metric15)
slicer = configureSlicer('HealpixComplexSlicer',
                         kwargs={'nside':16},
                         metricDict=metricDict,
                         constraints=['filter = "r"'])

sliceList.append(slicer)
#PYTHONPATH environement variable.  For example:
#setenv PYTHONPATH $PYTHONPATH':/some/path/here/'
#or bash:
#export PYTHONPATH=$PYTHONPATH':/some/path/here/'

from lsst.sims.maf.driver.mafConfig import configureMetric, configureSlicer, makeDict

root.outputDir = 'OutMetrics'
root.dbAddress = {'dbAddress':'sqlite:///opsimblitz2_1060_sqlite.db'}
root.opsimName = 'opsimblitz2_1060'

root.modules = ['exampleNewMetrics']

sliceList = []

metric = configureMetric('exampleNewMetrics.SimplePercentileMetric', kwargs={'col':'airmass'})
slicer = configureSlicer('UniSlicer', metricDict=makeDict(metric), constraints=['filter="r"'])
sliceList.append(slicer)

metric = configureMetric('exampleNewMetrics.PercentileMetric', kwargs={'col':'airmass', 'percentile':75})
slicer = configureSlicer('UniSlicer', metricDict=makeDict(metric), constraints=['filter="r"'])
sliceList.append(slicer)

metric = configureMetric('exampleNewMetrics.MaxDifferenceMetric', kwargs={'colA':'fieldRA', 'colB':'ditheredRA'})
slicer = configureSlicer('OpsimFieldSlicer', metricDict=makeDict(metric), constraints=[''])
sliceList.append(slicer)

metric = configureMetric('exampleNewMetrics.MaxDifferenceMetric', kwargs={'colA':'fieldDec', 'colB':'ditheredDec'})
slicer = configureSlicer('OpsimFieldSlicer', metricDict=makeDict(metric), constraints=[''])
sliceList.append(slicer)
Exemple #23
0
root.outputDir = './MergeHist'
root.dbAddress = {'dbAddress':'sqlite:///ops2_1065_sqlite.db'}
root.opsimName = 'ops2_1065'
slicerList=[]
root.plotOnly = False

root.figformat = 'png'
filters = ['u','g','r','i','z','y']
colors={'u':'m','g':'b','r':'g','i':'y','z':'r','y':'k'}

slicerName='HealpixSlicer'
slicerkwargs={'nside':32}

for f in filters:
    m4 = configureMetric('Coaddm5Metric',
                         summaryStats={'MeanMetric':{}, 'RmsMetric':{}},
                         histMerge={'histNum':6, 'binsize':0.2, 'legendloc':'upper right',
                                    'color':colors[f], 'label':'%s'%f})
    metricDict = makeDict(m4)
    constraints = ['filter = "%s"' %(f)]
    slicer = configureSlicer(slicerName, kwargs=slicerkwargs, metricDict=metricDict,
                             constraints=constraints)
    slicerList.append(slicer)


for f in filters:
    m1 = configureMetric('CountMetric', kwargs={'col':'fiveSigmaDepth'},
                         histMerge={'histNum':1, 'legendloc':'upper right',
                                    'color':colors[f], 'label':'%s'%f} )

    slicer = configureSlicer('OneDSlicer',
                             kwargs={'sliceColName':'fiveSigmaDepth', 'binsize':0.1},metricDict=makeDict(m1),
Exemple #24
0
dbDir = '.'
runName = 'ops1_1140'
sqlitefile = os.path.join(dbDir, runName + '_sqlite.db')
root.dbAddress ={'dbAddress':'sqlite:///'+sqlitefile}
root.opsimName = runName
root.outputDir = 'OutDir'


slicerList = []
nside = 128
band='r'
slicerList = []


m1 = configureMetric('Coaddm5Metric',
                     plotDict={'title':'Co-added Depth', 'colorMin':25, 'colorMax':28})
slicer=configureSlicer('HealpixSlicer',
                       kwargs={'nside':nside, 'spatialkey1':'fieldRA', 'spatialkey2':'fieldDec'},
                       metricDict=makeDict(*[m1]),
                       constraints=['filter="%s"'%band])
slicerList.append(slicer)

m1 = configureMetric('Coaddm5Metric',
                     plotDict={'title':'Dithered Co-added Depth', 'colorMin':25, 'colorMax':28})
slicer=configureSlicer('HealpixSlicer',
                       kwargs={'nside':nside, 'spatialkey1':'ditheredRA', 'spatialkey2':'ditheredDec'},
                       metricDict=makeDict(*[m1]),
                       constraints=['filter="%s"'%band], metadata='dithered')
slicerList.append(slicer)

# Look at the proper motion precision
# Here is an example of a very very simple MAF configuration driver script
# to run:
# runDriver.py varMetricExample.py

# Import MAF helper functions
from lsst.sims.maf.driver.mafConfig import configureSlicer, configureMetric, makeDict

# Tell the driver where to get contributed modules
root.modules = ['mafContrib']
root.figformat = 'png'

# Set the output directory
root.outputDir = './VarMetric'
# This should be changed to point to an OpSim output on disk
root.dbAddress = {'dbAddress':'sqlite:///ops1_1140_sqlite.db'}
# Name of this run (filename base)
root.opsimName = 'ops1_1140'

# Configure a metric to run. Compute the recovered period for each HEALPIX.
# Once the period has been computed everywhere on the sky, compute the RMS as a summary statistic.
kwargs = {'col':'expMJD', 'periodMin':10., 'periodMax':40., 'metricName':'SinPeriodMetric', 'units':'days'}
metric = configureMetric('mafContrib.SinPeriodMetric', kwargs=kwargs,
                         summaryStats={'RmsMetric':{}})

# Configure a slicer.  Use the Healpixslicer to compute the metric at points in the sky.
# Set the constraint as an empty string if all data are to be returned.
slicer = configureSlicer('HealpixSlicer', metricDict=makeDict(metric),
                          constraints=['filter=\'r\''])

root.slicers = makeDict(slicer)
# Examples of all the plotting dictionary options

from lsst.sims.maf.driver.mafConfig import configureSlicer, configureMetric, makeDict

root.outputDir = './SimplePlotDict'
root.dbAddress = {'dbAddress': 'sqlite:///opsimblitz2_1060_sqlite.db'}
root.opsimName = 'ob2_1060'
nside = 16
slicerList = []

plotDict = {'title': 'A Great New Title', 'colorMin': 0.5, 'colorMax': 1.4}

m1 = configureMetric('MeanMetric',
                     plotDict=plotDict,
                     kwargs={
                         'col': 'finSeeing',
                         'metricName': 'wplotdict'
                     })
m2 = configureMetric('MeanMetric', kwargs={'col': 'finSeeing'})

metricDict = makeDict(m1, m2)

slicer = configureSlicer('HealpixSlicer',
                         kwargs={"nside": nside},
                         metricDict=metricDict,
                         constraints=['filter="r"'])
slicerList.append(slicer)
root.slicers = makeDict(*slicerList)
Exemple #27
0
# Make an empty list to hold all the slicer configs
sliceList = []

# Define the filters we want to loop over
filters = ['u', 'g', 'r', 'i', 'z', 'y']
# Make a dict of what colors to use for different filters
colors = {'u': 'm', 'g': 'b', 'r': 'g', 'i': 'y', 'z': 'Orange', 'y': 'r'}

# Look at the single-visit depth and airmass for observations in each filter and merge
# them into a single histogram
for f in filters:
    m1 = configureMetric('CountMetric',
                         kwargs={'col': 'fiveSigmaDepth'},
                         histMerge={
                             'histNum': 1,
                             'legendloc': 'upper right',
                             'color': colors[f],
                             'label': '%s' % f,
                             'ylabel': 'Count'
                         })
    slicer = configureSlicer('OneDSlicer',
                             kwargs={
                                 "sliceColName": 'fiveSigmaDepth',
                                 'binsize': 0.1,
                             },
                             metricDict=makeDict(m1),
                             constraints=["filter = '%s'" % (f)])
    sliceList.append(slicer)
    m1 = configureMetric('CountMetric',
                         kwargs={'col': 'airmass'},
                         histMerge={
root.outputDir = './PlotDict'
root.dbAddress = {'dbAddress':'sqlite:///opsimblitz2_1060_sqlite.db'}
root.opsimName =  'ob2_1060'
nside=16
slicerList=[]




plotDict={'title':'title!', 'cmap':'RdBu', 'xlabel':'xlabel!', 'ylabel':'ylabel!', 
           'label':'label!', 'addLegend':True, 'color':'r', 'bins':150,
          'cbarFormat':'%.4g', 'cumulative':True, 'logScale':True,'colorMin':0.65, 'colorMax':1.5,
          'xMin':0.5, 'xMax':1.6, 'linestyle':'--', 'maxl':40, 'removeDipole':False}


m1 = configureMetric('MeanMetric',  plotDict=plotDict, kwargs={'col': 'finSeeing', 'metricName':'wplotdict'})
m2 = configureMetric('MeanMetric', kwargs={'col': 'finSeeing'})

metricDict = makeDict(m1,m2)

slicer = configureSlicer('HealpixSlicer',kwargs={"nside":nside},
                          metricDict = metricDict,constraints=['filter="r"'])
# For skymap units, title, ylog, cbarFormat, cmap, percentileClip, plotMin, plotMax, zp, normVal
# also on hist:  ylabel, bins, cumulative,ylog, color, scale, label, addLegend

slicerList.append(slicer)

plotDict={ 'title':'title!', 'xMin':0.5, 'xMax':1.7, 'ylabel':'ylabel!',
           'xlabel':'xlabel!', 'label':'label!', 'addLegend':True, 'color':'r',
           'yMin':0.1,'yMax':10000., 'logScale':True, 'linestyle':'--'}
Exemple #29
0
dbDir = '.'
runName = 'ops1_1140'
sqlitefile = os.path.join(dbDir, runName + '_sqlite.db')
root.dbAddress ={'dbAddress':'sqlite:///'+sqlitefile}
root.opsimName = runName
root.outputDir = 'GapsDir'


slicerList = []
nside = 128
band='r'
slicerList = []


# Let's do a really high res with the chip gaps on!

nside = 2048/2

m1 = configureMetric('CountMetric', kwargs={'col':'expMJD'})
slicer = configureSlicer('HealpixSlicer',
                       kwargs={'nside':nside, 'spatialkey1':'fieldRA', 'spatialkey2':'fieldDec',
                               'useCamera':True, 'radius':2.014},
                       metricDict=makeDict(*[m1]),
                       constraints=['filter="%s" and  fieldRA > 0 and fieldRA < %f and  fieldDec < 0 and fieldDec > %f'%
                                    (band, np.radians(10), np.radians(-10))])
slicerList.append(slicer)


root.slicers=makeDict(*slicerList)
# Test for mafConfig setup. 

from lsst.sims.maf.driver.mafConfig import configureMetric, configureSlicer, makeDict

root.outputDir = 'OutMetrics'
root.dbAddress = {'dbAddress':'sqlite:///opsimblitz2_1060_sqlite.db'}
root.opsimName = 'opsimblitz2_1060'

root.modules = ['mafContrib']

sliceList = []

metric = configureMetric('mafContrib.NightsWithNFiltersMetric')
slicer = configureSlicer('HealpixSlicer', metricDict=makeDict(metric), constraints=[''])
sliceList.append(slicer)

metric = configureMetric('mafContrib.NightsWithNFiltersMetric')
slicer = configureSlicer('HealpixSlicer', kwargs={'spatialkey1':'yearlyDitherRA',
                                                  'spatialkey2':'yearlyDitherDec'},
                         metricDict=makeDict(metric), constraints=[''], metadata='yearly dither')
sliceList.append(slicer)

metric = configureMetric('mafContrib.NightsWithNFiltersMetric', kwargs={'nFilters':4})
slicer = configureSlicer('OneDSlicer', kwargs={'sliceColName':'night', 'binsize':30},
                         metricDict=makeDict(metric), constraints=[''])
sliceList.append(slicer)

root.slicers = makeDict(*sliceList)


Exemple #31
0
from lsst.sims.maf.driver.mafConfig import configureMetric, configureSlicer, makeDict



root.outputDir = 'Hastacker'
root.dbAddress = {'dbAddress':'sqlite:///opsimblitz2_1060_sqlite.db'}
root.opsimName = 'opsimblitz2_1060'

sliceList = []

metric1 = configureMetric('MeanMetric', kwargs={'col':'HA'})
metric2 = configureMetric('MinMetric', kwargs={'col':'HA'})
metric3 = configureMetric('MaxMetric', kwargs={'col':'HA'})
metric4 = configureMetric('MedianMetric', kwargs={'col':'HA'})
metric5 = configureMetric('MedianMetric', kwargs={'col':'normairmass'})
metric6 =  configureMetric('MedianAbsMetric', kwargs={'col':'HA'})

metricDict=makeDict(metric1,metric2,metric3,metric4, metric5,metric6)
slicer=configureSlicer('HealpixSlicer', metricDict=metricDict, constraints=['filter = "r"', 'filter="g"'])

sliceList.append(slicer)
root.slicers = makeDict(*sliceList)

root.verbose = True
Exemple #32
0
def mConfig(config, runName, dbDir='.', outputDir='Out', slicerName='HealpixSlicer',
            benchmark='design', **kwargs):
    """
    A MAF config for SSTAR-like analysis of an opsim run.

    runName must correspond to the name of the opsim output
        (minus '_sqlite.db', although if added this will be stripped off)

    dbDir is the directory the database resides in

    outputDir is the output directory for MAF

    Uses 'slicerName' for metrics which have the option of using
      [HealpixSlicer, OpsimFieldSlicer, or HealpixSlicerDither]
      (dithered healpix slicer uses ditheredRA/dec values).

    Uses 'benchmark' (which can be design or stretch) to scale plots of number of visits and coadded depth.
    """

    # Setup Database access
    config.outputDir = outputDir
    if runName.endswith('_sqlite.db'):
        runName = runName.replace('_sqlite.db', '')
    sqlitefile = os.path.join(dbDir, runName + '_sqlite.db')
    config.dbAddress ={'dbAddress':'sqlite:///'+sqlitefile}
    config.opsimName = runName
    config.figformat = 'pdf'

    config.verbose = True

    opsimdb = utils.connectOpsimDb(config.dbAddress)
    totalNVisits = opsimdb.fetchNVisits()
    totalSlewN = opsimdb.fetchTotalSlewN()

    slicerList=[]
    histNum = 0

    # Calculate the mean and median slewtime.
    metricList = []
    # Mean Slewtime
    metricList.append(configureMetric('MeanMetric', kwargs={'col':'slewTime'},
                         displayDict={'group':'Slew Summary'}))
    # Median Slewtime
    metricList.append(configureMetric('MedianMetric', kwargs={'col':'slewTime'},
                         displayDict={'group':'Slew Summary'}))
    # Calculate the total number of visits.
    metricList.append(configureMetric('CountMetric', kwargs={'col':'expMJD', 'metricName':'TotalNVisits'},
                         summaryStats={'IdentityMetric':{'metricName':'Count'}},
                         displayDict={'group':'Slew Summary'}))
    # Calculate the total open shutter time.
    metricList.append(configureMetric('SumMetric', kwargs={'col':'visitExpTime', 'metricName':'Open Shutter Time'},
                         summaryStats={'IdentityMetric':{'metricName':'Time (s)'}},
                         displayDict={'group':'Slew Summary'}))
    # Number of nights
    metricList.append(configureMetric('CountUniqueMetric', kwargs={'col':'night'},
                                     displayDict={'group':'Slew Summary'}))
    # Mean exposure time
    metricList.append(configureMetric('MeanMetric', kwargs={'col':'visitExpTime'},
                                      displayDict={'group':'Slew Summary'}))
    # Mean visit time
    metricList.append(configureMetric('MeanMetric', kwargs={'col':'visitTime'},
                                      displayDict={'group':'Slew Summary'}))
    metricDict = makeDict(*metricList)
    slicer = configureSlicer('UniSlicer', metricDict=metricDict, constraints=[''], metadata='All Visits',
                             metadataVerbatim=True)
    slicerList.append(slicer)




    # Stats for angle:
    angles = ['telAlt', 'telAz', 'rotTelPos']

    for angle in angles:
        metricList = []
        metricList.append(configureMetric('MaxMetric', kwargs={'col':angle},
                                          displayDict={'group':'Slew Angle Stats', 'subgroup':angle}))
        metricList.append(configureMetric('MinMetric', kwargs={'col':angle},
                                          displayDict={'group':'Slew Angle Stats', 'subgroup':angle}))
        metricList.append(configureMetric('MeanMetric', kwargs={'col':angle},
                                          displayDict={'group':'Slew Angle Stats', 'subgroup':angle}))
        metricList.append(configureMetric('RmsMetric', kwargs={'col':angle},
                                          displayDict={'group':'Slew Angle Stats', 'subgroup':angle}))
        metricDict = makeDict(*metricList)
        slicer = configureSlicer('UniSlicer', metricDict=metricDict, constraints=[''], metadata=angle,
                                 metadataVerbatim=True, table='slewState')
        slicerList.append(slicer)




    # Make some calls to other tables to get slew stats
    colDict = {'domAltSpd':'Dome Alt Speed','domAzSpd':'Dome Az Speed','telAltSpd': 'Tel Alt Speed',
               'telAzSpd': 'Tel Az Speed', 'rotSpd':'Rotation Speed'}
    for key in colDict.keys():
        metricList=[]
        metricList.append(configureMetric('MaxMetric', kwargs={'col':key},
                                          displayDict={'group':'Slew Speed', 'subgroup':colDict[key]}))
        metricList.append(configureMetric('MeanMetric', kwargs={'col':key},
                                          displayDict={'group':'Slew Speed', 'subgroup':colDict[key]}))
        metricList.append(configureMetric('MaxPercentMetric', kwargs={'col':key, 'metricName':'% of slews'},
                                          displayDict={'group':'Slew Speed', 'subgroup':colDict[key]}))

        metricDict = makeDict(*metricList)
        slicer = configureSlicer('UniSlicer', metricDict=metricDict, constraints=[''],
                                 table='slewMaxSpeeds', metadata=colDict[key], metadataVerbatim=True)
        slicerList.append(slicer)


    # Use the slew stats
    slewTypes = ['DomAlt', 'DomAz', 'TelAlt', 'TelAz', 'Rotator', 'Filter',
                 'TelOpticsOL', 'Readout', 'Settle', 'TelOpticsCL']

    for slewType in slewTypes:
        metricList = []
        metricList.append(configureMetric('ActivePercentMetric',
                                          kwargs={'col':'actDelay', 'activity':slewType,
                                                  'metricName':'ActivePerc',
                                                  'norm':100./totalSlewN},
                                          displayDict={'group':'Slew', 'subgroup':slewType}) )
        metricList.append(configureMetric('ActiveMeanMetric',
                                          kwargs={'col':'actDelay', 'activity':slewType,
                                                  'metricName':'ActiveAve'},
                                          displayDict={'group':'Slew', 'subgroup':slewType}) )
        metricList.append(configureMetric('ActiveMaxMetric',
                                          kwargs={'col':'actDelay', 'activity':slewType,
                                                  'metricName':'Max'},
                                          displayDict={'group':'Slew', 'subgroup':slewType}) )

        metricDict = makeDict(*metricList)
        slicer = configureSlicer('UniSlicer', metricDict=metricDict,
                                 constraints=['actDelay>0 and activity="%s"'%slewType],
                                 table='slewActivities', metadata=slewType,
                                 metadataVerbatim=True)
        slicerList.append(slicer)
        metricList = []
        metricList.append(configureMetric('ActivePercentMetric',
                                          kwargs={'col':'actDelay', 'activity':slewType,
                                                  'metricName':'ActivePerc in crit',
                                                  'norm':100./totalSlewN},
                                          displayDict={'group':'Slew', 'subgroup':slewType}) )
        metricList.append(configureMetric('ActiveMeanMetric',
                                          kwargs={'col':'actDelay', 'activity':slewType,
                                                  'metricName':'ActiveAve in crit'},
                                          displayDict={'group':'Slew', 'subgroup':slewType}) )
        metricDict = makeDict(*metricList)
        slicer = configureSlicer('UniSlicer', metricDict=metricDict,
                                 constraints=['actDelay>0 and inCriticalPath="True" and activity="%s"'%slewType],
                                 table='slewActivities',
                                 metadata=slewType,
                                 metadataVerbatim=True)
        slicerList.append(slicer)
        metricList = []
        metricList.append(configureMetric('AveSlewFracMetric',
                                          kwargs={'col':'actDelay','activity':slewType,
                                                  'metricName':'Total Ave'},
                                          displayDict={'group':'Slew', 'subgroup':slewType}))
        metricList.append(configureMetric('ContributionMetric',
                                          kwargs={'col':'actDelay','activity':slewType,
                                                  'metricName':'Contribution'},
                                          displayDict={'group':'Slew', 'subgroup':slewType}))
        metricDict = makeDict(*metricList)
        slicer = configureSlicer('UniSlicer', metricDict=metricDict,constraints=[''],
                                 table='slewActivities', metadata=slewType, metadataVerbatim=True)
        slicerList.append(slicer)


    config.slicers=makeDict(*slicerList)
    return config
import numpy as np
from lsst.sims.maf.driver.mafConfig import configureSlicer, configureMetric, makeDict

# A driver config for the plots on https://confluence.lsstcorp.org/display/SIM/MAF+documentation
# and https://confluence.lsstcorp.org/display/SIM/MAF%3A++Writing+a+new+metric

root.outputDir = './Doc'
root.dbAddress = {'dbAddress':'sqlite:///opsimblitz2_1060_sqlite.db'}
root.opsimName = 'opsimblitz2_1060'

root.figformat='png'

slicerList=[]

m1 = configureMetric('CountMetric', kwargs={'col':'slewTime'}, plotDict={'logScale':True})
slicer = configureSlicer('OneDSlicer', kwargs={"sliceColName":'slewTime', 'binsize':5.},
                         metricDict=makeDict(m1), constraints=[''] )
slicerList.append(slicer)

constraints = ["filter = \'%s\'"%'r']
m1 = configureMetric('MinMetric', kwargs={'col':'airmass'}, plotDict={'cmap':'RdBu'})
metricDict = makeDict(m1)
slicer = configureSlicer('OpsimFieldSlicer', metricDict=metricDict, constraints=constraints )
slicerList.append(slicer)

nside=64
constraints = ["filter = \'%s\'"%'r']
m2 = configureMetric('Coaddm5Metric', plotDict={'zp':27., 'percentileClip':95, 'units':'Co-add m5 - %.1f'%27.} )
metricDict = makeDict(m2)
slicer = configureSlicer('HealpixSlicer',
                          kwargs={"nside":nside,'spatialkey1':"fieldRA", 'spatialkey2':"fieldDec"},
Exemple #34
0
root.dbAddress = {'dbAddress':'sqlite:///opsimblitz2_1060_sqlite.db'}
# Name of this run (filename base)
root.opsimName = 'opsimblitz2_1060'

# Make an empty list to hold all the slicer configs
sliceList = []

# Make a set of SQL where constraints to only use each filter
constraints = []
filters = ['u','g','r','i','z','y']
for f in filters:
    constraints.append("filter = '%s'"%f)
#["filter = 'u'", "filter = 'g'", "filter = 'r'", "filter = 'i'", "filter = 'z'", "filter = 'y'"]

# Run 2 metrics, the mean seeing and the co-added 5-sigma limiting depth.
metric1 = configureMetric('MeanMetric', kwargs={'col':'finSeeing'})
metric2 = configureMetric('Coaddm5Metric', plotDict={'cbarFormat':'%.3g'})

# Configure a slicer.  Use the Healpix slicer to make sky maps and power spectra.
slicer = configureSlicer('HealpixSlicer', metricDict=makeDict(metric1,metric2),
                          kwargs={'nside':16}, constraints=constraints)
sliceList.append(slicer)

metric = configureMetric('MeanMetric', kwargs={'col':'finSeeing'})
# Configure a slicer.  Use the UniSlicer to simply take all the data.
slicer = configureSlicer('UniSlicer', metricDict=makeDict(metric),
                          constraints=constraints)
sliceList.append(slicer)