Exemplo n.º 1
0
    def testBlobs(self):
        """
        Set up a blob selection survey
        """
        nside = 32
        survey_length = 2.0  # days

        surveys = []
        # Set up the DD
        dd_surveys = generate_dd_surveys(nside=nside)
        surveys.append(dd_surveys)

        surveys.append(gen_blob_surveys(nside))
        surveys.append(gen_greedy_surveys(nside))

        scheduler = Core_scheduler(surveys, nside=nside)
        observatory = Model_observatory(nside=nside)
        observatory, scheduler, observations = sim_runner(
            observatory, scheduler, survey_length=survey_length, filename=None)

        # Make sure some blobs executed
        assert ('blob, gg, b' in observations['note'])
        assert ('blob, gg, a' in observations['note'])
        # assert('blob, u' in observations['note'])

        # Make sure some greedy executed
        assert ('' in observations['note'])
        # Check that the a DD was observed
        assert ('DD:ELAISS1' in observations['note'])
        # Make sure a few different filters were observed
        assert (len(np.unique(observations['filter'])) > 3)
        # Make sure lots of observations executed
        assert (observations.size > 1000)
        # Make sure nothing tried to look through the earth
        assert (np.min(observations['alt']) > 0)
Exemplo n.º 2
0
    def testGreedy(self):
        """
        Set up a greedy survey and run for a few days. A crude way to touch lots of code.
        """
        nside = 32
        survey_length = 2.0  # days

        surveys = gen_greedy_surveys(nside)
        # Depricating Pairs_survey_scripted
        #surveys.append(Pairs_survey_scripted(None, ignore_obs='DD'))

        # Set up the DD
        dd_surveys = generate_dd_surveys(nside=nside)
        surveys.extend(dd_surveys)

        scheduler = Core_scheduler(surveys, nside=nside)
        observatory = Model_observatory(nside=nside)
        observatory, scheduler, observations = sim_runner(
            observatory, scheduler, survey_length=survey_length, filename=None)

        # Check that greedy observed some
        assert ('' in observations['note'])
        # Check that the a DD was observed
        assert ('DD:ELAISS1' in observations['note'])
        # Make sure a few different filters were observed
        assert (len(np.unique(observations['filter'])) > 3)
        # Make sure lots of observations executed
        assert (observations.size > 1000)
        # Make sure nothing tried to look through the earth
        assert (np.min(observations['alt']) > 0)
Exemplo n.º 3
0
def gen_greedy_surveys(nside, add_DD=True):
    """
    Make a quick set of greedy surveys
    """
    target_map = standard_goals(nside=nside)
    norm_factor = calc_norm_factor(target_map)
    filters = ['u', 'g', 'r', 'i', 'z', 'y']
    surveys = []

    for filtername in filters:
        bfs = []
        bfs.append(
            bf.M5_diff_basis_function(filtername=filtername, nside=nside))
        bfs.append(
            bf.Target_map_basis_function(filtername=filtername,
                                         target_map=target_map[filtername],
                                         out_of_bounds_val=np.nan,
                                         nside=nside,
                                         norm_factor=norm_factor))
        bfs.append(
            bf.Slewtime_basis_function(filtername=filtername, nside=nside))
        bfs.append(bf.Strict_filter_basis_function(filtername=filtername))
        # Masks, give these 0 weight
        bfs.append(
            bf.Zenith_shadow_mask_basis_function(nside=nside,
                                                 shadow_minutes=60.,
                                                 max_alt=76.))
        bfs.append(
            bf.Moon_avoidance_basis_function(nside=nside, moon_distance=40.))
        bfs.append(bf.Clouded_out_basis_function())

        bfs.append(bf.Filter_loaded_basis_function(filternames=filtername))

        weights = np.array([3.0, 0.3, 3., 3., 0., 0., 0., 0.])
        surveys.append(
            Greedy_survey(bfs,
                          weights,
                          block_size=1,
                          filtername=filtername,
                          dither=True,
                          nside=nside,
                          ignore_obs='DD'))

    surveys.append(Pairs_survey_scripted(None, ignore_obs='DD'))
    if add_DD:
        dd_surveys = generate_dd_surveys(nside=nside)

    surveys.extend(dd_surveys)

    return surveys
Exemplo n.º 4
0
def run_simple_sim():
    nside = 32
    survey_length = 2.1  # days

    surveys = gen_greedy_surveys(nside)
    surveys.append(Pairs_survey_scripted(None, ignore_obs='DD'))

    # Set up the DD
    dd_surveys = generate_dd_surveys(nside=nside)
    surveys.extend(dd_surveys)

    scheduler = Core_scheduler(surveys, nside=nside)
    observatory = Mock_observatory(nside=nside)
    observatory, scheduler, observations = sim_runner(
        observatory, scheduler, survey_length=survey_length, filename=None)
def make_scheduler(scale_down=False, max_dither=0.7, nexp=1):
    nside = 32
    per_night = True  # Dither DDF per night

    camera_ddf_rot_limit = 75.

    extra_info = {}
    exec_command = ''
    for arg in sys.argv:
        exec_command += ' ' + arg
    extra_info['exec command'] = exec_command
    try:
        extra_info['git hash'] = subprocess.check_output(
            ['git', 'rev-parse', 'HEAD'])
    except subprocess.CalledProcessError:
        extra_info['git hash'] = 'Not in git repo'

    extra_info['file executed'] = os.path.realpath(__file__)

    fileroot = 'baseline_nexp%i_' % nexp
    file_end = 'v1.6_'

    if scale_down:
        footprints = nes_light_footprints(nside=nside)
        fileroot = fileroot + 'scaleddown_'
    else:
        footprints = standard_goals(nside=nside)

    # Set up the DDF surveys to dither
    dither_detailer = detailers.Dither_detailer(per_night=per_night,
                                                max_dither=max_dither)
    details = [
        detailers.Camera_rot_detailer(min_rot=-camera_ddf_rot_limit,
                                      max_rot=camera_ddf_rot_limit),
        dither_detailer
    ]
    ddfs = generate_dd_surveys(nside=nside, nexp=nexp, detailers=details)

    greedy = gen_greedy_surveys(nside, nexp=nexp, footprints=footprints)
    blobs = generate_blobs(nside, nexp=nexp, footprints=footprints)
    surveys = [ddfs, blobs, greedy]
    scheduler = Core_scheduler(surveys, nside=nside)
    return scheduler
Exemplo n.º 6
0
                        filtername2=filtername2,
                        ideal_pair_time=pair_time,
                        nside=nside,
                        survey_note=survey_name,
                        ignore_obs='DD',
                        dither=True))

    return surveys


if __name__ == "__main__":
    nside = 32
    survey_length = 365.25 * 10  # Days
    years = int(survey_length / 365.25)

    greedy = gen_greedy_surveys(nside)
    ddfs = generate_dd_surveys(nside=nside)
    blobs = generate_blobs(nside)

    surveys = [ddfs, blobs, greedy]

    n_visit_limit = None
    scheduler = Core_scheduler(surveys, nside=nside)
    observatory = Model_observatory(nside=nside)
    observatory, scheduler, observations = sim_runner(
        observatory,
        scheduler,
        survey_length=survey_length,
        filename='blob_no_slew_%i.db' % years,
        n_visit_limit=n_visit_limit)
Exemplo n.º 7
0
    extra_info['git hash'] = subprocess.check_output(
        ['git', 'rev-parse', 'HEAD'])
    extra_info['file executed'] = os.path.realpath(__file__)

    # Just load up all the potential footprints, then use the arg to grab the right one
    target_maps = {}
    target_maps['big_sky'] = big_sky(nside=nside)
    target_maps['gp_heavy'] = gp_smooth(nside=nside)
    target_maps['baseline'] = standard_goals(nside=nside)
    target_maps['big_sky_nouiy'] = big_sky_nouiy(nside=nside)
    target_maps['newA'] = newA(nside=nside)
    target_maps['newB'] = newB(nside=nside)
    target_maps['bluer_footprint'] = bluer_footprint(nside=nside)
    target_maps['stuck_rolling'] = stuck_rolling(nside=nside)
    target_maps['big_sky_dust'] = big_sky_dust(nside=nside)

    greedy = gen_greedy_surveys(nside,
                                nexp=nexp,
                                target_map=target_maps[target_name])
    ddfs = generate_dd_surveys(nside=nside, nexp=nexp)
    blobs = generate_blobs(nside,
                           nexp=nexp,
                           mixed_pairs=True,
                           target_map=target_maps[target_name])
    surveys = [ddfs, blobs, greedy]
    run_sched(surveys,
              survey_length=survey_length,
              fileroot=os.path.join(outDir, target_name),
              verbose=verbose,
              extra_info=extra_info)
