Utils

rubin_sim.maf.utils.astrom_precision(fwhm, snr, systematic_floor=0.0)[source]

Calculate the approximate precision of astrometric measurements, given a particular seeing and SNR value.

Parameters:
  • fwhm (float or np.ndarray (N,)) – The seeing (FWHMgeom) of the observation.

  • snr (float` or np.ndarray (N,)) – The SNR of the object.

  • systematic_floor (float) – Systematic noise floor for astrometric error, in arcseconds. Default here is 0, for backwards compatibility. General Rubin use should be 0.01.

Returns:

astrom_err – The astrometric precision, in arcseconds.

Return type:

float or numpy.ndarray (N,)

rubin_sim.maf.utils.calc_coadded_depth(nvisits, single_visit_depth)[source]

Calculate the coadded depth expected for a given number of visits and single visit depth.

Parameters:
  • nvisits (dict of int or float) – Dictionary (per filter) of number of visits

  • single_visit_depth (dict of float) – Dictionary (per filter) of the single visit depth

Returns:

coadded_depth – Dictionary of coadded depths per filter.

Return type:

dict of float

rubin_sim.maf.utils.coadd_m5(mags)[source]

Coadded depth, assuming Gaussian noise.

rubin_sim.maf.utils.collapse_night(data_slice, night_col='night', filter_col='filter', m5_col='fiveSigmaDepth', mjd_col='observationStartMJD')[source]

Collapse a data_slice into per-filter, per-night values for the ‘night’, ‘filter’, ‘median observationStartMJD’, and ‘fiveSigmaDepth’.

rubin_sim.maf.utils.get_date_version()[source]

Get today’s date and a dictionary with the MAF version information. This is written into configuration output files, to help track MAF runs.

Returns:

String with today’s date, Dictionary with version information.

Return type:

str, dict

rubin_sim.maf.utils.get_sim_data(db_con, sqlconstraint, dbcols, stackers=None, table_name=None, full_sql_query=None)[source]

Query an opsim database for the needed data columns and run any required stackers.

Parameters:
  • db_con (str or SQLAlchemy connectable, or sqlite3 connection) – Filename to a sqlite3 file, or a connection object that can be used by pandas.read_sql

  • sqlconstraint (str or None) – SQL constraint to apply to query for observations. Ignored if full_sql_query is set.

  • dbcols (list [str]) – Columns required from the database. Ignored if full_sql_query is set.

  • stackers (list [rubin_sim.maf.stackers], optional) – Stackers to be used to generate additional columns. Default None.

  • table_name (str (None)) – Name of the table to query. Default None will try “observations”. Ignored if full_sql_query is set.

  • full_sql_query (str) – The full SQL query to use. Overrides sqlconstraint, dbcols, tablename.

Returns:

sim_data – A numpy structured array with columns resulting from dbcols + stackers, for observations matching the SQLconstraint.

Return type:

np.ndarray

rubin_sim.maf.utils.load_inst_zeropoints()[source]

Load up and return instrumental zeropoints and atmospheric extinctions.

rubin_sim.maf.utils.m52snr(m, m5, gamma=0.04)[source]

Calculate the SNR for a star of magnitude m in an observation with 5-sigma limiting magnitude depth m5. Assumes gaussian distribution of photons and might not be strictly due in bluer filters. See table 2 and equation 5 in astroph/0805.2366.

Parameters:
  • m (float or np.ndarray (N,)) – The magnitude of the star

  • m5 (float or np.ndarray (N,)) – The m5 limiting magnitude of the observation

  • gamma (float or None) – The ‘gamma’ value used when calculating photometric or astrometric errors and weighting SNR accordingly. See equation 5 of the LSST Overview paper. Use “None” to discount the gamma factor completely and use standard 5*10^(0.4 * (m5-m)).

Returns:

snr – The SNR

Return type:

float or np.ndarray (N,)

rubin_sim.maf.utils.name_sanitize(in_string)[source]

Convert a string to a more file name (and web) friendly format.

Parameters:

in_string (str) – The input string to be sanitized. Typically these are combinations of metric names and metadata.

Returns:

out_string – The string after removal/replacement of non-friendly characters.

Return type:

str

rubin_sim.maf.utils.optimal_bins(datain, binmin=None, binmax=None, nbin_max=200, nbin_min=1, verbose=False)[source]

Set an ‘optimal’ number of bins using the Freedman-Diaconis rule.

Parameters:
  • datain (numpy.ndarray or numpy.ma.MaskedArray) – The data for which we want to set the bin_size.

  • binmin (float) – The minimum bin value to consider (if None, uses minimum data value).

  • binmax (float) – The maximum bin value to consider (if None, uses maximum data value).

  • nbin_max (int) – The maximum number of bins to create. Sometimes the ‘optimal bin_size’ implies an unreasonably large number of bins, if the data distribution is unusual.

  • nbin_min (int) – The minimum number of bins to create. Default is 1.

  • verbose (bool) – Turn off warning messages. This utility very often raises warnings and these should likely be logging messages at a lower logging level, but for now - just use the verbose flag to turn these off or on.

Returns:

nbins – The number of bins.

Return type:

int

rubin_sim.maf.utils.percentile_clipping(data, percentile=95.0)[source]

Calculate the minimum and maximum values of a distribution of points, after discarding data more than ‘percentile’ from the median. This is useful for determining useful data ranges for plots. Note that ‘percentile’ percent of the data is retained.

Parameters:
  • data (numpy.ndarray) – The data to clip.

  • percentile (float) – Retain values within percentile of the median.

Returns:

minimum, maximum – The minimum and maximum values of the clipped data.

Return type:

float, float

rubin_sim.maf.utils.radec2pix(nside, ra, dec)[source]

Calculate the nearest healpixel ID of an RA/Dec array, assuming nside.

Parameters:
  • nside (int) – The nside value of the healpix grid.

  • ra (numpy.ndarray, (N,)) – The RA values to be converted to healpix ids, in radians.

  • dec (numpy.ndarray, (N,)) – The Dec values to be converted to healpix ids, in radians.

Returns:

hpid – The healpix ids.

Return type:

numpy.ndarray, (N,)

rubin_sim.maf.utils.scale_benchmarks(run_length, benchmark='design')[source]

Set design and stretch values of the number of visits or area of the footprint or seeing/Fwhmeff/skybrightness and single visit depth (based on SRD values). Scales number of visits for the length of the run, relative to 10 years.

Parameters:
  • run_length (float) – The length (in years) of the run.

  • benchmark (str) – design or stretch - which version of the SRD values to return.

Returns:

benchmarks – A dictionary containing the number of visits, area of footprint, seeing and FWHMeff values, skybrightness and single visit depth for either the design or stretch SRD values.

Return type:

dict of floats

rubin_sim.maf.utils.sigma_slope(x, sigma_y)[source]

Calculate the uncertainty in fitting a line, as given by the spread in x values and the uncertainties in the y values.

Parameters:
  • x (numpy.ndarray) – The x values of the data

  • sigma_y (numpy.ndarray) – The uncertainty in the y values

Returns:

The uncertainty in the line fit

Return type:

float

rubin_sim.maf.utils.stellar_mags(stellar_type, rmag=19.0)[source]

Calculates the expected magnitudes in LSST filters for a typical star of the given spectral type.

Based on mapping of Kuruz models to spectral types here: http://www.stsci.edu/hst/observatory/crds/k93models.html

Parameters:
  • stellar_type (str) – Spectral type of a star (O,B,A,F,G,K,M), or for white dwarf colors, one of ‘HeWD_25200_80, ‘WD_11000_85’, ‘WD_3000_85’

  • rmag (float) – The expected r-band magnitude of the star.

Returns:

The expected magnitudes in LSST filters.

Return type:

dict of floats