Traces¶
All of the kinds of traces in UConnRCMPy
-
class
uconnrcmpy.traces.
AltExperimentalPressureTrace
(file_path, initial_pressure_in_torr)¶ Process an alternate experimental pressure trace.
These pressure traces do not have an associated voltage trace, but the machinery in the VoltageTrace class is useful for filtering.
-
class
uconnrcmpy.traces.
ExperimentalPressureTrace
(voltage_trace, initial_pressure_in_torr, factor)¶ Pressure trace from a single experiment.
Parameters: - voltage_trace (
VoltageTrace
) – Instance of class containing the voltage trace of the experiment. - initial_pressure_in_torr (
float
) – The initial pressure of the experiment, in units of Torr - factor (
float
) – The factor set on the charge amplifier
-
pressure
¶ numpy.ndarray
– The pressure trace computed from the filtered voltage trace
-
time
¶ numpy.ndarray
– A 1-D array containting the time. Copied fromVoltageTrace.time
-
frequency
¶ int
– Integer sampling frequency of the experiment. Copied fromVoltageTrace.frequency
-
is_reactive
¶ bool
– Boolean if the pressure trace represents a reactive or or non-reactive experiment
-
derivative
¶ numpy.ndarray
– 1-D array containing the raw derivative computed from thepressure
trace.
-
zeroed_time
¶ numpy.ndarray
– 1-D array containing the time, with the zero point set at the end of compression.
-
calculate_derivative
(dep_var, indep_var)¶ Calculate the derivative.
Parameters: - dep_var (
numpy.ndarray
) – Dependent variable (e.g., the pressure) - indep_var (
numpy.ndarray
) – Independent variable (e.g., the time)
Returns: 1-D array containing the derivative
Return type: Notes
The derivative is calculated by a second-order forward method and any places where the derivative is infinite are set to zero.
- dep_var (
-
change_EOC_time
(time, is_reactive=True)¶ Change the EOC time for an experiment
Parameters: - time (
float
) – The new value of the EOC time - is_reactive (
boolean
) – The experiment is reactive or not
- time (
-
find_EOC
()¶ Find the index and pressure at the end of compression.
Returns: Returns a tuple with types ( float
,int
,bool
) representing the pressure at the end of compression, the index of the end of compression relative to the start of the pressure trace, and a boolean that is True if the case is reactive and False otherwise, respectivelyReturn type: tuple
Notes
The EOC is found by moving backwards from the maximum pressure point and testing the values of the pressure. When the test value becomes greater than the previous pressure, we have reached the minimum pressure before ignition, in the case of a reactive experiment. Then, the EOC is the maximum of the pressure before this minimum point. If the pressure at the minimum is close to the initial pressure, assume the case is non-reactive and set the EOC pressure and the index to the max pressure point.
-
pressure_fit
(comptime=0.08)¶ Fit a line to the pressure trace before compression starts.
Parameters: comptime ( float
, optional) – Desired compression time, computed from the EOC, to when the pressure fit should startReturns: Numpy object containing the parameters of the fit Return type: numpy.polyfit
-
savetxt
(filename, **kwargs)¶ Save a text file output of the pressure trace.
Save a text file with the time in the first column and the filtered pressure in the second column. The keyword arguments are the same as
numpy.savetxt
.Parameters: filename ( str
) – Filename of the output file
- voltage_trace (
-
class
uconnrcmpy.traces.
PressureFromVolume
(volume, p_initial, T_initial, chem_file=’species.cti’, cti_source=None)¶ Create a pressure trace given a volume trace.
Using Cantera to evaluate the thermodynamic properties, compute a pressure trace from a volume trace.
Parameters: - volume (
numpy.ndarray
) – 1-D array containing the reactor volume - p_initial (
float
) – Initial pressure of the experiment, in bar - T_initial (
float
, optional) – Initial temperature of the experiment, in Kelvin. Optional for Cantera versions greater than 2.2.0. - chem_file (
str
, optional) – Filename of the chemistry file to be used
-
pressure
¶ numpy.ndarray
– The pressure trace
Notes
The pressure is computed in a
cantera.Solution
object by setting the volume and the entropy according to an isentropic process using the given volume trace.- volume (
-
class
uconnrcmpy.traces.
TemperatureFromPressure
(pressure, T_initial, chem_file=’species.cti’, cti_source=None)¶ Create a temperature trace given a pressure trace.
Using Cantera to evaluate the thermodynamic properties, compute a pressure trace from a volume trace.
Parameters: - pressure (
numpy.ndarray
) – 1-D array containing the pressure - T_initial (
float
) – Initial temperature of the experiment, in Kelvin. Optional for Cantera versions greater than 2.2.0. - chem_file (
str
, optional) – Filename of the chemistry file to be used
-
temperature
¶ numpy.ndarray
– The temperature trace
Notes
The temperature is computed in a
cantera.Solution
object by setting the pressure and the entropy according to an isentropic process using the given pressure trace.- pressure (
-
class
uconnrcmpy.traces.
VoltageTrace
(file_path)¶ Voltage signal from a single experiment.
Parameters: file_path ( pathlib.Path
) –Path
object associated with the particular experiment-
signal
¶ numpy.ndarray
– 2-D array containing the raw signal from the experimental text file. First column is the time, second column is the voltage.
-
time
¶ numpy.ndarray
– The time loaded from the signal trace
-
filtered_voltage
¶ numpy.ndarray
– The voltage trace after filtering
Note
The first sample of the voltage is set equal to the mean of the first 200 points to eliminate DAQ startup effects seen in some data.
-
change_filter_freq
(value)¶ Change the filter frequency
This method is intended to be used after the
VoltageTrace
has already been created. It sets thefilter_frequency
attribute and then runs the filtering.Parameters: value ( float
orNone
) – Value for the filter frequency. IfNone
, an optimal frequency will be estimated by the procedure detailed in the documentation for thefilter_frequency
attribute.
-
filter_frequency
¶ The cutoff frequency for the low-pass filter
When setting the frequency, if the
value
isNone
, determines the optimal cutoff frequency for a first-order Butterworth low-pass filter by analyzing the root-mean-squared residuals for a sequence of cutoff frequencies. The residuals plotted as a function of the cutoff frequency tend to have a linear portion for a range of cutoff frequencies. Analysis of typical data files from our RCM has shown this range to start nearnyquist_freq*0.05
. The end point is determined by looping through values fromnyquist_freq*0.5
tonyquist_freq*0.1
and finding the location where the coefficient of determination of a linear fit is maximized. A line is fit to this portion of the residuals curve and the intersection point of a horizontal line through the y-intercept of the fit and the residuals curve is used to determine the optimal cutoff frequency (see Figure 2 in Yu et al. [1]). The methodology is described by Yu et al. [1], and the code is modifed from Duarte [2].References
[1] (1, 2) B. Yu, D. Gabriel, L. Noble, and K.N. An, “Estimate of the Optimum Cutoff Frequency for the Butterworth Low-Pass Digital Filter”, Journal of Applied Biomechanics, Vol. 15, pp. 318-329, 1999. DOI: 10.1123/jab.15.3.318 [2] M. Duarte, “Residual Analysis”, v.3 2014/06/13, http://nbviewer.ipython.org/github/demotu/BMC/blob/master/notebooks/ResidualAnalysis.ipynb
-
filtering
(data)¶ Filter the input using a low-pass filter.
The filter is a first-order Butterworth filter, with the cutoff frequency taken from the instance attribute
filter_frequency
.Parameters: data ( numpy.ndarray
) – The data that should be filteredReturns: 1-D array of the same length as the input data Return type: numpy.ndarray
-
savetxt
(filename, **kwargs)¶ Save a text file output of the voltage trace.
Save a text file with the time in the first column and the filtered voltage in the second column. The keyword arguments are the same as
numpy.savetxt
.Parameters: filename ( str
) – Filename of the output file
-
-
class
uconnrcmpy.traces.
VolumeFromPressure
(pressure, v_initial, T_initial, chem_file=’species.cti’, cti_source=None)¶ Create a volume trace given a pressure trace.
Using Cantera to evaluate the thermodynamic properties, compute a volume trace from a pressure trace.
Parameters: - pressure (
numpy.ndarray
) – 1-D array containing the reactor pressure - v_initial (
float
) – Initial volume of the experiment, in m**3 - T_initial (
float
, optional) – Initial temperature of the experiment, in Kelvin. Optional for Cantera versions greater than 2.2.0. - chem_file (
str
, optional) – Filename of the chemistry file to be used
-
volume
¶ numpy.ndarray
– The volume trace
Notes
The volume is computed according to the formula
\[v_i = v_{initial}*\rho_{initial}/\rho_i\]where the index \(i\) indicates the current point. The state is set at each point by setting the pressure from the input array and the entropy to be constant. The volume is computed by the isentropic relationship described above.
- pressure (