<jupyter_start><jupyter_text>Supernova cadence metricThis metric is an estimate of the redshift limit z of a faint [(x1,color) = (-2.0,0.2)] supernovae. Depending on Signal-to-Noise thresholds (defined by the user), mean cadences and mean five-sigma depth values (from simulation), z is corresponding to the detection limit. This metric reflects cadences and m5 dependencies on supernova detection.Input parameters- band- Signal-To-Noise ratio (SNR per band): use as detection thresholds (typical values given below)- mag_range: magnitude range considered- dt_range : cadence range (in days-1) for the study- zmin, zmax: min and mad redshifts for the study- Li_files : list of npy files with light curves- mag_to_flux : list of npy files with mag to flux conversionThis metric may be run yearly, per season or using the complete survey.  Imports<jupyter_code>import lsst.sims.maf.metricBundles as metricBundles
import lsst.sims.maf.slicers as slicers
import lsst.sims.maf.db as db
import lsst.sims.maf.utils as utils
import sqlite3
import numpy as np
from sn_metrics.sn_cadence_metric import SNCadenceMetric
import sn_plotter_metrics.cadencePlot as sn_plot<jupyter_output><empty_output><jupyter_text>DB file choice<jupyter_code>dbName = 'descddf_v1.5_10yrs.db'
dbFile = '/home/philippe/LSST/DB_Files/{}'.format(dbName)
opsimdb = db.OpsimDatabase(dbFile)
version = opsimdb.opsimVersion
#propinfo, proptags = opsimdb.fetchPropInfo()
#print('proptags and propinfo', proptags, propinfo)
runLength = opsimdb.fetchRunLength()<jupyter_output>Cannot access Config table to retrieve runLength; using default 10 years<jupyter_text>Field choice (DD or WFD)¶<jupyter_code>fieldtype='WFD' #fieldtype: DD or WFD
bands = 'r' 

propinfo, proptags = opsimdb.fetchPropInfo()
print('proptags and propinfo', proptags, propinfo)

sqlconstraint = opsimdb.createSQLWhere(fieldtype, proptags)

if fieldtype == 'DD':
    SNR = dict(zip('griz', [25., 25., 30., 35.]))  # SNR for DD
    mag_range = [23., 27.5]  # DD mag range
    dt_range = [0.5, 25.]  # DD dt range
    coadd = True
    zmin = 0.4
    zmax = 0.7
if fieldtype == 'WFD':
    SNR = dict(zip('griz', [30., 40., 30., 20.]))  # SNR for WFD
    mag_range = [21., 25.5]  # WFD mag range
    dt_range = [0.5, 30.]  # WFD dt range
    coadd = False
    zmin = 0.1
    zmax = 0.6
    
Li_files = ['../reference_files/Li_SNCosmo_-2.0_0.2.npy']
mag_to_flux_files = ['../reference_files/Mag_to_Flux_SNCosmo.npy']
names_ref = ['SNCosmo']<jupyter_output>No proposal table available - no proposalIds have been assigned.
proptags and propinfo {} {}
No WFD proposals found<jupyter_text>Define slicer<jupyter_code>slicer = slicers.HealpixSlicer(nside=64)<jupyter_output>Healpix slicer using NSIDE=64, approximate resolution 54.967783 arcminutes<jupyter_text>Run for selected years<jupyter_code>bundleList= []
names = []
yearDates = list(range(0, int(round(365 * runLength)) + 365, 365))
for band in bands: #Loop on the bands
    #sql_i = sqlconstraint+' AND '
    sql_i = ''
    sql_i += 'filter = "%s"' % (band) #sql constraint on the band
    
    for season in range(1,2):
        metric = SNCadenceMetric(coadd=coadd)
            
        sql_y = sql_i + ' AND night > %i AND night <= %i' % (
                    yearDates[np.max([0,season-2])], yearDates[np.min([9,season + 2])]) #sql constraint on the year 
        bundleList.append(metricBundles.MetricBundle(
            metric, slicer, sql_y, runName= dbName))
        names.append('{}_{}'.format(band,season))
print(len(bundleList))
bdict = dict(zip(names, bundleList))
outDir = '{}_Cadence'.format(dbName)
#resultsDb = db.ResultsDb(outDir=outDir)
#bundleDict = metricBundles.makeBundlesDictFromList(bundleList)
#bgroup = metricBundles.MetricBundleGroup(bundleDict, opsimdb, outDir=outDir, resultsDb=resultsDb)
#resu = bgroup.runAll()

resultsDb = db.ResultsDb(outDir=outDir)
mbg = metricBundles.MetricBundleGroup(bdict, opsimdb,
                                          outDir=outDir, resultsDb=resultsDb)

result = mbg.runAll()<jupyter_output>Querying database SummaryAllProps with constraint filter = "r" AND night > 0 AND night <= 1095 for columns ['numExposures', 'fiveSigmaDepth', 'visitTime', 'filter', 'fieldRA', 'fieldDec', 'observationStartMJD', 'observationId', 'night', 'visitExposureTime']
Found 136219 visits
Running:  ['r_1']
Completed metric generation.
Running reduce methods.
Running summary statistics.
Completed.<jupyter_text>Imports for display<jupyter_code>%matplotlib inline
import pandas as pd
for key, val in bdict.items():
    band = key.split('_')[0]
    metValues = val.metricValues[~val.metricValues.mask]
    res = pd.DataFrame()
    for io,val in enumerate(metValues):
        res = pd.concat((res,val))
        if io > 5000:
            break
        """
        print(val.columns)
        if res is None:
            res = val
        else:
            print(val)
            res = np.concatenate((res, val))
            break
        """
    #res = np.unique(res)
    #print(res)
    sn_plot.plotCadence(band,Li_files, mag_to_flux_files,
                        SNR[band],res.to_records(index=False),
                        names_ref,
                        mag_range=mag_range, dt_range=dt_range,dbName=dbName.split('.')[0])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11507109004739337, 'fraction_numerical': 0.02009478672985782, 'mean_word_length': 3.844811753902663, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '188644', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1876, 'n_tokens_neox': 1776, 'n_words': 463, 'path': 'notebooks/SNCadence.ipynb', 'repo_name': 'LSSTDESC/sn_pipe', 'size': '5275'}