Isopy Data Types

Key strings

Key strings should be created using isopy.keystring() and isopy.askeystring() functions and not by invoking the key string objects directly.

Key strings are a subclass of str and therefore contains all the method that a python string does. Unless specifically noted below these methods will return a str rather than a key string.

keystring

isopy.keystring(key, *, allow_reformatting=True, flavour='any')[source]

Returns an key string with the highest priority compatible flavour.

Parameters
  • key – A string to be converted into a key string.

  • allow_reformatting (bool, Default = True) – If True the string can be reformatted to get the correct format. If False only a string that already has the correct format is considered.

  • flavour – The possible flavour(s) of the key string.

Examples

>>> isopy.keystring('pd')
ElementKeyString('Pd')
>>> isopy.keystring('pd', allow_reformatting=False)
GeneralKeyString('pd')
>>> key = isopy.keystring('pd', flavour = 'general'); key
GeneralKeyString('pd')
>>>  isopy.keystring(key) # The element flavour has a higher priority
ElementKeyString('Pd')
Return type

IsopyKeyString

askeystring

isopy.askeystring(key, *, allow_reformatting=True, flavour='any')[source]

Returns a key string preserving the flavour if valid.

If key is a key string with a flavour not in flavour an exception is raised. If the key flavour is in flavour it will not be converted to a flavour of higher priority.

Parameters
  • key – A string to be converted into a key string.

  • allow_reformatting (bool, Default = True) – If True the string can be reformatted to get the correct format. If False only a string that already has the correct format is considered.

  • flavour – The possible flavour(s) of the key string.

Examples

>>> isopy.askeystring('pd')
ElementKeyString('Pd')
>>> isopy.askeystring('pd', allow_reformatting=False)
GeneralKeyString('pd')
>>> key = isopy.askeystring('pd', flavour = 'general'); key
GeneralKeyString('pd')
>>>  isopy.askeystring(key) # Preserves the flavour
GeneralKeyString('pd')
Return type

IsopyKeyString

iskeystring

isopy.iskeystring(item, *, flavour=None, flavour_in=None)[source]

Returns True if the supplied string is an key string otherwise returns False.

Parameters
  • item – The string to be verified.

  • flavour (flavour_like, Optional) – If given then True is returned if the flavour of item is equal to flavour.

  • flavour_in (flavour_like Optional) – If given then then True is returned if the flavour of item is found in flavour_in.

Return type

bool

Examples

>>> isopy.iskeystring('Pd')
False
>>> key = isopy.keystring('pd')
>>> isopy.iskeystring(key)
True
>>> isopy.iskeystring(key, flavour='isotope')
False
>>> isopy.iskeystring(key, flavour_in='element|isotope')
True

MassKeyString

class isopy.core.MassKeyString[source]

String representation of a mass number.

flavour

The flavour of the key string.

mass_number

A reference to itself.

Type

MassKeyString

Examples

>>> isopy.keystring('76')
'76'
>>> isopy.keystring(76)
'76'

Mass key strings also support the <,> <=, >= operators:

>>> isopy.keystring('76') > 75
True
>>> isopy.keystring('76') <= 75
False
str(format=None)[source]

Return a str object of the key string.

the optional format can either be a string matching one of the format options or a string which can be formatted using the format options as key words.

Format options are: * "m" and "key" - Same as str(keystring) * "math" - Key string formatted for latex math mode. * “”latex”” - Same as above but including $ $ math deliminators.

Examples

>>> key = isopy.keystring('101')
>>> key.str()
'101'
>>> key.str('key is "{m}"')
'key is "101"'

ElementKeyString

class isopy.core.ElementKeyString[source]

A string representation of an element symbol limited to two letters.

The first letter is in upper case and subsequent letters are in lower case.

flavour

The flavour of the key string.

element_symbol

A reference to itself.

Type

ElementKeyString

isotopes

A key list of all the present day naturally occuring isotopes of this element.

Type

IsotopeKeyList

Examples

>>> isopy.keystring('Pd')
'Pd'
>>> isopy.keystring('pd')
'pd'
str(format=None)[source]

Return a str object of the key string.

the optional format can either be a string matching one of the format options or a string which can be formatted using the format options as key words.

Format options are: * "key" - Same as str(keystring). * "Es", "es", "ES" - Element symbol capitalised, in lower case and in upper case respectivley. * "Name", "name", "NAME" - Full element name capitalised, in lower case and in upper case respectivley. * "math" - Key string formatted for latex math mode. * “”latex”” - Same as above but including $ $ math deliminators.

Examples

>>> key = isopy.ElementKeyString('ru')
>>> key.str()
'Ru'
>>> key.str('Name')
'Ruthenium'
>>> key.str('Name of "{es}" is {Name}')
'name of "ru" is Ruthenium'

IsotopeKeyString

class isopy.core.IsotopeKeyString[source]

A string representation of an isotope consisting of a mass number followed by an element symbol.

flavour

The flavour of the key string.

mass_number

The mass number of this isotope.

Type

MassKeyString

element_symbol

The element symbol of this isotope.

Type

ElementKeyString

isotopes

A reference to itself.

Type

IsotopeKeyList

mz

The mass to charge ratio of this isotope on the basis of the mass number.

Type

float

Examples

>>> isopy.keystring('Pd104')
'104Pd'
>>> isopy.keystring('104pd')
'104Pd'

in can be used to test if a string is equal to the mass number or an element symbol of an isotope key string.

>>> 'pd' in isopy.keystring('Pd104')
True
>>> 104 in isopy.keystring('Pd104')
True
str(format=None)[source]

Return a str object of the key string.

the optional format can either be a string matching one of the format options or a string which can be formatted using the format options as key words.

Format options are: * "key" - Same as str(keystring). * All format options listed for :func:`MassKeyString.str`_ * All format options listed for :func:`ElementKeyString.str`_ * All combinations of mass key string format options and the element key string options, e.g. ‘esm’ or ‘mName’. * All combinations listed above but with a "-" between the two format options. * "math" - Key string formatted for latex math mode. * “”latex”” - Same as above but including $ $ math deliminators.

Examples

>>> key = isopy.keystring('101ru')
>>> key.str()
'101Ru'
>>> key.str('esm')
'ru101'
>>> key.str('esm')
'ru101'
>>> key.str('Name-m')
'Ruthenium-101'
>>> key.str('Mass {m} of element {Name}')
'Mass 101 of Ruthenium'

MoleculeKeyString

class isopy.core.MoleculeKeyString[source]

A string representation of an molecue consisting of a element and/or isotope key strings.

Mass numbers must be before the element symbols. Any number after the element symbol is assumed to be a multiple. Capital letters signify a new element symbol and must be used when listing succesive element symbols. Parenthesis, or square brackets, can be used to group elements or to seperate mass numbers from multipliers. Multiple + and - signs are used to signify

