コード例 #1
0
ファイル: tests.py プロジェクト: pyfusion/pyfusion
    def test_channel_list(self):

        ch01 = Channel('test_1', Coords('dummy', (0,0,0)))
        ch02 = Channel('test_2', Coords('dummy', (0,0,0)))
        ch03 = Channel('test_3', Coords('dummy', (0,0,0)))
                       
        new_cl = ChannelList([ch01, ch02, ch03])
コード例 #2
0
ファイル: tests.py プロジェクト: pyfusion/pyfusion
    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')
コード例 #3
0
ファイル: tests.py プロジェクト: pyfusion/pyfusion
 def test_channels_SQL(self):
     test_coords = Coords('cylindrical',(0.0,0.0,0.0))
     test_ch = Channel('test_1', test_coords)
     test_ch.save()
     if pyfusion.orm_manager.IS_ACTIVE:
         session = pyfusion.orm_manager.Session()
         our_channel = session.query(Channel).first()
         self.assertEqual(our_channel.name, 'test_1')
コード例 #4
0
ファイル: tests.py プロジェクト: pyfusion/pyfusion
 def test_ORM_floatdelta(self):
     """ check that floatdelta can be saved to database"""
     channel_01 = Channel('channel_01', Coords('dummy', (0,0,0)))
     channel_02 = Channel('channel_02', Coords('dummy', (0,0,0)))
     fd = FloatDelta(channel_01, channel_02, 0.45)
     fd.save()
     if pyfusion.orm_manager.IS_ACTIVE:
         session = pyfusion.orm_manager.Session()
         db_fd = session.query(FloatDelta).first()
         self.assertEqual(db_fd.delta, 0.45)
コード例 #5
0
ファイル: fetch_local.py プロジェクト: SyntaxVoid/PyFusionGUI
    def do_fetch(self):
        chan_name = (self.diag_name.split('-'))[-1]  # remove -
        filename_dict = {'diag_name': chan_name, 'shot': self.shot}

        self.basename = path.join(pf.config.get('global', 'localdatapath'),
                                  data_filename % filename_dict)

        files_exist = path.exists(self.basename)
        if not files_exist:
            raise Exception, "file " + self.basename + " not found."
        else:
            signal_dict = newload(self.basename)

        if ((chan_name == array(['MP5', 'HMP13', 'HMP05'])).any()): flip = -1.
        else: flip = 1.
        if self.diag_name[0] == '-': flip = -flip
        #        coords = get_coords_for_channel(**self.__dict__)
        ch = Channel(self.diag_name, Coords('dummy', (0, 0, 0)))
        output_data = TimeseriesData(
            timebase=Timebase(signal_dict['timebase']),
            signal=Signal(flip * signal_dict['signal']),
            channels=ch)
        output_data.meta.update({'shot': self.shot})

        return output_data
コード例 #6
0
ファイル: fetch.py プロジェクト: pyfusion/pyfusion
 def do_fetch(self):
     output_data = super(H1DataFetcher, self).do_fetch()
     coords = get_coords_for_channel(**self.__dict__)
     ch = Channel(self.mds_path, coords)
     output_data.channels = ch
     output_data.meta.update({'shot': self.shot, 'kh': self.get_kh()})
     return output_data
コード例 #7
0
ファイル: tests.py プロジェクト: pyfusion/pyfusion
 def test_timebase_and_coords(self):
     n_ch = 10
     n_samples = 1024
     timebase = Timebase(np.arange(n_samples)*1.e-6)
     channels = ChannelList(*(Channel('ch_%d' %i, Coords('cylindrical',(1.0,i,0.0))) for i in 2*np.pi*np.arange(n_ch)/n_ch))
     multichannel_data = get_multimode_test_data(channels = channels,
                                                 timebase = timebase,
                                                 noise = 0.5)
