コード例 #1
0
    def sanity_zerocross1dExample(self):
        """
      Checking sanity of zerocross1d example
    """
        import numpy as np
        import matplotlib.pylab as plt
        from PyAstronomy import pyaC

        # Generate some 'data'
        x = np.arange(100.)**2
        y = np.sin(x)

        # Set the last data point to zero.
        # It will not be counted as a zero crossing!
        y[-1] = 0

        # Set point to zero. This will be counted as a
        # zero crossing
        y[10] = 0.0

        # Get coordinates and indices of zero crossings
        xc, xi = pyaC.zerocross1d(x, y, getIndices=True)

        # Plot the data
        plt.plot(x, y, 'b.-')
        # Add black points where the zero line is crossed
        plt.plot(xc, np.zeros(len(xc)), 'kp')
        # Add green points at data points preceding an actual
        # zero crossing.
        plt.plot(x[xi], y[xi], 'gp')
コード例 #2
0
ファイル: sanityOfmtools.py プロジェクト: sczesla/PyAstronomy
 def sanity_zerocross1dExample(self):
   """
     Checking sanity of zerocross1d example
   """
   import numpy as np
   import matplotlib.pylab as plt
   from PyAstronomy import pyaC
   
   # Generate some 'data'
   x = np.arange(100.)**2
   y = np.sin(x)
   
   # Set the last data point to zero.
   # It will not be counted as a zero crossing!
   y[-1] = 0
   
   # Set point to zero. This will be counted as a
   # zero crossing
   y[10] = 0.0
   
   # Get coordinates and indices of zero crossings
   xc, xi = pyaC.zerocross1d(x, y, getIndices=True)
   
   # Plot the data
   plt.plot(x, y, 'b.-')
   # Add black points where the zero line is crossed
   plt.plot(xc, np.zeros(len(xc)), 'kp')
   # Add green points at data points preceding an actual
   # zero crossing.
   plt.plot(x[xi], y[xi], 'gp')
コード例 #3
0
ファイル: ToF_all_TC.py プロジェクト: mako32/mytestproject
            def get_first_zc(enclosed_signal):

                global_miny = min(enclosed_signal)
                global_minx = np.argmin(enclosed_signal)
                zero_finder = zero_crossing_finder(enclosed_signal)
                list_of_new_zc = []

                temp_zct = np.array(zero_finder)
                temp_zct = np.append(global_minx, temp_zct)
                temp_zct = sorted(temp_zct)

                y = np.array(enclosed_signal)
                x = [i for i, j in enumerate(enclosed_signal)]
                x = np.array(x)
                #lists of zero crossings of boundary
                xc, xi = pyaC.zerocross1d(x, y, getIndices=True)
                xc = np.append(global_minx, xc)
                xc = sorted(xc)

                ast_crossings = []
                for x, y in enumerate(xc):
                    if y == global_minx:
                        ast_crossings.append(xc[x - 1])
                        break

                ast_crossings = np.array(ast_crossings)

                return ast_crossings
コード例 #4
0
ファイル: sanityOfmtools.py プロジェクト: sczesla/PyAstronomy
 def sanity_zerocross1d(self):
   """
     Checking sanity of zerocross1d
   """
   import numpy as np
   from PyAstronomy import pyaC
   
   x = np.arange(3.)
   y = np.array([0, 3, 0])
   
   xz = pyaC.zerocross1d(x, y)
   self.assertEqual(len(xz), 0, msg="Found zero crossing in 0,3,0 array (problem with first/last point).")
   
   y = np.array([-1., 1., -2.])
   xz, xi = pyaC.zerocross1d(x, y, getIndices=True)
   self.assertEqual(len(xz), 2, msg="Found the following zero crossings in -1,1,-2 array: " + str(xz))
   self.assertEqual(len(xz), len(xi), "Number of values and indicies is not identical.")
   
   self.assertAlmostEqual(np.max(np.abs(np.array([0.5, 1.+1./3.])-xz)), 0.0, delta=1e-8, msg="Found unexpected zero crossings: " + str(xz))
   self.assertEqual(np.max(np.abs(xi - np.array([0,1]))), 0, msg="Found unexpected indices: " + str(xi))