Molecule keys strings with more than one component is enclosed in square brackets. Isotope molecules are enclosed in square brackets if there is more than one component in the molecule.

flavour

The flavour of the key string.

element_symbol

A molecule key string containing the element formula for this molecule.

Type

MoleculeKeyList

isotopes

A molecule key string containing all the isotopes for this molecule.

Type

MoleculeKeyList

mz

The mass to charge ratio for each molecule in the list on the basis of the mass number. Negative charges will return a positive number.

Type

float

components

The components of this molecule.

Type

tuple

n

The multiplier of this molecule.

Type

int

charge

The charge of this molecule.

Type

None, int

Examples

>>> isopy.keystring('H2O')
'[H2O]'
>>> isopy.keystring('(1H)2(16O)')
'[[1H]2[16O]]'
>>> isopy.keystring('137Ba++')
'137Ba++'
str(format=None)[source]

Return a str object of the key string.

the optional format can either be a string matching one of the format options or a string which can be formatted using the format options as key words.

Format options are: * "key" - Same as str(keystring). * "math" - Key string formatted for latex math mode. * “”latex”” - Same as above but including $ $ math deliminators.

RatioKeyString

class isopy.core.RatioKeyString[source]

A string representation of a ratio of two key strings.

A string must consist of a numerator and denominator seperated by “/”. The numerator and denominator key strings can be of different flavours. Nested ratios can be created using a combination of “/”, “//”, “///” etc upto a maximum of 9 nested ratios.

flavour

The flavour of this key string.

numerator

The numerator of this ratio.

Type

keystring

denominator

The denominator of this ratio.

Type

keystring

Examples

>>> isopy.keystring('Pd108/105pd')
'104Pd/108Pd'
>>> isopy.keystring('Pd108/105pd//ge')
'108Pd/105Pd//Ge

in can be used to test if a string is equal to the numerator or denominator of the ratio.

>>> 'pd108' in isopy.keystring('108Pd/Ge')
True
>>> 'as/ge' in isopy.keystring('Pd108/105pd//as/ge')
True
str(format=None, nformat=None, dformat=None)[source]

Return a str object of the key string.

the optional format can either be a string matching one of the format options or a string which can be formatted using the format options as key words.

Format options are: * "key" - Same as str(keystring), does consider nformat and dformat. * "n" - The numerator. nformat can be given to specify format of the numerator. * "d" - The denominator. dformat can be given to specify format of the denominator. * "n/d" - The ratio including nformat and dformat. This is the default is format is not given. * "math" - Key string formatted for latex math mode. * “”latex”” - Same as above but including $ $ math deliminators.

format can be a tuple or a dict which will be unpacked into format, nformat and dformat. This is useful for ratios of ratios.

Examples

>>> key = isopy.RatioKeyString('101ru/104ru')
>>> key.str()
'101Ru/104Ru'
>>> key.str(nformat='Name-m', dformat='esm')
'Ruthenium-101/ru104'
>>> key.str('Ratio is "{n/d}"')
'Ratio is "101Ru/104Ru"'
>>> key.str('numerator is: {n}, denominator is: {d}', dformat='esm')
'numerator is: 101Ru, denominator is: ru104'

GeneralKeyString

class isopy.core.GeneralKeyString[source]

A general key string that can hold any string value.

No formatting is applied to the string.

flavour

The flavour of this key string.

Examples

>>> isopy.keystring('harry')
'harry'
>>> isopy.keystring('pd', flavour='general')
'pd'
str(format=None)[source]

Return a str object of the key string.

the optional format can either be a string matching one of the format options or a string which can be formatted using the format options as key words.

Format options are: * "key" - Same as str(keystring) * "math" - Key string formatted for latex math mode. * “”latex”” - Same as above but including $ $ math deliminators.

Examples

>>> key = isopy.GeneralKeyString('hermione')
>>> key.str()
'hermione'
>>> key.str('{key} is really smart')
'hermione is really smart'

Key list

Key lists should be created using isopy.keylist() and isopy.askeylist() functions and not by invoking the key string objects directly.

Key strings are a subclass of tuple and therefore contains all the method that a normal tuple does. Only those method which behave differently from tuple are documented here.

keylist

isopy.keylist(*keys, ignore_duplicates=False, allow_duplicates=True, allow_reformatting=True, sort=False, flavour='any')[source]

Returns a key list with the highest priority flavour compatible with each key string.

keys can consist of single strings, sequences of strings, dictionaries, isopy arrays and numpy arrays. For dictionaries and arrays the keys or dtype.name values are used as keys. Strings containing whitespace will be split into multiple strings. This only applied to strings given directly as a key, not for string contained within other object.

Parameters
  • *keys – Keys to be included in the list.

  • ignore_duplicates (bool, Default = True) – If True all duplicate items will be removed from the sequence.

  • allow_duplicates (bool, Default = True) – If False a ListDuplicateError will be raised if the sequence contains any duplicate items.

  • allow_reformatting (bool, Default = True) – If True the string can be reformatted to get the correct format. If False only strings that already have the correct format are considered.

  • sort (bool) – If True the keys in will be sorted

  • flavour – The possible flavour(s) of key strings in the key list.

Examples

>>> isopy.keylist(['ru', 'pd', 'cd'])
IsopyKeyList('Ru', 'Pd', 'Cd', flavour='element')
>>> isopy.keylist('ru pd cd') # Split into multiple keys
IsopyKeyList('Ru', 'Pd', 'Cd', flavour='element')
>>> isopy.keylist(['ru pd cd']) # Strings in other objects are left as is
IsopyKeyList('ru pd cd', flavour='general')
>>> d = dict(ru=1, pd=2, cd=3)
>>> isopy.keylist(d)
IsopyKeyList('Ru', 'Pd', 'Cd', flavour='element')
>>> a = isopy.array(d, flavour = 'general')
>>> isopy.keylist(a)
IsopyKeyList('Ru', 'Pd', 'Cd', flavour='element')
Return type

IsopyKeyList

askeylist

isopy.askeylist(*keys, ignore_duplicates=False, allow_duplicates=True, allow_reformatting=True, sort=False, flavour='any')[source]

Returns a key list preserving the flavour of each key string if it has a valid flavour.

If a key is a key string with a flavour not in flavour an exception is raised. If the key flavour is in flavour it will not be converted to a flavour of higher priority.

keys can consist of single strings, sequences of strings, dictionaries, isopy arrays and numpy arrays. For dictionaries and arrays the keys or dtype.name values are used as keys.

Parameters
  • *keys – Keys to be included in the list.

  • ignore_duplicates (bool, Default = True) – If True all duplicate items will be removed from the sequence.

  • allow_duplicates (bool, Default = True) – If False a ListDuplicateError will be raised if the sequence contains any duplicate items.

  • allow_reformatting (bool, Default = True) – If True the string can be reformatted to get the correct format. If False only strings that already have the correct format are considered.

  • sort (bool) – If True the keys in will be sorted

  • flavour – The possible flavour(s) of key strings in the key list.

