Skip to content
Snippets Groups Projects
Commit 6d73bb88 authored by Alexander Martínez Méndez's avatar Alexander Martínez Méndez
Browse files

Agregar archivos iniciales

parent 3ad01915
Branches master
No related tags found
No related merge requests found
.ipynb_checkpoints/amplitude-checkpoint.png

30.6 KiB

This diff is collapsed.
This diff is collapsed.
amplitude.png

54.9 KiB

%% Cell type:markdown id:a4d202eb-9d92-4857-b2af-aba670f9090b tags:
# Análisis de Datos Racimo Tormenta
%% Cell type:markdown id:52bc4c5f-1baf-4e8f-8a1d-0b0e51fa8695 tags:
Notebook para el análisis de datos del proyecto racimo tormenta.
A continuación se realiza el análisis de un archivo de datos de una estación *Racimo tormenta*. Resumiendo se realiza lo siguiente:
1. Se cargan la librerias necesarias.
2. Se descarga el archivo de datos desde el repositorio de datos **Dataverse**.
3. Se analiza el archivo de datos y se genera una nueva versión del mismo.
4. Por último, se publica la nueva versión de los datos en el repositorio **Dataverse**.
%% Cell type:markdown id:d277a53c-cccc-4996-8944-620130575372 tags:
## Cargar Librerias
%% Cell type:markdown id:e96a3270-365f-4f90-9d5a-d2673f176f11 tags:
Importar las librerias necesarias para el análisis e interacciones de los datos
%% Cell type:code id:5d4d6478-6b92-46a4-a849-7fc4d5a3b119 tags:
``` python
import numpy as np
import matplotlib.pylab as plt
import scipy
from scipy import stats
from scipy.fftpack import fftfreq, irfft, rfft
import sys
import os
from matplotlib import cm
from matplotlib.colors import ListedColormap, LinearSegmentedColormap
import math
import datetime as datetime
import time
import matplotlib.dates as md
#!pip install --user -e git+https://github.com/IQSS/dataverse-client-python.git#egg=dataverse
%matplotlib inline
sys.getdefaultencoding()
```
%% Cell type:markdown id:6e994b24-64db-40ca-8d89-698456ba2f5b tags:
---
%% Cell type:markdown id:97659221-fc8b-4e1a-b6d9-2ef11fd5410c tags:
## Descargar datos
%% Cell type:markdown id:14c40ec4-7904-4690-8619-f9cf1cbdafec tags:
En esta sección descargaremos el archivo de datos desde el repositorio **Dataverse**.
%% Cell type:markdown id:14901417-d762-42f9-83e5-2bed2e3c3138 tags:
<img src="imagenes/dataverse-jupyter_datos.jpg" alt="drawing" width="600"/>
%% Cell type:markdown id:b0683242-aecf-4fee-91f6-1fbd91aff17e tags:
Ir a https://dataverse.redclara.net/dataverseuser.xhtml?selectTab=apiTokenTab y copiar el **Token** de usuario
%% Cell type:code id:89723f93-88a1-4bd4-ac98-76a5d4e75c48 tags:
``` python
%env API_TOKEN=TOKENdeUSUARIO
```
%% Cell type:markdown id:eac7066f-c26e-4297-85ad-4f1c632ade0b tags:
Descargar dataset
%% Cell type:code id:bf02c4eb-bfed-478e-8315-2ca2bfbe6470 tags:
``` python
%env SERVER_URL=https://dataverse.redclara.net
%env PERSISTENT_ID=doi:10.21348/FK2/RBNNPC
%env VERSION=DRAFT
!curl -L -O -J -H "X-Dataverse-key:$API_TOKEN" $SERVER_URL/api/access/dataset/:persistentId/?persistentId=$PERSISTENT_ID
```
%% Cell type:markdown id:52c1b78f-5325-4a21-9933-d25cf8e927ab tags:
Descomprimir archivo de datos
%% Cell type:code id:0c7d3e5e-31fe-42b7-be08-e9c9f793a7da tags:
``` python
!unzip dataverse_files.zip
!rm dataverse_files.zip
!rm MANIFEST.TXT
```
%% Cell type:markdown id:927a9fb3-a065-45f2-b075-cf650d73d8b5 tags:
---
%% Cell type:markdown id:960fdf13-2b85-4fca-a1fb-ed0aa016e468 tags:
## Calibración del detector
%% Cell type:markdown id:3b8b509b-c69e-4c8d-98e2-6f9d7cc825c3 tags:
En esta sección realizaremos un análisis del archivo de datos descargado y generaremos una nueva versión del mismo. Graficamos la amplitud y la frecuencia para de manera visual, selecccionar el subconjunto de datos donde se presenta el evento.
%% Cell type:markdown id:440109c1-3272-4702-9a0c-fd5e2b8e6b1d tags:
### Vista preliminar de los datos de calibración
%% Cell type:markdown id:4ed58223-c091-4de4-b9c7-2cf4b3dd674f tags:
Cargar datos en formato *array numpy*
%% Cell type:code id:78a31578-66f3-4363-80b4-856aabede298 tags:
``` python
data = np.loadtxt('Descargas/Lighting_2021_11_10_01_56.dat', comments='#')
```
%% Cell type:markdown id:7c03fdf2-6a4a-4d30-87e3-3b025a43f6c1 tags:
Describir datos
%% Cell type:code id:6733522b-ab2c-4b49-841a-a45bc4dfd377 tags:
``` python
from scipy import stats
stats.describe(data)
```
%% Cell type:markdown id:c754f55c-22ff-46b9-a414-7fa07a4497d6 tags:
### Amplitud y frecuencia de la señal
%% Cell type:markdown id:badb8819-ef05-4e8c-867c-8b4a03f554d2 tags:
Función para graficar amplitud y frecuencia.
%% Cell type:code id:05f9f0b6-dd57-4e7e-92ca-4718cf85808e tags:
``` python
def Lightning_Analysis(data, dt, Np):
mean = np.mean(data[:,1])
sigma = np.std(data[:,1])
peaks = []
MTFt = [] # Multiple-termination flash (MTF) relative times
MTSt = [] # Multiple.termination stroke (MTS) relative times
MTSv = []
T_count = 0 # Terminations counter
MTFc = 1 # MTF counter
MTSc = 0 # MTS counter
N = len(data)
MTSw = 1e-3 # time window for differentiating MTF and MTS events
threshold = mean + 5*sigma # Peak threshold
# Termination identification
for i in range(N):
if (data[i,1] > threshold):
T_count += 1
peaks.append(i)
t1 = data[i,0]
if T_count > 1:
Td = t1 - t0
if Td > MTSw:
MTFt.append(Td)
MTFc += 1
MTSv.append(MTSc)
MTSc = 0
else:
MTSt.append(Td)
MTSc += 1
t0 = t1
print (u'Terminations above 5\u03C3 = %d\n' %T_count)
print (u'Number of strokes = %d\n' %MTFc)
s = data[:,1]
Y = np.fft.fft(s)
N = len(Y)/2+1
fa = 1.0/dt
X = np.linspace(0, fa/2, int(N), endpoint=True)
sfft = np.abs(Y[:int(N)])
print('Sample Time = %.5f s' % dt)
print('Frequency = %.2f Hz' % fa)
sfft = np.array(sfft)
pos = int(np.where(sfft[1:-1] == np.amax(sfft[1:-1]))[0])
frec_pico = 868.35 # X[pos+1]
print ("Maximum frequency = %.2f Hz" %frec_pico)
if T_count >= Np:
# Signal plot
plt.figure(figsize = (16,4))
plt.subplot(1,2,1)
plt.plot(data[:,0], data[:,1])
plt.axhline(threshold, color='red')
plt.xlabel('Time [s]', fontsize = 20)
plt.ylabel('Amplitude [ADC]', fontsize = 20)
plt.savefig("amplitude.png", dpi=150)
# Spectrum plotting
plt.subplot(1,2,2)
plt.axvline(frec_pico, color='red')
plt.loglog(X, sfft)
plt.xlabel('Frequency [Hz]', fontsize = 20)
plt.axis([1e-1,1e5,1e1,1e7])
plt.grid()
plt.show()
return frec_pico, peaks, MTFt, MTSt, T_count, MTFc, MTSv
```
%% Cell type:markdown id:4da5b0b2-97c4-455b-b9f9-028e817f3fa9 tags:
Graficar
%% Cell type:code id:66982705-0db4-43d7-8bd0-22ec2ae7b907 tags:
``` python
dt = 10e-6 # sampling period
Np = 0. # filter signals per number of peaks above 5 sigma
fp1, peaks1, MTFt, MTSt, pN1, MTFc, MTSc = Lightning_Analysis(data, dt, Np) # Returns maximum peak frequency and peak positions
```
%% Cell type:markdown id:eccbba23-922e-430b-816b-41ca7212cae5 tags:
### Escalar señal y enfocar
%% Cell type:markdown id:c15cc352-a82b-404d-9a47-09860ae25950 tags:
Definir parámetros de escalado y foco
%% Cell type:code id:aaea4b8a-0639-479e-8f66-ad59fb179ac8 tags:
``` python
R1 = 0
R2 = 200
P = 5
```
%% Cell type:markdown id:5a59c5cb-19db-4872-9046-6f0471498da0 tags:
Crear nuevo *array* de datos.
%% Cell type:code id:0d8a87c1-5ab1-4e9f-b2d8-8d10572ebad8 tags:
``` python
newdata = data[R1:R2]*[1,P]
```
%% Cell type:markdown id:6abec110-ecf4-44e0-b88c-3a3a94b8b4aa tags:
Graficar señal escalada
%% Cell type:code id:53d02f88-4245-4b93-a2c4-7da1cb9c4448 tags:
``` python
dt = 10e-6 # sampling period
Np = 0. # filter signals per number of peaks above 5 sigma
fp1, peaks1, MTFt, MTSt, pN1, MTFc, MTSc = Lightning_Analysis(newdata, dt, Np) # Returns maximum peak frequency and peak positions
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment