speasy.core package

class speasy.core.AllowedKwargs(allowed_list)[source]

Bases: object

A decorator that prevent from passing unexpected kwargs to a function

Methods

speasy.core.all_of_type(collection: Sequence, expected_type: Type) bool[source]

Returns true only if the type of all elements in given collection is expected_type

Parameters:
collection: Sequence

Any iterable object

expected_type: Type

the type you expect to match

Returns:
bool

True only if the type of all elements in given collection is expected_type

Examples

>>> all_of_type([1,2,3], int)
True
>>> all_of_type([1,2,3.], int)
False
speasy.core.deprecation(message: str) None[source]

Shows a deprecation warning.

Parameters:
message: str

Custom message to show

speasy.core.epoch_to_datetime64(epoch_array: array) array[source]

Converts an array of floats encoded as Unix Epoch (seconds since 1970) to an array of numpy datetime64[ns]

Parameters:
epoch_arraynp.array

Input array of folats (Epoch)

Returns:
np.array

Output array of datetime64[ns]

Examples

>>> epoch_to_datetime64(np.arange(2))
array(['1970-01-01T00:00:00.000000000', '1970-01-01T00:00:01.000000000'],
      dtype='datetime64[ns]')
speasy.core.fix_name(name: str)[source]

Makes given input compatible with python charset https://docs.python.org/3/reference/lexical_analysis.html#identifiers

Parameters:
name: str

input string to sanitize

Returns:
str

a string compatible with python naming rules

Examples

>>> fix_name('Parker Solar Probe (PSP)')
'Parker_Solar_Probe_PSP'
>>> fix_name('IS⊙ISEPI_Lo')
'ISoISEPI_Lo'
>>> fix_name('all_Legal_strings_123')
'all_Legal_strings_123'
speasy.core.is_collection(value: Any) bool[source]
Parameters:
valueAny
Returns:
bool

True if given value is collection like object but not a string

speasy.core.listify(obj: Any) List[source]

Wraps inside a list anything that is not a list. Useful in for loops when you can’t be sure the object you want to iterate is a list.

Parameters:
obj: Any

Any object or list

Returns:
list

list(obj) if obj is not a list

Examples

>>> for i in listify(1):
...     print(i)
...
1
>>> for i in listify([1,2,3]):
...     print(i)
...
1
2
3
speasy.core.make_utc_datetime(input_dt: str | datetime | float64 | float | datetime64) datetime[source]

Makes UTC datetime from given input.

Parameters:
input_dt: str or datetime or np.float64 or float

Datetime to convert, can be either en Epoch, a datetime or a string

Returns:
datetime

A datetime.datetime object forced to UTC time zone

Examples

>>> make_utc_datetime('2018-01-02')
datetime.datetime(2018, 1, 2, 0, 0, tzinfo=datetime.timezone.utc)
>>> make_utc_datetime(0.)
datetime.datetime(1970, 1, 1, 0, 0)
>>> from datetime import datetime
>>> make_utc_datetime(datetime(2020,1,1))
datetime.datetime(2020, 1, 1, 0, 0, tzinfo=datetime.timezone.utc)
speasy.core.mkdir(directory: str) None[source]

Creates directory and parents if they do not exist

Parameters:
directory: str

Path to create

speasy.core.pack_kwargs(**kwargs: Any) Dict[source]

Packs given keyword arguments into a dictionary

Parameters:
kwargs: Any

Any keyword argument is accepted

Returns:
dict

A dict with all kwargs packed

Examples

>>> pack_kwargs(a=1, b="2")
{'a': 1, 'b': '2'}
speasy.core.progress_bar(leave=True, progress=False, desc=None, **kwargs)[source]

Subpackages

Submodules