stats package

stats.trust_statistical_tools_base

stats.trust_statistical_tools_spatial

Morad Ben Tayeb CEA Saclay - DM2S/STMF/LGLS Mars 2021 - Stage 6 mois

The main class is SpatialPostProcessing. Using this package allows the following:

  • extract 2D profiles from lata/med files using visit

  • plot the 2D spatial profiles

  • plot the spatial autocorrelations & calculate the Taylor micro-scale

  • plot the spatial energy spectrum using the Welch method

class stats.trust_statistical_tools_spatial.SpatialPostProcessing

Bases: StatisticalPostProcessing

Spatial post processing to analyze lata files. Mainly, we give the possibility for the user to extract profiles from visit Query. All required is to precise the starting and ending point of the segment. Once defined, visit will be launched automatically (in terminal) and a .Curve file will be created. The idea afterwards is to read these curve files and save them as numpy arrays to plot them, compute correlations, spectra, etc.

extract_field(lata, field, name, frame=-1)

Method to extract field from by launching visit and save the result as .okc file. By default, frame = -1 that means we choose the last frame of the simulation.

Parameters:
  • lata (str) – Path to the lata file.

  • field (str) – Name of the field. Example: “VITESSE_X_ELEM_dom”

  • name (str) – Name of the saved .okc file

  • frame (int) – Selected frame, frame = -1 for the last frame, optional.

Return type:

None

extract_profile(lata, field, start_point, end_point, name, frame=-1)

Method to extract profile from by launching visit and save the result as .curve file. By default frame = -1 that means the last frame of the simulation.

Parameters:
  • lata (str) – Path to the lata file.

  • field (str) – Name of the field. Example: “VITESSE_X_ELEM_dom”

  • start_point (tuple) – Starting point of the segment. Example: (0.,0.,0.)

  • end_point (tuple) – Ending point of the segment. Example: (0.1,0.,0.)

  • name (str) – Name of the saved . curve file

  • frame (int) – Selected frame, frame = -1 for the last frame, optional.

Return type:

None

getDimensions(lata, field, frame=-1)

Get dimensions, [Nx, Ny, Nz].

getField(name, format='IJK', dimX=-1, dimY=-1, dimZ=-1)

Return the fields.

Parameters:

name (str) – Name of the .okc file gived by the user in extract_field method or already stored.

Returns:

  • field (array) – Return the field in the format asked.

  • X (array) – X coordinates. If format = “XYZ”.

  • Y (array) – Y coordinates. If format = “XYZ”.

  • Z (array) – Z coordinates. If format = “XYZ”.

getFrames(lata, field)

Get total number of frames

Parameters:

name (str) – Name of the saved . curve file

Returns:

N – Number of frames

Return type:

int

getSpatialValues(name)

Return the spatial values.

Parameters:

name (str) – Name of the .curve file gived by the user in extract_profile method.

Returns:

  • X (array) – Distance.

  • Y (array) – Field.

plot(x1, y1, label1='', linestyle1='-', linewidth1=0.5, **kwargs)

Method to plot one are multiple data. Calls the StatisticalPostProcessing plot.

Parameters:
  • x (array)

  • y (array)

  • label (str)

  • linewidth (float) – To plot multiple data, you can use keywords x1 = …, y1 = …, …

Return type:

None

spatialAutoCorrelation(X, Y, max_lag=None, fit=False)

Computes spatial signal autocorrelation.

Parameters:
  • X (array) – Distances.

  • Y (array) – Field.

  • max_lag (float, Optional) – Maximum lag value

  • fit (boolean) – Set to True to perform a parbola fit on autocorrelation

Returns:

  • dist (array) – Distances.

  • autocorr (array) – Array of signal autocorrelation.

  • Xfit (array) – Result of parabola fit for X-axis, only if fit = True

  • Yfit (array) – The parabola fit, only if fit = True

spatialEnergySpectrum(X, Y)

Computes spatial energy spectrum with Welch method.

Parameters:
  • X (array) – Distances.

  • Y (array) – Field.

Returns:

  • lambd (array) – Wave number.

  • power (array) – Energy.

stats.trust_statistical_tools_temporal

Morad Ben Tayeb CEA Saclay - DM2S/STMF/LGLS Mars 2021 - Stage 6 mois

The main class is TemporalPostProcessing. Using this package allows the following:

  • plot the instantaneous evolution of a probe(s) in same/different son file(s)

  • Plot the fluctuations evolution of a probe(s) in same/different son file(s) at a given t_start

  • plot the dt/residu evolution of a simulation

  • plot the spatial mean evolution of several probes along a segment and/or points from several files

  • plot the convergence of the statistical data along a considered probe(s); i.e: several window averaging

  • plot the time autocorrelations & calculate the Taylor micro-scale of a probe(s) in same/different son file(s)

  • plot the temporal energy spectrum using the Welch method

class stats.trust_statistical_tools_temporal.TemporalPostProcessing

Bases: StatisticalPostProcessing

energySpectrum(sonFiles, x, y, z=None, component='X', startTime=None, hanning=False, fft=False)

Computes the temporal energy spectrum using the Welch method.

Parameters:
  • sonFiles (list) – List of .son files path

  • x (float) – Coordinate.

  • y (float) – Coordinate.

  • z (float) – Coordinate, Optional.

  • component (str) – “X”, “Y”, “Z”, or “magnitude” for 2D plot Z = None, optional

  • startTime (float) – Starting time of the statistic analysis.