コード例 #8
0
ファイル: tests.py プロジェクト: pyfusion/pyfusion
    def test_channellist_ORM(self):

        ch01 = Channel('test_1', Coords('dummy', (0,0,0)))
        ch02 = Channel('test_2', Coords('dummy', (0,0,0)))
        ch03 = Channel('test_3', Coords('dummy', (0,0,0)))

        new_cl = ChannelList(ch03, ch01, ch02)

        new_cl.save()

        # get our channellist
        if pyfusion.orm_manager.IS_ACTIVE:
            session = pyfusion.orm_manager.Session()
            our_channellist = session.query(ChannelList).order_by("id").first()

            self.assertEqual(our_channellist[0].name, 'test_3')
            self.assertEqual(our_channellist[1].name, 'test_1')
            self.assertEqual(our_channellist[2].name, 'test_2')
コード例 #9
0
ファイル: tests.py プロジェクト: pyfusion/pyfusion
    def test_remove_mean_single_channel(self):
        tb = generate_timebase(t0=-0.5, n_samples=1.e2, sample_freq=1.e2)
        # nonzero signal mean
        tsd = TimeseriesData(timebase=tb,
                             signal=Signal(np.arange(len(tb))), channels=ChannelList(Channel('ch_01',Coords('dummy',(0,0,0)))))

        filtered_tsd = tsd.subtract_mean()

        assert_almost_equal(np.mean(filtered_tsd.signal), 0)
コード例 #10
0
ファイル: fetch.py プロジェクト: SyntaxVoid/PyFusionGUI
 def do_fetch(self):
     print(self.shot, self.mds_path)
     output_data = super(DIIIDDataFetcher, self).do_fetch()
     coords = get_coords_for_channel(**self.__dict__)
     ch = Channel(self.mds_path, coords)
     output_data.channels = ch
     output_data.meta.update({'shot': self.shot})
     output_data.config_name = ch
     return output_data
コード例 #11
0
def fetch_data_from_file(fetcher):
    prm_dict = read_prm_file(fetcher.basename + ".prm")
    bytes = int(prm_dict['DataLength(byte)'][0])
    bits = int(prm_dict['Resolution(bit)'][0])
    if not (prm_dict.has_key('ImageType')):  #if so assume unsigned
        bytes_per_sample = 2
        dat_arr = Array.array('H')
        offset = 2**(bits - 1)
        dtype = np.dtype('uint16')
    else:
        if prm_dict['ImageType'][0] == 'INT16':
            bytes_per_sample = 2
            if prm_dict['BinaryCoding'][0] == 'offset_binary':
                dat_arr = Array.array('H')
                offset = 2**(bits - 1)
                dtype = np.dtype('uint16')
            elif prm_dict['BinaryCoding'][0] == "shifted_2's_complementary":
                dat_arr = Array.array('h')
                offset = 0
                dtype = np.dtype('int16')
            else:
                raise NotImplementedError, ' binary coding ' + prm_dict[
                    'BinaryCoding']

    fp = open(fetcher.basename + '.dat', 'rb')
    dat_arr.fromfile(fp, bytes / bytes_per_sample)
    fp.close()

    clockHz = None

    if prm_dict.has_key('SamplingClock'):
        clockHz = double(prm_dict['SamplingClock'][0])
    if prm_dict.has_key('SamplingInterval'):
        clockHz = clockHz / double(prm_dict['SamplingInterval'][0])
    if prm_dict.has_key('ClockSpeed'):
        if clockHz != None:
            pyfusion.utils.warn(
                'Apparent duplication of clock speed information')
        clockHz = double(prm_dict['ClockSpeed'][0])
        clockHz = LHD_A14_clk(fetcher.shot)  # see above
    if clockHz != None:
        timebase = arange(len(dat_arr)) / clockHz
    else:
        raise NotImplementedError, "timebase not recognised"

    ch = Channel("%s-%s" % (fetcher.diag_name, fetcher.channel_number),
                 Coords('dummy', (0, 0, 0)))
    if fetcher.gain != None:
        gain = fetcher.gain
    else:
        gain = 1
    output_data = TimeseriesData(timebase=Timebase(timebase),
                                 signal=Signal(gain * dat_arr),
                                 channels=ch)
    output_data.meta.update({'shot': fetcher.shot})

    return output_data
