LASP 1.0
Library for Acoustic Signal Processing
Loading...
Searching...
No Matches
lasp.lasp_measurement.Measurement Class Reference

Provides access to measurement data stored in the h5 measurement file format. More...

Public Member Functions

 __init__ (self, fn)
 Initialize a Measurement object based on the filename.
 
 setAttribute (self, atrname, value)
 Set an attribute in the measurement file, and keep a local copy in memory for efficient accessing.
 
 name (self)
 Returns filename base without extension.
 
 channelNames (self)
 
 channelNames (self, newchnames)
 
 channelConfig (self)
 
 channelConfig (self, List[DaqChannel] chcfg)
 
 qtys (self)
 
 qtys (self, newqtys)
 
 file (self, mode='r')
 Contextmanager which opens the storage file and yields the file.
 
 comment (self)
 Return the measurement comment.
 
 comment (self, cmt)
 Set the measurement comment.
 
 recTime (self)
 Returns the total recording time of the measurement, in float seconds.
 
 time (self)
 Returns the measurement time in seconds since the epoch.
 
 timestr (self)
 Return a properly formatted string of the measurement time, in order of.
 
 rms (self, channels=None, substract_average=False)
 Returns the root mean square values for each channel.
 
 variance (self, channels=None)
 
 rawData (self, channels=None, **kwargs)
 Returns the raw data as stored in the measurement file, without any transformations applied.
 
 iterData (self, channels, **kwargs)
 
 data (self, channels=None, **kwargs)
 Returns the measurement data, scaled and sensitivity applied.
 
 CPS (self, channels=None, **kwargs)
 Compute single-sided Cross-Power-Spectrum of the measurement channels.
 
 periodicAverage (self, N, channels=None, noiseCorrection=True, **kwargs)
 Return the (coherent) periodic average the measurement.
 
 periodicCPS (self, N, channels=None, **kwargs)
 Compute Cross-Spectral Density based on periodic excitation.
 
 sensitivity (self)
 Sensitivity of the data in U^-1, from floating point data scaled between -1.0 and 1.0 to Units [U].
 
 sensitivity (self, sens)
 Set the sensitivity of the measurement in the file.
 
 checkOverflow (self, channels)
 Coarse check for overflow in measurement.
 
 exportAsWave (self, fn=None, force=False, dtype=None, normalize=False, **kwargs)
 Export measurement file as wave.
 

Static Public Member Functions

 fromtxt (fn, skiprows, samplerate, sensitivity, mfn=None, timestamp=None, delimiter='\t', firstcoltime=True)
 Converts a txt file to a LASP Measurement file, opens the associated Measurement object and returns it.
 
Measurement fromnpy (data, samplerate, sensitivity, mfn, timestamp=None, List[SIQtys] qtys=None, List[str] channelNames=None, force=False)
 Creates a LASP measurement file from input numpy array data.
 
 fromWaveFile (fn, newfn=None, force=False, timestamp=None)
 Convert a measurement file to a wave file, and return the measurement handle.
 

Public Attributes

 fn
 
 fn_base
 
 has_video
 
 nblocks
 
 blocksize
 
 nchannels
 
 dtype
 
 sampwidth
 
 samplerate
 
 N
 
 T
 
 version_major
 
 version_minor
 
 channelNames
 
 sensitivity
 
 qtys
 

Protected Attributes

 _channelNames
 
 _comment
 
 _sens
 
 _time
 
 _qtys
 

Detailed Description

Provides access to measurement data stored in the h5 measurement file format.

Definition at line 184 of file lasp_measurement.py.

Constructor & Destructor Documentation

◆ __init__()

lasp.lasp_measurement.Measurement.__init__ (   self,
  fn 
)

Initialize a Measurement object based on the filename.

Definition at line 188 of file lasp_measurement.py.

Member Function Documentation

◆ channelConfig() [1/2]

lasp.lasp_measurement.Measurement.channelConfig (   self)

Definition at line 304 of file lasp_measurement.py.

