scopesim.utils module

Helper functions for ScopeSim.

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.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.change_table_entry(tbl, col_name, new_val, old_val=None, position=None)[source]
scopesim.utils.check_keys(input_dict: Union[Mapping, Iterable], required_keys: Set, action: str = 'error', all_any: str = 'all') bool[source]

Check to see if all/any of the required keys are present in a dict.

Changed in version v0.8.0: The required_keys parameter should now be a set.

Parameters:
input_dictUnion[Mapping, Iterable]

The mapping to be checked.

required_keysSet

Set containing the keys to look for.

action{“error”, “warn”, “warning”}, optional

What to do in case the check does not pass. The default is “error”.

all_any{“all”, “any”}, optional

Whether to check if “all” or “any” of the required_keys are present. The default is “all”.

Returns:
keys_presentbool

True if check succeded, False otherwise.

Raises:
ValueError

Raised when an invalid parameter was passed or when action was set to “error” (the default) and the required_keys were not found.

scopesim.utils.close_loop(*close_loop(zip(x, y)))[source]
scopesim.utils.convert_table_comments_to_dict(tbl)[source]
scopesim.utils.deriv_polynomial2d(poly)[source]

Derive (gradient) of a Polynomial2D model.

Parameters:
polyastropy.modeling.models.Polynomial2D
Returns:
gradienttuple of Polynomial2d
scopesim.utils.figure_factory(nrows=1, ncols=1, **kwargs)[source]

Default way to init fig and ax, to easily modify later.

scopesim.utils.figure_grid_factory(nrows=1, ncols=1, **kwargs)[source]

Gridspec variant.

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.from_rc_config(item)[source]
scopesim.utils.get_fits_type(filename)[source]
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.is_fits(filename) bool[source]
scopesim.utils.log_bug_report(level=10) None[source]

Emit bug report as logging message.

scopesim.utils.log_to_file(enable=True)[source]

Enable or disable logging to file (convenience function).

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

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

scopesim.utils.power_vector(val, degree)[source]

Return the vector of powers of val up to a degree.

scopesim.utils.pretty_print_dict(dic, indent=0)[source]
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.real_colname(name, colnames, silent=True)[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.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.top_level_catch(func)[source]

Catch any unhandled exceptions, log it including bug report.

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.

scopesim.utils.zendist2airmass(zendist)[source]

Convert zenith distance to airmass.

Parameters:
zenith distance[deg]

Zenith distance angle

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

zenith_dist is in degrees.

X = sec(Z)