コード例 #12
0
ファイル: tests.py プロジェクト: pyfusion/pyfusion
 def test_dataset_filter_nocopy(self):
     n_ch = 10
     n_samples = 640
     timebase = Timebase(np.arange(n_samples)*1.e-6)
     channels = ChannelList(*(Channel('ch_%d' %i, Coords('cylindrical',(1.0,i,0.0))) for i in 2*np.pi*np.arange(n_ch)/n_ch))
     multichannel_data = get_multimode_test_data(channels = channels,
                                                 timebase = timebase,
                                                 noise = 0.5)
     dataset = multichannel_data.segment(64, copy=False)
     new_dataset = dataset.segment(16, copy=False)
コード例 #13
0
    def do_fetch(self):
        # TODO support non-signal datatypes
        if self.fetch_mode == 'thin client':
            ch = Channel(self.mds_path_components['nodepath'],
                         Coords('dummy', (0, 0, 0)))
            data = self.acq.connection.get(
                self.mds_path_components['nodepath'])
            dim = self.acq.connection.get('dim_of(%s)' %
                                          self.mds_path_components['nodepath'])
            # TODO: fix this hack (same hack as when getting signal from node)
            if len(data.shape) > 1:
                data = np.array(data)[0, ]
            if len(dim.shape) > 1:
                dim = np.array(dim)[0, ]
            output_data = TimeseriesData(timebase=Timebase(dim),
                                         signal=Signal(data),
                                         channels=ch)
            output_data.meta.update({'shot': self.shot})
            return output_data

        elif self.fetch_mode == 'http':
            data_url = self.acq.server + '/'.join([
                self.mds_path_components['tree'],
                str(self.shot), self.mds_path_components['tagname'],
                self.mds_path_components['nodepath']
            ])

            data = mdsweb.data_from_url(data_url)
            ch = Channel(self.mds_path_components['nodepath'],
                         Coords('dummy', (0, 0, 0)))
            t = Timebase(data.data.dim)
            s = Signal(data.data.signal)
            output_data = TimeseriesData(timebase=t, signal=s, channels=ch)
            output_data.meta.update({'shot': self.shot})
            return output_data

        else:
            node = self.tree.getNode(self.mds_path)
            if int(node.dtype) == 195:
                return get_tsd_from_node(self, node)
            else:
                raise Exception('Unsupported MDSplus node type')
コード例 #14
0
ファイル: tests.py プロジェクト: pyfusion/pyfusion
 def test_timeseries_filter_nocopy(self):
     # Use reduce_time filter for testing...
     n_ch = 10
     n_samples = 5000
     timebase = Timebase(np.arange(n_samples)*1.e-6)
     channels = ChannelList(*(Channel('ch_%d' %i, Coords('cylindrical',(1.0,i,0.0))) for i in 2*np.pi*np.arange(n_ch)/n_ch))
     multichannel_data = get_multimode_test_data(channels = channels,
                                                 timebase = timebase,
                                                 noise = 0.5)
     new_data = multichannel_data.reduce_time([0,1.e-3], copy=False)
     self.assertTrue(new_data is multichannel_data)
コード例 #15
0
ファイル: fetch.py プロジェクト: SyntaxVoid/PyFusionGUI
 def fetch(self):
     tb = generate_timebase(t0=float(self.t0),
                            n_samples=int(self.n_samples),
                            sample_freq=float(self.sample_freq))
     sig = Signal(
         float(self.amplitude) * sin(2 * pi * float(self.frequency) * tb))
     dummy_channel = Channel('ch_01', Coords('dummy', (0, 0, 0)))
     output_data = TimeseriesData(timebase=tb,
                                  signal=sig,
                                  channels=ChannelList(dummy_channel))
     output_data.meta.update({'shot': self.shot})
     return output_data
