Common utilities

Below we list all the functions available in the NURI software specifically designed to search for and extract data from a given period of time. More details about each function, with examples on how to execute them, can be found further down this page. A live example can be executed from this Google Colab tutorial .

data_chunk (data, hours[, samp_per_hr])

Concatenate data chunks for a given time period.

day_and_night (data, daytime[, samp_per_hr])

Split data into separate day and night time-series.

downsample (data, downfactor)

Downsample data time series.

fix_jumps (data[, nsamp, edge])

Fix jumps in time series data.

get_variance (data[, period, bin_size])

is_float (a)

Return whether input variable is a float.

make_video ()

Make video out of saved figures.

normalize (data)

rescale (freqs, data[, num, mode])

str2timestamp (*times)

Convert times into datetime timestamps.

str2datetime (*dates)

Convert input string date to datetime format.

transform_data (data_full, length[, ...])

Data chunk selection

nuri. data_chunk ( data , hours , samp_per_hr = 3600 ) [source]

Concatenate data chunks for a given time period. Given a specific time period, this method will loop through all available days and concatenate time series data that fall in the same time period. This function is used in our paper when building Power Spectral Densities at low frequencies.

Parameters :
data numpy.ndarray

Input magnetic field data.

hours list [ int ]

Start and final hours of the daily period.

samp_per_hr int

Number of samples in an hour of data.

Returns :
avg list

List of concatenated time series values.

Examples

In the example below, we concatenate 2 hours of time series data, from 9 to 11 AM, over a 4-day period, from 1st to 5th of April 2016. The data are sampled at 1-Hertz, so 3,600 data points per hour. Therefore, a total of 3600 data points * 2 hours * 4 days = 28,800 data points returned.

>>> data = nuri.get_data('2016-4-1','2016-4-5','/content/drive/MyDrive/CityMagData/1Hz',station=2,sensor='biomed',scalar=True)
>>> data = nuri.data_chunk(data.value,[9,11],samp_per_hr=3600)
>>> print(len(data))
28800

Day & night split

nuri. day_and_night ( data , daytime , samp_per_hr = 3600 ) [source]

Split data into separate day and night time-series.

Parameters :
data numpy.ndarray

Input magnetic field data.

daytime list [ list [ int ] ]

List of daytime hour ranges. Multiple ranges can be provided in case the night time starts after midnight.

samp_per_hr int

Number of samples in an hour of data.

Returns :
day list [ float ]

Concatenated daytime time-series.

night list [ float ]

Concatenated nighttime time-series.

Examples

>>> data = nuri.get_data('2016-4-1','2016-4-3','/content/drive/MyDrive/CityMagData/1Hz',station=2,sensor='biomed',scalar=True)
>>> day, night = nuri.day_and_night(data.value,daytime=[[0,1],[4.5,24]])
>>> print(len(day),len(night))
147581 25200

Date to Timestamps

nuri. str2timestamp ( * times ) [source]

Convert times into datetime timestamps.

Parameters :
times list [ str ]

Start and final times of the target period.

Returns :
time_list list [ float ]

Dates converted into floating timestamps

Examples

>>> times = nuri.str2timestamp('2016-4-1','2016-4-5')
>>> print(times)
(1459468800.0, 1459814400.0)