示例#1
0
文件: data.py 项目: FabricioS/pyphs
    def wavwrite(self,
                 name,
                 index,
                 fs_in,
                 filename=None,
                 path=None,
                 gain=1,
                 fs_out=None):
        """
        write phs.simulation.data.name[index] in the folder pointed by \
phs.paths['wav'].
        """
        if fs_out is None:
            fs_out = fs_in
        if filename is None:
            filename = name
        if path is None:
            path = os.getcwd()
        if not os.path.exists(path):
            os.makedirs(path)
        data = getattr(self, name)
        sig = []
        for el in data():
            s = gain * el[index]
            if abs(s) >= 1:
                s = 0.
            sig.append(s)
        wavwrite(sig, fs_in, path + os.sep + filename, fs_out=fs_out)
示例#2
0
    def wavwrite(self,
                 name,
                 index,
                 path=None,
                 gain=1.,
                 fs=None,
                 normalize=True,
                 timefades=0.):
        """
========
wavwrite
========

Write data to wave file.

Parameters
----------
name: str
    Name of the data generator to export (e.g. 'x', 'y', 'dxH').

index: int
    Index of the component of the data generator to read (e.g. if name is 'x'
    and index is 0, the signal is x[index]).

path: str or None, optional
    Raw path to the generated wave file. Notice '.wav' is appended by default.
    If None, the simulation path and the data generator name is used (default).

gain: float, optional
    Gain applied to the signal before writing to file. Default is 1.

fs: float or None, optional
    Sample rate for the generated wave file. Resampling is performed with
    scipy.signal.resample. If None, the simulation samplerate is use (default).

normalize: Bool
    If True, the signal is normalised by the maximum absolute value. Default is
    False.

timefades: float, optional
    Fade-in and fade-out time to avoid clics. Default is 0.

See also
---------
pyphs.misc.signals.waves.wavwrite
        """
        if fs is None:
            fs = self.config['fs']
        if path is None:
            path = self.config['path'] + os.sep + name + str(index)
        print(path)
        args = {
            'ind': index,
            'imin': 0,
            'imax': None,
            'decim': 1,
            'postprocess': lambda e: gain * e
        }
        sig = getattr(self, name)(**args)
        wavwrite(sig,
                 self.config['fs'],
                 path,
                 fs_out=fs,
                 normalize=normalize,
                 timefades=timefades)
示例#3
0
文件: h5data.py 项目: A-Falaize/pyphs
    def wavwrite(self, name, index, path=None, gain=1.,
                 fs=None, normalize=True, timefades=0.):
        """
        wavwrite
        ========

        Write data to wave file.

        Parameters
        ----------
        name: str
            Name of the data generator to export (e.g. 'x', 'y', 'dxH').

        index: int
            Index of the component of the data generator to read (e.g. if name
            is 'x' and index is 0, the signal is x[index]).

        path: str or None, optional
            Raw path to the generated wave file. Notice '.wav' is appended by
            default. If None, the simulation path and the data generator name
            is used (default).

        gain: float, optional
            Gain applied to the signal before writing to file. Default is 1.

        fs: float or None, optional
            Sample rate for the generated wave file. Resampling is performed
            with scipy.signal.resample. If None, the simulation samplerate is
            use (default).

        normalize: Bool
            If True, the signal is normalised by the maximum absolute value.
            Default is False.

        timefades: float, optional
            Fade-in and fade-out time to avoid clics. Default is 0.

        See also
        ---------
        pyphs.misc.signals.waves.wavwrite

        """
        # close flag
        if not self._open:
            self.h5open()
            close = True
        else:
            close = False

        # samplerate
        if fs is None:
            fs = self.fs
        if path is None:
            path = self.config['path'] + os.sep + name + str(index)

        # recover signal
        sig = getattr(self, name)(vslice=index,
                                  tslice=slice(self.start, self.stop, 1),
                                  postprocess=lambda e: gain*e)

        # write .wav file
        wavwrite(sig, self.fs, path,
                 fs_out=fs, normalize=normalize, timefades=timefades)

        # close flag
        if close:
            self.h5close()
示例#4
0
    def wavwrite(self,
                 name,
                 index,
                 path=None,
                 gain=1.,
                 fs=None,
                 normalize=True,
                 timefades=0.):
        """
        wavwrite
        ========

        Write data to wave file.

        Parameters
        ----------
        name: str
            Name of the data generator to export (e.g. 'x', 'y', 'dxH').

        index: int
            Index of the component of the data generator to read (e.g. if name
            is 'x' and index is 0, the signal is x[index]).

        path: str or None, optional
            Raw path to the generated wave file. Notice '.wav' is appended by
            default. If None, the simulation path and the data generator name
            is used (default).

        gain: float, optional
            Gain applied to the signal before writing to file. Default is 1.

        fs: float or None, optional
            Sample rate for the generated wave file. Resampling is performed
            with scipy.signal.resample. If None, the simulation samplerate is
            use (default).

        normalize: Bool
            If True, the signal is normalised by the maximum absolute value.
            Default is False.

        timefades: float, optional
            Fade-in and fade-out time to avoid clics. Default is 0.

        See also
        ---------
        pyphs.misc.signals.waves.wavwrite

        """
        # close flag
        if not self._open:
            self.h5open()
            close = True
        else:
            close = False

        # samplerate
        if fs is None:
            fs = self.fs
        if path is None:
            path = self.config['path'] + os.sep + name + str(index)

        # recover signal
        sig = getattr(self, name)(vslice=index,
                                  tslice=slice(self.start, self.stop, 1),
                                  postprocess=lambda e: gain * e)

        # write .wav file
        wavwrite(sig,
                 self.fs,
                 path,
                 fs_out=fs,
                 normalize=normalize,
                 timefades=timefades)

        # close flag
        if close:
            self.h5close()