コード例 #16
0
ファイル: tests.py プロジェクト: SyntaxVoid/PyFusionGUI
    def test_remove_noncontiguous(self):
        tb1 = generate_timebase(t0=-0.5, n_samples=1.e2, sample_freq=1.e2)
        tb2 = generate_timebase(t0=-0.5, n_samples=1.e2, sample_freq=1.e2)
        tb3 = generate_timebase(t0=-0.5, n_samples=1.e2, sample_freq=1.e2)
        # nonzero signal mean
        tsd1 = TimeseriesData(timebase=tb1,
                              signal=Signal(np.arange(len(tb1))),
                              channels=ChannelList(
                                  Channel('ch_01', Coords('dummy',
                                                          (0, 0, 0)))))
        tsd2 = TimeseriesData(timebase=tb2,
                              signal=Signal(np.arange(len(tb2))),
                              channels=ChannelList(
                                  Channel('ch_01', Coords('dummy',
                                                          (0, 0, 0)))))
        tsd3 = TimeseriesData(timebase=tb3,
                              signal=Signal(np.arange(len(tb3))),
                              channels=ChannelList(
                                  Channel('ch_01', Coords('dummy',
                                                          (0, 0, 0)))))

        self.assertTrue(tb1.is_contiguous())
        self.assertTrue(tb2.is_contiguous())
        self.assertTrue(tb3.is_contiguous())
        tsd2.timebase[-50:] += 1.0
        self.assertFalse(tb2.is_contiguous())

        ds = DataSet('ds')
        for tsd in [tsd1, tsd2, tsd3]:
            ds.add(tsd)

        for tsd in [tsd1, tsd2, tsd3]:
            self.assertTrue(tsd in ds)

        filtered_ds = ds.remove_noncontiguous()
        for tsd in [tsd1, tsd3]:
            self.assertTrue(tsd in filtered_ds)

        self.assertFalse(tsd2 in filtered_ds)
コード例 #17
0
def get_probe_angles(input_data, closed=False):
    """  
    return a list of thetas for a given signal (timeseries) or a string that specifies it.
              get_probe_angles('W7X:W7X_MIRNOV_41_BEST_LOOP:(20180912,43)')

    This is a kludgey way to read coordinates.  Should be through acquisition.base or
    acquisition.'device' rather than looking up config directly
    """
    import pyfusion
    if isinstance(input_data, str):
        pieces = input_data.split(':')
        if len(pieces) == 3:
            dev_name, diag_name, shotstr = pieces
            shot_number = eval(shotstr)
            dev = pyfusion.getDevice(dev_name)
            data = dev.acq.getdata(shot_number, diag_name, time_range=[0, 0.1])
        else:
            from pyfusion.data.timeseries import TimeseriesData, Timebase, Signal
            from pyfusion.data.base import Channel, ChannelList, Coords
            input_data = TimeseriesData(Timebase([0, 1]), Signal([0, 1]))
            dev_name, diag_name = pieces
            # channels are amongst options
            opts = pyfusion.config.pf_options('Diagnostic', diag_name)
            chans = [
                pyfusion.config.pf_get('Diagnostic', diag_name, opt)
                for opt in opts if 'channel_' in opt
            ]
            # for now, assume config_name is some as name
            input_data.channels = ChannelList(
                *[Channel(ch, Coords('?', [0, 0, 0])) for ch in chans])

    Phi = np.array([
        2 * np.pi / 360 * float(
            pyfusion.config.get(
                'Diagnostic:{cn}'.format(
                    cn=c.config_name if c.config_name != '' else c.name),
                'Coords_reduced').split(',')[0]) for c in input_data.channels
    ])

    Theta = np.array([
        2 * np.pi / 360 * float(
            pyfusion.config.get(
                'Diagnostic:{cn}'.format(
                    cn=c.config_name if c.config_name != '' else c.name),
                'Coords_reduced').split(',')[1]) for c in input_data.channels
    ])

    if closed:
        Phi = np.append(Phi, Phi[0])
        Theta = np.append(Theta, Theta[0])
    return (dict(Theta=Theta, Phi=Phi))
