hyperspy.misc.date_time_tools module

hyperspy.misc.date_time_tools.ISO_format_to_serial_date(date, time, timezone='UTC')

Convert ISO format to a serial date.

hyperspy.misc.date_time_tools.datetime_to_serial_date(dt)

Convert datetime.datetime object to a serial date.

hyperspy.misc.date_time_tools.get_date_time_from_metadata(metadata, formatting='ISO')

Get the date and time from a metadata tree.

Parameters
  • metadata (metadata object) –

  • formatting (string, ('ISO', 'datetime', 'datetime64')) – Default: ‘ISO’. This parameter set the formatting of the date, and the time, it can be ISO 8601 string, datetime.datetime or a numpy.datetime64 object. In the later case, the time zone is not supported.

Returns

Return type

string, datetime.datetime or numpy.datetime64 object

Example

>>> s = hs.load("example1.msa")
>>> s.metadata
    ├── General
    │   ├── date = 1991-10-01
    │   ├── original_filename = example1.msa
    │   ├── time = 12:00:00
    │   └── title = NIO EELS OK SHELL
>>> s = get_date_time_from_metadata(s.metadata)
'1991-10-01T12:00:00'
>>> s = get_date_time_from_metadata(s.metadata, formatting='ISO')
'1991-10-01T12:00:00'
>>> s = get_date_time_from_metadata(s.metadata, formatting='datetime')
>>> s = get_date_time_from_metadata(s.metadata, formatting='datetime64')
hyperspy.misc.date_time_tools.serial_date_to_ISO_format(serial)

Convert serial_date to a tuple of string (date, time, time_zone) in ISO format. By default, the serial date is converted in local time zone.

hyperspy.misc.date_time_tools.serial_date_to_datetime(serial)

Convert serial date to a datetime.datetime object.

hyperspy.misc.date_time_tools.update_date_time_in_metadata(dt, metadata)

Update the date and time in a metadata tree.

Parameters
  • dt (date and time information: it can be a ISO 8601 string,) – a datetime.datetime or a numpy.datetime64 object

  • metadata (metadata object to update) –

Returns

Return type

metadata object

Example

>>> s = hs.load("example1.msa")
>>> dt = '2016-12-12T12:12:12-05:00'
>>> s.metadata = update_date_time_in_metadata(dt, s.metadata)
>>> s.metadata
    ├── General
    │   ├── date = 2016-12-12
    │   ├── original_filename = example1.msa
    │   ├── time = 12:12:12
    │   ├── time_zone = 'EST'
    │   └── title = NIO EELS OK SHELL