Exemplo n.º 8
0
def scienceRadarBatch(colmap=None,
                      runName='opsim',
                      extraSql=None,
                      extraMetadata=None,
                      nside=64,
                      benchmarkArea=18000,
                      benchmarkNvisits=825,
                      DDF=True):
    """A batch of metrics for looking at survey performance relative to the SRD and the main
    science drivers of LSST.

    Parameters
    ----------

    """
    # Hide dependencies
    from mafContrib.LSSObsStrategy.galaxyCountsMetric_extended import GalaxyCountsMetric_extended
    from mafContrib import Plasticc_metric, plasticc_slicer, load_plasticc_lc, TDEsAsciiMetric

    if colmap is None:
        colmap = ColMapDict('fbs')

    if extraSql is None:
        extraSql = ''
    if extraSql == '':
        joiner = ''
    else:
        joiner = ' and '

    bundleList = []
    # Get some standard per-filter coloring and sql constraints
    filterlist, colors, filterorders, filtersqls, filtermetadata = filterList(
        all=False, extraSql=extraSql, extraMetadata=extraMetadata)

    standardStats = standardSummary(withCount=False)

    healslicer = slicers.HealpixSlicer(nside=nside)
    subsetPlots = [plots.HealpixSkyMap(), plots.HealpixHistogram()]

    # Load up the plastic light curves
    models = ['SNIa-normal', 'KN']
    plasticc_models_dict = {}
    for model in models:
        plasticc_models_dict[model] = list(
            load_plasticc_lc(model=model).values())

    #########################
    # SRD, DM, etc
    #########################
    fOb = fOBatch(runName=runName,
                  colmap=colmap,
                  extraSql=extraSql,
                  extraMetadata=extraMetadata,
                  benchmarkArea=benchmarkArea,
                  benchmarkNvisits=benchmarkNvisits)
    astromb = astrometryBatch(runName=runName,
                              colmap=colmap,
                              extraSql=extraSql,
                              extraMetadata=extraMetadata)
    rapidb = rapidRevisitBatch(runName=runName,
                               colmap=colmap,
                               extraSql=extraSql,
                               extraMetadata=extraMetadata)

    # loop through and modify the display dicts - set SRD as group and their previous 'group' as the subgroup
    temp_list = []
    for key in fOb:
        temp_list.append(fOb[key])
    for key in astromb:
        temp_list.append(astromb[key])
    for key in rapidb:
        temp_list.append(rapidb[key])
    for metricb in temp_list:
        metricb.displayDict['subgroup'] = metricb.displayDict['group'].replace(
            'SRD', '').lstrip(' ')
        metricb.displayDict['group'] = 'SRD'
    bundleList.extend(temp_list)

    displayDict = {
        'group': 'SRD',
        'subgroup': 'Year Coverage',
        'order': 0,
        'caption': 'Number of years with observations.'
    }
    slicer = slicers.HealpixSlicer(nside=nside)
    metric = metrics.YearCoverageMetric()
    for f in filterlist:
        plotDict = {'colorMin': 7, 'colorMax': 10, 'color': colors[f]}
        summary = [
            metrics.AreaSummaryMetric(area=18000,
                                      reduce_func=np.mean,
                                      decreasing=True,
                                      metricName='N Seasons (18k) %s' % f)
        ]
        bundleList.append(
            mb.MetricBundle(metric,
                            slicer,
                            filtersqls[f],
                            plotDict=plotDict,
                            metadata=filtermetadata[f],
                            displayDict=displayDict,
                            summaryMetrics=summary))

    #########################
    # Solar System
    #########################
    # Generally, we need to run Solar System metrics separately; they're a multi-step process.

    #########################
    # Cosmology
    #########################

    displayDict = {
        'group': 'Cosmology',
        'subgroup': 'Galaxy Counts',
        'order': 0,
        'caption': None
    }
    plotDict = {'percentileClip': 95., 'nTicks': 5}
    sql = extraSql + joiner + 'filter="i"'
    metadata = combineMetadata(extraMetadata, 'i band')
    metric = GalaxyCountsMetric_extended(filterBand='i',
                                         redshiftBin='all',
                                         nside=nside)
    summary = [
        metrics.AreaSummaryMetric(area=18000,
                                  reduce_func=np.sum,
                                  decreasing=True,
                                  metricName='N Galaxies (18k)')
    ]
    summary.append(metrics.SumMetric(metricName='N Galaxies (all)'))
    # make sure slicer has cache off
    slicer = slicers.HealpixSlicer(nside=nside, useCache=False)
    bundle = mb.MetricBundle(metric,
                             slicer,
                             sql,
                             plotDict=plotDict,
                             metadata=metadata,
                             displayDict=displayDict,
                             summaryMetrics=summary,
                             plotFuncs=subsetPlots)
    bundleList.append(bundle)
    displayDict['order'] += 1

    # let's put Type Ia SN in here
    displayDict['subgroup'] = 'SNe Ia'
    # XXX-- use the light curves from PLASTICC here
    displayDict['caption'] = 'Fraction of normal SNe Ia'
    sql = extraSql
    slicer = plasticc_slicer(plcs=plasticc_models_dict['SNIa-normal'],
                             seed=42,
                             badval=0)
    metric = Plasticc_metric(metricName='SNIa')
    # Set the maskval so that we count missing objects as zero.
    summary_stats = [metrics.MeanMetric(maskVal=0)]
    plotFuncs = [plots.HealpixSkyMap()]
    bundle = mb.MetricBundle(metric,
                             slicer,
                             sql,
                             runName=runName,
                             summaryMetrics=summary_stats,
                             plotFuncs=plotFuncs,
                             metadata=extraMetadata,
                             displayDict=displayDict)
    bundleList.append(bundle)
    displayDict['order'] += 1

    displayDict['subgroup'] = 'Camera Rotator'
    displayDict[
        'caption'] = 'Kuiper statistic (0 is uniform, 1 is delta function) of the '
    slicer = slicers.HealpixSlicer(nside=nside)
    metric1 = metrics.KuiperMetric('rotSkyPos')
    metric2 = metrics.KuiperMetric('rotTelPos')
    for f in filterlist:
        for m in [metric1, metric2]:
            plotDict = {'color': colors[f]}
            displayDict['order'] = filterorders[f]
            displayDict['caption'] += f"{m.colname} for visits in {f} band."
            bundleList.append(
                mb.MetricBundle(m,
                                slicer,
                                filtersqls[f],
                                plotDict=plotDict,
                                displayDict=displayDict,
                                summaryMetrics=standardStats,
                                plotFuncs=subsetPlots))

    # XXX--need some sort of metric for weak lensing

    #########################
    # Variables and Transients
    #########################
    displayDict = {
        'group': 'Variables/Transients',
        'subgroup': 'Periodic Stars',
        'order': 0,
        'caption': None
    }
    for period in [
            0.5,
            1,
            2,
    ]:
        for magnitude in [21., 24.]:
            amplitudes = [0.05, 0.1, 1.0]
            periods = [period] * len(amplitudes)
            starMags = [magnitude] * len(amplitudes)

            plotDict = {
                'nTicks': 3,
                'colorMin': 0,
                'colorMax': 3,
                'xMin': 0,
                'xMax': 3
            }
            metadata = combineMetadata(
                'P_%.1f_Mag_%.0f_Amp_0.05-0.1-1' % (period, magnitude),
                extraMetadata)
            sql = None
            displayDict['caption'] = 'Metric evaluates if a periodic signal of period %.1f days could ' \
                                     'be detected for an r=%i star. A variety of amplitudes of periodicity ' \
                                     'are tested: [1, 0.1, and 0.05] mag amplitudes, which correspond to ' \
                                     'metric values of [1, 2, or 3]. ' % (period, magnitude)
            metric = metrics.PeriodicDetectMetric(periods=periods,
                                                  starMags=starMags,
                                                  amplitudes=amplitudes,
                                                  metricName='PeriodDetection')
            bundle = mb.MetricBundle(metric,
                                     healslicer,
                                     sql,
                                     metadata=metadata,
                                     displayDict=displayDict,
                                     plotDict=plotDict,
                                     plotFuncs=subsetPlots,
                                     summaryMetrics=standardStats)
            bundleList.append(bundle)
            displayDict['order'] += 1

    # XXX add some PLASTICC metrics for kilovnova and tidal disruption events.
    displayDict['subgroup'] = 'KN'
    displayDict['caption'] = 'Fraction of Kilonova (from PLASTICC)'
    displayDict['order'] = 0
    slicer = plasticc_slicer(plcs=plasticc_models_dict['KN'],
                             seed=43,
                             badval=0)
    metric = Plasticc_metric(metricName='KN')
    plotFuncs = [plots.HealpixSkyMap()]
    summary_stats = [metrics.MeanMetric(maskVal=0)]
    bundle = mb.MetricBundle(metric,
                             slicer,
                             extraSql,
                             runName=runName,
                             summaryMetrics=summary_stats,
                             plotFuncs=plotFuncs,
                             metadata=extraMetadata,
                             displayDict=displayDict)
    bundleList.append(bundle)

    # Tidal Disruption Events
    displayDict['subgroup'] = 'TDE'
    displayDict[
        'caption'] = 'Fraction of TDE lightcurves that could be identified, outside of DD fields'
    detectSNR = {'u': 5, 'g': 5, 'r': 5, 'i': 5, 'z': 5, 'y': 5}

    # light curve parameters
    epochStart = -22
    peakEpoch = 0
    nearPeakT = 10
    postPeakT = 14  # two weeks
    nPhaseCheck = 1

    # condition parameters
    nObsTotal = {'u': 0, 'g': 0, 'r': 0, 'i': 0, 'z': 0, 'y': 0}
    nObsPrePeak = 1
    nObsNearPeak = {'u': 0, 'g': 0, 'r': 0, 'i': 0, 'z': 0, 'y': 0}
    nFiltersNearPeak = 3
    nObsPostPeak = 0
    nFiltersPostPeak = 2

    metric = TDEsAsciiMetric(asciifile=None,
                             detectSNR=detectSNR,
                             epochStart=epochStart,
                             peakEpoch=peakEpoch,
                             nearPeakT=nearPeakT,
                             postPeakT=postPeakT,
                             nPhaseCheck=nPhaseCheck,
                             nObsTotal=nObsTotal,
                             nObsPrePeak=nObsPrePeak,
                             nObsNearPeak=nObsNearPeak,
                             nFiltersNearPeak=nFiltersNearPeak,
                             nObsPostPeak=nObsPostPeak,
                             nFiltersPostPeak=nFiltersPostPeak)
    slicer = slicers.HealpixSlicer(nside=32)
    sql = extraSql + joiner + "note not like '%DD%'"
    md = extraMetadata
    if md is None:
        md = " NonDD"
    else:
        md += 'NonDD'
    bundle = mb.MetricBundle(metric,
                             slicer,
                             sql,
                             runName=runName,
                             summaryMetrics=standardStats,
                             plotFuncs=plotFuncs,
                             metadata=md,
                             displayDict=displayDict)
    bundleList.append(bundle)

    # XXX -- would be good to add some microlensing events, for both MW and LMC/SMC.

    #########################
    # Milky Way
    #########################

    displayDict = {'group': 'Milky Way', 'subgroup': ''}

    displayDict['subgroup'] = 'N stars'
    slicer = slicers.HealpixSlicer(nside=nside, useCache=False)
    sum_stats = [metrics.SumMetric(metricName='Total N Stars')]
    for f in filterlist:
        displayDict['order'] = filterorders[f]
        displayDict['caption'] = 'Number of stars in %s band with an measurement error due to crowding ' \
                                 'of less than 0.1 mag' % f
        # Configure the NstarsMetric - note 'filtername' refers to the filter in which to evaluate crowding
        metric = metrics.NstarsMetric(crowding_error=0.1,
                                      filtername='r',
                                      seeingCol=colmap['seeingGeom'],
                                      m5Col=colmap['fiveSigmaDepth'])
        plotDict = {'nTicks': 5, 'logScale': True, 'colorMin': 100}
        bundle = mb.MetricBundle(metric,
                                 slicer,
                                 filtersqls[f],
                                 runName=runName,
                                 summaryMetrics=sum_stats,
                                 plotFuncs=subsetPlots,
                                 plotDict=plotDict,
                                 displayDict=displayDict)
        bundleList.append(bundle)

    #########################
    # DDF
    #########################
    if DDF:
        # Hide this import to avoid adding a dependency.
        from lsst.sims.featureScheduler.surveys import generate_dd_surveys, Deep_drilling_survey
        ddf_surveys = generate_dd_surveys()

        # Add on the Euclid fields
        # XXX--to update. Should have a spot where all the DDF locations are stored.
        ddf_surveys.append(
            Deep_drilling_survey([], 58.97, -49.28, survey_name='DD:EDFSa'))
        ddf_surveys.append(
            Deep_drilling_survey([], 63.6, -47.60, survey_name='DD:EDFSb'))

        # For doing a high-res sampling of the DDF for co-adds
        ddf_radius = 1.8  # Degrees
        ddf_nside = 512

        ra, dec = hpid2RaDec(ddf_nside, np.arange(hp.nside2npix(ddf_nside)))

        displayDict = {'group': 'DDF depths', 'subgroup': None}

        for survey in ddf_surveys:
            displayDict['subgroup'] = survey.survey_name
            # Crop off the u-band only DDF
            if survey.survey_name[0:4] != 'DD:u':
                dist_to_ddf = angularSeparation(ra, dec, np.degrees(survey.ra),
                                                np.degrees(survey.dec))
                goodhp = np.where(dist_to_ddf <= ddf_radius)
                slicer = slicers.UserPointsSlicer(ra=ra[goodhp],
                                                  dec=dec[goodhp],
                                                  useCamera=False)
                for f in filterlist:
                    metric = metrics.Coaddm5Metric(
                        metricName=survey.survey_name + ', ' + f)
                    summary = [
                        metrics.MedianMetric(metricName='Median depth ' +
                                             survey.survey_name + ', ' + f)
                    ]
                    plotDict = {'color': colors[f]}
                    sql = filtersqls[f]
                    displayDict['order'] = filterorders[f]
                    displayDict['caption'] = 'Coadded m5 depth in %s band.' % (
                        f)
                    bundle = mb.MetricBundle(metric,
                                             slicer,
                                             sql,
                                             metadata=filtermetadata[f],
                                             displayDict=displayDict,
                                             summaryMetrics=summary,
                                             plotFuncs=[],
                                             plotDict=plotDict)
                    bundleList.append(bundle)

        displayDict = {'group': 'DDF Transients', 'subgroup': None}
        for survey in ddf_surveys:
            displayDict['subgroup'] = survey.survey_name
            if survey.survey_name[0:4] != 'DD:u':
                slicer = plasticc_slicer(
                    plcs=plasticc_models_dict['SNIa-normal'],
                    seed=42,
                    ra_cen=survey.ra,
                    dec_cen=survey.dec,
                    radius=np.radians(3.),
                    useCamera=False)
                metric = Plasticc_metric(metricName=survey.survey_name +
                                         ' SNIa')
                sql = extraSql
                summary_stats = [metrics.MeanMetric(maskVal=0)]
                plotFuncs = [plots.HealpixSkyMap()]
                bundle = mb.MetricBundle(metric,
                                         slicer,
                                         sql,
                                         runName=runName,
                                         summaryMetrics=summary_stats,
                                         plotFuncs=plotFuncs,
                                         metadata=extraMetadata,
                                         displayDict=displayDict)
                bundleList.append(bundle)
                displayDict['order'] = 10

    # Set the runName for all bundles and return the bundleDict.
    for b in bundleList:
        b.setRunName(runName)
    bundleDict = mb.makeBundlesDictFromList(bundleList)

    return bundleDict