コード例 #18
0
    def do_fetch(self):
        channel_length = int(self.length)
        outdata = np.zeros(1024 * 2 * 256 + 1)
        ##  !! really should put a wrapper around gethjdata to do common stuff
        #  outfile is only needed if the direct passing of binary won't work
        #  with tempfile.NamedTemporaryFile(prefix="pyfusion_") as outfile:
        # get in two steps to make debugging easier
        allrets = gethjdata.gethjdata(self.shot,
                                      channel_length,
                                      self.path,
                                      verbose=VERBOSE,
                                      opt=1,
                                      ierror=2,
                                      isample=-1,
                                      outdata=outdata,
                                      outname='')
        ierror, isample, getrets = allrets
        if ierror != 0:
            raise LookupError(
                'hj Okada style data not found for {s}:{c}'.format(
                    s=self.shot, c=self.path))

        ch = Channel(self.path, Coords('dummy', (0, 0, 0)))

        # the intent statement causes the out var to be returned in the result lsit
        # looks like the time,data is interleaved in a 1x256 array
        # it is fed in as real*64, but returns as real*32! (as per fortran decl)
        debug_(pyfusion.DEBUG,
               4,
               key='Heliotron_fetch',
               msg='after call to getdata')
        # timebase in secs (ms in raw data) - could add a preferred unit?
        # this is partly allowed for in savez_compressed, newload, and
        # for plotting, in the config file.
        # important that the 1e-3 be inside the Timebase()
        output_data = TimeseriesData(timebase=Timebase(
            1e-3 * getrets[1::2][0:isample]),
                                     signal=Signal(getrets[2::2][0:isample]),
                                     channels=ch)
        output_data.meta.update({'shot': self.shot})
        if pyfusion.VERBOSE > 0: print('HJ config name', self.config_name)
        output_data.config_name = self.config_name
        stprms = get_static_params(shot=self.shot, signal=self.path)
        if len(list(stprms)
               ) == 0:  # maybe this should be ignored - how do we use it?
            raise LookupError(
                ' failure to get params for {shot}:{path}'.format(
                    shot=self.shot, path=self.path))
        output_data.params = stprms
        return output_data
コード例 #19
0
ファイル: fetch.py プロジェクト: SyntaxVoid/PyFusionGUI
 def do_fetch(self):
     output_data = super(H1DataFetcher, self).do_fetch()
     coords = get_coords_for_channel(**self.__dict__)
     ch = Channel(self.mds_path, coords)
     output_data.channels = ch
     #SH modified so that we can see different main currents for different field strengths
     main_current, sec_current, kh = self.get_kh()
     output_data.meta.update({
         'shot': self.shot,
         'kh': kh,
         'main_current': main_current,
         'sec_current': sec_current,
         'heating_freq': self.get_heating_freq()
     })
     return output_data
コード例 #20
0
ファイル: fetch.py プロジェクト: pyfusion/pyfusion
     def do_fetch(self):
         channel_length = int(self.length)
         outdata=np.zeros(1024*2*256+1)
         with tempfile.NamedTemporaryFile(prefix="pyfusion_") as outfile:
             getrets=gethjdata.gethjdata(self.shot,channel_length,self.path,
                                         VERBOSE, OPT,
                                         outfile.name, outdata)
         ch = Channel(self.path,
                      Coords('dummy', (0,0,0)))

         output_data = TimeseriesData(timebase=Timebase(getrets[1::2]),
                                 signal=Signal(getrets[2::2]), channels=ch)
         output_data.meta.update({'shot':self.shot})
         
         return output_data
