def _get_dphase(self, min_dphase = -np.pi, get_fourier_value=0): """ remap to [min_dphase, min_dphase+2pi] #SRH modified 24June2013 to return the complex value also """ if get_fourier_value==0: phases = np.array([self._get_single_channel_phase(i) for i in range(self.signal.shape[0])]) else: fourier_vals = []; phases = [] for i in range(self.signal.shape[0]): phases_tmp, fourier_vals_tmp = self._get_single_channel_phase(i, get_fourier_value = 1) phases.append(phases_tmp) fourier_vals.append(fourier_vals_tmp) phases = np.array(phases) fourier_vals = np.array(fourier_vals) d_phases = remap_periodic(phases[1:]-phases[:-1], min_val = min_dphase) #d_phase_dataset = OrderedDataSet(ordered_by="channel_1.name") d_phase_dataset = BaseOrderedDataSet('d_phase_%s' %datetime.now()) ## append then sort should be faster than ordereddataset.add() [ fewer sorts()] if self.phase_pairs != None: for i,phase_pair in enumerate(self.phase_pairs): ind_a = self.channels.get_channel_index(phase_pair[0]) ind_b = self.channels.get_channel_index(phase_pair[1]) d_phase_dataset.append(FloatDelta(self.channels[ind_a],self.channels[ind_b],d_phases[i])) else: for i, d_ph in enumerate(d_phases): d_phase_dataset.append(FloatDelta(self.channels[i], self.channels[i+1], d_ph)) #d_phase_dataset.sort() if get_fourier_value==0: return d_phase_dataset else: return d_phase_dataset, fourier_vals
def _get_dphase(self, min_dphase = -np.pi): """ remap to [min_dphase, min_dphase+2pi] """ phases = np.array([self._get_single_channel_phase(i) for i in range(self.signal.shape[0])]) debug_(pyfusion.DEBUG, 2, key='_get_dphase') if self.phase_pairs != None: tmp = [] for a,b in self.phase_pairs: ind_a = self.channels.get_channel_index(a) ind_b = self.channels.get_channel_index(b) tmp.append(phases[ind_b]-phases[ind_a]) d_phases=remap_periodic(np.array(tmp), min_val=min_dphase) else: d_phases = remap_periodic(phases[1:]-phases[:-1], min_val = min_dphase) #d_phase_dataset = OrderedDataSet(ordered_by="channel_1.name") d_phase_dataset = BaseOrderedDataSet('d_phase_%s' %datetime.now()) ## append then sort should be faster than ordereddataset.add() [ fewer sorts()] if self.phase_pairs != None: for i,phase_pair in enumerate(self.phase_pairs): ind_a = self.channels.get_channel_index(phase_pair[0]) ind_b = self.channels.get_channel_index(phase_pair[1]) d_phase_dataset.append(FloatDelta(self.channels[ind_a],self.channels[ind_b],d_phases[i])) else: for i, d_ph in enumerate(d_phases): d_phase_dataset.append(FloatDelta(self.channels[i], self.channels[i+1], d_ph)) #d_phase_dataset.sort() return d_phase_dataset
def test_baseordereddataset_label(self): test_ds = BaseOrderedDataSet('test_ods_1') test_ds.save() self.assertEqual(test_ds.label, 'test_ods_1') if pyfusion.orm_manager.IS_ACTIVE: session = pyfusion.orm_manager.Session() db_ods = session.query(BaseOrderedDataSet).filter_by(label='test_ods_1')
def _get_dphase(self, min_dphase = -np.pi, get_fourier_value=0): """ remap to [min_dphase, min_dphase+2pi] #SRH modified 24June2013 to return the complex value also """ if get_fourier_value==0: phases = np.array([self._get_single_channel_phase(i) for i in range(self.signal.shape[0])]) else: fourier_vals = []; phases = [] for i in range(self.signal.shape[0]): phases_tmp, fourier_vals_tmp = self._get_single_channel_phase(i, get_fourier_value = 1) phases.append(phases_tmp) fourier_vals.append(fourier_vals_tmp) phases = np.array(phases) fourier_vals = np.array(fourier_vals) d_phases = remap_periodic(phases[1:]-phases[:-1], min_val = min_dphase) #d_phase_dataset = OrderedDataSet(ordered_by="channel_1.name") d_phase_dataset = BaseOrderedDataSet('d_phase_%s' %datetime.now()) ## append then sort should be faster than ordereddataset.add() [ fewer sorts()] for i, d_ph in enumerate(d_phases): d_phase_dataset.append(FloatDelta(self.channels[i], self.channels[i+1], d_ph)) #d_phase_dataset.sort() if get_fourier_value==0: return d_phase_dataset else: return d_phase_dataset, fourier_vals
def test_ordered_dataset_ORM(self): channel_01 = Channel('channel_01', Coords('dummy', (0,0,0))) channel_02 = Channel('channel_02', Coords('dummy', (0,0,0))) channel_03 = Channel('channel_03', Coords('dummy', (0,0,0))) channel_04 = Channel('channel_04', Coords('dummy', (0,0,0))) fd1 = FloatDelta(channel_01, channel_02, 0.45) fd2 = FloatDelta(channel_02, channel_03, 0.25) fd3 = FloatDelta(channel_03, channel_04, 0.49) #ods = OrderedDataSet(ordered_by="channel_1.name") ods = BaseOrderedDataSet('test_ods') for fd in [fd3, fd1, fd2]: ods.append(fd) ods.save() # now read out of database if pyfusion.orm_manager.IS_ACTIVE: session = pyfusion.orm_manager.Session() db_ods = session.query(BaseOrderedDataSet).first() self.assertEqual(db_ods[0].channel_1.name, 'channel_03') self.assertEqual(db_ods[1].channel_1.name, 'channel_01') self.assertEqual(db_ods[2].channel_1.name, 'channel_02')
def _get_dphase(self, min_dphase=-np.pi): """ remap to [min_dphase, min_dphase+2pi] """ phases = np.array([ self._get_single_channel_phase(i) for i in range(self.signal.shape[0]) ]) debug_(pyfusion.DEBUG, 2, key='_get_dphase') if self.phase_pairs != None: tmp = [] for a, b in self.phase_pairs: ind_a = self.channels.get_channel_index(a) ind_b = self.channels.get_channel_index(b) tmp.append(phases[ind_b] - phases[ind_a]) d_phases = remap_periodic(np.array(tmp), min_val=min_dphase) else: d_phases = remap_periodic(phases[1:] - phases[:-1], min_val=min_dphase) #d_phase_dataset = OrderedDataSet(ordered_by="channel_1.name") d_phase_dataset = BaseOrderedDataSet('d_phase_%s' % datetime.now()) ## append then sort should be faster than ordereddataset.add() [ fewer sorts()] if self.phase_pairs != None: for i, phase_pair in enumerate(self.phase_pairs): ind_a = self.channels.get_channel_index(phase_pair[0]) ind_b = self.channels.get_channel_index(phase_pair[1]) d_phase_dataset.append( FloatDelta(self.channels[ind_a], self.channels[ind_b], d_phases[i])) else: for i, d_ph in enumerate(d_phases): d_phase_dataset.append( FloatDelta(self.channels[i], self.channels[i + 1], d_ph)) #d_phase_dataset.sort() return d_phase_dataset