123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335 |
- # -*- coding: utf-8 -*-
- """
- Created on Sat Oct 13 23:47:41 2018
- @author: aemdlabs
- """
- # -*- coding: utf-8 -*-
- """
- Created on Thu Sep 27 08:36:30 2018
- @author: aemdlabs
- """
- from PhyREC.NeoInterface import NeoSegment#, ReadMCSFile
- import PhyREC.PlotWaves as Rplt
- import quantities as pq
- import matplotlib.pyplot as plt
- import numpy as np
- import neo
- import PhyREC.SignalProcess as RPro
- import deepdish as dd
- def ReadMCSFile(McsFile, OutSeg=None, SigNamePrefix=''):
- import McsPy.McsData as McsData
- Dat = McsData.RawData(McsFile)
- Rec = Dat.recordings[0]
- NSamps = Rec.duration
- if OutSeg is None:
- OutSeg = NeoSegment()
- for AnaStrn, AnaStr in Rec.analog_streams.iteritems():
- if len(AnaStr.channel_infos) == 1:
- continue
- for Chn, Chinfo in AnaStr.channel_infos.iteritems():
- print ('Analog Stream ', Chinfo.label, Chinfo.sampling_frequency)
- ChName = str(SigNamePrefix + Chinfo.label)
- print(ChName)
- Fs = Chinfo.sampling_frequency
- Var, Unit = AnaStr.get_channel_in_range(Chn, 0, NSamps)
- sig = neo.AnalogSignal(pq.Quantity(Var, Chinfo.info['Unit']),
- t_start=0*pq.s,
- sampling_rate=Fs.magnitude*pq.Hz,
- name=ChName)
- OutSeg.AddSignal(sig)
- return OutSeg
-
- MCSMapI={'SE1':'Ch03',
- 'SE2':'Ch05',
- 'SE3':'Ch01',
- 'SE4':'Ch02',
- 'SE5':'Ch22',
- 'SE6':'Ch06',
- 'SE7':'Ch16',
- 'SE8':'Ch37',
- 'SE9':'Ch20',
- 'SE10':'Ch10',
- 'SE11':'Ch24',
- 'SE12':'Ch08',
- 'SE13':'Ch14',
- 'SE14':'Ch04',
- 'SE15':'Ch18',
- 'SE16':'Ch33',
- 'SE17':'Ch34',
- 'SE18':'Ch60',
- 'SE19':'Ch38',
- 'SE20':'Ch64',
- 'SE21':'Ch40',
- 'SE22':'Ch56',
- 'SE23':'Ch42',
- 'SE24':'Ch70',
- 'SE25':'Ch66',
- 'SE26':'Ch65',
- 'SE27':'Ch68',
- 'SE28':'Ch67',
- 'SE29':'Ch55',
- 'SE30':'Ch62',
- 'SE31':'Ch58',
- 'SE32':'Ch69',
- 'ME1':'Ch57',
- 'ME2':'Ch61',
- 'ME3':'Ch53',
- 'ME4':'Ch63',
- 'ME5':'Ch52',
- 'ME6':'Ch41',
- 'ME7':'Ch49',
- 'ME8':'Ch51',
- 'ME9':'Ch46',
- 'ME10':'Ch45',
- 'ME11':'Ch44',
- 'ME12':'Ch39',
- 'ME13':'Ch54',
- 'ME14':'Ch43',
- 'ME15':'Ch50',
- 'ME16':'Ch47',
- 'ME17':'Ch32',
- 'ME18':'Ch27',
- 'ME19':'Ch30',
- 'ME20':'Ch29',
- 'ME21':'Ch28',
- 'ME22':'Ch25',
- 'ME23':'Ch26',
- 'ME24':'Ch07',
- 'ME25':'Ch21',
- 'ME26':'Ch11',
- 'ME27':'Ch17',
- 'ME28':'Ch15',
- 'ME29':'Ch13',
- 'ME30':'Ch31',
- 'ME31':'Ch19',
- 'ME32':'Ch09',
- 'ME0':'Ch12',
- 'SE33':'Ch59'}
- MCSMap = {v: k for k, v in MCSMapI.iteritems()}
-
- #Col, Row
- MCSMapFacingDown={'Ch58':(0,1),
- 'Ch57':(0,2),
- 'Ch56':(0,3),
- 'Ch55':(0,4),
- 'Ch54':(0,5),
- 'Ch53':(0,6),
- 'Ch52':(0,7),
- 'Ch51':(0,8),
- 'Ch50':(0,9),
- 'Ch49':(0,10),
- 'Ch60':(1,0),
- 'Ch61':(1,1),
- 'Ch62':(1,2),
- 'Ch63':(1,3),
- 'Ch64':(1,4),
- 'Ch65':(1,5),
- 'Ch43':(1,6),
- 'Ch44':(1,7),
- 'Ch45':(1,8),
- 'Ch46':(1,9),
- 'Ch47':(1,10),
- 'Ch70':(2,0),
- 'Ch69':(2,1),
- 'Ch68':(2,2),
- 'Ch67':(2,3),
- 'Ch66':(2,4),
- 'Ch42':(2,5),
- 'Ch41':(2,6),
- 'Ch40':(2,7),
- 'Ch39':(2,8),
- 'Ch38':(2,9),
- 'Ch37':(2,10),
- 'Ch01':(3,0),
- 'Ch02':(3,1),
- 'Ch03':(3,2),
- 'Ch04':(3,3),
- 'Ch05':(3,4),
- 'Ch06':(3,5),
- 'Ch30':(3,6),
- 'Ch31':(3,7),
- 'Ch32':(3,8),
- 'Ch33':(3,9),
- 'Ch34':(3,10),
- 'Ch11':(4,0),
- 'Ch10':(4,1),
- 'Ch09':(4,2),
- 'Ch08':(4,3),
- 'Ch07':(4,4),
- 'Ch29':(4,5),
- 'Ch28':(4,6),
- 'Ch27':(4,7),
- 'Ch26':(4,8),
- 'Ch25':(4,9),
- 'Ch24':(4,10),
- 'Ch12':(0,0),
- 'Ch59':(5,0),
- 'Ch13':(5,1),
- 'Ch14':(5,2),
- 'Ch15':(5,3),
- 'Ch16':(5,4),
- 'Ch17':(5,5),
- 'Ch18':(5,6),
- 'Ch19':(5,7),
- 'Ch20':(5,8),
- 'Ch21':(5,9),
- 'Ch22':(5,10)}
- if __name__ == '__main__':
-
- ColTrs = {}
- for i in range(6):
- ColTrs[i] = [None] * 11
- for k, v in MCSMapFacingDown.iteritems():
- ColTrs[v[0]][v[1]] = k
-
-
- ##### 3rd session
- InFileM = '../Raw Data/2019-07-31T18-00-05B12784O18-T2-Longterm-Rec2.h5'
- InFileS = '../Raw Data/2019-07-31T18-00-05B12784O18-T2-Longterm-Rec2_2.h5'
- CalFile = dd.io.load('../CalibrationFile/Cal-Gm20190731_033840.h5')
- DatFile = '../Matlab/2019-07-31T18-00-05B12784O18-T2-Longterm-Rec2'
- Bits = 16
- vgs = 0.25
- gmsign = -1
- Range = 20e-3
-
- ivgainDC = pq.A/(118.8*pq.V)
- ivgainAC = pq.A/(1188*pq.V)
- Fhigh = 100
- Flow = 0.001
-
- DCchs = ('ME5', 'ME7', 'ME29', 'ME31', 'SE5', 'SE7', 'SE29', 'SE31')
- ACchs = MCSMapFacingDown.keys()
- Enc = ['M1','M2','S1','S2']
-
- Rec = ReadMCSFile(InFileM,
- OutSeg=None,
- SigNamePrefix='M')
-
- Rec = ReadMCSFile(InFileS,
- OutSeg=Rec,
- SigNamePrefix='S')
-
-
- plt.close('all')
-
- #%% Plot AC ############################################################
- plt.close('all')
- FigSize = (25*0.394, 15*0.394)
- Twind = (0*pq.s, None)
- VgsInVivo = CalFile['Vgs']
- CalRec = NeoSegment()
- tstop = np.array([])
-
- for sig in Rec.Signals():
- tstop = np.append(tstop,sig.t_stop)
- Twind = [0*pq.s, np.min(tstop)*pq.s]
-
- for isig, sig in enumerate(Rec.Signals()):
- if isig == 0:
- sig01 = sig.duplicate_with_new_array(np.zeros(len(sig.GetSignal(Time = Twind))))
- sig01.name = 'ME0'
- CalRec.AddSignal(sig01)
- if isig == 54:
- sig70 = sig.duplicate_with_new_array(np.zeros(len(sig.GetSignal(Time = Twind))))
- sig70.name = 'SE33'
- CalRec.AddSignal(sig70)
-
- if sig.name in Enc:
- continue
-
- gm = gmsign * np.interp(vgs,VgsInVivo,CalFile['GM'][sig.name])*pq.A/pq.V
- if CalFile['ChKo'][sig.name]==True:
- gm = 1.0*pq.A/pq.V
-
-
- SigProAC = [{'function': RPro.Gain, 'args': {'Gain': ivgainAC}},
- {'function': RPro.Gain, 'args': {'Gain': 1/gm}},
- {'function': RPro.RemoveDC, 'args': {}},
- ]
-
- SigProDC = [{'function': RPro.Gain, 'args': {'Gain': ivgainDC}},
- {'function': RPro.Gain, 'args': {'Gain': 1/gm}},
- {'function': RPro.SetZero, 'args': {'TWind': (None, 20*pq.s)}},
- {'function': RPro.Filter, 'args': {'Type':'highpass',
- 'Order':2,
- 'Freqs':(Flow,)}}
- ]
-
- sig = Rec.GetSignal(sig.name)
- if sig.name in DCchs:
- sig.ProcessChain = SigProDC
- else:
- sig.ProcessChain = SigProAC
- sig = sig.GetSignal(Time = Twind)
-
-
- CalRec.AddSignal(sig)
-
-
- ChNames = {val:key for (key, val) in CalRec.SigNames.items()}
-
- SigProEnc = [{'function': RPro.Gain, 'args': {'Gain': 1.0/50}},
- ]
- M1sig = Rec.GetSignal('M1')
- M2sig = Rec.GetSignal('M2')
- M1sig.ProcessChain = SigProEnc
- M2sig.ProcessChain = SigProEnc
- M1sig = M1sig.GetSignal(Time = Twind)
- M2sig = M2sig.GetSignal(Time = Twind)
- CalRec.AddSignal(M1sig)
- CalRec.AddSignal(M2sig)
- ChNames[66] = 'M1'
- ChNames[67] = 'M2'
-
- SortMap = np.ndarray([7, 11], dtype=object)
-
- for key, val in MCSMapFacingDown.items():
- SortMap[val[0], val[1]] = MCSMap[key]
- SortMap[6,0] ='M1'
- SortMap[6,1] ='M2'
- NeuroScopeMap = []
- for col in SortMap:
- ColName = []
- ColCh = []
- for ch in col:
- if ch ==None:
- continue
- ColName.append(ch)
- ColCh.append(CalRec.SigNames[ch])
- NeuroScopeMap.append((ColName, ColCh))
-
-
- ExpDat = CalRec.ExportNeuroscope(DatFile, Range, Bits,'V', ChNames, NeuroScopeMap)
-
- print('File exported to Neuroscope format, see "Cal Data" folder')
-
|