コード例 #5
0
ファイル: ToF_all_TC.py プロジェクト: mako32/mytestproject
def SOH_model(adc_captures_readout=[]):
    bounded_start, bounded_end = 2000, 40000
    # interpolates signal array by 100
    adc_captures_interp = interp(interp(adc_captures_readout, 10), 10)
    # finds all zero crossings in signal
    zc_loc = zero_crossing_finder(
        adc_captures_interp[bounded_start:bounded_end])

    # ensures that bounded area starts at the bounddary edges and not at 0
    timed_shift = (bounded_start + 2000 / 7.2) / 100
    shift = 2000

    bounded_signal = adc_captures_interp[bounded_start:bounded_end]
    global_miny = min(bounded_signal)
    global_minx = np.argmin(bounded_signal)
    zero_finder = zero_crossing_finder(bounded_signal)
    list_of_new_zc = []

    temp_zct = np.array(zero_finder)
    temp_zct = np.append(global_minx, temp_zct)
    temp_zct = sorted(temp_zct)

    y = np.array(bounded_signal)
    x = [i for i, j in enumerate(bounded_signal)]
    x = np.array(x)
    #lists of zero crossings of boundary
    xc, xi = pyaC.zerocross1d(x, y, getIndices=True)
    xc = np.append(global_minx, xc)
    xc = sorted(xc)

    ast_crossings = []
    for x, y in enumerate(xc):
        if y == global_minx:
            ast_crossings.append(xc[x - 2])
            ast_crossings.append(xc[x - 1])
            ast_crossings.append(xc[x + 1])
            ast_crossings.append(xc[x + 2])
            ast_crossings.append(xc[x + 3])
            break

    # computes zero crossings
    converted_ast = [(i + bounded_start) * 0.72 for i in ast_crossings]
    tdiff = [converted_ast[x] - converted_ast[x - 1] for x in range(1, 5)]
    value = tdiff[0] * tdiff[0] + tdiff[1] * tdiff[1] + tdiff[2] * tdiff[
        2] + tdiff[3] * tdiff[3]
    # y = mx+b of zero crossing model and returns SoH for the signal
    SoH = value * 0.0000595 + 36.99
    SoH = round(SoH, 2)

    return SoH, bounded_signal, ast_crossings, global_minx, timed_shift, adc_captures_interp, shift
コード例 #6
0
    def sanity_zerocross1d(self):
        """
      Checking sanity of zerocross1d
    """
        import numpy as np
        from PyAstronomy import pyaC

        x = np.arange(3.)
        y = np.array([0, 3, 0])

        xz = pyaC.zerocross1d(x, y)
        self.assertEqual(
            len(xz),
            0,
            msg=
            "Found zero crossing in 0,3,0 array (problem with first/last point)."
        )

        y = np.array([-1., 1., -2.])
        xz, xi = pyaC.zerocross1d(x, y, getIndices=True)
        self.assertEqual(
            len(xz),
            2,
            msg="Found the following zero crossings in -1,1,-2 array: " +
            str(xz))
        self.assertEqual(len(xz), len(xi),
                         "Number of values and indicies is not identical.")

        self.assertAlmostEqual(
            np.max(np.abs(np.array([0.5, 1. + 1. / 3.]) - xz)),
            0.0,
            delta=1e-8,
            msg="Found unexpected zero crossings: " + str(xz))
        self.assertEqual(np.max(np.abs(xi - np.array([0, 1]))),
                         0,
                         msg="Found unexpected indices: " + str(xi))
コード例 #7
0
    def get_Vlims(pr0):
        """Cruce por cero de pr0 - pr
        
        Devuelve solo los extremos
        """

        Vextreme = pyaC.zerocross1d(Vr, pr0 - pr)

        # Excepciones
        assert len(
            Vextreme
        ) == 3, '{} intersecciones entre PV y pr0. Posiblemente sea necesario modificar los límites de Vr'.format(
            len(Vextreme))

        return Vextreme[0], Vextreme[2]
コード例 #8
0
# %%
import numpy as np
import matplotlib.pylab as plt
from PyAstronomy import pyaC

