scopesim.utils module¶
Helper functions for ScopeSim
- scopesim.utils.add_SED_to_scopesim(file_in, file_out=None, wave_units='um')[source]¶
Adds the SED given in
file_in
to the ScopeSim 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 ScopeSim data directory i.e. torc.__data_dir__
- wave_unitsstr, astropy.Units
Units for the wavelength column, either as a string or as astropy units Default is [um]
- scopesim.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
- scopesim.utils.add_mags(mags)[source]¶
Returns a combined magnitude for a group of py_objects with
mags
- scopesim.utils.airmass2zendist(airmass)[source]¶
Convert airmass to zenith distance
- Parameters:
- airmassfloat (>= 1)
- Returns:
- zenith distance in degrees
- scopesim.utils.airmass_to_zenith_dist(airmass)[source]¶
returns zenith distance in degrees
Z = arccos(1/X)
- scopesim.utils.angle_in_arcseconds(distance, width)[source]¶
Returns the angular distance of an object in arcseconds.
Units must be consistent!
- scopesim.utils.check_keys(input_dict, required_keys, action='error', all_any='all')[source]¶
Checks to see if all/any of the required keys are present in a dict
- scopesim.utils.clean_dict(orig_dict, new_entries)[source]¶
Used for replacing OBS_DICT keywords with actual values
- Parameters:
- orig_dictdict
- new_entriesdict
OBS dict
- Returns:
- orig_dictdict
Updated dict
- scopesim.utils.deriv_polynomial2d(poly)[source]¶
Derivatives (gradient) of a Polynomial2D model
- Parameters:
- polyastropy.modeling.models.Polynomial2D
- scopesim.utils.extract_base_from_unit(unit, base_unit)[source]¶
Extract
astropy
base unit from a compound unit- Parameters:
- unitastropy.Unit
- base_unitUnit, str
- Returns:
- new_unitUnit
The input unit minus any base units corresponding to
base_unit
- extracted_unitsUnit
Any base units corresponding to
base_unit
- scopesim.utils.extract_type_from_unit(unit, unit_type)[source]¶
Extract
astropy
physical type from a compound unit- Parameters:
- unitastropy.Unit
- unit_typestr
The physical type of the unit as given by
astropy
- Returns:
- new_unitUnit
The input unit minus any base units corresponding to
unit_type
- extracted_unitsUnit
Any base units corresponding to
unit_type
- scopesim.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
- scopesim.utils.from_currsys(item)[source]¶
Returns the current value of a bang-string from rc.__currsys__
- scopesim.utils.get_meta_quantity(meta_dict, name, fallback_unit='')[source]¶
Extract a Quantity from a dictionary
- Parameters:
- meta_dictdict
- namestr
- fallback_unitQuantity
- Returns:
- quantQuantity
- scopesim.utils.has_needed_keywords(header, suffix='')[source]¶
Check to see if the WCS keywords are in the header
- scopesim.utils.interp2(x_new, x_orig, y_orig)[source]¶
Checks and corrects for decreasing x_orig values
- scopesim.utils.moffat(r, alpha, beta)[source]¶
!!Unfinished!! Return a Moffat function
- Parameters:
- r
- alpha
- beta
- Returns:
- eta
- scopesim.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
- scopesim.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
- scopesim.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
Ball: “A Treatise on Spherical Astronomy”, Cambridge 1908
- scopesim.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
- scopesim.utils.quantify(item, unit)[source]¶
Ensure an item is a Quantity
- Parameters:
- itemint, float, array, list, Quantity
- unitstr, Unit
- Returns:
- quantQuantity
- scopesim.utils.return_latest_github_actions_jobs_status(owner_name='AstarVienna', repo_name='ScopeSim', branch='dev_master', actions_yaml_name='tests.yml')[source]¶
Gets the status of the latest test run
- scopesim.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
- scopesim.utils.set_logger_level(which='console', level='ERROR')[source]¶
Sets the level of logging for either the console or file logger
- Parameters:
- whichstr
[“console”, “file”]
- levelstr
[“ON”, “OFF”, “DEBUG”, “INFO”, “WARN”, “ERROR”, “CRITICAL”]
- scopesim.utils.setup_loggers(**kwargs)[source]¶
Sets up both console and file loggers.
Acceptable parameters are the same as the
!SIM.logging
sub dictionary
- scopesim.utils.stringify_dict(dic, ignore_types=(<class 'str'>, <class 'int'>, <class 'float'>))[source]¶
Turns a dict entries into strings for addition to FITS headers
- scopesim.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 asdistance
- Returns:
- diff_limitfloat
[arcsec] The angular diffraction limit. If distance is not None, diff_limit is in the same units as distance
- scopesim.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
- scopesim.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 withlength
- Returns:
- yastropy.Quantity
- scopesim.utils.unit_from_table(colname, table, default_unit='')[source]¶
Looks for the unit for a column based on the meta dict keyword “<col>_unit”
- scopesim.utils.write_report(text, filename=None, output=['rst'])[source]¶
Writes a report string to file in latex or rst format