scifysim.utilities module
- scifysim.utilities.coeff(dit, lead_transmission, context, eta=1.0, spectrum='flat', ds_sr=1.0, include_transmission=False, reverse_coeff=False)[source]
Obtains the coefficients including detector integration time, transmission, spectral channels, pixel solid angle, and quantum efficiency (default: 1.).
Parameters:
dit : detector integration time [s]
lead_transmission : The transmission of the leading element (often sky) of the transmission-emission chain
context : The spectral context of the instrument (defining the vega magnitudes)
eta : (default=1.) The quantum efficiency of the detector
spectrum : The type of spectrum of the object defaults to flat as opposed to the temperature of Vega.
ds_sr : When working with a map the solid angle of a pixel [sr] Can be found in simulator.vigneting_map.ds_sr after maps have been computed
Include transmission: whether to multiply by the transimission spectrum of the instrument The maps are now computed including the transmission of the instrument, so that is not necessary.
reverse_coeff: if True, compute the pure theoretical map, removing the effects from the instrument transmission and efficiency
- class scifysim.utilities.ee(expression)[source]
Bases:
object
Additional functionnality needed: see comments starting 2021/02/24 https://github.com/sympy/sympy/issues/5642
- __dict__ = mappingproxy({'__module__': 'scifysim.utilities', '__doc__': '\n Additional functionnality needed:\n see comments starting 2021/02/24 `<https://github.com/sympy/sympy/issues/5642>`_\n ', '__init__': <function ee.__init__>, 'lambdify': <function ee.lambdify>, 'numexpr_call': <function ee.numexpr_call>, 'numpy_call': <function ee.numpy_call>, '__call__': <function ee.__call__>, 'fprint': <function ee.fprint>, '__dict__': <attribute '__dict__' of 'ee' objects>, '__weakref__': <attribute '__weakref__' of 'ee' objects>, '__annotations__': {}})
- __init__(expression)[source]
ee is for Executable expression Encapsulates an expression for flexible lambda evaluation. expression : a sympy expression to lambdify
- __module__ = 'scifysim.utilities'
- __weakref__
list of weak references to the object (if defined)
- lambdify(args, modules='numexpr')[source]
Creates the lambda function. Currently, lambdification to numexpr does not support multiple outputs, so we create a list of lambda functions.
Parameters:
args : a tuple of sympy for symbols to use as inputs
modules : The module to use for computation.
- scifysim.utilities.eval_perf(afile, t_exp, n_frames=100, thetarget=None, update_params=False, instrumental_errors=True, seed=None, crop=1.0, target_coords=None, compensate_chromatic=True, modificators=None, plotall=False, use_tqdm=False)[source]
Evaluate the noise profile for a given parameter file.
Parameters:
afile : Config file
t_exp : Exposure time
n_frames : The number of frames for MC simulation to evaluate the instrumental noise
instrumental_errors : Bool. Whether to include instrumental errors
seed : seed to pass when generating the time series of instrumental errors
crop : factor to pass to the injector
target_coords : Coordinates of the target default:None : finds the target from catalog
compensate_chromatic : Bool Whether to run the optimization of the actuators to compensate for chromaticity in the combiner
plotall : Whether to plot a bunch of charts
use_tqdm : Whether tqdm should be used at the step of the MC simulations. (use false for parameter exploration)
Returns:
asim : The simulator object
prof : The noise profile object
characteristics : A dictionary containing a collection of performance statistics
- scifysim.utilities.extract_diffobs_map(maps, simulator, mod=<module 'numpy' from '/lhome/romain/miniconda3/envs/scify/lib/python3.8/site-packages/numpy/__init__.py'>, dit=1.0, mag=None, postprod=None, eta=1.0, K=None, reverse_coeff=False, normalize_collector=False)[source]
Here in photons per dit (default=1s)
Parameters:
- mapsTransmission maps for 1 ph/s/m2
at the entrance of atmo
simulator : a sumulator object (see comments below)
dit : Detector integration time [s]
mag : The magnitude of a source on the map
postprod : A post-processing (whitening matrix)
eta : The quantum efficiency of the detector
- KA matrix to extract the differential
observable quantities (kernel matrix). By default, the matrix is obtained from simulator.combiner.K
Simulator object is used for:
The head transmission (simulator.src.sky)
The solid angle of the pisel
The spectral context (for the spectral channels)
- scifysim.utilities.extract_diffobs_map_old(maps, simulator, dit=1.0, mag=None, postprod=None, eta=1.0, K=None)[source]
Here in photons per dit (default=1s)
Parameters:
- mapsTransmission maps for 1 ph/s/m2
at the entrance of atmo
simulator : a sumulator object (see comments below)
dit : Detector integration time [s]
mag : The magnitude of a source on the map
postprod : A post-processing (whitening matrix)
eta : The quantum efficiency of the detector
- KA matrix to extract the differential
observable quantities (kernel matrix). By default, the matrix is obtained from simulator.combiner.K
Simulator object is used for:
The head transmission (simulator.src.sky)
The solid angle of the pisel
The spectral context (for the spectral channels)
- scifysim.utilities.find_best_night(obs, target, showplot=True, duration=None)[source]
Parameters:
obs : Observatory object
showplot : Whether to show a plot of the max elevation
duration [h] : duration of the observing run
Returns:
if duration is None (default) :
besttime
anastropy.Time
objectelse :
(Tstart, Tend)
Start and end of the observing run
- scifysim.utilities.fit_distribution(hist, bincenters, mypdf, nsamples=None, p0=(0.0, 0.0))[source]
Fits the histogram to a given pdf
Arguments:
hist : array-like The empirical histogram given in density so that it has unity integral
bincenters : array-like The center of bins. Same shape as hist. tip: use
get_bincenters
to convert edges to bin centersmypdf : function A function of the histogram to fit
p0 : array-like Starting parameters for the fit. Typically a couple (loc, scale). Recommended is (mean, std).
Returns:
parameters: The best fit parameters (typically (loc, scale).
histerror : An estimation of the errors on the bins, based on Poissonian statistics (and set to the max for empty bins.
covariance: The covariance of the parameters.
- scifysim.utilities.get_bincenters(edges)[source]
Quickly converts bin edges to bin centers:
Arguments:
edges: Array of size n
Returns:
bincenters: Centers of the intervals (size n-1)
- scifysim.utilities.get_header_bl_data(header)[source]
Pulls the baseline infomation from the header
- scifysim.utilities.get_index_pos(ax, ay, thesim)[source]
Get the coordinates on the discrete map of a relative position
Arguments: * ax : [mas] Coordinate x * ay : [mas] Coordinate y * thesim : Simulator object
- scifysim.utilities.get_location(simple_map, map_extent=None, search_function=<function argmax>, mode='polar')[source]
Get location of the max or min of the map.
- scifysim.utilities.get_raw_array(config)[source]
Get the raw array for location of apertures from config file.
Arguments: * config : a config parser object sf.parsefile.ConfigParser
return: * For ground-based: (n_tel, 2[m]) * For space-based: (t[s], n_tel, 3[m])
- scifysim.utilities.get_star_params(star, verbose=True, showtable=False)[source]
Queries GAIA DR2 catalog for distance, radius and temperature of star:
Parameters:
star : str the name of the star
verbose: Whether to print the details found
showtable: Whether to show the table in list form
** returns:** * dist [pc] : Distance * T [K] : Effective temperature * R [Rsun] : Radius
- scifysim.utilities.get_star_params_GAIA_JMMC(star, verbose=True, showtable=False)[source]
Queries GAIA DR2 catalog for distance, radius and temperature of star:
Parameters:
star : str the name of the star
verbose: Whether to print the details found
showtable: Whether to show the table in list form
returns:
dist [pc] : Distance
T [K] : Effective temperature
R [Rsun] : Radius
- scifysim.utilities.get_uv(puparray)[source]
Computes the uv baselines for a given pupil configuration.
Parameters:
puparray : An array representing the location of each pupil
- scifysim.utilities.lambdifyz(symbols, expr, modules='numpy')[source]
Circumvents a bug in lambdify where silent variables will be simplified and therefore aren’t broadcasted. https://github.com/sympy/sympy/issues/5642
Use an extra argument = 0 when calling
Please, keep the function synchronous with kernuller
- scifysim.utilities.mag2sig(mag, dit, lead_transmission, context, eta=1.0, spectrum='flat', ds_sr=1.0)[source]
Obtains the coefficients including object magnitude, detector integration time, transmission, spectral channels, pixel solid angle, and quantum efficiency (default: 1.).
Parameters:
mag : Magnitude of object (Vega)
dit : detector integration time [s]
lead_transmission : The transmission of the leading element (often sky) of the transmission-emission chain
context : The spectral context of the instrument (defining the vega magnitudes)
eta : (default=1.) The quantum efficiency of the detector
spectrum : The type of spectrum of the object defaults to flat as opposed to the temperature of Vega.
ds_sr : When working with a map the solid angle of a pixel [sr] Can be found in simulator.vigneting_map.ds_sr after maps have been computed
- scifysim.utilities.matchseries(a, b, nmatch=10)[source]
Matches series b with series a with the nmatch last samples of a and the nmatch first samples of b.
a : 1D array the root of the series
b : 1D array the tail of the series
nmatch : integer The number of samples used to match the mean
Returns the concatenation.
- scifysim.utilities.parameters2latex(parameters, rename=None, column_to_rename='Name', rem=True, columns=None, latex_option='AA')[source]
This is done by capturing stdout in a call of
parameters.pretty_print()
Arguments:
parameters: a lmfit.Parameters object
- scifysim.utilities.parameters2table(parameters, rename=None, column_to_rename='Name', rem=True)[source]
Convenience function to convert a
lmfit.Parameters
object to an astropy table.This is done by capturing stdout in a call of
parameters.pretty_print()
Arguments:
parameters: a lmfit.Parameters object
rename: a dict with the new names or None to do nothing
column_to_rename: The name of the column for substitution
rem: if:
True: Substitute
column_to_replace
A
string
: the name of the new column
Returns: an astropy.table.Table object
- scifysim.utilities.prepare_all(afile, thetarget=None, update_params=False, instrumental_errors=True, seed=None, crop=0.7, res=100, target_coords=None, compensate_chromatic=True, modificators=None, update_start_end=True, statlocs=None, verbose=False)[source]
A shortcut to prepare a simulator object Parameters:
afile : Config file
thetarget : target name to replace in config file
update_params: (bool) default: False. When True, updates the parameters of the star based on databases such as GAIA DR3
instrumental_errors : Bool. Whether to include instrumental errors
seed : seed to pass when generating the time series of instrumental errors
crop : factor to pass to the injector
target_coords : Coordinates of the target default:None : finds the target from catalog
compensate_chromatic : Bool Whether to run the optimization of the actuators to compensate for chromaticity in the combiner
modificators : a dict of parameters to supersede the config file
Returns:
asim : A simulator object
- scifysim.utilities.produce_maps(asim, prof, adit=1.0, mypfa=0.01, mypdet=0.9, base_name='/tmp/R200_twinmaps_', total_time=10800, starmags=array([2., 2.42105263, 2.84210526, 3.26315789, 3.68421053, 4.10526316, 4.52631579, 4.94736842, 5.36842105, 5.78947368, 6.21052632, 6.63157895, 7.05263158, 7.47368421, 7.89473684, 8.31578947, 8.73684211, 9.15789474, 9.57894737, 10.]), decs=array([-90., -76.66666667, -63.33333333, -50., -36.66666667, -23.33333333, -10., 3.33333333, 16.66666667, 30.]), mapcrop=0.5, mapres=50)[source]
Utility macro that packages the production of multiple sensitivity maps for a given director object and noise profile
Parameters:
asim : Simulator director object
prof : Noise profile
Returns:
metamap : T
themap : The energy detector map in magnitude
theNPmap : The Neyman-Pearson detector map in magnitude
- scifysim.utilities.random_series_fft(ps, matchto=None, matchlength=10, keepall=False, seed=None)[source]
Returns a new series of data based on the provided power spectrum. If matchto is provided, the new series is adjusted for continuity to that data.
Parameters:
ps : A power spectrum
matchto : np.ndarray of preceding series. The mean of the first n (matchlength) values of the new series are matched to the mean of the last n values of this array.
matchlength : integer. The number of values to match
keepall : Boolean. If true, will return the concatenation of the new array with the old. If False, will return only the new array.
Returns:
a numpy ndarray of the time series
- scifysim.utilities.range2R(spectral_range, mode='bins')[source]
Convenience function to convert a sequence of wavelengths to the target spectral resolution.
Arguments:
spectral_range : (array-like) The series of wavelength channels [m]
mode : Decides what is considered a step in the series.
“bins” : The simulator wl bins as found in
simulator.lambda_science_range
: 2 pixels per bin in Hi-5“chans” : The individual wavelength step
“pixs” : The individual pixels (2.5 pixel per spectral channel)
Returns an array of the individual spectral resolutions
- scifysim.utilities.sp2mod(array, dtype=<class 'complex'>, mod=<module 'numpy' from '/lhome/romain/miniconda3/envs/scify/lib/python3.8/site-packages/numpy/__init__.py'>)[source]
Converts a sympy array/Matrix into an array of a given module
** Arguments :**
array : A sympy Matrix, vector or expression, with no free symbols
dtype : data type to aim for (default: complex)
mod : the module to convert to (default: numpy) will work with cupy, jax, etc…
- scifysim.utilities.table2latex(table, latex_option='AA')[source]
Utility to output a latex formatted table from astropy.
- scifysim.utilities.test_maps(fname='local_config/default_R200', target='GJ 86 A')[source]
Testing and comparing the 2 approaches to build transmission maps.
- scifysim.utilities.update_observing_night(config, time=None, duration=6.0, verbose=True, target_coords=None)[source]
Parameters
config : The parsed config file to modify
time : [fits format] (if None, will optimize for elevation)
duration : [h] Default: 6.h
verbose : Whether to print some of the intermediate results
target_coords : Coordinates of the object of interst.
None Default: Uses the target in the config file
astropy.SkyCoords
object.