예제 #1
0
def xoppy_loadspec(fileName, verbose=1, index=None):
    """
    gets the data block of the last spec scan
    :param fileName:
    :param verbose:
    :return:
    """

    sf = SpecFile(fileName)

    if verbose:
        print("Number of scans found %d" % (len(sf)))
        print(sf.list())
        print(type(sf.list()))

    if index == None:  #go trought all scane
        for index in range(len(sf)):
            s1 = sf[index]
            if verbose:
                print("\ndata shape: ", (s1.data.shape))

            h = s1.header
            for j in range(len(h)):
                if verbose: print("           %s" % h[j])

    else:
        s1 = sf[index]

    return s1.data
예제 #2
0
    def extract_data_from_xoppy_output(self, calculation_output):
        spec_file_name = calculation_output

        sf = SpecFile(spec_file_name)

        if len(sf) == 1:
            #load spec file with one scan, # is comment
            print(("Loading file:  ", spec_file_name))
            out = numpy.loadtxt(spec_file_name)
            if len(out) == 0 : raise Exception("Calculation gave no results (empty data)")

            #get labels
            # txt = open(spec_file_name).readlines()
            # tmp = [ line.find("#L") for line in txt]
            # itmp = numpy.where(numpy.array(tmp) != (-1))
            # labels = txt[int(itmp[0])].replace("#L ","").split("  ")
            # print("data labels: ", labels)

            calculated_data = DataExchangeObject("XOPPY", self.get_data_exchange_widget_name())

            calculated_data.add_content("xoppy_specfile", spec_file_name)
            calculated_data.add_content("xoppy_data", out)

            return calculated_data
        else:
          raise Exception("File %s contains %d scans. Cannot send it as xoppy_table" % (spec_file_name, len(sf)))
예제 #3
0
def read_SPEC_file(scan_path, calibScan):
    """Read SPEC file into an object

    Arguments:
        scan_path {path} -- path where SPEC file is stored
        calibScan {str} -- Calibration file name

    Returns:
        SpecFile object -- SpecFile Object as per SILX
    """
    spec_file = SpecFile( os.path.join(scan_path, f'{calibScan}') )
    
    return spec_file
예제 #4
0
    def list(self):
        """Return a string representation of a list of scan numbers.

        The scans numbers are listed in the order in which they appear
        in the file. Continuous ranges of scan numbers are represented
        as ``first:last``.

        For instance, let's assume our specfile contains following scans:
        *1, 2, 3, 4, 5, 684, 685, 687, 688, 689, 700, 688, 688*.
        This method will then return::

            "1:5,684:685,687:689,700,688,688"
        """
        number_list = SpecFile.list(self)
        return _format_number_list(number_list)
예제 #5
0
    def list(self):
        """Return a string representation of a list of scan numbers.

        The scans numbers are listed in the order in which they appear
        in the file. Continuous ranges of scan numbers are represented
        as ``first:last``.

        For instance, let's assume our specfile contains following scans:
        *1, 2, 3, 4, 5, 684, 685, 687, 688, 689, 700, 688, 688*.
        This method will then return::

            "1:5,684:685,687:689,700,688,688"
        """
        number_list = SpecFile.list(self)
        return _format_number_list(number_list)
예제 #6
0
파일: helxas.py 프로젝트: aripekka/helxas
    def read_I(self,
               sample_str,
               signal_scan_numbers,
               background_scan_numbers,
               tube_current=10):
        '''
        Loads the measured I scans into the memory
        '''
        specfile = SpecFile(os.path.join(self.datapath, self.datafile))
        self.scan_groups[sample_str] = {}
        self.scan_groups[sample_str]['signal'] = self._read_scans(
            specfile, signal_scan_numbers)
        self.scan_groups[sample_str]['background'] = self._read_scans(
            specfile, background_scan_numbers)

        self.scan_groups[sample_str]['signal']['tube_current'] = tube_current
        self.scan_groups[sample_str]['background'][
            'tube_current'] = tube_current
예제 #7
0
 def __init__(self, filename):
     SpecFile.__init__(self, filename)
예제 #8
0
# find the q range for data interpolation
##############################################################
limit_q = []
for idx in range(nb_scan):
    datadir = specdir + "SN" + str(scans[idx]) + '/data/'
    ccdfiletmp = os.path.join(datadir, "align_eiger2M_%05d.edf.gz")   # template for the CCD file names
    # ccdfiletmp = os.path.join("data_mpx4_%05d.edf.gz")  # ID01 template for image name
    # ccdfiletmp = os.path.join(spec_name + "_ascan_mu_%05d.nxs")  # SIXS template for image name
    # ccdfiletmp = os.path.join(datadir, "mgomega-2018_06_08_19-37-38_418.nxs")  # Cristal template for image name
    # ccdfiletmp = os.path.join("Sample2371_ref_00079_data_%06d.h5")   # P10 template for detector filenames
    if setup == 'CRISTAL':
        spec_file = h5py.File(ccdfiletmp, 'r')
    elif setup == 'P10':
        spec_file = open(specdir + "S" + str(scans[idx]) + '/' + spec_name, 'r')
    else:
        spec_file = SpecFile(specdir + spec_name)
    qx, qz, qy, _, _, _, _ = gridmap(specfile=spec_file, scan_nb=scans[idx], mydetector=detector,
                                     region=roi, myflatfield=flatfield, myhotpixels=hotpix_array,
                                     mysetup=setup, myrocking_angle=rocking_angle,
                                     follow_bragg=follow_delta, myenergy=energy, myoffsets=offsets)
    if len(limit_q) > 0:
        limit_q[0] = min(limit_q[0], qx.min())
        limit_q[1] = max(limit_q[1], qx.max())
        limit_q[2] = min(limit_q[2], qz.min())
        limit_q[3] = max(limit_q[3], qz.max())
        limit_q[4] = min(limit_q[4], qy.min())
        limit_q[5] = max(limit_q[5], qy.max())
    else:
        limit_q.extend([qx.min(), qx.max(), qz.min(), qz.max(), qy.min(), qy.max()])

#############################################################################
예제 #9
0
 def __init__(self, filename):
     SpecFile.__init__(self, filename)
예제 #10
0
파일: make_movie.py 프로젝트: duprazm/bcdi
####################################
try:
    FFMpegWriter = manimation.writers['ffmpeg']
except KeyError:
    print('KeyError: \'ffmpeg\'')
    sys.exit()
except RuntimeError:
    print("Could not import FFMpeg writer for movie generation")
    sys.exit()

if flatfield_file != "":
    flatfield = np.load(flatfield_file)['flatfield']
else:
    flatfield = None
spec_file = SpecFile(specdir + spec_prefix + ".spec")
motor_names = spec_file[str(scan) + '.1'].motor_names  # positioners
motor_positions = spec_file[str(scan) + '.1'].motor_positions  # positioners
labels = spec_file[str(scan) + '.1'].labels  # motor scanned
labels_data = spec_file[str(scan) + '.1'].data  # motor scanned
if detector == 0:
    counter = 'ei2minr'
elif detector == 1:
    counter = 'mpx4inr'
else:
    print('Wrong detector type')
    sys.exit()
ccdn = labels_data[labels.index(counter), :]

metadata = dict(title=movie_title)
writer = FFMpegWriter(fps=5, metadata=metadata)