scopesim.utils module¶
Helper functions for ScopeSim.
- 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]¶
Return 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]¶
Return zenith distance in degrees.
Z = arccos(1/X)
- scopesim.utils.angle_in_arcseconds(distance, width)[source]¶
Return the angular distance of an object in arcseconds.
Units must be consistent!
- scopesim.utils.bug_report() None[source]¶
Print versions of dependencies for inclusion in bug report.
- scopesim.utils.bug_report_to_file(filename) None[source]¶
Like bug_report, but writes to file instead of printing.
- scopesim.utils.check_keys(input_dict, required_keys, action='error', all_any='all')[source]¶
Check to see if all/any of the required keys are present in a dict.
- scopesim.utils.clean_dict(orig_dict, new_entries)[source]¶
Replace OBS_DICT keywords with actual values.
- Parameters:
- orig_dictdict
- new_entriesdict
OBS dict
- Returns:
- orig_dictdict
Updated dict
- scopesim.utils.deriv_polynomial2d(poly)[source]¶
Derive (gradient) of a Polynomial2D model.
- Parameters:
- polyastropy.modeling.models.Polynomial2D
- Returns:
- gradienttuple of Polynomial2d
- scopesim.utils.extract_base_from_unit(unit, base_unit)[source]¶
Extract
astropybase 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
astropyphysical 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.figure_factory(nrows=1, ncols=1, **kwargs)[source]¶
Default way to init fig and ax, to easily modify later.
- 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, cmds=None)[source]¶
Return 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]¶
Check and correct for decreasing x_orig values.
- scopesim.utils.log_to_file(enable=True)[source]¶
Enable or disable logging to file (convenience function).
- scopesim.utils.moffat(r, alpha, beta)[source]¶
!!Unfinished!! Return a Moffat function.
- Parameters:
- r
- alpha
- beta
- Returns:
- eta
- 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 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.power_vector(val, degree)[source]¶
Return the vector of powers of val up to a degree.
- scopesim.utils.quantify(item, unit, cmds=None)[source]¶
Ensure an item is a Quantity.
- Parameters:
- itemint, float, array, list, Quantity
- unitstr, Unit
- Returns:
- quantQuantity
- scopesim.utils.quantity_from_table(colname: str, table: Table, default_unit: str = '') Quantity[source]¶
- scopesim.utils.return_latest_github_actions_jobs_status(owner_name='AstarVienna', repo_name='ScopeSim', branch='dev_master', actions_yaml_name='tests.yml')[source]¶
Get 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_console_log_level(level='INFO')[source]¶
Set the level for the console handler (convenience function).
This controls what is actually printed to the console by ScopeSim. Accepted values are: DEBUG, INFO (default), WARNING, ERROR and CRITICAL.
- scopesim.utils.stringify_dict(dic, ignore_types=(<class 'str'>, <class 'int'>, <class 'float'>))[source]¶
Turn a dict entries into strings for addition to FITS headers.
- scopesim.utils.telescope_diffraction_limit(aperture_size, wavelength, distance=None)[source]¶
Return 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
distanceis 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.top_level_catch(func)[source]¶
Catch any unhandled exceptions, log it including bug report.
- 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 with length.
- Returns:
- yastropy.Quantity
- scopesim.utils.unit_from_table(colname: str, table: Table, default_unit: str = '') Unit[source]¶
Look for the unit for a column based on the meta dict keyword “<col>_unit”.
- scopesim.utils.update_logging(capture_warnings=True)[source]¶
Reload logging configuration from
rc.__config__.
- scopesim.utils.write_report(text, filename=None, output=None)[source]¶
Write a report string to file in latex or rst format.