-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathlinespike_with_data.py
100 lines (78 loc) · 2.69 KB
/
linespike_with_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Oct 4 20:00:24 2021
@author: cl
"""
import numpy as np
import pandas as pd
#First I read in the data
filepath = '/Users/clepart/Downloads/desidiff/2021/'
fName_lux = filepath + 'difflux.csv'
fName_WL = filepath + 'difwave.csv'
data_lux = pd.read_csv(fName_lux, delimiter=',', header=None)
data_WL = pd.read_csv(fName_WL, delimiter=',', header=None)
#transpose pandas dataframe from rows to columns
dataY = data_lux.T
dataX = data_WL.T
#pull out sub-bands after converting from a dataframe to a numpy array
dataX = dataX.to_numpy()
dataY = dataY.to_numpy()
BdataX = dataX[:,0]
BdataY = dataY[:,0]
RdataX = dataX[:,1]
RdataY = dataY[:,1]
ZdataX = dataX[:,2]
ZdataY = dataY[:,2]
#eliminate nan values, note this changes the sizes of the arrays (except B)
BdataX = BdataX[~np.isnan(BdataX)]
RdataX = RdataX[~np.isnan(RdataX)]
ZdataX = ZdataX[~np.isnan(ZdataX)]
BdataY = BdataY[~np.isnan(BdataY)]
RdataY = RdataY[~np.isnan(RdataY)]
ZdataY = ZdataY[~np.isnan(ZdataY)]
#Here's the main part that isn't just reformatting the data:
Bmask = np.ones(len(BdataY)) # setup the mask array with all ones and same size as BdataY
ybs = BdataY # get a copy of the data
# go through dely values looking for those >9 and set mask to zero for those values only
for i in range(len(ybs)):
if abs(ybs[i]) > 8:
Bmask[i] = 0
"""
Rmask = np.ones(len(RdataY)) # setup the mask array with all ones and same size as BdataY
ybs = RdataY # get a copy of the data
dely = abs(np.diff(ybs)) # find the diff
# go through dely values looking for those >9 and set mask to zero for those values only
for i in range(len(dely)):
if dely[i] > 8:
Rmask[i+1] = 0
newRdataY = np.multiply(RdataY, Rmask) #multiply each element of array by mask
Zmask = np.ones(len(ZdataY)) # setup the mask array with all ones and same size as BdataY
ybs = ZdataY # get a copy of the data
dely = abs(np.diff(ybs)) # find the diff
# go through dely values looking for those >9 and set mask to zero for those values only
for i in range(len(dely)):
if dely[i] > 3:
Zmask[i+1] = 0
newZdataY = np.multiply(ZdataY, Zmask) #multiply each element of array by mask
"""
for i in range(len(Bmask)):
if (Bmask[i] & Bmask[i-1]) == 0:
print('yup')
#else:
# Bmask[i] = 1
"""
import itertools
f_logic = np.abs(ybs) > 8
index=0
for _, g in itertools.groupby(f_logic):
ng = sum(1 for _ in g)
if _ and ng<=3:
Bmask[index:index+ng] = 0
index=index+ng
"""
newBdataY = np.multiply(BdataY, Bmask) #multiply each element of array by mask
import matplotlib.pyplot as plt
plt.plot(BdataX, newBdataY)
#plt.plot(RdataX, newRdataY)
#plt.plot(ZdataX, newZdataY)