Examples

>>> isopy.askeylist(['ru', 'pd', 'cd'])
IsopyKeyList('Ru', 'Pd', 'Cd', flavour='element')
>>> isopy.askeylist('ru pd cd') # Split into multiple keys
IsopyKeyList('Ru', 'Pd', 'Cd', flavour='element')
>>> isopy.askeylist(['ru pd cd']) # Strings in other objects are left as is
IsopyKeyList('ru pd cd', flavour='general')
>>> d = dict(ru=1, pd=2, cd=3)
>>> isopy.askeylist(d)
IsopyKeyList('Ru', 'Pd', 'Cd', flavour='element')
>>> a = isopy.array(d, flavour = 'general')
>>> isopy.askeylist(a)
IsopyKeyList('ru', 'pd', 'cd', flavour='general')
Return type

IsopyKeyList

iskeylist

isopy.iskeylist(item, *, flavour=None, flavour_in=None)[source]

Returns True if item is a key string list otherwise returns False.

Parameters
  • item – A sequence of strings to be verified.

  • flavour (flavour_like, Optional) – If given then True is returned if the flavour of item is equal to flavour.

  • flavour_in (flavour_like Optional) – If given then then True is returned if the flavour of item is found in flavour_in.

Return type

bool

Examples

>>> isopy.iskeylist(['Ru', 'Pd', 'Cd'])
False
>>> keys = isopy.keylist('ru pd cd')
>>> isopy.iskeylist(keys)
True
>>> isopy.iskeylist(keys, flavour='element|isotope')
False
>>> isopy.iskeylist(keys, flavour_in='element|isotope')
True

IsopyKeyList

class isopy.core.IsopyKeyList[source]

A sequence of key strings.

flavour

The flavour of the keys in the key list.

Type

ListFlavour

flavours

A tuple containing the flavour of each key in the list.

Type

tuple

mass_numbers

A key list containing the mass number of each key in the list. None if one or more of the keys is missing the mass_number attribute.

Type

IsopyKeyList

element_symbols

A key list containing the element symbol of each key in the list. None if one or more of the keys is missing the element_symbol attribute.

Type

IsopyKeyList

isotopes

A key list containing the isotopes of each key in the list. None if one or more of the keys is missing the isotopes attribute.

Type

IsopyKeyList

mz

A key list containing the mass to charge ratio of each key in the list. None if one or more of the keys is missing the mz attribute.

Type

tuple

numerators

A key list containing the ratio numerator of each key in the list. None if one or more of the keys is missing the numerator attribute.

Type

IsopyKeyList

denominators

A key list containing the ratio denominator of each key in the list. None if one or more of the keys is missing the denominator attribute.

Type

IsopyKeyList

common_denominator

The common demoninator of all ratio key strings in the sequence. None if there is no common denominator or the list contains non-ratio keys.

Type

IsopyKeyString, None

filter(key_eq=None, key_neq=None, **filters)[source]

Returns a new key list containing the keys that satify all the filter arguments given.

Parameters
  • key_eq (str, Sequence[str], Optional) – Only key strings equal to/found in key_eq pass this filter.

  • key_neq (str, Sequence[str], Optional) – Only key strings not equal to/found in key_neq pass this filter.

  • **filters

    A filter consists of the attribute name followed by the comparison type speperated by a _. Avaliable comparison types are:

    • eq for == for a single value or in for multiple values

    • neq for != for a single value or not in for multiple values

    • lt for <

    • gt for >

    • le for <=

    • ge for >=

    Any filter preceded by numerator_ or denominator_ will be forwarded to the numerator and denominator keys of ratio key strings.

Examples

>>> keylist = isopy.askeylist(['101Ru', '105Pd', '111Cd'])
>>> keylist.filter(key_neq = '105pd')
('101Ru', '111Cd')
>>> keylist.filter(element_symbol_eq=['pd', 'cd'])
('105Pd', '111Cd')
>>> keylist.filter(mass_number_le=105)
('101Ru', '105Pd')
>>> keylist = isopy.askeylist(['101Ru/102Ru', '108Pd/105Pd', '111Cd/110Cd'])
>>> keylist.filter(numerator_element_symbol_neq='pd')
('101Ru/102Ru', '111Cd/110Cd')
strlist(format=None)[source]

Return a list of str object for each key in the key list.

Analogous to [key.str(format) for key in keylist]

str(format=None)[source]

Return a string of the list formatted according to the format.

sorted()[source]

Returns a sorted copy of the list.

reversed()[source]

Returns a reversed copy of the list.

flatten(ignore_duplicates=False, allow_duplicates=True)[source]

Returns a flattened copy of the list. Only ratio key string can be flattened all other key strings will remain the same.

Parameters
  • ignore_duplicates (bool, Default = True) – If True all duplicate items will be removed from the sequence.

  • allow_duplicates (bool, Default = True) – If False a ListDuplicateError will be raised if the sequence contains any duplicate items.

Examples

>>> keylist = isopy.keylist(['103rh', 'ru/pd', 'ag', '111cd/105pd'])
>>> keylist.flatten()
('103Rh', 'Ru', 'Pd', Ag', '111Cd', '105Pd')

Arrays

Array must be created using one of the functions below. They can not be created by initialising isopy.core.IsopyArray directly.

Isopy arrays are subclass of a numpy.ndarray and therefore contains all the methods and attributes that a normal numpy ndarray does. However, these may not work as expected and caution is advised when using attributes/methods not described in IsopyArray.

array

isopy.array(values=None, keys=None, *, dtype=None, ndim=None, flavour='any', **columns_or_read_kwargs)[source]

Convert the input arguments to a isopy array.

If values is a string it assumes it is a filename and will load the contents of the file together with columns_or_read_kwargs. If values is ‘clipboard’ it will read values from the clipboard. If columns_or_read_kwargs in read_kwargs it assumes a is an excel file. Otherwise it assumes values is a CSV file.

Will attempt to convert the input into an flavour array. If flavour is a sequence of flavours then the first successful conversion is returned. If flavour is ‘any’ the flavours tried are ['mass', 'element', 'isotope', 'ratio', 'mixed', 'molecule', 'general'].

asarray

isopy.asarray(a, *, ndim=None, flavour=None, **read_kwargs)[source]

If a is an isopy array return it otherwise convert a into an isopy array and return it. If ndim is given a view of the array with the specified dimensionality is returned.

If a is a string it assumes it is a filename and will load the contents of the file together with read_kwargs. If a is ‘clipboard’ it will read values from the clipboard. If sheetname in read_kwargs it assumes a is an excel file. Otherwise it assumes a is a CSV file.

Will attempt to convert the input into an flavour array. If flavour is a sequence of flavours then the first successful conversion is returned. If flavour is ‘any’ the flavours tried are ['mass', 'element', 'isotope', 'ratio', 'mixed', 'molecule', 'general'].

asanyarray

isopy.asanyarray(a, *, dtype=None, ndim=None, flavour=None, **read_kwargs)[source]

Return isopy.asarray(a) if a possible otherwise return numpy.asanyarray(a).

The data type and number of dimensions of the returned array can be specified by dtype and *ndim, respectively.

If a is a string it assumes it is a filename and will load the contents of the file together with read_kwargs. If a is ‘clipboard’ it will read values from the clipboard. If sheetname in read_kwargs it assumes a is an excel file. Otherwise it assumes a is a CSV file.

Will attempt to convert the input into an flavour array. If flavour is a sequence of flavours then the first successful conversion is returned. If flavour is ‘any’ the flavours tried are ['mass', 'element', 'isotope', 'ratio', 'mixed', 'molecule', 'general'].

zeros

isopy.zeros(rows, keys=None, *, ndim=None, dtype=None, flavour='any')[source]

Create an isopy array filled with zeros.

If keys are not given, and cannot be inferred, then a normal numpy array is returned.

Parameters
  • rows (int, None) – Number of rows in the returned array. A value of -1 or None will return a 0-dimensional array unless overridden by ndim.

  • keys (Sequence[str], Optional) – Column names for the returned array. Can also be inferred from dtype if dtype is a named np.dtype.

  • ndim ({-1, 0, 1}, Optional) – Dimensions of the final array. A value of -1 will return an 0-dimensional array if size is 1 otherwise a 1-dimensional array is returned. An exception is raised if value is 0 and size is not -1 or 1.

  • dtype (numpy_dtype, Sequence[numpy_dtype]) – Data type of returned array. A sequence of data types can given to specify different datatypes for different columns in the final array. If not given np.float64 is used for all columns.

ones

isopy.ones(rows, keys=None, *, ndim=None, dtype=None, flavour='any')[source]

Create an isopy array filled with ones.

If keys are not given, and cannot be inferred, then a normal numpy array is returned.

Parameters
  • rows (int, None) – Number of rows in the returned array. A value of -1 or None will return a 0-dimensional array unless overridden by ndim.

  • keys (Sequence[str], Optional) – Column names for the returned array. Can also be inferred from dtype if dtype is a named np.dtype.

  • ndim ({-1, 0, 1}, Optional) – Dimensions of the final array. A value of -1 will return an 0-dimensional array if size is 1 otherwise a 1-dimensional array is returned. An exception is raised if value is 0 and size is not -1 or 1.

  • dtype (numpy_dtype, Sequence[numpy_dtype]) – Data type of returned array. A sequence of data types can given to specify different datatypes for different columns in the final array. If not given np.float64 is used for all columns.

empty

isopy.empty(rows, keys=None, *, ndim=None, dtype=None, flavour='any')[source]

Create an isopy array without initalising entries.

If keys are not given, and cannot be inferred, then a normal numpy array is returned.

Parameters
  • rows (int, None) – Number of rows in the returned array. A value of -1 or None will return a 0-dimensional array unless overridden by ndim.

  • keys (Sequence[str], Optional) – Column names for the returned array. Can also be inferred from dtype if dtype is a named np.dtype.

  • ndim ({-1, 0, 1}, Optional) – Dimensions of the final array. A value of -1 will return an 0-dimensional array if size is 1 otherwise a 1-dimensional array is returned. An exception is raised if value is 0 and size is not -1 or 1.

  • dtype (numpy_dtype, Sequence[numpy_dtype]) – Data type of returned array. A sequence of data types can given to specify different datatypes for different columns in the final array. If not given np.float64 is used for all columns.

full

isopy.full(rows, fill_value, keys=None, *, ndim=None, dtype=None, flavour='any')[source]

Create an isopy array filled with fill_value.

If keys are not given, and cannot be inferred, then a normal numpy array is returned.

Parameters
  • rows (int, None) – Number of rows in the returned array. A value of -1 or None will return a 0-dimensional array unless overridden by ndim.

  • fill_value – the value the array will be filled with.

  • keys (Sequence[str], Optional) – Column names for the returned array. Can also be inferred from dtype if dtype is a named np.dtype.

  • ndim ({-1, 0, 1}, Optional) – Dimensions of the final array. A value of -1 will return an 0-dimensional array if size is 1 otherwise a 1-dimensional array is returned. An exception is raised if value is 0 and size is not -1 or 1.

  • dtype (numpy_dtype, Sequence[numpy_dtype]) – Data type of returned array. A sequence of data types can given to specify different datatypes for different columns in the final array. If not given np.float64 is used for all columns.

random

isopy.random(rows, random_args=None, keys=None, *, distribution='normal', seed=None, ndim=None, dtype=None, flavour='any')[source]

Creates an an isopy array filled with random numbers.

If keys are not given, and cannot be inferred, then a normal numpy array is returned.

Parameters
  • rows (int, None) – Number of rows in the returned array. A value of -1 or None will return a 0-dimensional array unless overridden by ndim.

  • random_args – Arguments to be passed to the random generator when creating the random numbers for each column. Can be a single value or a tuple containing several values. If you want different arguments for different columns pass a list of values/tuples, one for each column.

  • keys (Sequence[str], Optional) – Column names for the returned array. Can also be inferred from dtype if dtype is a named np.dtype.

  • distribution – The name of the distribution to be used when calculating the random numbers. See here for a list of avaliable distributions.

  • seed – The seed passed to the random generator.

  • fill_value – the value the array will be filled with.

  • ndim ({-1, 0, 1}, Optional) – Dimensions of the final array. A value of -1 will return an 0-dimensional array if size is 1 otherwise a 1-dimensional array is returned. An exception is raised if value is 0 and size is not -1 or 1.

  • dtype (numpy_dtype, Sequence[numpy_dtype]) – Data type of returned array. A sequence of data types can given to specify different datatypes for different columns in the final array. If not given np.float64 is used for all columns.

Examples

>>> array = isopy.random(100, keys=('ru', 'pd', 'cd'))
>>> array
(row)      Ru (f8)    Pd (f8)    Cd (f8)
-------  ---------  ---------  ---------
0         -0.73359    0.11496   -0.00119
1         -0.59661   -0.14210    0.52218
2         -0.62663   -1.32210    0.71435
3          1.69478   -0.60308   -0.31961
4          0.99229    0.42969   -0.36984
            ...        ...        ...
95         1.29482   -1.49722    0.00716
96        -1.32433    0.99887   -0.02710
97        -0.34908    0.39324   -1.46929
98        -0.47520    0.39947   -0.16034
99         0.32749    0.53820   -0.23848
IsopyNdarray(100, flavour='element', default_value=nan)
>>> isopy.mean(array)
(row)      Ru (f8)    Pd (f8)    Cd (f8)
-------  ---------  ---------  ---------
None      -0.04493    0.07397   -0.06447
IsopyNdarray(-1, flavour='element', default_value=nan)
>>> isopy.sd(array)
(row)      Ru (f8)    Pd (f8)    Cd (f8)
-------  ---------  ---------  ---------
None       1.06521    1.03131    1.03173
IsopyNdarray(-1, flavour='element', default_value=nan)
>>> array = isopy.random(100, [(0, 1), (1, 0.1), (-1, 10)], keys=('ru', 'pd', 'cd'))
>>> array
(row)      Ru (f8)    Pd (f8)    Cd (f8)
-------  ---------  ---------  ---------
0          0.82868    0.97201    2.53042
1         -0.87905    1.04721   17.23299
2          0.04199    0.88000  -11.31050
3          0.11860    1.02957  -15.47807
4          0.02590    1.14512   -4.99726
            ...        ...        ...
95        -0.27775    1.04640   -9.34926
96        -0.09882    1.09960    7.67782
97        -0.22307    1.03733    9.68606
98         0.24518    1.04231   -4.08202
99        -0.75468    0.92260    0.70036
IsopyNdarray(100, flavour='element', default_value=nan)
>>> np.mean(array)
(row)      Ru (f8)    Pd (f8)    Cd (f8)
-------  ---------  ---------  ---------
None      -0.04996    0.99352   -1.02721
IsopyNdarray(-1, flavour='element', default_value=nan)
>>> isopy.sd(array)
(row)      Ru (f8)    Pd (f8)    Cd (f8)
-------  ---------  ---------  ---------
None       0.85324    0.09870    8.70021
IsopyNdarray(-1, flavour='element', default_value=nan)

isarray

isopy.isarray(item, *, flavour=None, flavour_in=None)[source]

Returns True if item is an isopy array otherwise returns False.

Return type

bool

IsopyArray

class isopy.core.IsopyArray[source]

An array where data is stored rows and columns of isopy key strings.

Parameters
  • values (dict, list, numpy_array, isopy_array) – Values can be a dictionary containing values or a sequence of values. A sequence containing values or sequences of values. A structured numpy array or a subclass thereof (e.g. pandas dataframe).

  • keys (Sequence[str], Optional) – Name of each column in the array. Does not need to be given if values is a dictionary or structured numpy array or if dtype is a np.dtype containing named columns.

  • ndim ({-1, 0, 1}, Optional) – Number of dimensions of the returned array. If -1 then the final array will be 0-dimensional if it has a size of 1 otherwise it will be 1-dimensional.

  • dtype (numpy_dtype, Sequence[numpy_dtype], dict[str, numpy_dtype], Optional) – Any data type accepted by numpy. Can also be a sequence of data types in which case the first data type in the sequence for which a conversion is possible is used. Data types for individual columns can be specified by a dictionary mapping the column name to the data type. If not given the data type is inferred from values if they already have a numpy data type. Otherwise values are converted to np.float64 if possible. If conversion fails the default data type from np.array(values[column]) is used.

ncols

The number of columns in the array

nrows

The number of rows in the array. If the array is 0-dimensional nrows is -1.

ndim

The number of dimensions of the data in the array.

size

The number of rows in the array. If the array is 0-dimensional size is 1.

datatypes

The data type for each column in the array.

keys

The column key strings

values()[source]

Returns a tuple containing the column values for each key in the array

Equivalent to tuple(array[key] for key in array.keys)

items()[source]

Returns a tuple containing a tuple with the key and the column values for each key in the array

Equivalent to tuple((key, array[key]) for key in array.keys)

get(key, default=Optional)[source]

Returns the values of column key if present in the array. Otherwise an numpy array filled with default is returned with the same shape as a column in the array. An exception will be raised if default cannot be broadcast to the correct shape.

If default is not given np.nan is used.

copy()[source]

Returns a copy of the array.

filter(**key_filters)[source]

Returns a view of the array containing the keys that satisfy the key_filters.

ratio(denominator=None, remove_denominator=True)[source]

Divide all values in the array by the denominator column and return a RatioArray.

If not denominator is given the key in the array with the largest value will be used as the denominator. If remove_denominator is True the denominator/denominator ratio is not included in the returned array.

deratio(denominator_value=1, sort_keys=True)[source]

Return a array with the numerators and the common denominator as columns. Values for the numerators will be copied from the original array and the entire array will be multiplied by denominator_value.

An exception is raised if the array flavour is not ‘ratio’ or if the array does not contain a common denominator.

normalise(value=1, key=None)[source]

Normalise the values in each row so that the the value of key is equal to value.

If key is a sequence of keys then the sum of those keys will be set equal to value. If keys is not given then the sum of all columns will be used. key can also be a callable that takes an array and return a key string.

Note returns a copy of the array.

Examples

>>> array = isopy.tb.make_ms_array('pd')
>>> array
(row)      102Pd (f8)    104Pd (f8)    105Pd (f8)    106Pd (f8)    108Pd (f8)    110Pd (f8)
-------  ------------  ------------  ------------  ------------  ------------  ------------
None          0.01020       0.11140       0.22330       0.27330       0.26460       0.11720
IsopyNdarray(-1, flavour='isotope', default_value=nan)
>>> array.normalise(10)
(row)      102Pd (f8)    104Pd (f8)    105Pd (f8)    106Pd (f8)    108Pd (f8)    110Pd (f8)
-------  ------------  ------------  ------------  ------------  ------------  ------------
None          0.10200       1.11400       2.23300       2.73300       2.64600       1.17200
IsopyNdarray(-1, flavour='isotope', default_value=nan)
>>> array.normalise(1, 'pd102')
(row)      102Pd (f8)    104Pd (f8)    105Pd (f8)    106Pd (f8)    108Pd (f8)    110Pd (f8)
-------  ------------  ------------  ------------  ------------  ------------  ------------
None          1.00000      10.92157      21.89216      26.79412      25.94118      11.49020
IsopyNdarray(-1, flavour='isotope', default_value=nan)
>>> array.normalise(10, ['pd106', 'pd108'])
(row)      102Pd (f8)    104Pd (f8)    105Pd (f8)    106Pd (f8)    108Pd (f8)    110Pd (f8)
-------  ------------  ------------  ------------  ------------  ------------  ------------
None          0.18963       2.07102       4.15133       5.08087       4.91913       2.17884
IsopyNdarray(-1, flavour='isotope', default_value=nan)
>>> array.normalise(10, isopy.keymax)
(row)      102Pd (f8)    104Pd (f8)    105Pd (f8)    106Pd (f8)    108Pd (f8)    110Pd (f8)
-------  ------------  ------------  ------------  ------------  ------------  ------------
None          0.37322       4.07611       8.17051      10.00000       9.68167       4.28833
IsopyNdarray(-1, flavour='isotope', default_value=nan)
default(value)[source]

Return a view of the array with a temporary default value.

This should only be used directly in conjuction with mathematical expressions. Any new view created will not inherit the default value.

Examples

>>> a1 = isopy.array([1,2,3], 'ru pd cd')
>>> a2 = isopy.array([20, 10], 'ru cd')
>>> a1 + a2 # Default value is np.nan
(row)      Ru (f8)    Pd (f8)    Cd (f8)
-------  ---------  ---------  ---------
None      21.00000        nan   13.00000
IsopyNdarray(-1, flavour='element', default_value=nan)
>>> a1 + a2.default(0) # a2 has a temporary default value of 0
(row)      Ru (f8)    Pd (f8)    Cd (f8)
-------  ---------  ---------  ---------
None      21.00000    2.00000   13.00000
IsopyNdarray(-1, flavour='element', default_value=nan)
tabulate(tablefmt='default', *, include_row=False, row_names=None, nrows=None, include_dtype=False, include_objinfo=False, keyfmt=None, floatfmt=None, intfmt=None, keys=None, **key_filters)

Turn the contents of the array/dictionary to a table.

Uses tabulate to turn the object into a table. Markdown, Latex and HTML table formats will render in jupyter notebooks. The default table style will render as HTML in jupyter notebooks but the text itself uses the “simple” table format.

Parameters
  • tablefmt (str) – Format of the table. See the tabulate documentation. for a list of option.

  • include_row (bool) – If True a column with the row number will be included in the table.

  • row_names – The name for each row in the table. Will replace the row number in the row column. If given the row column is always included regardless of the value given for include_row.

  • nrows (int | None) – The maximum number of rows shown in the table. If the number of rows exceeds nrows rows in the middle of the table will be omitted and replaced with a single row of ....

  • include_dtype (bool | None) – If True then the dtype of each column will be included in the column title.

  • include_objinfo (bool | None) – If True then the object info will be included at the end of the table.

  • keyfmt (str | None) – The format used for the column titles.

  • floatfmt (str | None) – The format for float values in the table, e.g. ".2f" for 2 decimal places.

  • intfmt (str | None) – The format for integer values in the table.

  • keys – The keys the table should contain. If not given all the keys in the item is shown.

  • **key_filters – Key filters to decide which keys should be included in the table.

Returns

A subclass of str that will render the table in jupyter notebooks if the table format is markdown, latex or html. Contains one custom method .copy() that will copy the text to the clipboard.

Return type

TableStr

to_array(keys=None, default=Optional, **key_filters)

Convert the object to an IsopyArray.

If keys are given then the array will only these keys will be used/considered for the output. If keys is not given then all the keys in the array/dictionary are used/considered. If key filters are specified then only the keys that pass these filters are included in the output.

to_refval(keys=None, default=Optional, *, default_value=Optional, ratio_function=Optional, molecule_functions=Optional, **key_filters)

Convert the object to a RefValDict.

If keys are given then the array will only these keys will be used/considered for the output. If keys is not given then all the keys in the array/dictionary are used/considered. If key filters are specified then only the keys that pass these filters are included in the output.

to_ndarray(keys=None, default=Optional, **key_filters)

Convert the object to a numpy ndarray.

If keys are given then the array will only these keys will be used/considered for the output. If keys is not given then all the keys in the array/dictionary are used/considered. If key filters are specified then only the keys that pass these filters are included in the output.

to_dict(keys=None, default=Optional, **key_filters)

Convert the object to a normal python dictionary.

If keys are given then the array will only these keys will be used/considered for the output. If keys is not given then all the keys in the array/dictionary are used/considered. If key filters are specified then only the keys that pass these filters are included in the output.

to_list(keys=None, default=Optional, **key_filters)

Convert the object to a list.

If keys are given then the array will only these keys will be used/considered for the output. If keys is not given then all the keys in the array/dictionary are used/considered. If key filters are specified then only the keys that pass these filters are included in the output.

to_dataframe(keys=None, default=Optional, **key_filters)

Convert the object to a pandas dataframe.

If keys are given then the array will only these keys will be used/considered for the output. If keys is not given then all the keys in the array/dictionary are used/considered. If key filters are specified then only the keys that pass these filters are included in the output.

to_clipboard(comments=None, keys_in_first='r', comment_symbol='#', keyfmt=None, dialect='excel')

Copy the array/dictionary to the clipboard.

Parameters
  • comments (str, Sequence[str], Optional) – Comments to be included

  • keys_in_first ({'c', 'r'}) – Only used if the input has keys. Give ‘r’ if the keys should be in the first row and ‘c’ if the keys should be in the first column.

  • comment_symbol (str, Default = '#') – This string will precede any comments.

  • keyfmt – Specify the format used for the key string. See the str() method of each key string for options.

  • dialect – The CSV dialect used to copy the data to the clipboard. Default to ‘excel’ which is a ‘, ‘ seperated file.

to_csv(filename, comments=None, keys_in_first='r', comment_symbol='#', keyfmt=None, dialect='excel')

Save the array/dictionary to a csv file.

Parameters
  • filename (str, StringIO, BytesIO) – Path/name of the csv file to be created. Any existing file with the same path/name will be over written. Also accepts file like objects.

  • comments (str, Sequence[str], Optional) – Comments to be included at the top of the file

  • keys_in_first ({'c', 'r'}) – Only used if the input has keys. Give ‘r’ if the keys should be in the first row and ‘c’ if the keys should be in the first column.

  • comment_symbol (str, Default = '#') – This string will precede any comments at the beginning of the file.

  • keyfmt – Specify the format used for the key string. See the str() method of each key string for options.

  • dialect – The CSV dialect used to save the file. Default to ‘excel’ which is a ‘, ‘ seperated file.

to_xlsx(filename, sheetname='sheet1', comments=None, keys_in_first='r', comment_symbol='#', keyfmt=None, start_at='A1', append=False, clear=True)

Save the array/dictionary to an excel workbook.

Parameters
  • filename (str, BytesIO) – Path/name of the excel file to be created. Any existing file with the same path/name will be overwritten. Also accepts file like objects.

  • sheetname (isopy_array_like, numpy_array_like) – Data will be saved in a sheet with this name.

  • comments (str, Sequence[str], Optional) – Comments to be included at the top of the file

  • keys_in_first ({'c', 'r'}) – Only used if the input has keys. Give ‘r’ if the keys should be in the first row and ‘c’ if the keys should be in the first column.

  • comment_symbol (str, Default = '#') – This string will precede any comments at the beginning of the file

  • keyfmt – Specify the format used for the key string. See the str() method of each key string for options.

  • start_at (str, (int, int)) – The first cell where the data is written. Can either be a excel style cell reference or a (row, column) tuple of integers.

  • append (bool, Default = False) – If True and filename exists it will append the data to this workbook. An exception is raised if filename is not a valid excel workbook.

  • clear (bool, Default = True) – If True any preexisting sheets are cleared before any new data is written to it.

Dictionaries

Isopy dictionaries must be created using one of the functions below. They can should not created by initialising isopy.core.IsopyDict or isopy.core.RefValDict directly.

Is a subclass of dict and therfore and contains all the methods that a normal dictionary does unless otherwise noted. Only methods that behave differently from a normal dictionary are documented for IsopyDict and RefValDict.

asdict

isopy.asdict(d, default_value=Optional, key_flavour=Optional)[source]

Return d if it is an IsopyDict otherwise convert d into one and return it.

The returned IsopyDict will have the specified default value and key flavour(s) if these are given.

asrefval

isopy.asrefval(d, default_value=Optional, key_flavour=Optional, ratio_function=Optional, molecule_functions=Optional)[source]

Return d if it is an RefValDict otherwise convert d into one and return it.

The returned RefValDict will have the specified default value and key flavour(s) if these are given.

isdict

isopy.isdict(item, key_flavour=Optional, default_value=Optional)[source]

Returns True if item is an isopy dict or refval dict otherwise returns False.

isrefval

isopy.isrefval(item, key_flavour=Optional, default_value=Optional, ratio_function=Optional, molecule_functions=Optional)[source]

Returns True if item is a refval dict otherwise returns False.

IsopyDict

class isopy.core.IsopyDict[source]

Dictionary where each value is stored by a isopy keystring key.

Parameters
  • args (dict[str, Any], Optional) – Dictionary(ies) where each key can be converted to a keystring.

  • default_value (Any, Default = None) – The default value for a key not present in the dictionary. Should ideally be the same type as the value stored in the dictionary

  • readonly (bool, Default = False) – If True the dictionary cannot be edited. This attribute is not inherited by child dictionaries.

  • key_flavour – Will attempt to convert each key into an key_flavour key string. If key_flavour is a sequence of flavours then the first successful conversion is used. If key_flavour is ‘any’ the flavours tried are ['mass', 'element', 'isotope', 'ratio', 'molecule', 'general'].

  • kwargs (Any, Optional) – Key, Value pairs to be included in the dictionary

readonly

True if the dictionary is readonly. Otherwise False. Readonly Attribute.

key_flavour

The possible flavours of the keys in this dictionary. Readonly attribute.

default_value

The default value for the dictionary. An exception will be raised if you try to change the value while readonly is true.

Examples

>>> isopy.IsopyDict({'Pd108': 108, '105Pd': 105, 'pd': 46})
IsopyDict(default_value = None, readonly = False,
{"108Pd": 108
"105Pd": 105
"Pd": 46})
>>> isopy.IsopyDict(Pd108 = 108, pd105= 105, pd=46, default_value=0)
IsopyDict(default_value = 0, readonly = False,
{"108Pd": 108
"105Pd": 105
"Pd": 46})
get(key=None, default=Optional)[source]

Return the the value for key if present in the dictionary. Otherwise default is returned.

If key is a sequence of keys a tuple containing the values for each key is returned.

If default is not given the default value of the dictionary is used.

Examples

>>> reference = isopy.IsopyDict({'108Pd': 100, '105Pd': 20, '104Pd': 150})
>>> reference.get('pd108')
100
>>> reference.get('104Pd/105Pd')
None
>>> reference.get('104Pd/105Pd', default=np.nan)
nan
>>> reference = isopy.IsopyDict({'108Pd': 100, '105Pd': 20, '104Pd': 150}, default_value=np.nan)
>>> reference.get('104Pd/105Pd')
nan

RefValDict

class isopy.core.RefValDict[source]

Dictionary where each value is stored as an array of floats by a isopy keystring key.

Each value in the dictionary has the same ndim and size. If the dictionary has a size of 1 ndim will always be 0.

Parameters
  • *args (dict[str, scalar], Optional) – Dictionary(ies) where each key can be converted to a keystring.

  • default_value (scalar, Default = np.nan) – The default value for a key not present in the dictionary.

  • readonly (bool, Default = True) – If True the dictionary cannot be edited. This attribute is not inherited by child dictionaries.

  • key_flavour – Will attempt to convert each key into an flavour key string. If flavour is a sequence of flavours then the first successful conversion is used. If flavour is ‘any’ the flavours tried are ['mass', 'element', 'isotope', 'ratio', 'molecule', 'general'].

  • ratio_function (callable) – The function that should be used to calculate the value of a missing ratio key string from the data present in the array. If None then no attempt is made to calculate the missing value. 'divide' is an alias for np.divide.

  • molecule_functions (None or (callable, callable, callable or None)) – A tuple of three functions that should be used to calculate the value of a missing molecule key string from the data present in the array. The first function is used to calculate the value for the components, the second function for the n and the final function for the charge. If the third item in the tuple is None then the charge is ignored. If None then no attempt is made to calculate the missing value. 'fraction' is an alias for (np.multiply, np.power, None), 'abundance' is an alias for (np.add, np.multiply, None) and 'mass' is an alias for (np.add, np.multiply, np.divide)

  • kwargs (scalar, Optional) – Key, Value pairs to be included in the dictionary

readonly

True if the dictionary is readonly. Otherwise False. Readonly Attribute.

key_flavour

The possible flavours of the keys in this dictionary. Readonly attribute.

default_value

The default value for the dictionary. An exception will be raised if you try to change the value while readonly is true.

ndim

The number of dimensions that each value array in the dictionary.

size

The size of each value array in the dictionary.

ratio_function

The function used to calculate the value of a missing ratio key string from the data present in the array. If None then no attempt is made to calculate the missing value.

molecule_functions

A tuple of three functions used to calculate the value of a missing molecule key string from the data present in the array. The first function is used to calculate the value for the components, the second function for the n and the final function for the charge. If the third item in the tuple is None then the charge is ignored. If None then no attempt is made to calculate the missing value.

Examples

>>> isopy.RefValDict({'Pd108': 108, '105Pd': 105, 'pd': 46})
RefValDict(default_value = nan, readonly = False,
{"108Pd": 108.0
"105Pd": 105.0
"Pd": 46.0})
>>> isopy.RefValDict(Pd108 = 108, pd105= 105, pd=46, default_value=0)
RefValDict(default_value = 0, readonly = False,
{"108Pd": 108.0
"105Pd": 105.0
"Pd": 46.0})
get(key=None, default=Optional)[source]

Return the the value for key if present in the dictionary. If default is not given the default value of the dictionary is used.

If key is a sequence of keys then an array in returned containing the value for each key.

If key is a RatioKeyString and not in the dictionary and the dictionary has a ratio function set then that function is used to calculate the

If key is a MoleculeKeyString and not in the dictionary and the dictionary has molecule functions set then those used to calculate the value of the molecule.

Examples

>>> reference = RefValDict({'108Pd': 100, '105Pd': 20, '104Pd': 150},
                            ratio_func=isopy.divide, molecule_funcs=(isopy.multiply, isopy.multiply, None))
>>> reference.get('pd108')
100
>>> reference.get('104Pd/105Pd') # Automatically divides the values
7.5
>>> reference.get('(105Pd)2') # Return the product of all the components multiplied by n ignoring any charge
40
tabulate(tablefmt='default', *, include_row=False, row_names=None, nrows=None, include_dtype=False, include_objinfo=False, keyfmt=None, floatfmt=None, intfmt=None, keys=None, **key_filters)

Turn the contents of the array/dictionary to a table.

Uses tabulate to turn the object into a table. Markdown, Latex and HTML table formats will render in jupyter notebooks. The default table style will render as HTML in jupyter notebooks but the text itself uses the “simple” table format.

Parameters
  • tablefmt (str) –

    Format of the table. See the tabulate documentation. for a list of option.

  • include_row (bool) – If True a column with the row number will be included in the table.

  • row_names – The name for each row in the table. Will replace the row number in the row column. If given the row column is always included regardless of the value given for include_row.

  • nrows (int | None) – The maximum number of rows shown in the table. If the number of rows exceeds nrows rows in the middle of the table will be omitted and replaced with a single row of ....

  • include_dtype (bool | None) – If True then the dtype of each column will be included in the column title.

  • include_objinfo (bool | None) – If True then the object info will be included at the end of the table.

  • keyfmt (str | None) – The format used for the column titles.

  • floatfmt (str | None) – The format for float values in the table, e.g. ".2f" for 2 decimal places.

  • intfmt (str | None) – The format for integer values in the table.

  • keys – The keys the table should contain. If not given all the keys in the item is shown.

  • **key_filters – Key filters to decide which keys should be included in the table.

Returns

A subclass of str that will render the table in jupyter notebooks if the table format is markdown, latex or html. Contains one custom method .copy() that will copy the text to the clipboard.

Return type

TableStr

to_array(keys=None, default=Optional, **key_filters)

Convert the object to an IsopyArray.

If keys are given then the array will only these keys will be used/considered for the output. If keys is not given then all the keys in the array/dictionary are used/considered. If key filters are specified then only the keys that pass these filters are included in the output.

to_refval(keys=None, default=Optional, *, default_value=Optional, ratio_function=Optional, molecule_functions=Optional, **key_filters)

Convert the object to a RefValDict.

If keys are given then the array will only these keys will be used/considered for the output. If keys is not given then all the keys in the array/dictionary are used/considered. If key filters are specified then only the keys that pass these filters are included in the output.

to_ndarray(keys=None, default=Optional, **key_filters)

Convert the object to a numpy ndarray.

If keys are given then the array will only these keys will be used/considered for the output. If keys is not given then all the keys in the array/dictionary are used/considered. If key filters are specified then only the keys that pass these filters are included in the output.

to_dict(keys=None, default=Optional, **key_filters)

Convert the object to a normal python dictionary.

If keys are given then the array will only these keys will be used/considered for the output. If keys is not given then all the keys in the array/dictionary are used/considered. If key filters are specified then only the keys that pass these filters are included in the output.

to_list(keys=None, default=Optional, **key_filters)

Convert the object to a list.

If keys are given then the array will only these keys will be used/considered for the output. If keys is not given then all the keys in the array/dictionary are used/considered. If key filters are specified then only the keys that pass these filters are included in the output.

to_dataframe(keys=None, default=Optional, **key_filters)

Convert the object to a pandas dataframe.

If keys are given then the array will only these keys will be used/considered for the output. If keys is not given then all the keys in the array/dictionary are used/considered. If key filters are specified then only the keys that pass these filters are included in the output.

to_clipboard(comments=None, keys_in_first='r', comment_symbol='#', keyfmt=None, dialect='excel')

Copy the array/dictionary to the clipboard.

Parameters
  • comments (str, Sequence[str], Optional) – Comments to be included

  • keys_in_first ({'c', 'r'}) – Only used if the input has keys. Give ‘r’ if the keys should be in the first row and ‘c’ if the keys should be in the first column.

  • comment_symbol (str, Default = '#') – This string will precede any comments.

  • keyfmt – Specify the format used for the key string. See the str() method of each key string for options.

  • dialect – The CSV dialect used to copy the data to the clipboard. Default to ‘excel’ which is a ‘, ‘ seperated file.

to_csv(filename, comments=None, keys_in_first='r', comment_symbol='#', keyfmt=None, dialect='excel')

Save the array/dictionary to a csv file.

Parameters
  • filename (str, StringIO, BytesIO) – Path/name of the csv file to be created. Any existing file with the same path/name will be over written. Also accepts file like objects.

  • comments (str, Sequence[str], Optional) – Comments to be included at the top of the file

  • keys_in_first ({'c', 'r'}) – Only used if the input has keys. Give ‘r’ if the keys should be in the first row and ‘c’ if the keys should be in the first column.

  • comment_symbol (str, Default = '#') – This string will precede any comments at the beginning of the file.

  • keyfmt – Specify the format used for the key string. See the str() method of each key string for options.

  • dialect – The CSV dialect used to save the file. Default to ‘excel’ which is a ‘, ‘ seperated file.

to_xlsx(filename, sheetname='sheet1', comments=None, keys_in_first='r', comment_symbol='#', keyfmt=None, start_at='A1', append=False, clear=True)

Save the array/dictionary to an excel workbook.

Parameters
  • filename (str, BytesIO) – Path/name of the excel file to be created. Any existing file with the same path/name will be overwritten. Also accepts file like objects.

  • sheetname (isopy_array_like, numpy_array_like) – Data will be saved in a sheet with this name.

  • comments (str, Sequence[str], Optional) – Comments to be included at the top of the file

  • keys_in_first ({'c', 'r'}) – Only used if the input has keys. Give ‘r’ if the keys should be in the first row and ‘c’ if the keys should be in the first column.

  • comment_symbol (str, Default = '#') – This string will precede any comments at the beginning of the file

  • keyfmt – Specify the format used for the key string. See the str() method of each key string for options.

  • start_at (str, (int, int)) – The first cell where the data is written. Can either be a excel style cell reference or a (row, column) tuple of integers.

  • append (bool, Default = False) – If True and filename exists it will append the data to this workbook. An exception is raised if filename is not a valid excel workbook.

  • clear (bool, Default = True) – If True any preexisting sheets are cleared before any new data is written to it.

Flavour

asflavour

isopy.asflavour(flavour)[source]

Convert flavour into a flavour object.

Each flavour is represented by a lower case string: mass, element, isotope, molecule, ratio, and general.

You can specify multiple flavours using | e.g element|isotope.

You can specify the allowed flavour of components in molecule key string using molecule[<flavour>]. Only element and isotope are valid sub-flavours of molecules. If the square brackets are omitted it defaults to any.

You can specify the flavour of the numerator and denominator for a ratio using ratio[<numerator_flavour>,<denominator_flavour>]. If you specify only one flavour inside the brackets it will be used for both the numerator and the denominator. If the square brackets are omitted then the numerator and denominator flavour defaults to any.