Exemplo n.º 9
0
def generate_ddf(ddf_name, nyears=10, space=2):
    previous_ddf = generate_dd_surveys()
    survey_names = np.array([survey.survey_name for survey in previous_ddf])
    survey_indx = np.where(survey_names == ddf_name)[0].max()
    ddf_ra = previous_ddf[survey_indx].ra * u.rad
    ddf_dec = previous_ddf[survey_indx].dec * u.rad

    site = Site('LSST')
    location = EarthLocation(lat=site.latitude,
                             lon=site.longitude,
                             height=site.height)

    mjd = np.arange(59853.5, 59853.5 + 365.25 * nyears, 20. / 60 / 24.)
    times = Time(mjd, format='mjd', location=location)

    airmass_limit = 2.5  # demand airmass lower than this
    twilight_limit = -18.  # Sun below this altitude in degrees
    dist_to_moon_limit = 30.  # minimum distance to keep from moon degrees
    zenith_limit = 10.  # Need to be this far away from zenith to start (20 min = 5 deg)
    g_m5_limit = 23.5  # mags

    season_gap = 20.  # days. Count any gap longer than this as it's own season
    season_length_limit = 80  # Days. Demand at least this many days in a season

    # How long to keep attempting a DDF
    expire_dict = {1: 36. / 24., 2: 0.5}

    sun_coords = get_sun(times)
    moon_coords = get_moon(times)

    sched_downtime_data = ScheduledDowntimeData(Time(mjd[0], format='mjd'))
    observatory_up = np.ones(mjd.size, dtype=bool)
    for dt in sched_downtime_data():
        indx = np.where((mjd >= dt['start'].mjd) & (mjd <= dt['end'].mjd))[0]
        observatory_up[indx] = False

    lst = times.sidereal_time('mean')

    sun_altaz = sun_coords.transform_to(AltAz(location=location))

    # generate a night label for each timestep
    sun_rise = np.where((sun_altaz.alt[0:-1] < 0) & (sun_altaz.alt[1:] > 0))[0]
    night = np.zeros(mjd.size, dtype=int)
    night[sun_rise] = 1
    night = np.cumsum(night) + 1  # 1-index for night

    sun_down = np.where(sun_altaz.alt < twilight_limit * u.deg)[0]

    ddf_coord = SkyCoord(ra=ddf_ra, dec=ddf_dec)
    ddf_altaz = ddf_coord.transform_to(AltAz(location=location, obstime=times))
    ddf_airmass = 1. / np.cos(np.radians(90. - ddf_altaz.az.deg))
    zenith = AltAz(alt=90. * u.deg, az=0. * u.deg)
    ddf_zenth_dist = zenith.separation(ddf_altaz)

    nside = 32
    ddf_indx = raDec2Hpid(nside, ddf_coord.ra.deg, ddf_coord.dec.deg)
    sm = SkyModelPre()

    g_sb = mjd * 0 + np.nan

    indices = np.where((sun_altaz.alt < twilight_limit * u.deg)
                       & (ddf_airmass > airmass_limit))[0]
    # In theory, one could reach into the sky brightness model and do a much faster interpolation
    # There might be an airmass limit on the sky brightness.
    for indx in sun_down:
        g_sb[indx] = sm.returnMags(mjd[indx],
                                   indx=[ddf_indx],
                                   filters='g',
                                   badval=np.nan)['g']

    dist_to_moon = ddf_coord.separation(moon_coords)
    seeing_model = SeeingModel()
    ddf_approx_fwhmEff = seeing_model(0.7, ddf_airmass)
    # I think this should pluck out the g-filter. Really should be labled
    ddf_approx_fwhmEff = ddf_approx_fwhmEff['fwhmEff'][1].ravel()

    ddf_m5 = m5_flat_sed('g',
                         g_sb,
                         ddf_approx_fwhmEff,
                         30.,
                         ddf_airmass,
                         nexp=1.)

    # demand sun down past twilight, ddf is up, and observatory is open, and not too close to the moon
    good = np.where((ddf_airmass < airmass_limit)
                    & (sun_altaz.alt < twilight_limit * u.deg)
                    & (ddf_airmass > 0) & (observatory_up == True)
                    & (dist_to_moon > dist_to_moon_limit * u.deg)
                    & (ddf_zenth_dist > zenith_limit * u.deg)
                    & (ddf_m5 > g_m5_limit))

    potential_nights = np.unique(night[good])
    night_gap = potential_nights[1:] - potential_nights[0:-1]
    big_gap = np.where(night_gap > season_gap)[0] + 1
    season = potential_nights * 0
    season[big_gap] = 1
    season = np.cumsum(season)

    u_seasons = np.unique(season)
    season_lengths = []
    for se in u_seasons:
        in_se = np.where(season == se)
        season_lengths.append(
            np.max(potential_nights[in_se]) - np.min(potential_nights[in_se]))
    season_lengths = np.array(season_lengths)

    good_seasons = u_seasons[np.where(season_lengths > season_length_limit)[0]]
    gn = np.isin(season, good_seasons)
    potential_nights = potential_nights[gn]
    season = season[gn]

    obs_attempts = []
    for sea in np.unique(season):
        night_indx = np.where(season == sea)
        obs_attempts.append(
            place_obs(potential_nights[night_indx], space=space))
    obs_attempts = np.concatenate(obs_attempts)

    mjd_observe = []
    m5_approx = []
    for indx in np.where(obs_attempts > 0)[0]:
        in_night_indx = np.where(night == potential_nights[indx])[0]
        best_depth_indx = np.min(
            np.where(
                ddf_m5[in_night_indx] == np.nanmax(ddf_m5[in_night_indx]))[0])
        mjd_start = mjd[in_night_indx[best_depth_indx]]
        m5_approx.append(ddf_m5[in_night_indx[best_depth_indx]])
        mjd_end = mjd_start + expire_dict[obs_attempts[indx]]
        mjd_observe.append((mjd_start, mjd_end))

    result = np.zeros(len(mjd_observe),
                      dtype=[('mjd_start', '<f8'), ('mjd_end', '<f8'),
                             ('label', '<U10')])
    mjd_observe = np.array(mjd_observe)
    result['mjd_start'] = mjd_observe[:, 0]
    result['mjd_end'] = mjd_observe[:, 1]
    result['label'] = ddf_name

    return result  #, ddf_ra, ddf_dec #, previous_ddf[survey_indx].observations, m5_approx
