Time Conversion

Time is handled primary in epoch time, or seconds since 1/1/1970, and includes conversion to Unix timestamps, datetime objects, and MATLAB datenum.

dt642epoch(dt64)

Convert numpy.datetime64 array to epoch time (seconds since 1/1/1970 00:00:00)

epoch2dt64(ep_time)

Convert from epoch time (seconds since 1/1/1970 00:00:00) to numpy.datetime64 array

dt642date(dt64)

Convert numpy.datetime64 array to list of datetime objects

date2dt64(dt)

Convert numpy.datetime64 array to list of datetime objects

epoch2date(ep_time[, offset_hr, to_str])

Convert from epoch time (seconds since 1/1/1970 00:00:00) to a list of datetime objects

date2epoch(dt)

Convert list of datetime objects to epoch time

date2str(dt[, format_str])

Convert list of datetime objects to legible strings

date2matlab(dt)

Convert list of datetime objects to MATLAB datenum

matlab2date(matlab_dn)

Convert MATLAB datenum to list of datetime objects

dolfyn.time.epoch2dt64(ep_time)[source]

Convert from epoch time (seconds since 1/1/1970 00:00:00) to numpy.datetime64 array

Parameters:

ep_time (xarray.DataArray) – Time coordinate data-array or single time element

Returns:

time (numpy.datetime64) – The converted datetime64 array

dolfyn.time.dt642epoch(dt64)[source]

Convert numpy.datetime64 array to epoch time (seconds since 1/1/1970 00:00:00)

Parameters:

dt64 (numpy.datetime64) – Single or array of datetime64 object(s)

Returns:

time (float) – Epoch time (seconds since 1/1/1970 00:00:00)

dolfyn.time.date2dt64(dt)[source]

Convert numpy.datetime64 array to list of datetime objects

Parameters:

time (datetime.datetime) – The converted datetime object

Returns:

dt64 (numpy.datetime64) – Single or array of datetime64 object(s)

dolfyn.time.dt642date(dt64)[source]

Convert numpy.datetime64 array to list of datetime objects

Parameters:

dt64 (numpy.datetime64) – Single or array of datetime64 object(s)

Returns:

time (datetime.datetime) – The converted datetime object

dolfyn.time.epoch2date(ep_time, offset_hr=0, to_str=False)[source]

Convert from epoch time (seconds since 1/1/1970 00:00:00) to a list of datetime objects

Parameters:
  • ep_time (xarray.DataArray) – Time coordinate data-array or single time element

  • offset_hr (int) – Number of hours to offset time by (e.g. UTC -7 hours = PDT)

  • to_str (logical) – Converts datetime object to a readable string

Returns:

time (datetime.datetime) – The converted datetime object or list(strings)

Notes

The specific time instance is set during deployment, usually sync’d to the deployment computer. The time seen by DOLfYN is in the timezone of the deployment computer, which is unknown to DOLfYN.

dolfyn.time.date2str(dt, format_str=None)[source]

Convert list of datetime objects to legible strings

Parameters:
  • dt (datetime.datetime) – Single or list of datetime object(s)

  • format_str (string) – Timestamp string formatting, default: ‘%Y-%m-%d %H:%M:%S.%f’. See datetime.strftime documentation for timestamp string formatting

Returns:

time (string) – Converted timestamps

dolfyn.time.date2epoch(dt)[source]

Convert list of datetime objects to epoch time

Parameters:

dt (datetime.datetime) – Single or list of datetime object(s)

Returns:

time (float) – Datetime converted to epoch time (seconds since 1/1/1970 00:00:00)

dolfyn.time.date2matlab(dt)[source]

Convert list of datetime objects to MATLAB datenum

Parameters:

dt (datetime.datetime) – List of datetime objects

Returns:

time (float) – List of timestamps in MATLAB datnum format

dolfyn.time.matlab2date(matlab_dn)[source]

Convert MATLAB datenum to list of datetime objects

Parameters:

matlab_dn (float) – List of timestamps in MATLAB datnum format

Returns:

dt (datetime.datetime) – List of datetime objects