コード例 #21
0
 def do_fetch(self):
     print(self.pointname)
     print(self.shot)
     if self.NC!=None:
         print(self.NC)
         t_name = '{}_time'.format(self.pointname)
         NC_vars = self.NC.variables.keys()
         if self.pointname in NC_vars:
             print('Reading cache!!!!')
             t_axis = self.NC.variables[t_name].data[:].copy()
             data = self.NC.variables[self.pointname].data[:].copy()
     else:
         tmp = self.acq.connection.get('ptdata2("{}",{})'.format(self.pointname, self.shot))
         data = tmp.data()
         tmp = self.acq.connection.get('dim_of(ptdata2("{}",{}))'.format(self.pointname, self.shot))
         t_axis = tmp.data()
         self.write_cache = True
     print(t_axis)
     print(data)
     coords = get_coords_for_channel(**self.__dict__)
     ch = Channel(self.pointname, coords)
     # con=MDS.Connection('atlas.gat.com::')
     # pointname = 'MPI66M067D'
     # shot = 164950
     # tmp = con.get('ptdata2("{}",{})'.format(pointname, shot))
     # dat = tmp.data()
     # tmp = con.get('dim_of(ptdata2("{}",{}))'.format(pointname, shot))
     # t = tmp.data()
     if self.NC!=None and self.write_cache:
         print self.pointname
         self.NC.createDimension(t_name, len(t_axis))
         f_time = self.NC.createVariable(t_name,'d',(t_name,))
         f_time[:] = +t_axis
         print('Wrote time')
         sig = self.NC.createVariable(self.pointname,'f',(t_name,))
         sig[:] = +data
         print('Wrote signal')
     output_data = TimeseriesData(timebase=Timebase(t_axis),
                             signal=Signal(data), channels=ch)
     # output_data = super(DIIIDDataFetcherPTdata, self).do_fetch()
     # coords = get_coords_for_channel(**self.__dict__)
     # ch = Channel(self.mds_path, coords)
     # output_data.channels = ch
     # output_data.meta.update({'shot':self.shot, 'kh':self.get_kh()})
     # print(ch)
     output_data.config_name = ch
     self.fetch_mode = 'ptdata'
     return output_data
コード例 #22
0
ファイル: tests.py プロジェクト: pyfusion/pyfusion
    def test_svd_data(self):
        n_ch = 10
        n_samples = 1024
        timebase = Timebase(np.arange(n_samples)*1.e-6)
        channels = ChannelList(*(Channel('ch_%02d' %i, Coords('cylindrical',(1.0,i,0.0))) for i in 2*np.pi*np.arange(n_ch)/n_ch))
        multichannel_data = get_multimode_test_data(channels = channels,
                                                    timebase = timebase,
                                                    noise = 0.5)

        test_svd = multichannel_data.svd()
        self.assertTrue(isinstance(test_svd, SVDData))
        self.assertEqual(len(test_svd.topos[0]), n_ch)
        self.assertEqual(len(test_svd.chronos[0]), n_samples)
        assert_array_almost_equal(test_svd.chrono_labels, timebase)
        for c_i, ch in enumerate(channels):
            self.assertEqual(ch, test_svd.channels[c_i])
コード例 #23
0
def get_tsd_from_node(fetcher, node):
    """Return pyfusion TimeSeriesData corresponding to an MDSplus signal node."""
    # TODO: load actual coordinates
    ch = Channel(fetcher.mds_path_components['nodepath'],
                 Coords('dummy', (0, 0, 0)))
    signal = Signal(node.data())
    dim = node.dim_of().data()
    # TODO: stupid hack,  the test signal has dim  of [[...]], real data
    # has [...].  Figure out  why. (...probably because  original signal
    # uses a build_signal function)
    if len(dim) == 1:
        dim = dim[0]
    timebase = Timebase(dim)
    output_data = TimeseriesData(timebase=timebase, signal=signal, channels=ch)
    output_data.meta.update({'shot': fetcher.shot})
    return output_data