Exemplo n.º 10
0
def scienceRadarBatch(colmap=None,
                      runName='',
                      extraSql=None,
                      extraMetadata=None,
                      nside=64,
                      benchmarkArea=18000,
                      benchmarkNvisits=825,
                      DDF=True):
    """A batch of metrics for looking at survey performance relative to the SRD and the main
    science drivers of LSST.

    Parameters
    ----------

    """
    # Hide dependencies
    from mafContrib.LSSObsStrategy.galaxyCountsMetric_extended import GalaxyCountsMetric_extended
    from mafContrib import Plasticc_metric, plasticc_slicer, load_plasticc_lc

    if colmap is None:
        colmap = ColMapDict('opsimV4')

    if extraSql is None:
        extraSql = ''
    if extraSql == '':
        joiner = ''
    else:
        joiner = ' and '

    bundleList = []

    healslicer = slicers.HealpixSlicer(nside=nside)
    subsetPlots = [plots.HealpixSkyMap(), plots.HealpixHistogram()]

    # Load up the plastic light curves
    models = ['SNIa-normal', 'KN']
    plasticc_models_dict = {}
    for model in models:
        plasticc_models_dict[model] = list(
            load_plasticc_lc(model=model).values())

    #########################
    # SRD, DM, etc
    #########################
    sql = extraSql
    displayDict = {
        'group': 'SRD',
        'subgroup': 'fO',
        'order': 0,
        'caption': None
    }
    metric = metrics.CountMetric(col=colmap['mjd'], metricName='fO')
    plotDict = {
        'xlabel': 'Number of Visits',
        'Asky': benchmarkArea,
        'Nvisit': benchmarkNvisits,
        'xMin': 0,
        'xMax': 1500
    }
    summaryMetrics = [
        metrics.fOArea(nside=nside,
                       norm=False,
                       metricName='fOArea',
                       Asky=benchmarkArea,
                       Nvisit=benchmarkNvisits),
        metrics.fOArea(nside=nside,
                       norm=True,
                       metricName='fOArea/benchmark',
                       Asky=benchmarkArea,
                       Nvisit=benchmarkNvisits),
        metrics.fONv(nside=nside,
                     norm=False,
                     metricName='fONv',
                     Asky=benchmarkArea,
                     Nvisit=benchmarkNvisits),
        metrics.fONv(nside=nside,
                     norm=True,
                     metricName='fONv/benchmark',
                     Asky=benchmarkArea,
                     Nvisit=benchmarkNvisits)
    ]
    caption = 'The FO metric evaluates the overall efficiency of observing. '
    caption += (
        'foNv: out of %.2f sq degrees, the area receives at least X and a median of Y visits '
        '(out of %d, if compared to benchmark). ' %
        (benchmarkArea, benchmarkNvisits))
    caption += ('fOArea: this many sq deg (out of %.2f sq deg if compared '
                'to benchmark) receives at least %d visits. ' %
                (benchmarkArea, benchmarkNvisits))
    displayDict['caption'] = caption
    bundle = mb.MetricBundle(metric,
                             healslicer,
                             sql,
                             plotDict=plotDict,
                             displayDict=displayDict,
                             summaryMetrics=summaryMetrics,
                             plotFuncs=[plots.FOPlot()])
    bundleList.append(bundle)
    displayDict['order'] += 1

    displayDict = {
        'group': 'SRD',
        'subgroup': 'Gaps',
        'order': 0,
        'caption': None
    }
    plotDict = {'percentileClip': 95.}
    for filtername in 'ugrizy':
        sql = extraSql + joiner + 'filter ="%s"' % filtername
        metric = metrics.MaxGapMetric()
        summaryMetrics = [
            metrics.PercentileMetric(
                percentile=95,
                metricName='95th percentile of Max gap, %s' % filtername)
        ]
        bundle = mb.MetricBundle(metric,
                                 healslicer,
                                 sql,
                                 plotFuncs=subsetPlots,
                                 summaryMetrics=summaryMetrics,
                                 displayDict=displayDict,
                                 plotDict=plotDict)
        bundleList.append(bundle)
        displayDict['order'] += 1

    #########################
    # Solar System
    #########################

    # XXX -- may want to do Solar system seperatly

    # XXX--fraction of NEOs detected (assume some nominal size and albido)
    # XXX -- fraction of MBAs detected
    # XXX -- fraction of KBOs detected
    # XXX--any others? Planet 9s? Comets? Neptune Trojans?

    #########################
    # Cosmology
    #########################

    displayDict = {
        'group': 'Cosmology',
        'subgroup': 'galaxy counts',
        'order': 0,
        'caption': None
    }
    plotDict = {'percentileClip': 95.}
    sql = extraSql + joiner + 'filter="i"'
    metric = GalaxyCountsMetric_extended(filterBand='i',
                                         redshiftBin='all',
                                         nside=nside)
    summary = [
        metrics.AreaSummaryMetric(area=18000,
                                  reduce_func=np.sum,
                                  decreasing=True,
                                  metricName='N Galaxies (WFD)')
    ]
    summary.append(metrics.SumMetric(metricName='N Galaxies (all)'))
    # make sure slicer has cache off
    slicer = slicers.HealpixSlicer(nside=nside, useCache=False)
    bundle = mb.MetricBundle(metric,
                             slicer,
                             sql,
                             plotDict=plotDict,
                             displayDict=displayDict,
                             summaryMetrics=summary,
                             plotFuncs=subsetPlots)
    bundleList.append(bundle)
    displayDict['order'] += 1

    # let's put Type Ia SN in here
    displayDict['subgroup'] = 'SNe Ia'
    metadata = ''
    # XXX-- use the light curves from PLASTICC here
    displayDict['Caption'] = 'Fraction of normal SNe Ia'
    sql = ''
    slicer = plasticc_slicer(plcs=plasticc_models_dict['SNIa-normal'],
                             seed=42,
                             badval=0)
    metric = Plasticc_metric(metricName='SNIa')
    # Set the maskval so that we count missing objects as zero.
    summary_stats = [metrics.MeanMetric(maskVal=0)]
    plotFuncs = [plots.HealpixSkyMap()]
    bundle = mb.MetricBundle(metric,
                             slicer,
                             sql,
                             runName=runName,
                             summaryMetrics=summary_stats,
                             plotFuncs=plotFuncs,
                             metadata=metadata,
                             displayDict=displayDict)
    bundleList.append(bundle)
    displayDict['order'] += 1

    # XXX--need some sort of metric for weak lensing and camera rotation.

    #########################
    # Variables and Transients
    #########################
    displayDict = {
        'group': 'Variables and Transients',
        'subgroup': 'Periodic Stars',
        'order': 0,
        'caption': None
    }
    periods = [0.1, 0.5, 1., 2., 5., 10., 20.]  # days

    plotDict = {}
    metadata = ''
    sql = extraSql
    displayDict[
        'Caption'] = 'Measure of how well a periodic signal can be measured combining amplitude and phase coverage. 1 is perfect, 0 is no way to fit'
    for period in periods:
        summary = metrics.PercentileMetric(
            percentile=10.,
            metricName='10th %%-ile Periodic Quality, Period=%.1f days' %
            period)
        metric = metrics.PeriodicQualityMetric(
            period=period,
            starMag=20.,
            metricName='Periodic Stars, P=%.1f d' % period)
        bundle = mb.MetricBundle(metric,
                                 healslicer,
                                 sql,
                                 metadata=metadata,
                                 displayDict=displayDict,
                                 plotDict=plotDict,
                                 plotFuncs=subsetPlots,
                                 summaryMetrics=summary)
        bundleList.append(bundle)
        displayDict['order'] += 1

    # XXX add some PLASTICC metrics for kilovnova and tidal disruption events.
    displayDict['subgroup'] = 'KN'
    displayDict['caption'] = 'Fraction of Kilonova (from PLASTICC)'
    sql = ''
    slicer = plasticc_slicer(plcs=plasticc_models_dict['KN'],
                             seed=43,
                             badval=0)
    metric = Plasticc_metric(metricName='KN')
    summary_stats = [metrics.MeanMetric(maskVal=0)]
    plotFuncs = [plots.HealpixSkyMap()]
    bundle = mb.MetricBundle(metric,
                             slicer,
                             sql,
                             runName=runName,
                             summaryMetrics=summary_stats,
                             plotFuncs=plotFuncs,
                             metadata=metadata,
                             displayDict=displayDict)
    bundleList.append(bundle)

    displayDict['order'] += 1

    # XXX -- would be good to add some microlensing events, for both MW and LMC/SMC.

    #########################
    # Milky Way
    #########################

    # Let's do the proper motion, parallax, and DCR degen of a 20nd mag star
    rmag = 20.
    displayDict = {
        'group': 'Milky Way',
        'subgroup': 'Astrometry',
        'order': 0,
        'caption': None
    }

    sql = extraSql
    metadata = ''
    plotDict = {'percentileClip': 95.}
    metric = metrics.ParallaxMetric(metricName='Parallax Error r=%.1f' %
                                    (rmag),
                                    rmag=rmag,
                                    seeingCol=colmap['seeingGeom'],
                                    filterCol=colmap['filter'],
                                    m5Col=colmap['fiveSigmaDepth'],
                                    normalize=False)
    summary = [
        metrics.AreaSummaryMetric(area=18000,
                                  reduce_func=np.median,
                                  decreasing=False,
                                  metricName='Median Parallax Error (WFD)')
    ]
    summary.append(
        metrics.PercentileMetric(percentile=95,
                                 metricName='95th Percentile Parallax Error'))
    bundle = mb.MetricBundle(metric,
                             healslicer,
                             sql,
                             metadata=metadata,
                             displayDict=displayDict,
                             plotDict=plotDict,
                             plotFuncs=subsetPlots,
                             summaryMetrics=summary)
    bundleList.append(bundle)
    displayDict['order'] += 1

    metric = metrics.ProperMotionMetric(
        metricName='Proper Motion Error r=%.1f' % rmag,
        rmag=rmag,
        m5Col=colmap['fiveSigmaDepth'],
        mjdCol=colmap['mjd'],
        filterCol=colmap['filter'],
        seeingCol=colmap['seeingGeom'],
        normalize=False)
    summary = [
        metrics.AreaSummaryMetric(
            area=18000,
            reduce_func=np.median,
            decreasing=False,
            metricName='Median Proper Motion Error (WFD)')
    ]
    summary.append(
        metrics.PercentileMetric(
            metricName='95th Percentile Proper Motion Error'))
    bundle = mb.MetricBundle(metric,
                             healslicer,
                             sql,
                             metadata=metadata,
                             displayDict=displayDict,
                             plotDict=plotDict,
                             summaryMetrics=summary,
                             plotFuncs=subsetPlots)
    bundleList.append(bundle)
    displayDict['order'] += 1

    metric = metrics.ParallaxDcrDegenMetric(
        metricName='Parallax-DCR degeneracy r=%.1f' % (rmag),
        rmag=rmag,
        seeingCol=colmap['seeingEff'],
        filterCol=colmap['filter'],
        m5Col=colmap['fiveSigmaDepth'])
    caption = 'Correlation between parallax offset magnitude and hour angle for a r=%.1f star.' % (
        rmag)
    caption += ' (0 is good, near -1 or 1 is bad).'
    # XXX--not sure what kind of summary to do here
    summary = [metrics.MeanMetric(metricName='Mean DCR Degeneracy')]
    bundle = mb.MetricBundle(metric,
                             healslicer,
                             sql,
                             metadata=metadata,
                             displayDict=displayDict,
                             summaryMetrics=summary,
                             plotFuncs=subsetPlots)
    bundleList.append(bundle)
    displayDict['order'] += 1

    for b in bundleList:
        b.setRunName(runName)

    #########################
    # DDF
    #########################
    ddf_time_bundleDicts = []
    if DDF:
        # Hide this import to avoid adding a dependency.
        from lsst.sims.featureScheduler.surveys import generate_dd_surveys
        ddf_surveys = generate_dd_surveys()
        # For doing a high-res sampling of the DDF for co-adds
        ddf_radius = 1.8  # Degrees
        ddf_nside = 512

        ra, dec = hpid2RaDec(ddf_nside, np.arange(hp.nside2npix(ddf_nside)))

        displayDict = {
            'group': 'DDF depths',
            'subgroup': None,
            'order': 0,
            'caption': None
        }

        # Run the inter and intra gaps at the center of the DDFs
        for survey in ddf_surveys:
            slicer = slicers.UserPointsSlicer(ra=np.degrees(survey.ra),
                                              dec=np.degrees(survey.dec),
                                              useCamera=False)
            ddf_time_bundleDicts.append(
                interNight(colmap=colmap,
                           slicer=slicer,
                           runName=runName,
                           nside=64,
                           extraSql='note="%s"' % survey.survey_name,
                           subgroup=survey.survey_name)[0])
            ddf_time_bundleDicts.append(
                intraNight(colmap=colmap,
                           slicer=slicer,
                           runName=runName,
                           nside=64,
                           extraSql='note="%s"' % survey.survey_name,
                           subgroup=survey.survey_name)[0])

        for survey in ddf_surveys:
            displayDict['subgroup'] = survey.survey_name
            # Crop off the u-band only DDF
            if survey.survey_name[0:4] != 'DD:u':
                dist_to_ddf = angularSeparation(ra, dec, np.degrees(survey.ra),
                                                np.degrees(survey.dec))
                goodhp = np.where(dist_to_ddf <= ddf_radius)
                slicer = slicers.UserPointsSlicer(ra=ra[goodhp],
                                                  dec=dec[goodhp],
                                                  useCamera=False)
                for filtername in ['u', 'g', 'r', 'i', 'z', 'y']:
                    metric = metrics.Coaddm5Metric(
                        metricName=survey.survey_name + ', ' + filtername)
                    summary = [
                        metrics.MedianMetric(metricName='median depth ' +
                                             survey.survey_name + ', ' +
                                             filtername)
                    ]
                    sql = extraSql + joiner + 'filter = "%s"' % filtername
                    bundle = mb.MetricBundle(metric,
                                             slicer,
                                             sql,
                                             metadata=metadata,
                                             displayDict=displayDict,
                                             summaryMetrics=summary,
                                             plotFuncs=[])
                    bundleList.append(bundle)
                    displayDict['order'] += 1

        displayDict = {
            'group': 'DDF Transients',
            'subgroup': None,
            'order': 0,
            'caption': None
        }
        for survey in ddf_surveys:
            displayDict['subgroup'] = survey.survey_name
            if survey.survey_name[0:4] != 'DD:u':
                slicer = plasticc_slicer(
                    plcs=plasticc_models_dict['SNIa-normal'],
                    seed=42,
                    ra_cen=survey.ra,
                    dec_cen=survey.dec,
                    radius=np.radians(3.),
                    useCamera=False)
                metric = Plasticc_metric(metricName=survey.survey_name +
                                         ' SNIa')
                sql = ''
                summary_stats = [metrics.MeanMetric(maskVal=0)]
                plotFuncs = [plots.HealpixSkyMap()]
                bundle = mb.MetricBundle(metric,
                                         slicer,
                                         sql,
                                         runName=runName,
                                         summaryMetrics=summary_stats,
                                         plotFuncs=plotFuncs,
                                         metadata=metadata,
                                         displayDict=displayDict)
                bundleList.append(bundle)

    displayDict['order'] += 1

    for b in bundleList:
        b.setRunName(runName)

    bundleDict = mb.makeBundlesDictFromList(bundleList)

    intraDict = intraNight(colmap=colmap,
                           runName=runName,
                           nside=nside,
                           extraSql=extraSql,
                           extraMetadata=extraMetadata)[0]
    interDict = interNight(colmap=colmap,
                           runName=runName,
                           nside=nside,
                           extraSql=extraSql,
                           extraMetadata=extraMetadata)[0]

    bundleDict.update(intraDict)
    bundleDict.update(interDict)
    for ddf_time in ddf_time_bundleDicts:
        bundleDict.update(ddf_time)

    return bundleDict
