Beispiel #1
0
    def test_iso8601(self):
        expected = "2010-11-03T13:39:34"
        spec = utils.iso8601("Wed Nov 03 13:39:34 2010")
        self.assertEqual(spec, expected)

        expected = "2017-09-15T04:39:10"
        spock = utils.iso8601("09/15/17 04:39:10")
        self.assertEqual(spock, expected)
Beispiel #2
0
    def toTree(self, scan_list=[]):
        '''
        convert scans from chosen SPEC file into NXroot object and structure
        
        called from nexpy.readers.readspec.ImportDialog.get_data__prjPySpec() after clicking <Ok> in dialog
        
        Each scan in the range from self.scanmin to self.scanmax (inclusive)
        will be converted to a NXentry.  Scan data will go in a NXdata where 
        the signal=1 is the last column and the corresponding axes= is the first column.
        
        :param [int] scanlist
        :raises: ValueError is Min or Max scan number are not given properly
        '''
        import spec2nexus
        from spec2nexus import utils
        # check that scan_list is valid
        if len(scan_list) == 0:
            return None

        if self.SPECfile is None:
            return None

        complete_scan_list = list(self.SPECfile.scans)
        for key in [str(s) for s in scan_list]:
            if key not in complete_scan_list:
                msg = 'scan ' + str(key) + ' was not found'
                raise ValueError(msg)

        root = NXroot()

        root.attrs['spec2nexus'] = str(spec2nexus.__version__)
        header0 = self.SPECfile.headers[0]
        root.attrs['SPEC_file'] = self.SPECfile.fileName
        root.attrs['SPEC_epoch'] = header0.epoch
        root.attrs['SPEC_date'] = utils.iso8601(header0.date)
        root.attrs['SPEC_comments'] = '\n'.join(header0.comments)
        try:
            c = header0.comments[0]
            user = c[c.find('User = '******'=')[1].strip()
            root.attrs['SPEC_user'] = user
        except:
            pass
        root.attrs['SPEC_num_headers'] = len(self.SPECfile.headers)

        self.progress_bar.setVisible(True)
        self.progress_bar.setRange(scan_list[0], scan_list[-1])
        for key in [str(s) for s in scan_list]:
            scan = self.SPECfile.getScan(key)
            scan.interpret()
            entry = NXentry()
            entry.title = str(scan)
            entry.date = utils.iso8601(scan.date)
            entry.command = scan.scanCmd
            entry.scan_number = NXfield(scan.scanNum)
            entry.comments = '\n'.join(scan.comments)
            entry.data = self.scan_NXdata(scan)  # store the scan data
            entry.positioners = self.metadata_NXlog(
                scan.positioner, 'SPEC positioners (#P & #O lines)')
            if hasattr(scan, 'metadata') and len(scan.metadata) > 0:
                entry.metadata = self.metadata_NXlog(
                    scan.metadata,
                    'SPEC metadata (UNICAT-style #H & #V lines)')

            if len(scan.G) > 0:
                entry.G = NXlog()
                desc = "SPEC geometry arrays, meanings defined by SPEC diffractometer support"
                # e.g.: SPECD/four.mac
                # http://certif.com/spec_manual/fourc_4_9.html
                entry.G.attrs['description'] = desc
                for item, value in scan.G.items():
                    entry.G[item] = NXfield(list(map(float, value.split())))
            if scan.T != '':
                entry['counting_basis'] = NXfield(
                    'SPEC scan with constant counting time')
                entry['T'] = NXfield(float(scan.T))
                entry['T'].units = 'seconds'
                entry[
                    'T'].description = 'SPEC scan with constant counting time'
            elif scan.M != '':
                entry['counting_basis'] = NXfield(
                    'SPEC scan with constant monitor count')
                entry['M'] = NXfield(float(scan.M))
                entry['M'].units = 'counts'
                entry[
                    'M'].description = 'SPEC scan with constant monitor count'
            if scan.Q != '':
                entry['Q'] = NXfield(list(map(float, scan.Q)))
                entry['Q'].description = 'hkl at start of scan'

            root['scan_' + str(key)] = entry

            self.progress_bar.setValue(int(key))
            self.update_progress()

        return root
Beispiel #3
0
    def toTree(self, scan_list=[]):
        """
        convert scans from chosen SPEC file into NXroot object and structure
        
        called from nexpy.readers.readspec.ImportDialog.get_data__prjPySpec() after clicking <Ok> in dialog
        
        Each scan in the range from self.scanmin to self.scanmax (inclusive)
        will be converted to a NXentry.  Scan data will go in a NXdata where 
        the signal=1 is the last column and the corresponding axes= is the first column.
        
        :param [int] scanlist
        :raises: ValueError is Min or Max scan number are not given properly
        """
        import spec2nexus
        from spec2nexus import utils

        # check that scan_list is valid
        if len(scan_list) == 0:
            return None

        if self.SPECfile is None:
            return None

        complete_scan_list = self.SPECfile.scans.keys()
        for key in scan_list:
            if key not in complete_scan_list:
                msg = "scan " + str(key) + " was not found"
                raise ValueError, msg

        root = NXroot()

        root.attrs["spec2nexus"] = str(spec2nexus.__version__)
        header0 = self.SPECfile.headers[0]
        root.attrs["SPEC_file"] = self.SPECfile.fileName
        root.attrs["SPEC_epoch"] = header0.epoch
        root.attrs["SPEC_date"] = utils.iso8601(header0.date)
        root.attrs["SPEC_comments"] = "\n".join(header0.comments)
        try:
            c = header0.comments[0]
            user = c[c.find("User = "******"=")[1].strip()
            root.attrs["SPEC_user"] = user
        except:
            pass
        root.attrs["SPEC_num_headers"] = len(self.SPECfile.headers)

        self.progress_bar.setVisible(True)
        self.progress_bar.setRange(scan_list[0], scan_list[-1])
        for key in scan_list:
            scan = self.SPECfile.getScan(key)
            scan.interpret()
            entry = NXentry()
            entry.title = str(scan)
            entry.date = utils.iso8601(scan.date)
            entry.command = scan.scanCmd
            entry.scan_number = NXfield(scan.scanNum)
            entry.comments = "\n".join(scan.comments)
            entry.data = self.scan_NXdata(scan)  # store the scan data
            entry.positioners = self.metadata_NXlog(scan.positioner, "SPEC positioners (#P & #O lines)")
            if hasattr(scan, "metadata") and len(scan.metadata) > 0:
                entry.metadata = self.metadata_NXlog(scan.metadata, "SPEC metadata (UNICAT-style #H & #V lines)")

            if len(scan.G) > 0:
                entry.G = NXlog()
                desc = "SPEC geometry arrays, meanings defined by SPEC diffractometer support"
                # e.g.: SPECD/four.mac
                # http://certif.com/spec_manual/fourc_4_9.html
                entry.G.attrs["description"] = desc
                for item, value in scan.G.items():
                    entry.G[item] = NXfield(map(float, value.split()))
            if scan.T != "":
                entry["counting_basis"] = NXfield("SPEC scan with constant counting time")
                entry["T"] = NXfield(float(scan.T))
                entry["T"].units = "seconds"
                entry["T"].description = "SPEC scan with constant counting time"
            elif scan.M != "":
                entry["counting_basis"] = NXfield("SPEC scan with constant monitor count")
                entry["M"] = NXfield(float(scan.M))
                entry["M"].units = "counts"
                entry["M"].description = "SPEC scan with constant monitor count"
            if scan.Q != "":
                entry["Q"] = NXfield(map(float, scan.Q))
                entry["Q"].description = "hkl at start of scan"

            root["scan_" + str(key)] = entry

            self.progress_bar.setValue(key)
            self.update_progress()

        return root
 def writer(self, h5parent, writer, scan, *args, **kws):
     '''Describe how to store this data in an HDF5 NeXus file'''
     write_dataset(h5parent, "date", iso8601(scan.date)  )
 def writer(self, h5parent, writer, scan, *args, **kws):
     '''Describe how to store this data in an HDF5 NeXus file'''
     write_dataset(h5parent, "date", iso8601(scan.date))