◆ channelConfig() [2/2]

lasp.lasp_measurement.Measurement.channelConfig (   self,
List[DaqChannel chcfg 
)

Definition at line 317 of file lasp_measurement.py.

◆ channelNames() [1/2]

lasp.lasp_measurement.Measurement.channelNames (   self)

Definition at line 294 of file lasp_measurement.py.

◆ channelNames() [2/2]

lasp.lasp_measurement.Measurement.channelNames (   self,
  newchnames 
)

Definition at line 298 of file lasp_measurement.py.

◆ checkOverflow()

lasp.lasp_measurement.Measurement.checkOverflow (   self,
  channels 
)

Coarse check for overflow in measurement.

Return: True if overflow is possible, else False

Definition at line 615 of file lasp_measurement.py.

◆ comment() [1/2]

lasp.lasp_measurement.Measurement.comment (   self)

Return the measurement comment.

Returns: The measurement comment (text string)

Definition at line 361 of file lasp_measurement.py.

◆ comment() [2/2]

lasp.lasp_measurement.Measurement.comment (   self,
  cmt 
)

Set the measurement comment.

Args: cmt: Comment text string to set

Definition at line 370 of file lasp_measurement.py.

◆ CPS()

lasp.lasp_measurement.Measurement.CPS (   self,
  channels = None,
**  kwargs 
)

Compute single-sided Cross-Power-Spectrum of the measurement channels.

Args: channels: Channels to compute for (numbers)

Optional arguments: nfft: FFT length window: Window type overlap: Overlap percentage (value between 0.0 and up to and including 100.0) weighting:

Returns: Cross-power-spectra. C[freq, ch_i, ch_j] = C_ij

Definition at line 481 of file lasp_measurement.py.

◆ data()

lasp.lasp_measurement.Measurement.data (   self,
  channels = None,
**  kwargs 
)

Returns the measurement data, scaled and sensitivity applied.

Definition at line 471 of file lasp_measurement.py.

◆ exportAsWave()

lasp.lasp_measurement.Measurement.exportAsWave (   self,
  fn = None,
  force = False,
  dtype = None,
  normalize = False,
**  kwargs 
)

Export measurement file as wave.

In case the measurement data is stored as floats, the values are scaled to the proper integer (PCM) data format.

Args: fn: If given, this will be the filename to write to. If the filename does not end with '.wav', this extension is added.

force: If True, overwrites any existing files with the given name , otherwise a RuntimeError is raised.

dtype: if not None, convert data to this data type. Options are 'int16', 'int32', 'float32'.

normalize: If set: normalize the level to something sensible.

Definition at line 635 of file lasp_measurement.py.

◆ file()

lasp.lasp_measurement.Measurement.file (   self,
  mode = 'r' 
)

Contextmanager which opens the storage file and yields the file.

Args: mode: Opening mode for the file. Should either be 'r', or 'r+'

Definition at line 349 of file lasp_measurement.py.

◆ fromnpy()

Measurement lasp.lasp_measurement.Measurement.fromnpy (   data,
  samplerate,
  sensitivity,
  mfn,
  timestamp = None,
List[SIQtys]   qtys = None,
List[str]   channelNames = None,
  force = False 
)
static

Creates a LASP measurement file from input numpy array data.

Opens the associated Measurement object and returns it.

Args: data: Numpy array, first column is sample, second is channel. Can also be specified with a single column for single-channel data.

samplerate: Sampling frequency in [Hz]

sensitivity: 1D array of channel sensitivities in [U^-1], where U is the recorded unit.

mfn: Filepath of the file where the data is stored.

timestamp: If given, a custom timestamp for the measurement (integer containing seconds since epoch).

qtys: If a list of physical quantity data is given here

channelNames: Name of the channels

force: If True, overwrites existing files with specified mfn name.

Definition at line 771 of file lasp_measurement.py.

◆ fromtxt()

lasp.lasp_measurement.Measurement.fromtxt (   fn,
  skiprows,
  samplerate,
  sensitivity,
  mfn = None,
  timestamp = None,
  delimiter = '\t',
  firstcoltime = True 
)
static

Converts a txt file to a LASP Measurement file, opens the associated Measurement object and returns it.

The measurement file will have the same file name as the txt file, except with h5 extension.

Args: fn: Filename of text file skiprows: Number of header rows in text file to skip samplerate: Sampling frequency in [Hz] sensitivity: 1D array of channel sensitivities mfn: Filepath where measurement file is stored. If not given, a h5 file will be created along fn, which shares its basename timestamp: If given, a custom timestamp for the measurement (integer containing seconds since epoch). If not given, the timestamp is obtained from the last modification time. delimiter: Column delimiter firstcoltime: If true, the first column is the treated as the sample time.

Definition at line 708 of file lasp_measurement.py.

◆ fromWaveFile()

lasp.lasp_measurement.Measurement.fromWaveFile (   fn,
  newfn = None,
  force = False,
  timestamp = None 
)
static

Convert a measurement file to a wave file, and return the measurement handle.

Definition at line 860 of file lasp_measurement.py.

◆ iterData()

lasp.lasp_measurement.Measurement.iterData (   self,
  channels,
**  kwargs 
)

Definition at line 463 of file lasp_measurement.py.

◆ name()

lasp.lasp_measurement.Measurement.name (   self)

Returns filename base without extension.

Definition at line 289 of file lasp_measurement.py.

◆ periodicAverage()

lasp.lasp_measurement.Measurement.periodicAverage (   self,
  N,
  channels = None,
  noiseCorrection = True,
**  kwargs 
)

Return the (coherent) periodic average the measurement.

This method is useful for a situation of periodic excitation.

Args: N: The number of samples in one period. This value should correspond with the period of the excitation! noiseCorrection: whether to apply coherent averaging, according to the Sliding Window correlation method (SWiC): Telle et al.: A Novel Approach for Impulse Response Measurements with Time-Varying Noise. If set to False, just the arithmetic average is used.

Definition at line 515 of file lasp_measurement.py.

◆ periodicCPS()

lasp.lasp_measurement.Measurement.periodicCPS (   self,
  N,
  channels = None,
**  kwargs 
)

Compute Cross-Spectral Density based on periodic excitation.

Uses noise reduction by time-averaging the data.

Definition at line 562 of file lasp_measurement.py.

◆ qtys() [1/2]

lasp.lasp_measurement.Measurement.qtys (   self)

Definition at line 331 of file lasp_measurement.py.

◆ qtys() [2/2]

lasp.lasp_measurement.Measurement.qtys (   self,
  newqtys 
)

Definition at line 335 of file lasp_measurement.py.

◆ rawData()

lasp.lasp_measurement.Measurement.rawData (   self,
  channels = None,
**  kwargs 
)

Returns the raw data as stored in the measurement file, without any transformations applied.

args: channels: list, or tuple of channel numbers to export. If not defined, all channels in the measurement are returned

returns: Numpy array with data. The first axis is always the time instance, the second axis the channel number.

Definition at line 439 of file lasp_measurement.py.

◆ recTime()

lasp.lasp_measurement.Measurement.recTime (   self)

Returns the total recording time of the measurement, in float seconds.

Definition at line 383 of file lasp_measurement.py.

◆ rms()

lasp.lasp_measurement.Measurement.rms (   self,
  channels = None,
  substract_average = False 
)

Returns the root mean square values for each channel.

Args: channels: list of channels substract_average: If set to true, computes the rms of only the oscillating component of the signal, which is in fact the signal variance.

Returns: 1D array with rms values for each channel

Definition at line 406 of file lasp_measurement.py.

◆ sensitivity() [1/2]

lasp.lasp_measurement.Measurement.sensitivity (   self)

Sensitivity of the data in U^-1, from floating point data scaled between -1.0 and 1.0 to Units [U].

If the sensitivity is not stored in the measurement file, this function returns 1.0 for each channel

Definition at line 583 of file lasp_measurement.py.

◆ sensitivity() [2/2]

lasp.lasp_measurement.Measurement.sensitivity (   self,
  sens 
)

Set the sensitivity of the measurement in the file.

Args: sens: sensitivity data, should be a float, or an array of floats equal to the number of channels.

Definition at line 593 of file lasp_measurement.py.

◆ setAttribute()

lasp.lasp_measurement.Measurement.setAttribute (   self,
  atrname,
  value 
)

Set an attribute in the measurement file, and keep a local copy in memory for efficient accessing.

Definition at line 278 of file lasp_measurement.py.

◆ time()

lasp.lasp_measurement.Measurement.time (   self)

Returns the measurement time in seconds since the epoch.

Definition at line 389 of file lasp_measurement.py.

◆ timestr()

lasp.lasp_measurement.Measurement.timestr (   self)

Return a properly formatted string of the measurement time, in order of.

year-month-day hour etc.

Definition at line 395 of file lasp_measurement.py.

◆ variance()

lasp.lasp_measurement.Measurement.variance (   self,
  channels = None 
)

Definition at line 436 of file lasp_measurement.py.

Member Data Documentation

◆ _channelNames

lasp.lasp_measurement.Measurement._channelNames
protected

Definition at line 228 of file lasp_measurement.py.

◆ _comment

lasp.lasp_measurement.Measurement._comment
protected

Definition at line 240 of file lasp_measurement.py.

◆ _qtys

lasp.lasp_measurement.Measurement._qtys
protected

Definition at line 259 of file lasp_measurement.py.

◆ _sens

lasp.lasp_measurement.Measurement._sens
protected

Definition at line 247 of file lasp_measurement.py.

◆ _time

lasp.lasp_measurement.Measurement._time
protected

Definition at line 256 of file lasp_measurement.py.

◆ blocksize

lasp.lasp_measurement.Measurement.blocksize

Definition at line 209 of file lasp_measurement.py.

◆ channelNames

lasp.lasp_measurement.Measurement.channelNames

Definition at line 306 of file lasp_measurement.py.

◆ dtype

lasp.lasp_measurement.Measurement.dtype

Definition at line 211 of file lasp_measurement.py.

◆ fn

lasp.lasp_measurement.Measurement.fn

Definition at line 194 of file lasp_measurement.py.

◆ fn_base

lasp.lasp_measurement.Measurement.fn_base

Definition at line 197 of file lasp_measurement.py.

◆ has_video

lasp.lasp_measurement.Measurement.has_video

Definition at line 205 of file lasp_measurement.py.

◆ N

lasp.lasp_measurement.Measurement.N

Definition at line 215 of file lasp_measurement.py.

◆ nblocks

lasp.lasp_measurement.Measurement.nblocks

Definition at line 209 of file lasp_measurement.py.

◆ nchannels

lasp.lasp_measurement.Measurement.nchannels

Definition at line 209 of file lasp_measurement.py.

◆ qtys

lasp.lasp_measurement.Measurement.qtys

Definition at line 307 of file lasp_measurement.py.

◆ samplerate

lasp.lasp_measurement.Measurement.samplerate

Definition at line 214 of file lasp_measurement.py.

◆ sampwidth

lasp.lasp_measurement.Measurement.sampwidth

Definition at line 212 of file lasp_measurement.py.

◆ sensitivity

lasp.lasp_measurement.Measurement.sensitivity

Definition at line 306 of file lasp_measurement.py.

◆ T

lasp.lasp_measurement.Measurement.T

Definition at line 216 of file lasp_measurement.py.

◆ version_major

lasp.lasp_measurement.Measurement.version_major

Definition at line 219 of file lasp_measurement.py.

◆ version_minor

lasp.lasp_measurement.Measurement.version_minor

Definition at line 220 of file lasp_measurement.py.


The documentation for this class was generated from the following file: