Exemple #1
0
    def begin(self):
        if self.h5file is None:
            self.template = copy_nexus_template(self.sink.loadTemplate())
            if not isinstance(self.template, dict):
                raise NicosError('The template should be of type dict')

            self.h5file = h5py.File(self._filename, 'w')
            self.h5file.attrs['file_name'] = numpy.string_(self._filename)
            tf = NXTime()
            self.h5file.attrs['file_time'] = numpy.string_(tf.formatTime())
Exemple #2
0
    def begin(self):
        if self.dataset.settype == POINT and not self.h5file:
            self.template = copy_nexus_template(self.sink.loadTemplate())

            self.h5file = h5py.File(self.startdataset.filepaths[0], 'w')
            self.h5file.attrs['file_name'] = numpy.string_(
                self.startdataset.filepaths[0])
            tf = NXTime()
            self.h5file.attrs['file_time'] = numpy.string_(tf.formatTime())

            if not isinstance(self.template, dict):
                raise NicosError('The template should be of type dict')

            # Update meta information of devices, only if not present
            if not self.dataset.metainfo:
                self.manager.updateMetainfo()

            self.createStructure()
Exemple #3
0
class BOATemplateProvider(NexusTemplateProvider):
    """
      NeXus template generation for BOA at SINQ
    """
    _boa_default = {
        "NeXus_Version": "4.3.0",
        "instrument": "BOA",
        "owner": DeviceAttribute('BOA', 'responsible'),
        "entry:NXentry": {
            "title": DeviceDataset('Exp', 'title'),
            "proposal_title": DeviceDataset('Exp', 'title'),
            "proposal_id": DeviceDataset('Exp', 'proposal'),
            "start_time": NXTime(),
            "end_time": NXTime(),
            "user:NXuser": {
                "name": DeviceDataset('Exp', 'users'),
                "email": DeviceDataset('Exp', 'localcontact')
            },
            "sample:NXsample": {
                "sample_name": DeviceDataset('Sample', 'samplename'),
                "hugo": NexusSampleEnv(),
            },
            "control:NXmonitor": {
                "mode":
                DetectorDataset('mode', "string"),
                "Monitor":
                DetectorDataset('monitorval',
                                'float32',
                                units=NXAttribute('counts', 'string')),
                "preset":
                DetectorDataset('preset', 'float32'),
                "time":
                DetectorDataset('elapsedtime',
                                'float32',
                                units=NXAttribute('seconds', 'string')),
            },
            "proton_beam:NXmonitor": {
                "data":
                DetectorDataset('protoncurr',
                                'int32',
                                units=NXAttribute('counts', 'string'))
            },
            "white_beam:NXmonitor": {
                "data":
                DetectorDataset('monitorval',
                                'int32',
                                units=NXAttribute('counts', 'string'))
            },
        },
    }
    _tables = ['Table2', 'Table3', 'Table4', 'Table5', 'Table6']
    _detectors = ['embl', 'andor', 'single_el737']
    _detector = None

    def containsDetector(self, table):
        for det in self._detectors:
            if det in table.setups:
                return det
        return None

    def makeTable(self, table_name):
        table = session.getDevice(table_name)
        det = self.containsDetector(table)
        if det:
            self._detector = det
            table.removeSetup(det)
        devices = table.getTableDevices()
        content = dict()
        for d in devices:
            try:
                dev = session.getDevice(d)
                content[dev.name] = DeviceDataset(dev.name,
                                                  dtype='float32',
                                                  units=NXAttribute(
                                                      dev.unit, 'string'))
            except Exception as e:
                session.log.info('Failed to write device %s, Exception: %s', d,
                                 e)
        equipment = ','.join(table.setups)
        content['equipment'] = ConstDataset(equipment, 'string')
        if det:
            table.addSetup(det)
            content['detector'] = ConstDataset(det, 'string')
        return content

    def makeDetector(self):
        name = self._detector
        if 'single' in name:
            name = 'single'
        content = dict()
        if name == 'single':
            content['data'] = DetectorDataset('countval',
                                              'int32',
                                              units=NXAttribute(
                                                  'counts', 'string'))
        elif name == 'andor':
            content['data'] = ImageDataset(0,
                                           0,
                                           signal=NXAttribute(1, 'int32'))
        elif name == 'embl':
            content['data'] = ImageDataset(0,
                                           0,
                                           signal=NXAttribute(1, 'int32'))
        return name, content

    def makeData(self, name):
        content = dict()
        content['data'] = NXLink('/entry/%s/data' % (name))
        content['None'] = NXScanLink()
        return content

    def getTemplate(self):
        boa_template = copy.deepcopy(self._boa_default)
        entry = boa_template['entry:NXentry']
        for tbl in self._tables:
            tblcontent = self.makeTable(tbl)
            entry[tbl.lower() + ':NXcollection'] = tblcontent
        if self._detector:
            name, content = self.makeDetector()
            entry[name + ':NXdetector'] = content
            entry['data:Nxdata'] = self.makeData(name)
        else:
            session.log.info('No detector FOUND! May be: check setup???')
        return boa_template
Exemple #4
0
    DeviceAttribute, DeviceDataset, ImageDataset, NexusSampleEnv, \
    NXAttribute, NXLink, NXScanLink, NXTime
from nicos.nexus.nexussink import NexusTemplateProvider

from nicos_sinq.nexus.specialelements import TwoThetaArray

# Default template for HRPT including most of the devices
hrpt_default = {
    "NeXus_Version": "4.3.0",
    "instrument": "HRPT",
    "owner": DeviceAttribute('HRPT', 'responsible'),
    "entry1:NXentry": {
        "title": DeviceDataset('Exp', 'title'),
        "proposal_title": DeviceDataset('Exp', 'title'),
        "proposal_id": DeviceDataset('Exp', 'proposal'),
        "start_time": NXTime(),
        "definition": ConstDataset('NXmonopd', 'string'),
        "end_time": NXTime(),
        "user:NXuser": {
            "name": DeviceDataset('Exp', 'users'),
            "email": DeviceDataset('Exp', 'localcontact')
        },
        "proposal_user:NXuser": {
            "name": DeviceDataset('Exp', 'users'),
        },
        "sample:NXsample": {
            "sample_name":
            DeviceDataset('Sample', 'samplename'),
            "name":
            NXLink('/entry1/sample/sample_name'),
            "sample_table_rotation":
Exemple #5
0
 def create(self, name, h5parent, sinkhandler):
     if sinkhandler.dataset.finished:
         self.time = sinkhandler.dataset.finished
     else:
         self.time = time.time()
     NXTime.create(self, name, h5parent, sinkhandler)
Exemple #6
0
 def create(self, name, h5parent, sinkhandler):
     self.time = sinkhandler.dataset.started
     NXTime.create(self, name, h5parent, sinkhandler)
Exemple #7
0
 def __init__(self):
     NXTime.__init__(self)
     self.time = 0