コード例 #24
0
ファイル: tests.py プロジェクト: pyfusion/pyfusion
    def test_flucstruc_phases(PfTestCase):
        
        n_ch = 10
        n_samples = 5000
        timebase = Timebase(np.arange(n_samples)*1.e-6)
        channels = ChannelList(*(Channel('ch_%d' %i, Coords('cylindrical',(1.0,i,0.0))) for i in 2*np.pi*np.arange(n_ch)/n_ch))
        multichannel_data = get_multimode_test_data(channels = channels,
                                                    timebase = timebase,
                                                    noise = 0.5)

        data_reduced_time=multichannel_data.reduce_time([0,0.002]).subtract_mean().normalise(method='v',separate=True)

        fs_set=data_reduced_time.flucstruc()
        phases = []
        for fs in fs_set:
            for j in range(0,len(fs.dphase)):
                phases.append(fs.dphase[j].delta)
コード例 #25
0
ファイル: fetch.py プロジェクト: SyntaxVoid/PyFusionGUI
    def do_fetch(self):
        print("Shot: {}\nPoint Name: {}".format(self.shot, self.pointname))
        if not hasattr(self, 'NC'):
            self.NC = None
        if self.NC is not None:
            #print(self.NC)
            t_name = '{}_time'.format(self.pointname)
            NC_vars = self.NC.variables.keys()
        else:
            NC_vars = []
        if self.pointname in NC_vars:
            print('   Pointname in NC cache, Reading...\n')
            t_axis = self.NC.variables[t_name].data[:].copy()
            data = self.NC.variables[self.pointname].data[:].copy()
            self.write_cache = False
        else:
            print('   Fetching from ptdata')
            tmp = self.acq.connection.get('ptdata2("{}",{})'.format(
                self.pointname, self.shot))
            data = tmp.data()
            tmp = self.acq.connection.get('dim_of(ptdata2("{}",{}))'.format(
                self.pointname, self.shot))
            t_axis = tmp.data()
            self.write_cache = True
        coords = get_coords_for_channel(**self.__dict__)
        ch = Channel(self.pointname, coords)
        if self.NC is not None and self.write_cache:

            print("\t Writing to NC file disabled temporarily.")

            #print('   Writing pointname to NC file\n')
            #self.NC.createDimension(t_name, len(t_axis))
            #f_time = self.NC.createVariable(t_name,'d',(t_name,))
            #f_time[:] = +t_axis
            # sig = self.NC.createVariable(self.pointname,'f',(t_name,))
            #sig[:] = +data
        output_data = TimeseriesData(timebase=Timebase(t_axis),
                                     signal=Signal(data),
                                     channels=ch)
        output_data.config_name = ch
        self.fetch_mode = 'ptdata'
        return output_data
コード例 #26
0
ファイル: fetch.py プロジェクト: pyfusion/pyfusion
    def do_fetch(self):
        print self.shot, self.senal
        data_dim = tjiidata.dimens(self.shot, self.senal)
        if data_dim[0] < MAX_SIGNAL_LENGTH:
            data_dict = tjiidata.lectur(self.shot, self.senal, data_dim[0],
                                        data_dim[0], data_dim[1])
        else:
            raise ValueError, 'Not loading data to avoid segmentation fault in tjiidata.lectur'
        ch = Channel(self.senal, Coords('dummy', (0, 0, 0)))

        if self.invert == 'true':  #yuk - TODO: use boolean type from config
            s = Signal(-np.array(data_dict['y']))
        else:
            s = Signal(np.array(data_dict['y']))

        output_data = TimeseriesData(timebase=Timebase(data_dict['x']),
                                     signal=s,
                                     channels=ch)
        output_data.meta.update({'shot': self.shot})
        return output_data