Exemplo n.º 11
0
    bfs.append(
        basis_functions.Filter_loaded_basis_function(filternames=filtername))
    weights = np.array([3.0, 0.3, 3., 3., 0., 0., 0., 0.])
    surveys.append(
        survey.Greedy_survey(bfs,
                             weights,
                             block_size=1,
                             filtername=filtername,
                             dither=True,
                             nside=nside,
                             ignore_obs='DD'))
    greedy_surveys.append(surveys[-1])

# Set up the DD surveys
dd_surveys = survey.generate_dd_surveys()
survey_list_o_lists = [dd_surveys, pair_surveys, greedy_surveys]

# Debug to stop at a spot if needed
n_visit_limit = None

# put in as list-of-lists so pairs get evaluated first.
scheduler = fs.Core_scheduler(survey_list_o_lists, nside=nside)
observatory = Speed_observatory(nside=nside, quickTest=True)
observatory, scheduler, observations = sim_runner(
    observatory,
    scheduler,
    survey_length=survey_length,
    filename='baseline_test%iyrs.db' % years,
    delete_past=True,
    n_visit_limit=n_visit_limit)
Exemplo n.º 12
0
def scienceRadarBatch(colmap=None, runName='opsim', extraSql=None, extraMetadata=None, nside=64,
                      benchmarkArea=18000, benchmarkNvisits=825, DDF=True):
    """A batch of metrics for looking at survey performance relative to the SRD and the main
    science drivers of LSST.

    Parameters
    ----------

    """
    # Hide dependencies
    from mafContrib.LSSObsStrategy.galaxyCountsMetric_extended import GalaxyCountsMetric_extended
    from mafContrib import (Plasticc_metric, plasticc_slicer, load_plasticc_lc,
                            TdePopMetric, generateTdePopSlicer,
                            generateMicrolensingSlicer, MicrolensingMetric)

    if colmap is None:
        colmap = ColMapDict('fbs')

    if extraSql is None:
        extraSql = ''
    if extraSql == '':
        joiner = ''
    else:
        joiner = ' and '

    bundleList = []
    # Get some standard per-filter coloring and sql constraints
    filterlist, colors, filterorders, filtersqls, filtermetadata = filterList(all=False,
                                                                              extraSql=extraSql,
                                                                              extraMetadata=extraMetadata)

    standardStats = standardSummary(withCount=False)

    healslicer = slicers.HealpixSlicer(nside=nside)
    subsetPlots = [plots.HealpixSkyMap(), plots.HealpixHistogram()]

    # Load up the plastic light curves - SNIa-normal are loaded in descWFDBatch
    models = ['SNIa-normal', 'KN']
    plasticc_models_dict = {}
    for model in models:
        plasticc_models_dict[model] = list(load_plasticc_lc(model=model).values())

    #########################
    # SRD, DM, etc
    #########################
    fOb = fOBatch(runName=runName, colmap=colmap, extraSql=extraSql, extraMetadata=extraMetadata,
                  benchmarkArea=benchmarkArea, benchmarkNvisits=benchmarkNvisits)
    astromb = astrometryBatch(runName=runName, colmap=colmap, extraSql=extraSql, extraMetadata=extraMetadata)
    rapidb = rapidRevisitBatch(runName=runName, colmap=colmap, extraSql=extraSql, extraMetadata=extraMetadata)

    # loop through and modify the display dicts - set SRD as group and their previous 'group' as the subgroup
    temp_list = []
    for key in fOb:
        temp_list.append(fOb[key])
    for key in astromb:
        temp_list.append(astromb[key])
    for key in rapidb:
        temp_list.append(rapidb[key])
    for metricb in temp_list:
        metricb.displayDict['subgroup'] = metricb.displayDict['group'].replace('SRD', '').lstrip(' ')
        metricb.displayDict['group'] = 'SRD'
    bundleList.extend(temp_list)

    displayDict = {'group': 'SRD', 'subgroup': 'Year Coverage', 'order': 0,
                   'caption': 'Number of years with observations.'}
    slicer = slicers.HealpixSlicer(nside=nside)
    metric = metrics.YearCoverageMetric()
    for f in filterlist:
        plotDict = {'colorMin': 7, 'colorMax': 10, 'color': colors[f]}
        summary = [metrics.AreaSummaryMetric(area=18000, reduce_func=np.mean, decreasing=True,
                                             metricName='N Seasons (18k) %s' % f)]
        bundleList.append(mb.MetricBundle(metric, slicer, filtersqls[f],
                                          plotDict=plotDict, metadata=filtermetadata[f],
                                          displayDict=displayDict, summaryMetrics=summary))

    #########################
    # Solar System
    #########################
    # Generally, we need to run Solar System metrics separately; they're a multi-step process.


    #########################
    # Galaxies
    #########################

    displayDict = {'group': 'Galaxies', 'subgroup': 'Galaxy Counts', 'order': 0, 'caption': None}
    plotDict = {'percentileClip': 95., 'nTicks': 5}
    sql = extraSql + joiner + 'filter="i"'
    metadata = combineMetadata(extraMetadata, 'i band')
    metric = GalaxyCountsMetric_extended(filterBand='i', redshiftBin='all', nside=nside)
    summary = [metrics.AreaSummaryMetric(area=18000, reduce_func=np.sum, decreasing=True,
                                         metricName='N Galaxies (18k)')]
    summary.append(metrics.SumMetric(metricName='N Galaxies (all)'))
    # make sure slicer has cache off
    slicer = slicers.HealpixSlicer(nside=nside, useCache=False)
    displayDict['caption'] = 'Number of galaxies across the sky, in i band. Generally, full survey footprint.'
    bundle = mb.MetricBundle(metric, slicer, sql, plotDict=plotDict,
                             metadata=metadata,
                             displayDict=displayDict, summaryMetrics=summary,
                             plotFuncs=subsetPlots)
    bundleList.append(bundle)
    displayDict['order'] += 1


    #########################
    # Cosmology
    #########################

    # note the desc batch does not currently take the extraSql or extraMetadata arguments.
    descBundleDict = descWFDBatch(colmap=colmap, runName=runName, nside=nside)
    for d in descBundleDict:
        bundleList.append(descBundleDict[d])

    #########################
    # Variables and Transients
    #########################
    displayDict = {'group': 'Variables/Transients',
                   'subgroup': 'Periodic Stars',
                   'order': 0, 'caption': None}
    for period in [0.5, 1, 2,]:
        for magnitude in [21., 24.]:
            amplitudes = [0.05, 0.1, 1.0]
            periods = [period] * len(amplitudes)
            starMags = [magnitude] * len(amplitudes)

            plotDict = {'nTicks': 3, 'colorMin': 0, 'colorMax': 3, 'xMin': 0, 'xMax': 3}
            metadata = combineMetadata('P_%.1f_Mag_%.0f_Amp_0.05-0.1-1' % (period, magnitude),
                                       extraMetadata)
            sql = None
            displayDict['caption'] = 'Metric evaluates if a periodic signal of period %.1f days could ' \
                                     'be detected for an r=%i star. A variety of amplitudes of periodicity ' \
                                     'are tested: [1, 0.1, and 0.05] mag amplitudes, which correspond to ' \
                                     'metric values of [1, 2, or 3]. ' % (period, magnitude)
            metric = metrics.PeriodicDetectMetric(periods=periods, starMags=starMags,
                                                  amplitudes=amplitudes,
                                                  metricName='PeriodDetection')
            bundle = mb.MetricBundle(metric, healslicer, sql, metadata=metadata,
                                     displayDict=displayDict, plotDict=plotDict,
                                     plotFuncs=subsetPlots, summaryMetrics=standardStats)
            bundleList.append(bundle)
            displayDict['order'] += 1

    # XXX add some PLASTICC metrics for kilovnova and tidal disruption events.
    displayDict['subgroup'] = 'KN'
    displayDict['caption'] = 'Fraction of Kilonova (from PLASTICC)'
    displayDict['order'] = 0
    slicer = plasticc_slicer(plcs=plasticc_models_dict['KN'], seed=43, badval=0)
    metric = Plasticc_metric(metricName='KN')
    plotFuncs = [plots.HealpixSkyMap()]
    summary_stats = [metrics.MeanMetric(maskVal=0)]
    bundle = mb.MetricBundle(metric, slicer, extraSql, runName=runName, summaryMetrics=summary_stats,
                             plotFuncs=plotFuncs, metadata=extraMetadata,
                             displayDict=displayDict)
    bundleList.append(bundle)

    # Tidal Disruption Events
    displayDict['subgroup'] = 'TDE'
    displayDict['caption'] = 'TDE lightcurves that could be identified'

    metric = TdePopMetric()
    slicer = generateTdePopSlicer()
    sql = ''
    plotDict = {'reduceFunc': np.sum, 'nside': 128}
    plotFuncs = [plots.HealpixSkyMap()]
    bundle = mb.MetricBundle(metric, slicer, sql, runName=runName,
                             plotDict=plotDict, plotFuncs=plotFuncs,
                             summaryMetrics=[metrics.MeanMetric(maskVal=0)],
                             displayDict=displayDict)
    bundleList.append(bundle)


    # Microlensing events
    displayDict['subgroup'] = 'Microlensing'
    displayDict['caption'] = 'Fast microlensing events'

    plotDict = {'nside': 128}
    sql = ''
    slicer = generateMicrolensingSlicer(min_crossing_time=1, max_crossing_time=10)
    metric = MicrolensingMetric(metricName='Fast Microlensing')
    bundle = mb.MetricBundle(metric, slicer, sql, runName=runName,
                             summaryMetrics=[metrics.MeanMetric(maskVal=0)],
                             plotFuncs=[plots.HealpixSkyMap()], metadata=extraMetadata,
                             displayDict=displayDict, plotDict=plotDict)
    bundleList.append(bundle)

    displayDict['caption'] = 'Slow microlensing events'
    slicer = generateMicrolensingSlicer(min_crossing_time=100, max_crossing_time=1500)
    metric = MicrolensingMetric(metricName='Slow Microlensing')
    bundle = mb.MetricBundle(metric, slicer, sql, runName=runName,
                             summaryMetrics=[metrics.MeanMetric(maskVal=0)],
                             plotFuncs=[plots.HealpixSkyMap()], metadata=extraMetadata,
                             displayDict=displayDict, plotDict=plotDict)
    bundleList.append(bundle)

    #########################
    # Milky Way
    #########################

    displayDict = {'group': 'Milky Way', 'subgroup': ''}

    displayDict['subgroup'] = 'N stars'
    slicer = slicers.HealpixSlicer(nside=nside, useCache=False)
    sum_stats = [metrics.SumMetric(metricName='Total N Stars, crowding')]
    for f in filterlist:
        stellar_map = maps.StellarDensityMap(filtername=f)
        displayDict['order'] = filterorders[f]
        displayDict['caption'] = 'Number of stars in %s band with an measurement error due to crowding ' \
                                 'of less than 0.2 mag' % f
        # Configure the NstarsMetric - note 'filtername' refers to the filter in which to evaluate crowding
        metric = metrics.NstarsMetric(crowding_error=0.2, filtername=f, ignore_crowding=False,
                                      seeingCol=colmap['seeingGeom'], m5Col=colmap['fiveSigmaDepth'],
                                      maps=[])
        plotDict = {'nTicks': 5, 'logScale': True, 'colorMin': 100}
        bundle = mb.MetricBundle(metric, slicer, filtersqls[f], runName=runName,
                                 summaryMetrics=sum_stats,
                                 plotFuncs=subsetPlots, plotDict=plotDict,
                                 displayDict=displayDict, mapsList=[stellar_map])
        bundleList.append(bundle)


    slicer = slicers.HealpixSlicer(nside=nside, useCache=False)
    sum_stats = [metrics.SumMetric(metricName='Total N Stars, no crowding')]
    for f in filterlist:
        stellar_map = maps.StellarDensityMap(filtername=f)
        displayDict['order'] = filterorders[f]
        displayDict['caption'] = 'Number of stars in %s band with an measurement error ' \
                                 'of less than 0.2 mag, not considering crowding' % f
        # Configure the NstarsMetric - note 'filtername' refers to the filter in which to evaluate crowding
        metric = metrics.NstarsMetric(crowding_error=0.2, filtername=f, ignore_crowding=True,
                                      seeingCol=colmap['seeingGeom'], m5Col=colmap['fiveSigmaDepth'],
                                      metricName='Nstars_no_crowding', maps=[])
        plotDict = {'nTicks': 5, 'logScale': True, 'colorMin': 100}
        bundle = mb.MetricBundle(metric, slicer, filtersqls[f], runName=runName,
                                 summaryMetrics=sum_stats,
                                 plotFuncs=subsetPlots, plotDict=plotDict,
                                 displayDict=displayDict, mapsList=[stellar_map])
        bundleList.append(bundle)


    #########################
    # DDF
    #########################
    if DDF:
        # Hide this import to avoid adding a dependency.
        from lsst.sims.featureScheduler.surveys import generate_dd_surveys, Deep_drilling_survey
        ddf_surveys = generate_dd_surveys()

        # Add on the Euclid fields
        # XXX--to update. Should have a spot where all the DDF locations are stored.
        ddf_surveys.append(Deep_drilling_survey([], 58.97, -49.28, survey_name='DD:EDFSa'))
        ddf_surveys.append(Deep_drilling_survey([], 63.6, -47.60, survey_name='DD:EDFSb'))

        # For doing a high-res sampling of the DDF for co-adds
        ddf_radius = 1.8  # Degrees
        ddf_nside = 512

        ra, dec = hpid2RaDec(ddf_nside, np.arange(hp.nside2npix(ddf_nside)))

        displayDict = {'group': 'DDF depths', 'subgroup': None}

        for survey in ddf_surveys:
            displayDict['subgroup'] = survey.survey_name
            # Crop off the u-band only DDF
            if survey.survey_name[0:4] != 'DD:u':
                dist_to_ddf = angularSeparation(ra, dec, np.degrees(survey.ra), np.degrees(survey.dec))
                goodhp = np.where(dist_to_ddf <= ddf_radius)
                slicer = slicers.UserPointsSlicer(ra=ra[goodhp], dec=dec[goodhp], useCamera=False)
                for f in filterlist:
                    metric = metrics.Coaddm5Metric(metricName=survey.survey_name + ', ' + f)
                    summary = [metrics.MedianMetric(metricName='Median depth ' + survey.survey_name+', ' + f)]
                    plotDict = {'color': colors[f]}
                    sql = filtersqls[f]
                    displayDict['order'] = filterorders[f]
                    displayDict['caption'] = 'Coadded m5 depth in %s band.' % (f)
                    bundle = mb.MetricBundle(metric, slicer, sql, metadata=filtermetadata[f],
                                             displayDict=displayDict, summaryMetrics=summary,
                                             plotFuncs=[], plotDict=plotDict)
                    bundleList.append(bundle)

        displayDict = {'group': 'DDF Transients', 'subgroup': None}
        for survey in ddf_surveys:
            displayDict['subgroup'] = survey.survey_name
            if survey.survey_name[0:4] != 'DD:u':
                slicer = plasticc_slicer(plcs=plasticc_models_dict['SNIa-normal'], seed=42,
                                         ra_cen=survey.ra, dec_cen=survey.dec, radius=np.radians(3.),
                                         useCamera=False)
                metric = Plasticc_metric(metricName=survey.survey_name+' SNIa')
                sql = extraSql
                summary_stats = [metrics.MeanMetric(maskVal=0)]
                plotFuncs = [plots.HealpixSkyMap()]
                bundle = mb.MetricBundle(metric, slicer, sql, runName=runName,
                                         summaryMetrics=summary_stats,
                                         plotFuncs=plotFuncs, metadata=extraMetadata,
                                         displayDict=displayDict)
                bundleList.append(bundle)
                displayDict['order'] = 10

    # Set the runName for all bundles and return the bundleDict.
    for b in bundleList:
        b.setRunName(runName)
    bundleDict = mb.makeBundlesDictFromList(bundleList)

    return bundleDict
    footprints_hp = simple_footprint()
    observatory = Model_observatory(nside=nside)
    conditions = observatory.return_conditions()
    footprints = Footprint(conditions.mjd_start,
                           sun_RA_start=conditions.sun_RA_start,
                           nside=nside)
    for i, key in enumerate(footprints_hp):
        footprints.footprints[i, :] = footprints_hp[key]

    # Set up the DDF surveys to dither
    dither_detailer = detailers.Dither_detailer(per_night=per_night,
                                                max_dither=max_dither)
    details = [detailers.Zero_rot_detailer(), dither_detailer]
    ddfs = generate_dd_surveys(nside=nside,
                               nexp=nexp,
                               detailers=details,
                               frac_total=0.0045,
                               aggressive_frac=0.002)

    greedy = gen_greedy_surveys(nside, nexp=nexp, footprints=footprints)
    blobs = generate_blobs(nside, nexp=nexp, footprints=footprints)
    surveys = [ddfs, blobs, greedy]
    run_sched(surveys,
              survey_length=survey_length,
              verbose=verbose,
              fileroot=os.path.join(outDir, fileroot + file_end),
              extra_info=extra_info,
              nside=nside,
              illum_limit=illum_limit)
        footprints.footprints[i, :] = footprints_hp[key]

    # Set up the DDF surveys to dither
    dither_detailer = detailers.Dither_detailer(per_night=per_night,
                                                max_dither=max_dither)
    details = [
        detailers.Camera_rot_detailer(min_rot=-camera_ddf_rot_limit,
                                      max_rot=camera_ddf_rot_limit),
        dither_detailer
    ]
    euclid_detailers = [
        detailers.Camera_rot_detailer(min_rot=-camera_ddf_rot_limit,
                                      max_rot=camera_ddf_rot_limit),
        detailers.Euclid_dither_detailer()
    ]
    ddfs = generate_dd_surveys(nside=nside,
                               nexp=nexp,
                               detailers=details,
                               euclid_detailers=euclid_detailers)

    greedy = gen_greedy_surveys(nside, nexp=nexp, footprints=footprints)
    blobs = generate_blobs(nside, nexp=nexp, footprints=footprints)
    surveys = [ddfs, blobs, greedy]
    run_sched(surveys,
              survey_length=survey_length,
              verbose=verbose,
              fileroot=os.path.join(outDir, fileroot + file_end),
              extra_info=extra_info,
              nside=nside,
              illum_limit=illum_limit)
