simcado.utils module

Helper functions for SimCADO

simcado.utils.add_SED_to_simcado(file_in, file_out=None, lam_units='um')[source]

Adds the SED given in file_in to the SimCADO data directory

Parameters
file_instr

path to the SED file. Can be either FITS or ASCII format with 2 columns Column 1 is the wavelength, column 2 is the flux

file_outstr, optional

Default is None. The file path to save the ASCII file. If None, the SED is saved to the SimCADO data directory i.e. to <utils.__pkg_dir__>/data/

lam_unitsstr, astropy.Units

Units for the wavelength column, either as a string or as astropy units Default is [um]

simcado.utils.add_keyword(filename, keyword, value, comment='', ext=0)[source]

Add a keyword, value pair to an extension header in a FITS file

Parameters
filenamestr

Name of the FITS file to add the keyword to

keywordstr
valuestr, float, int
commentstr
extint, optional

The fits extension index where the keyword should be added. Default is 0

simcado.utils.add_mags(mags)[source]

Returns a combined magnitude for a group of objects with mags

simcado.utils.airmass2zendist(airmass)[source]

Convert airmass to zenith distance

Parameters
airmassfloat (>= 1)
Returns
zenith distance in degrees
simcado.utils.airmass_to_zenith_dist(airmass)[source]

returns zenith distance in degrees

Z = arccos(1/X)

simcado.utils.angle_in_arcseconds(distance, width)[source]

Returns the angular distance of an object in arcseconds. Units must be consistent

simcado.utils.atmospheric_refraction(lam, z0=60, temp=0, rel_hum=60, pres=750, lat=-24.5, h=3064)[source]

Compute atmospheric refraction

The function computes the angular difference between the apparent position of a star seen from the ground and its true position.

Parameters
lamfloat, np.ndarray

[um] wavelength bin centres

z0float, optional

[deg] zenith distance. Default is 60 deg from zenith

tempfloat, optional

[deg C] ground temperature. Default is 0 deg C

rel_humfloat, optional

[%] relative humidity. Default is 60%

presfloat, optional

[millibar] air pressure. Default is 750 mbar

latfloat, optional

[deg] latitude. Default set for Cerro Armazones: 24.5 deg South

hfloat, optional

[m] height above sea level. Default is 3064 m

Returns
angfloat, np.ndarray

[arcsec] angle between real position and refracted position

References

See Stone 1996 and the review by S. Pedraz - http://www.caha.es/newsletter/news03b/pedraz/newslet.html

simcado.utils.bug_report()[source]

Get versions of dependencies for inclusion in bug report

simcado.utils.deriv_polynomial2d(poly)[source]

Derivatives (gradient) of a Polynomial2D model

Parameters
polyastropy.modeling.models.Polynomial2D
simcado.utils.dist_mod_from_distance(d)[source]

mu = 5 * np.log10(d) - 5

simcado.utils.distance_from_dist_mod(mu)[source]

d = 10**(1 + mu / 5)

simcado.utils.download_file(url, save_dir='/home/docs/checkouts/readthedocs.org/user_builds/simcado/checkouts/latest/simcado/data')[source]

Download the extra data that aren’t in the SimCADO package

simcado.utils.find_file(filename, path=None, silent=False)[source]

Find a file in search path

Parameters
filenamestr

name of a file to look for

pathlist

list of directories to search (default: [‘./’])

silentbool

if True, remain silent when file is not found

Returns
Absolute path of the file
simcado.utils.get_extras()[source]

Downloads large files that SimCADO needs to simulate MICADO

simcado.utils.is_fits(filename)[source]

Checks if file is a FITS file based on extension

Parameters
filenamestr
Returns
flagbool
simcado.utils.moffat(r, alpha, beta)[source]

!!Unfinished!! Return a Moffat function

Parameters
r
alpha
beta
Returns
eta
simcado.utils.msg(cmds, message, level=3)[source]

Prints a message based on the level of verbosity given in cmds

Parameters
cmdsUserCommands

just for the SIM_VERBOSE and SIM_MESSAGE_LEVEL keywords

messagestr

message to be printed

levelint, optional

all messages with level <= SIM_MESSAGE_LEVEL are printed. I.e. level=5 messages are not important, level=1 are very important

simcado.utils.nearest(arr, val)[source]

Return the index of the value from ‘arr’ which is closest to ‘val’

Parameters
arrnp.ndarray, list, tuple

Array to be searched

valfloat, int

Value to find in arr

Returns
iint

index of array where the nearest value to val is

simcado.utils.parallactic_angle(ha, de, lat=-24.589167)[source]

Compute the parallactic angle

Parameters
hafloat

[hours] hour angle of target point

defloat

[deg] declination of target point

latfloat

[deg] latitude of observatory, defaults to Armazones

Returns
parangfloat

The parallactic angle

Notes

The parallactic angle is defined as the angle PTZ, where P is the .. math:: taneta = frac{cosphisin H}{sinphi cosdelta - cosphi sindelta cos H} It is negative (positive) if the target point is east (west) of the meridian.

References

  1. Ball: “A Treatise on Spherical Astronomy”, Cambridge 1908

simcado.utils.poissonify(arr)[source]

Add a realisation of the poisson process to the array ‘arr’.

Parameters
arrnp.ndarray

The input array which needs a Poisson distribution applied to items

Returns
arrnp.ndarray

The input array, but with every pixel altered according to a poisson distribution

simcado.utils.quantify(item, unit)[source]

Ensure an item is a Quantity

Parameters
itemint, float, array, list, Quantity
unitstr, Unit
Returns
quantQuantity
simcado.utils.seq(start, stop, step=1)[source]

Replacement for numpy.arange modelled after R’s seq function

Returns an evenly spaced sequence from start to stop. stop is included if the difference between start and stop is an integer multiple of step.

From the documentation of numpy.range: “When using a non-integer step, such as 0.1, the results will often not be consistent.” This replacement aims to avoid these inconsistencies.

Parameters
start, stop: [int, float]

the starting and (maximal) end values of the sequence.

step[int, float]

increment of the sequence, defaults to 1

simcado.utils.telescope_diffraction_limit(aperture_size, wavelength, distance=None)[source]

Returns the diffraction limit of a telescope

Parameters
aperture_sizefloat

[m] The diameter of the primary mirror

wavelengthfloat

[um] The wavelength for diffarction

distancefloat, optional

Default is None. If distance is given, the transverse distance for the diffraction limit is returned in the same units as distance

Returns
diff_limitfloat

[arcsec] The angular diffraction limit. If distance is not None, diff_limit is in the same units as distance

simcado.utils.transverse_distance(angle, distance)[source]

Turn an angular distance into a proper transverse distance

Parameters
anglefloat

[arcsec] The on-sky angle

distancefloat

The distance to the object. Units are arbitary

Returns
trans_distancefloat

proper transverse distance. Has the same Units as distance

simcado.utils.unify(x, unit, length=1)[source]

Convert all types of input to an astropy array/unit pair

Parameters
xint, float, np.ndarray, astropy.Quantity

The array to be turned into an astropy.Quantity

unitastropy.Quantity

The units to attach to the array

lengthint, optional

If x is a scalar, and the desired output is an array with length

Returns
yastropy.Quantity
simcado.utils.zendist2airmass(zendist)[source]

Convert zenith distance to airmass

Parameters
zenith distance[deg]

Zenith distance angle

Returns
airmass in sec(z) approximation
simcado.utils.zenith_dist_to_airmass(zenith_dist)[source]

zenith_dist is in degrees

X = sec(Z)