コード例 #27
0
 def do_fetch(self):
     sig = self.conn.get(self.mds_path)
     dim = self.conn.get('DIM_OF(' + self.mds_path + ')')
     scl = 1.0
     coords = get_coords_for_channel(**self.__dict__)
     ch = Channel(self.config_name, coords)
     timedata = dim.data()
     output_data = TimeseriesData(timebase=Timebase(1e-9 * timedata),
                                  signal=scl * Signal(sig),
                                  channels=ch)
     output_data.meta.update({'shot': self.shot})
     if hasattr(self, 'mdsshot'):  # intended for checks - not yet used.
         output_data.mdsshot = self.mdsshot
     output_data.config_name = self.config_name
     output_data.utc = [timedata[0], timedata[-1]]
     #output_data.units = dat['units'] if 'units' in dat else ''
     debug_(pyfusion.DEBUG,
            level=1,
            key='W7M_do_fetch',
            msg='entering W7X MDS do_fetch')
     return (output_data)
コード例 #28
0
ファイル: fetch_local.py プロジェクト: bdb112/pyfusion
    def do_fetch(self):
        chan_name = (self.diag_name.split('-'))[-1]  # remove -
        filename_dict = {'shot':self.shot, # goes with Boyd's local stg
                         'config_name':self.config_name}

        #filename_dict = {'diag_name':self.diag_name, # goes with retrieve names
        #                 'channel_number':self.channel_number,
        #                 'shot':self.shot}

        debug_(pf.DEBUG, 4, key='local_fetch')
        for each_path in pf.config.get('global', 'localdatapath').split('+'):
            self.basename = path.join(each_path, data_filename %filename_dict)
    
            files_exist = path.exists(self.basename)
            if files_exist: break

        if not files_exist:
            raise Exception("file {fn} not found. (localdatapath was {p})"
                            .format(fn=self.basename, 
                                    p=pf.config.get('global', 
                                                    'localdatapath').split('+')))
        else:
            signal_dict = newload(self.basename)
            
        if ((chan_name == array(['MP5','HMP13','HMP05'])).any()):  
            flip = -1.
            print('flip')
        else: flip = 1.
        if self.diag_name[0]=='-': flip = -flip
#        coords = get_coords_for_channel(**self.__dict__)
        ch = Channel(self.diag_name,  Coords('dummy', (0,0,0)))
        output_data = TimeseriesData(timebase=Timebase(signal_dict['timebase']),
                                 signal=Signal(flip*signal_dict['signal']), channels=ch)
        # bdb - used "fetcher" instead of "self" in the "direct from LHD data" version
        output_data.config_name = self.config_name  # when using saved files, same as name
        output_data.meta.update({'shot':self.shot})

        return output_data
コード例 #29
0
import bz2
from pyfusion.acquisition.base import BaseDataFetcher
from pyfusion.data.timeseries import Signal, Timebase, TimeseriesData
from pyfusion.data.base import Coords, Channel, ChannelList

import numpy as np
#####

# Generate generic channel with dummy coordinates.
generic_ch = lambda x: Channel('channel_%03d' %
                               (x + 1), Coords('dummy', (x, 0, 0)))

named_ch = lambda x: Channel(x, Coords('dummy', (x, 0, 0)))


class BinaryMultiChannelTimeseriesFetcher(BaseDataFetcher):
    """Fetch binary data from specified filename.

    
    This data fetcher uses two configuration parameters, filename (required) and a dtype specification

    The filename parameter can include a substitution string ``(shot)`` which will be replaced with the shot number.

    dtype will be evaluated as string, numpy can be used with np namespace
    e.g. np.float32

    """
    def read_dtype(self):
        dtype = self.__dict__.get("dtype", None)
        return eval(dtype)
コード例 #30
0
ファイル: tests.py プロジェクト: pyfusion/pyfusion
def get_n_channels(n_ch):
    """Return a list of n_ch channels."""
    poloidal_coords = 2*np.pi*np.arange(n_ch)/n_ch
    channel_gen = (Channel('ch_%02d' %i, Coords('cylindrical', (1.0,i,0.0)))
                   for i in poloidal_coords)
    return ChannelList(*channel_gen)