Esempio n. 1
0
def get_coords_for_channel(channel_name=None, **kwargs):
    config_dict = kwargs.copy()
    if channel_name:
        config_dict.update(get_config_as_dict("Diagnostic", channel_name))
    coord_name = "dummy"
    coord_values = (0.0, 0.0, 0.0)
    transforms = []
    for k in config_dict.keys():
        if k.startswith("coords_"):
            coord_name = k[7:]
            coord_values = tuple(map(float, config_dict[k].split(",")))
    coords_instance = Coords(coord_name, coord_values)
    if "coord_transform" in config_dict:
        transform_list = pyfusion.config.pf_options("CoordTransform", config_dict["coord_transform"])
        for transform_name in transform_list:
            # this seems to return all the globals too
            transform_class_str = pyfusion.config.pf_get(
                "CoordTransform", config_dict["coord_transform"], transform_name
            )
            # so tyr to exclude the globals
            if pyfusion.config.has_option("global", transform_name):
                continue
            transform_class = import_from_str(transform_class_str)
            # if not hasattr(transform_class, 'output_coord'):
            #    raise Exception('??')
            coords_instance.load_transform(transform_class)
    debug_(pyfusion.DEBUG, 1, key=["coord", "device_name"])
    return coords_instance
Esempio n. 2
0
def get_coords_for_channel(channel_name=None, **kwargs):
    config_dict = kwargs.copy()
    if channel_name:
        config_dict.update(get_config_as_dict('Diagnostic', channel_name))
    coord_name = 'dummy'
    coord_values = (0.0,0.0,0.0)
    transforms = []
    for k in config_dict.keys():
        if k.startswith('coords_'):
            coord_name = k[7:]
            coord_values = tuple(map(float,config_dict[k].split(',')))
    coords_instance = Coords(coord_name, coord_values)
    if 'coord_transform' in config_dict:
        transform_list = pyfusion.config.pf_options('CoordTransform', config_dict['coord_transform'])
        for transform_name in transform_list:
            # this seems to return all the globals too
            transform_class_str = pyfusion.config.pf_get('CoordTransform', config_dict['coord_transform'], transform_name)
            # so tyr to exclude the globals
            if pyfusion.config.has_option('global',transform_name):
                continue
            transform_class = import_from_str(transform_class_str)
            #if not hasattr(transform_class, 'output_coord'):
            #    raise Exception('??')
            coords_instance.load_transform(transform_class)
    debug_(pyfusion.DEBUG,1, key=['coord', 'device_name'])        
    return coords_instance
Esempio n. 3
0
 def load_from_config(self, **kwargs):
     for kw in kwargs.iteritems():
         if kw[0] == 'coord_transform':
             transform_list = pyfusion.config.pf_options('CoordTransform', kw[1])
             for transform_name in transform_list:
                 transform_class_str = pyfusion.config.pf_get('CoordTransform', kw[1], transform_name)
                 transform_class = import_from_str(transform_class_str)
                 self.load_transform(transform_class)
         elif kw[0].startswith('coords_'):
             coord_values = tuple(map(float,kw[1].split(',')))
             self.add_coords(**{kw[0][7:]: coord_values})
Esempio n. 4
0
    def __init__(self, config_name, **kwargs):
        if pyfusion.config.pf_has_section('Device', config_name):
            self.__dict__.update(get_config_as_dict('Device', config_name))
        self.__dict__.update(kwargs)
        self.name = config_name

        #### attach acquisition
        if hasattr(self, 'acq_name'):
            acq_class_str = pyfusion.config.pf_get('Acquisition',
                                          self.acq_name, 'acq_class')
            self.acquisition = import_from_str(acq_class_str)(self.acq_name)
            # shortcut
            self.acq = self.acquisition
        else:
            pyfusion.logging.warning(
                "No acquisition class specified for device")
Esempio n. 5
0
    def getdata(self, shot, config_name=None, **kwargs):
        """Get the data and return prescribed subclass of BaseData.
        
        :param shot: shot number
        :param config_name: ?? bdb name of a fetcher class in the configuration file
        :returns: an instance of a subclass of \
        :py:class:`~pyfusion.data.base.BaseData` or \
        :py:class:`~pyfusion.data.base.BaseDataSet`

        This method needs to know which  data fetcher class to use, if a
        config_name      argument     is      supplied      then     the
        ``[Diagnostic:config_name]``   section   must   exist   in   the
        configuration   file  and   contain  a   ``data_fetcher``  class
        specification, for example::

         [Diagnostic:H1_mirnov_array_1_coil_1]
         data_fetcher = pyfusion.acquisition.H1.fetch.H1DataFetcher
         mds_path = \h1data::top.operations.mirnov:a14_14:input_1
         coords_cylindrical = 1.114, 0.7732, 0.355
         coord_transform = H1_mirnov

        If a ``data_fetcher`` keyword argument is supplied, it overrides
        the configuration file specification.

        The  fetcher  class  is  instantiated,  including  any  supplied
        keyword arguments, and the result of the ``fetch`` method of the
        fetcher class is returned.
        """
        from pyfusion import config
        # if there is a data_fetcher arg, use that, otherwise get from config
        if 'data_fetcher' in kwargs:
            fetcher_class_name = kwargs['data_fetcher']
        else:
            fetcher_class_name = config.pf_get('Diagnostic',
                                               config_name,
                                               'data_fetcher')
        fetcher_class = import_from_str(fetcher_class_name)
        ## Problem:  no check to see if it is a diag of the right device!??
        d = fetcher_class(self, shot,
                             config_name=config_name, **kwargs).fetch()
        d.history += "\n:: shot: {s} :: config: {c}".format(s=shot, c=config_name)

        return d