Exemplo n.º 15
0
import numpy as np
import healpy as hp
from lsst.sims.featureScheduler.surveys import generate_dd_surveys
import lsst.sims.skybrightness as sb
from lsst.sims.utils import m5_flat_sed
from lsst.sims.seeingModel import SeeingModel
import sys

if __name__ == "__main__":

    dds = generate_dd_surveys()
    mjd0 = 59853.5
    delta_t = 15./60./24.  # to days
    survey_length = 10.*365.25
    sun_limit = np.radians(-12.)  # degrees

    nominal_seeing = 0.7  #  arcsec

    filtername = 'g'


    seeing_model = SeeingModel()

    seeing_indx = 1 #np.where(seeing_model.filter_list == filtername)[0]

    # result

    mjds = np.arange(mjd0, mjd0+survey_length, delta_t)

    # XXX Temp
    #mjds = mjds[0:100]
Exemplo n.º 16
0
    observatory = Model_observatory(nside=nside)
    conditions = observatory.return_conditions()
    footprints = Footprint(conditions.mjd_start,
                           sun_RA_start=conditions.sun_RA_start,
                           nside=nside)
    for i, key in enumerate(footprints_hp):
        footprints.footprints[i, :] = footprints_hp[key]

    # Set up the DDF surveys to dither
    dither_detailer = detailers.Dither_detailer(per_night=per_night,
                                                max_dither=max_dither)
    details = [
        detailers.Camera_rot_detailer(min_rot=-camera_ddf_rot_limit,
                                      max_rot=camera_ddf_rot_limit),
        dither_detailer
    ]
    ddfs = generate_dd_surveys(nside=nside, nexp=nexp, detailers=details)

    greedy = gen_greedy_surveys(nside, nexp=nexp, footprints=footprints)
    blobs = generate_blobs(nside, nexp=nexp, footprints=footprints)
    surveys = [ddfs, blobs, greedy]
    run_sched(surveys,
              survey_length=survey_length,
              verbose=verbose,
              fileroot=os.path.join(outDir, fileroot + file_end),
              extra_info=extra_info,
              nside=nside,
              illum_limit=illum_limit,
              cloud_limit=cloud_limit)
                           sun_RA_start=conditions.sun_RA_start,
                           nside=nside)
    for i, key in enumerate(footprints_hp):
        footprints.footprints[i, :] = footprints_hp[key]

    # Set up the DDF surveys to dither
    dither_detailer = detailers.Dither_detailer(per_night=per_night,
                                                max_dither=max_dither)
    details = [
        detailers.Camera_rot_detailer(min_rot=-camera_ddf_rot_limit,
                                      max_rot=camera_ddf_rot_limit),
        dither_detailer
    ]
    ddfs = generate_dd_surveys(nside=nside,
                               nexp=nexp,
                               detailers=details,
                               frac_total=ddf_frac_total,
                               aggressive_frac=aggressive_frac,
                               delays=delays)

    greedy = gen_greedy_surveys(nside, nexp=nexp, footprints=footprints)
    blobs = generate_blobs(nside, nexp=nexp, footprints=footprints)
    surveys = [ddfs, blobs, greedy]
    run_sched(surveys,
              survey_length=survey_length,
              verbose=verbose,
              fileroot=os.path.join(outDir, fileroot + file_end),
              extra_info=extra_info,
              nside=nside,
              illum_limit=illum_limit)