Returns:

  • f (array) – Frequencies array.

  • power (array) – Computed Welch method.

  • label (str) – Label of the field (can be used as label in plot method)

getdtValues(sonFiles, entry='dt')

This method plots the data found in the FILE.dt_ev

Parameters:

entry (str) –

can be one of the following :
  • entry = “dt” . This is the default entry for tracking the time step evolution

  • entry = “facsec”

  • entry = “residu=max|Ri|”

  • entry = “dt_stab”

  • entry = “Ri=max|dV/dt|”

Returns:

  • X (array) – An array of time values

  • Y (array) – An array of the chosen entry: Residuals, time step, …

instantaneousValues(sonFiles, x, y, z=None, component='X')

Get fields (time, velocities, …)

Parameters:
  • sonFiles (list) – List of .son files path

  • x (float) – Coordinate.

  • y (float) – Coordinate.

  • z (float) – Coordinate, Optional.

  • component (str) – “X”, “Y”, “Z”, “magnitude” or “kinetic”

Returns:

  • time (array) – time values

  • field (array) – field values

  • label (str) – Label of the field (can be used as label in plot method)

plot(x1, y1, label1='', linestyle1='-', linewidth1=0.5, **kwargs)

Method to plot one are multiple data. Calls the StatisticalPostProcessing plot.

Parameters:
  • x (array)

  • y (array)

  • label (str)

  • linewidth (float)

  • kwargs (dictionnary) – To plot multiple data, you can use keywords x1 = …, y1 = …, x2 = …, y2 = …, …

Returns:

None – Return nothing.

Return type:

None

Examples

obj.plot(
    X,
    Y,
    label1 = "Vitesse_x",
    linestyle1 = '-',
    linewidth1=0.5,
    xscale="linear",    # or "log" ...
    yscale="linear",    # or "log" ...
    title="My title",
    xlabel="distance",
    ylabel="Vitesse_x",
    name = "profX"
    )

# Multi-plot
obj.plot(
    x1 = X, y1  = Y, label1 = "Vitesse_X",
    x2 = X2, y2 = Y2, label2 = "Vitesse_Y",
    title = "Velocities", xlabel="distance", ylabel="Velocities", name = "ProfY"
)
temporalAutoCorrelation(sonFiles, x, y, z=None, digit=5, component='X', startTime=None, max_lag=None, fit=False, mode='autocorrelation')

Performs temporal autocorrelation on signal.

Parameters:
  • sonFiles (list) – List of .son files path

  • x (float) – Coordinate.

  • y (float) – Coordinate.

  • z (float) – Coordinate, Optional.

  • component (str) – “X”, “Y”, “Z”, or “magnitude” for 2D Z = None, optional

  • startTime (float) – Starting time of the statistic analysis

  • max_lag (float) – maximum lag for autocorrelation

  • fit (Boolean) – When the value is “False”, the method does not Returns the parabola fit.

  • mode (str) –

    You can select a mode as this:

    • mode = "autocorrelation" (default)

    • mode = "fft" returns only Fourier transform of autocorrlation

    • mode = "autocorrelation fft" for both

Returns:

  • X (array) – array of time values.

  • autocorr (array) – array of signal autocorrelation.

  • Xfit (array) – Array of time values, only if fit is True.

  • Yfit (array) – Parabola fit, only if fit is True.

  • Xfft (array) – Array of frenquencies, Only if "fft" is in mode.

  • Yfft (array) – Fourier transform of autocorrelation, Only if "fft" is in mode.

  • label (str) – Label of the field (can be used as label in plot method)

temporalAverageWindows(sonFiles, x, y, z=None, component='X', startTime=None, endTime=None, window=1, mode=None)

Window averaging, statistical convergence, etc.

Parameters:
  • sonFiles (list) – List of .son files path

  • x (float) – Coordinate.

  • y (float) – Coordinate.

  • z (float) – Coordinate, Optional.

  • component (str) – “X”, “Y”, “Z”, “magnitude” or “kinetic”

  • startTime (float) – Starting time of the statistic analysis

  • endTime (float) – Ending time of the statistic analysis

  • window (float) – Time of a single window

  • mode (str) –

    • “average” = window average,

    • ”convergence” = statistical convergence,

    • ”mean” = mean of average window

    • ”difference” = plots absolute difference from the first mean,

    • ”error” = error between accumulated time average and mean

Returns:

  • X (array) – Array of time values.

  • Y (array) – Array that contains the chosen mod: Statistical convergence, window averaging,…

  • label (str) – Label of the field (can be used as label in plot method)

temporalFluctuations(sonFiles, x, y, z=None, startTime=None, component='X')

Method that computes fluctuation of a signal

Parameters:
  • sonFiles (list) – List of .son files path

  • x (float) – Coordinate.

  • y (float) – Coordinate.

  • z (float) – Coordinate, Optional.

  • startTime (float) – Starting time choosen to analyze data

  • step_time (float) – Step time in .son file

  • component (str) – “X”, “Y”, “Z”, “magnitude” or “kinetic”

Returns:

  • time (array) – Time values

  • fluc (array) – Fluctuations values

  • label (str) – Label of the field (can be used as label in plot method)

temporalSegmentSpatialMean(sonFiles, component='X')

Performs the temporal spatial average on a segment.

Parameters:

component (str) – “X”, “Y”, “Z”, or “magnitude” for 2D plot Z = None, optional

Returns:

  • X (array) – Time values.

  • Y (array) – Spatial average on segment.

  • label (str) – Label of the field (can be used as label in plot method)

stats.trust_statistical_tools_IJK