Esempio n. 6
0
def get_coords_for_channel(channel_name=None, **kwargs):
    config_dict = kwargs.copy()
    if channel_name:
        config_dict.update(get_config_as_dict('Diagnostic', channel_name))
    coord_name = 'dummy'
    coord_values = (0.0,0.0,0.0)
    transforms = []
    for k in config_dict.keys():
        if k.startswith('coords_'):
            coord_name = k[7:]
            coord_values = tuple(map(float,config_dict[k].split(',')))
    coords_instance = Coords(coord_name, coord_values)
    if config_dict.has_key('coord_transform'):
        transform_list = pyfusion.config.pf_options('CoordTransform', config_dict['coord_transform'])
        for transform_name in transform_list:
            transform_class_str = pyfusion.config.pf_get('CoordTransform', config_dict['coord_transform'], transform_name)
            transform_class = import_from_str(transform_class_str)
            coords_instance.load_transform(transform_class)

    return coords_instance
Esempio n. 7
0
    def getdata(self, shot, config_name=None, **kwargs):
        """Get the data and return prescribed subclass of BaseData.
        
        :param shot: shot number
        :param config_name: ?? bdb name of a fetcher class in the configuration file
        :returns: an instance of a subclass of \
        :py:class:`~pyfusion.data.base.BaseData` or \
        :py:class:`~pyfusion.data.base.BaseDataSet`

        This method needs to know which  data fetcher class to use, if a
        config_name      argument     is      supplied      then     the
        ``[Diagnostic:config_name]``   section   must   exist   in   the
        configuration   file  and   contain  a   ``data_fetcher``  class
        specification, for example::

         [Diagnostic:H1_mirnov_array_1_coil_1]
         data_fetcher = pyfusion.acquisition.H1.fetch.H1DataFetcher
         mds_path = \h1data::top.operations.mirnov:a14_14:input_1
         coords_cylindrical = 1.114, 0.7732, 0.355
         coord_transform = H1_mirnov

        If a ``data_fetcher`` keyword argument is supplied, it overrides
        the configuration file specification.

        The  fetcher  class  is  instantiated,  including  any  supplied
        keyword arguments, and the result of the ``fetch`` method of the
        fetcher class is returned.
        """
        from pyfusion import config
        # if there is a data_fetcher arg, use that, otherwise get from config
        if kwargs.has_key('data_fetcher'):
            fetcher_class_name = kwargs['data_fetcher']
        else:
            fetcher_class_name = config.pf_get('Diagnostic', config_name,
                                               'data_fetcher')
        fetcher_class = import_from_str(fetcher_class_name)
        d = fetcher_class(self, shot, config_name=config_name,
                          **kwargs).fetch()
        d.history += "\n:: shot: %d\n:: config: %s" % (shot, config_name)

        return d
Esempio n. 8
0
def getDevice(device_name):
    """Find and instantiate Device (sub)class from config."""
    dev_class_str = pyfusion.config.pf_get('Device', device_name, 'dev_class')
    return import_from_str(dev_class_str)(device_name)
Esempio n. 9
0
 def check_module(self, module_name):
     path = 'pyfusion.acquisition'
     import_from_str('.'.join([path, module_name]))
     import_from_str('.'.join([path, module_name, 'acq']))
     import_from_str('.'.join([path, module_name, 'fetch']))
Esempio n. 10
0
 def test_import_from_str(self):
     from pyfusion.conf.utils import import_from_str
     string_value = "pyfusion.acquisition.FakeData.acq.FakeDataAcquisition"
     from pyfusion.acquisition.FakeData.acq import FakeDataAcquisition
     self.assertEqual(import_from_str(string_value), FakeDataAcquisition)
Esempio n. 11
0
 def check_module(self, module_name):
     path = 'pyfusion.acquisition'
     import_from_str('.'.join([path, module_name]))
     import_from_str('.'.join([path, module_name, 'acq']))
     import_from_str('.'.join([path, module_name, 'fetch']))
Esempio n. 12
0
 def test_import_from_str(self):
     from pyfusion.conf.utils import import_from_str
     string_value = "pyfusion.acquisition.FakeData.acq.FakeDataAcquisition"
     from pyfusion.acquisition.FakeData.acq import FakeDataAcquisition
     self.assertEqual(import_from_str(string_value), FakeDataAcquisition)