pystellibs package#
Subpackages#
Submodules#
pystellibs.astropy_units module#
Declare missing photometric and spectral units for use with astropy.
- class Quantity[source]#
Bases:
ndarrayA ~astropy.units.Quantity represents a number with some associated unit.
See also: https://docs.astropy.org/en/stable/units/quantity.html
- Parameters:
value (number, ~numpy.ndarray, ~astropy.units.Quantity (sequence), or str) – The numerical value of this quantity in the units given by unit. If a Quantity or sequence of them (or any other valid object with a
unitattribute), creates a new Quantity object, converting to unit units as needed. If a string, it is converted to a number or Quantity, depending on whether a unit is present.unit (unit-like) – An object that represents the unit associated with the input value. Must be an ~astropy.units.UnitBase object or a string parseable by the
unitspackage.dtype (dtype, optional) – The dtype of the resulting Numpy array or scalar that will hold the value. If not provided, it is determined from the input, except that any integer and (non-Quantity) object inputs are converted to float by default. If None, the normal numpy.dtype introspection is used, e.g. preventing upcasting of integers.
copy (bool, optional) – If True (default), then the value is copied. Otherwise, a copy will only be made if
__array__returns a copy, if value is a nested sequence, or if a copy is needed to satisfy an explicitly givendtype. (The False option is intended mostly for internal use, to speed up initialization where a copy is known to have been made. Use with care.)order ({'C', 'F', 'A'}, optional) – Specify the order of the array. As in ~numpy.array. This parameter is ignored if the input is a Quantity and
copy=False.subok (bool, optional) – If False (default), the returned array will be forced to be a Quantity. Otherwise, Quantity subclasses will be passed through, or a subclass appropriate for the unit will be used (such as ~astropy.units.Dex for
u.dex(u.AA)).ndmin (int, optional) – Specifies the minimum number of dimensions that the resulting array should have. Ones will be prepended to the shape as needed to meet this requirement. This parameter is ignored if the input is a Quantity and
copy=False.
- Raises:
TypeError – If the value provided is not a Python numeric type.
TypeError – If the unit provided is not either a
Unitobject or a parseable string unit.
Notes
Quantities can also be created by multiplying a number or array with a
Unit. See https://docs.astropy.org/en/latest/units/Unless the
dtypeargument is explicitly specified, integer or (non-Quantity) object inputs are converted to float by default.- static __new__(cls, value, unit=None, dtype=<class 'numpy.inexact'>, copy=True, order=None, subok=False, ndmin=0)[source]#
- Parameters:
cls (type[Self])
value (QuantityLike)
- Return type:
Self
- all(axis=None, out=None, keepdims=False, *, where=True)[source]#
Returns True if all elements evaluate to True.
Refer to numpy.all for full documentation.
See also
numpy.allequivalent function
- any(axis=None, out=None, keepdims=False, *, where=True)[source]#
Returns True if any of the elements of a evaluate to True.
Refer to numpy.any for full documentation.
See also
numpy.anyequivalent function
- argmax(axis=None, out=None, *, keepdims=False)[source]#
Return indices of the maximum values along the given axis.
Refer to numpy.argmax for full documentation.
See also
numpy.argmaxequivalent function
- argmin(axis=None, out=None, *, keepdims=False)[source]#
Return indices of the minimum values along the given axis.
Refer to numpy.argmin for detailed documentation.
See also
numpy.argminequivalent function
- argsort(axis=-1, kind=None, order=None)[source]#
Returns the indices that would sort this array.
Refer to numpy.argsort for full documentation.
See also
numpy.argsortequivalent function
- property cgs#
Returns a copy of the current Quantity instance with CGS units. The value of the resulting object will be scaled.
- choose(choices, out=None, mode='raise')[source]#
Use an index array to construct a new array from a set of choices.
Refer to numpy.choose for full documentation.
See also
numpy.chooseequivalent function
- decompose(bases=())[source]#
Generates a new Quantity with the units decomposed. Decomposed units have only irreducible units in them (see astropy.units.UnitBase.decompose).
- Parameters:
bases (sequence of ~astropy.units.UnitBase, optional) – The bases to decompose into. When not provided, decomposes down to any irreducible units. When provided, the decomposed result will only contain the given units. This will raises a ~astropy.units.UnitsError if it’s not possible to do so.
- Returns:
newq – A new object equal to this quantity with units decomposed.
- Return type:
~astropy.units.Quantity
- property equivalencies#
A list of equivalencies that will be applied by default during unit conversions.
- fill(value)[source]#
Fill the array with a scalar value.
- Parameters:
value (scalar) – All elements of a will be assigned this value.
Examples
>>> import numpy as np >>> a = np.array([1, 2]) >>> a.fill(0) >>> a array([0, 0]) >>> a = np.empty(2) >>> a.fill(1) >>> a array([1., 1.])
Fill expects a scalar value and always behaves the same as assigning to a single array element. The following is a rare example where this distinction is important:
>>> a = np.array([None, None], dtype=object) >>> a[0] = np.array(3) >>> a array([array(3), None], dtype=object) >>> a.fill(np.array(3)) >>> a array([array(3), array(3)], dtype=object)
Where other forms of assignments will unpack the array being assigned:
>>> a[...] = np.array(3) >>> a array([3, 3], dtype=object)
- property flat#
A 1-D iterator over the Quantity array.
This returns a
QuantityIteratorinstance, which behaves the same as the ~numpy.flatiter instance returned by ~numpy.ndarray.flat, and is similar to, but not a subclass of, Python’s built-in iterator object.
- info#
Container for meta information like name, description, format. This is required when the object is used as a mixin column within a table, but can be used as a general way to store meta information.
- insert(obj, values, axis=None)[source]#
Insert values along the given axis before the given indices and return a new ~astropy.units.Quantity object.
This is a thin wrapper around the numpy.insert function.
- Parameters:
obj (int, slice or sequence of int) – Object that defines the index or indices before which
valuesis inserted.values (array-like) – Values to insert. If the type of
valuesis different from that of quantity,valuesis converted to the matching type.valuesshould be shaped so that it can be broadcast appropriately The unit ofvaluesmust be consistent with this quantity.axis (int, optional) – Axis along which to insert
values. Ifaxisis None then the quantity array is flattened before insertion.
- Returns:
out – A copy of quantity with
valuesinserted. Note that the insertion does not occur in-place: a new quantity array is returned.- Return type:
~astropy.units.Quantity
Examples
>>> import astropy.units as u >>> q = [1, 2] * u.m >>> q.insert(0, 50 * u.cm) <Quantity [ 0.5, 1., 2.] m>
>>> q = [[1, 2], [3, 4]] * u.m >>> q.insert(1, [10, 20] * u.m, axis=0) <Quantity [[ 1., 2.], [ 10., 20.], [ 3., 4.]] m>
>>> q.insert(1, 10 * u.m, axis=1) <Quantity [[ 1., 10., 2.], [ 3., 10., 4.]] m>
- property isscalar#
True if the value of this quantity is a scalar, or False if it is an array-like object.
Note
This is subtly different from numpy.isscalar in that numpy.isscalar returns False for a zero-dimensional array (e.g.
np.array(1)), while this is True for quantities, since quantities cannot represent true numpy scalars.
- item(*args)[source]#
Copy an element of an array to a scalar Quantity and return it.
Like
item()except that it always returns a Quantity, not a Python scalar.
- mean(axis=None, dtype=None, out=None, keepdims=False, *, where=True)[source]#
Returns the average of the array elements along given axis.
Refer to numpy.mean for full documentation.
See also
numpy.meanequivalent function
- put(indices, values, mode='raise')[source]#
Set
a.flat[n] = values[n]for all n in indices.Refer to numpy.put for full documentation.
See also
numpy.putequivalent function
- round(decimals=0, out=None)[source]#
Return a with each element rounded to the given number of decimals.
Refer to numpy.around for full documentation.
See also
numpy.aroundequivalent function
- searchsorted(v, side='left', sorter=None)[source]#
Find indices where elements of v should be inserted in a to maintain order.
For full documentation, see numpy.searchsorted
See also
numpy.searchsortedequivalent function
- property si#
Returns a copy of the current Quantity instance with SI units. The value of the resulting object will be scaled.
- std(axis=None, dtype=None, out=None, ddof=0, keepdims=False, *, where=True)[source]#
Returns the standard deviation of the array elements along given axis.
Refer to numpy.std for full documentation.
See also
numpy.stdequivalent function
- take(indices, axis=None, out=None, mode='raise')[source]#
Return an array formed from the elements of a at the given indices.
Refer to numpy.take for full documentation.
See also
numpy.takeequivalent function
- to(unit, equivalencies=[], copy=True)[source]#
Return a new ~astropy.units.Quantity object with the specified unit.
- Parameters:
unit (unit-like) – An object that represents the unit to convert to. Must be an ~astropy.units.UnitBase object or a string parseable by the ~astropy.units package.
equivalencies (list of tuple) – A list of equivalence pairs to try if the units are not directly convertible. See astropy:unit_equivalencies. If not provided or
[], class default equivalencies will be used (none for ~astropy.units.Quantity, but may be set for subclasses) If None, no equivalencies will be applied at all, not even any set globally or within a context.copy (bool, optional) – If True (default), then the value is copied. Otherwise, a copy will only be made if necessary.
See also
to_valueget the numerical value in a given unit.
- to_string(unit=None, precision=None, format=None, subfmt=None, *, formatter=None)[source]#
Generate a string representation of the quantity and its unit.
The behavior of this function can be altered via the numpy.set_printoptions function and its various keywords. The exception to this is the
thresholdkeyword, which is controlled via the[units.quantity]configuration itemlatex_array_threshold. This is treated separately because the numpy default of 1000 is too big for most browsers to handle.- Parameters:
unit (unit-like, optional) – Specifies the unit. If not provided, the unit used to initialize the quantity will be used.
precision (number, optional) – The level of decimal precision. If None, or not provided, it will be determined from NumPy print options.
format (str, optional) –
The format of the result. If not provided, an unadorned string is returned. Supported values are:
’latex’: Return a LaTeX-formatted string
’latex_inline’: Return a LaTeX-formatted string that uses negative exponents instead of fractions
formatter (str, callable, dict, optional) – The formatter to use for the value. If a string, it should be a valid format specifier using Python’s mini-language. If a callable, it will be treated as the default formatter for all values and will overwrite default Latex formatting for exponential notation and complex numbers. If a dict, it should map a specific type to a callable to be directly passed into numpy.array2string. If not provided, the default formatter will be used.
subfmt (str, optional) –
Subformat of the result. For the moment, only used for
format='latex'andformat='latex_inline'. Supported values are:’inline’: Use
$ ... $as delimiters.’display’: Use
$\displaystyle ... $as delimiters.
- Returns:
A string with the contents of this Quantity
- Return type:
str
- to_value(unit=None, equivalencies=[])[source]#
The numerical value, possibly in a different unit.
- Parameters:
unit (unit-like, optional) – The unit in which the value should be given. If not given or None, use the current unit.
equivalencies (list of tuple, optional) – A list of equivalence pairs to try if the units are not directly convertible (see astropy:unit_equivalencies). If not provided or
[], class default equivalencies will be used (none for ~astropy.units.Quantity, but may be set for subclasses). If None, no equivalencies will be applied at all, not even any set globally or within a context.
- Returns:
value – The value in the units specified. For arrays, this will be a view of the data if no unit conversion was necessary.
- Return type:
ndarray or scalar
See also
toGet a new instance in a different unit.
- tolist()[source]#
Return the array as an
a.ndim-levels deep nested list of Python scalars.Return a copy of the array data as a (nested) Python list. Data items are converted to the nearest compatible builtin Python type, via the ~numpy.ndarray.item function.
If
a.ndimis 0, then since the depth of the nested list is 0, it will not be a list at all, but a simple Python scalar.- Parameters:
none
- Returns:
y – The possibly nested list of array elements.
- Return type:
object, or list of object, or list of list of object, or …
Notes
The array may be recreated via
a = np.array(a.tolist()), although this may sometimes lose precision.Examples
For a 1D array,
a.tolist()is almost the same aslist(a), except thattolistchanges numpy scalars to Python scalars:>>> import numpy as np >>> a = np.uint32([1, 2]) >>> a_list = list(a) >>> a_list [np.uint32(1), np.uint32(2)] >>> type(a_list[0]) <class 'numpy.uint32'> >>> a_tolist = a.tolist() >>> a_tolist [1, 2] >>> type(a_tolist[0]) <class 'int'>
Additionally, for a 2D array,
tolistapplies recursively:>>> a = np.array([[1, 2], [3, 4]]) >>> list(a) [array([1, 2]), array([3, 4])] >>> a.tolist() [[1, 2], [3, 4]]
The base case for this recursion is a 0D array:
>>> a = np.array(1) >>> list(a) Traceback (most recent call last): ... TypeError: iteration over a 0-d array >>> a.tolist() 1
- trace(offset=0, axis1=0, axis2=1, dtype=None, out=None)[source]#
Return the sum along diagonals of the array.
Refer to numpy.trace for full documentation.
See also
numpy.traceequivalent function
- property unit#
A ~astropy.units.UnitBase object representing the unit of this quantity.
- class Unit[source]#
Bases:
NamedUnitThe main unit class.
There are a number of different ways to construct a Unit, but always returns a UnitBase instance. If the arguments refer to an already-existing unit, that existing unit instance is returned, rather than a new one.
From a string:
Unit(s, format=None, parse_strict='silent')
Construct from a string representing a (possibly compound) unit.
The optional format keyword argument specifies the format the string is in, by default
"generic". For a description of the available formats, see astropy.units.format.The optional
parse_strictkeyword argument controls what happens when the string does not comply with the specified format. It may be one of the following:'raise': (default) raise a ValueError exception.'warn': emit a UnitParserWarning, and return a unit.'silent': return a unit silently.
With
'warn'or'silent'the parser might be able to parse the string and return a normal unit, but if it fails then an UnrecognizedUnit instance is returned.From a number:
Unit(number)
Creates a dimensionless unit.
From a UnitBase instance:
Unit(unit)
Returns the given unit unchanged.
From no arguments:
Unit()
Returns the dimensionless unit.
The last form, which creates a new Unit is described in detail below.
See also: https://docs.astropy.org/en/stable/units/
- Parameters:
st (str or list of str) – The name of the unit. If a list, the first element is the canonical (short) name, and the rest of the elements are aliases.
represents (unit-like, optional) – The unit that this named unit represents.
doc (str, optional) – A docstring describing the unit.
format (dict, optional) –
A mapping to format-specific representations of this unit. For example, for the
Ohmunit, it might be nice to have it displayed as\Omegaby thelatexformatter. In that case, format argument should be set to:{'latex': r'\Omega'}
namespace (dict, optional) – When provided, inject the unit (and all of its aliases) into the given namespace.
- Raises:
ValueError – If any of the given unit names are already in the registry.
ValueError – If any of the given unit names are not valid Python tokens.
ValueError – If
representscannot be parsed as a unit, e.g., because it is a malformed string or a |Quantity| that is not a scalar.
- decompose(bases=())[source]#
Return a unit object composed of only irreducible units.
- Parameters:
bases (sequence of UnitBase, optional) – The bases to decompose into. When not provided, decomposes down to any irreducible units. When provided, the decomposed result will only contain the given units. This will raises a UnitsError if it’s not possible to do so.
- Returns:
unit – New object containing only irreducible unit objects.
- Return type:
~astropy.units.CompositeUnit
- property represents: UnitBase#
The unit that this named unit represents.
pystellibs.basel module#
pystellibs.btsettl module#
pystellibs.config module#
pystellibs.elodie module#
pystellibs.grid module#
- class Grid[source]#
Bases:
objectA simple table class to hold data and header information.
- __init__(data, header)#
- Parameters:
data (ndarray[tuple[Any, ...], dtype[_ScalarT]])
header (Dict)
- Return type:
None
- data: ndarray[tuple[Any, ...], dtype[_ScalarT]] = <dataclasses._MISSING_TYPE object>#
- header: Dict = <dataclasses._MISSING_TYPE object>#