# Generate some 'data'
x = np.arange(100.)**2
y = np.sin(x)

# Set the last data point to zero.
# It will not be counted as a zero crossing!
y[-1] = 0

# Set point to zero. This will be counted as a
# zero crossing
y[10] = 0.0

# Get coordinates and indices of zero crossings
xc, xi = pyaC.zerocross1d(x, y, getIndices=True)

# Plot the data
plt.plot(x, y, 'b.-')
# Add black points where the zero line is crossed
plt.plot(xc, np.zeros(len(xc)), 'kp')
# Add green points at data points preceding an actual
# zero crossing.
plt.plot(x[xi], y[xi], 'gp')
plt.show()

# %%
コード例 #9
0
             i] == "Sleep stage 3" or v_Hyp_Petit[
                 i] == "Sleep stage 4" or v_Hyp_Petit[
                     i] == "Sleep stage R":
 etiquetas.append(v_Hyp_Petit[i])
 datos.append(
     np.array(v_Sig_Petit[s_FirstInd_Petit:s_LastInd_Petit]))
 dato_df = pd.DataFrame(
     v_Sig_Petit[s_FirstInd_Petit:s_LastInd_Petit])
 descriptores[9 * s_SigRef_Petit].append(dato_df.mean()[0])
 descriptores[9 * s_SigRef_Petit + 1].append(dato_df.var()[0])
 descriptores[9 * s_SigRef_Petit + 2].append(dato_df.kurt()[0])
 descriptores[9 * s_SigRef_Petit + 3].append(dato_df.skew()[0])
 descriptores[9 * s_SigRef_Petit + 4].append(
     len(
         pyaC.zerocross1d(
             x=arreglo_x,
             y=np.array(
                 v_Sig_Petit[s_FirstInd_Petit:s_LastInd_Petit]))
     ))
 # Frecuencia
 dato_fft = sp.fftpack.fft(dato_df)
 fftfreq = sp.fftpack.fftfreq(len(dato_fft), 1 / s_FsHz_Petit)
 potencia_02 = 0
 potencia_28 = 0
 potencia_814 = 0
 potencia_14inf = 0
 for i in range(len(fftfreq)):
     if abs(fftfreq[i]) <= 2:
         potencia_02 = potencia_02 + abs(dato_fft[i][0])**2
     elif abs(fftfreq[i]) < 8:
         potencia_28 = potencia_28 + abs(dato_fft[i][0])**2
     elif abs(fftfreq[i]) < 14:
コード例 #10
0
#ptl.figure()
while 1:
    s_LastInd = s_FirstInd + s_WinSizeSam
    if s_LastInd > 501:
        break
    for i in range(len(v_Hyp)-1):
        if ((v_HypTime[i] <= s_FirstInd/s_FsHz) and (s_FirstInd/s_FsHz < v_HypTime[i+1])):
            if v_Hyp[i] != "Sleep stage ?":
                etiquetas.append(v_Hyp[i])
                datos.append(v_Sig[s_FirstInd:s_LastInd])
                dato_df = pd.DataFrame(v_Sig[s_FirstInd:s_LastInd])
                descriptores[0].append(dato_df.mean()[0])
                descriptores[1].append(dato_df.var()[0])
                descriptores[2].append(dato_df.kurt()[0])
                descriptores[3].append(dato_df.skew()[0])
                descriptores[4].append(len(pyaC.zerocross1d(x=arreglo_x, y=np.array(v_Sig[s_FirstInd:s_LastInd]))))
                sw = yasa.sw_detect(dato_df.transpose(), s_FsHz, remove_outliers=True)
                descriptores[5].append(sw.summary().shape[0])
                suma = 0
                for i in range(sw.summary().shape[0]):
                    suma = suma + (sw.summary()['Duration'].iloc[i])
                descriptores[6].append(suma)
                # Frecuencia
                dato_fft = sp.fftpack.fft(dato_df)
                fftfreq = sp.fftpack.fftfreq(len(dato_fft), 1/s_FsHz)
                potencia_02 = 0
                potencia_28 = 0
                potencia_814 =  0
                potencia_14inf = 0
                for i in range(len(fftfreq)):
                    if abs(fftfreq[i]) <= 2: