def readBOA(filename):
    f = h5py.File(filename, 'r')
    meta = {}
    entry = f['entry']
    meta['title'] = decodeHDF(entry['title'][0])
    meta['collection_description'] = decodeHDF(entry['comment'][0]).strip()
    # todo normalize times to RFC format
    meta['start_time'] = decodeHDF(entry['start_time'][0])
    # todo normalize times to RFC format
    meta['instrument'] = 'BOA'

    sample = {}
    sample['name'] = decodeHDF(entry['sample/name'][0])
    if pathExists(entry,'sample/temperature'.split('/')):
        sample['temperature'] = decodeHDF(entry['sample/temperature'][0])
    else:
        sample['temperature'] = 'UNKNOWN'
    # TODO: check a number of files and see if you can find an entry for magnets.
    # It coulkd also be that the name is magnetic_field.    
    if pathExists(entry,'sample/magnet'.split('/') or entry, 'sample/magnetic_field'):
        sample['magnet'] = decodeHDF(entry['sample/magnet'][0])
    else:
        sample['magnet'] = 'UNKNOWN'
    meta['sample'] = sample
    meta['user'] = decodeHDF(entry['user/name'][0])
    meta['email'] = decodeHDF(entry['user/email'][0])
    meta['experiment_identifier'] = decodeHDF(entry['proposal_id'][0])
    f.close()
    return meta
def readAMOR(filename):
    if os.path.exists(filename):
        print('hdf file found')
    else:
        filename = filename.replace(".hdf", ".ccl")
        if os.path.exists(filename):
            print('ccl file found')
        else:
            filename = filename.replace(".ccl", ".dat")
            if os.path.exists(filename):
                print('dat file found')
            else:
                print('datatype unknown')
    cclsuffix = '.ccl'
    datsuffix = '.dat'
    hdfsuffix = '.hdf'
    print(filename)
    meta = {}
    dataset = ["Date", "User", "Sample Name", "Title", "ProposalID"]
    if (filename.endswith(cclsuffix) or filename.endswith(datsuffix)):
        f = open(filename, 'r')
        x = 0
        for line in f:
            if line.startswith('#data'):
                break
            extractedData = line.split('=')
            if len(extractedData) == 2:
                key = extractedData[0].strip()
                if key in dataset:
                    meta[key] = extractedData[1].strip()
        meta['detector_mode'] = '1d'
        f.close()

    elif (filename.endswith(hdfsuffix)):
        print('read data')
        f = h5py.File(filename, 'r')
        entry = f['entry1']
        meta['title'] = decodeHDF(entry['title'][0])
        meta['collection_description'] = decodeHDF(entry['comment'][0]).strip()
        # todo normalize times to RFC format
        meta['date'] = decodeHDF(entry['start_time'][0])
        # todo normalize times to RFC format
        meta['instrument'] = 'AMOR'
        sample = {}
        sample['name'] = decodeHDF(entry['sample/name'][0])
        if pathExists(entry, 'sample/temperature'.split('/')):
            sample['temperature'] = decodeHDF(entry['sample/temperature'][0])
        else:
            sample['temperature'] = 'UNKNOWN'
        if pathExists(entry, 'sample/magnet'.split('/')):
            sample['magnet'] = decodeHDF(entry['sample/magnet'][0])
        else:
            sample['magnet'] = 'UNKNOWN'
        meta['sample'] = sample
        meta['user'] = decodeHDF(entry['proposal_user/name'][0])
        meta['email'] = decodeHDF(entry['proposal_user/email'][0])
        meta['experiment_identifier'] = decodeHDF(entry['proposal_id'][0])
        f.close()
    return meta
def readHRPT(filename):
    f = h5py.File(filename, 'r')
    meta = {}
    entry = f['entry1']
    meta['title'] = decodeHDF(entry['title'][0])
    # meta['collection_description'] = decodeHDF(entry['comment'][0]).strip()
    # todo normalize times to RFC format
    meta['start_time'] = decodeHDF(entry['start_time'][0])
    # todo normalize times to RFC format
    # meta['end_time'] = decodeHDF(entry['end_time'][0])
    meta['instrument'] = 'HRPT'
    meta['wavelength'] = decodeHDF(entry['HRPT/Monochromator/lambda'][0])
    meta['detector two_theta start'] = decodeHDF(
        entry['HRPT/HRPT-CERCA-Detector/two_theta_start'][0])
    meta['proton_monitor'] = decodeHDF(
        entry['HRPT/HRPT-CERCA-Detector/proton_monitor'][0])
    meta['summed counts'] = decodeHDF(entry['data1/counts'][0])
    meta['position_monochromator_lift'] = decodeHDF(
        entry['HRPT/Monochromator/lift'][0])
    sample = {}
    sample['name'] = decodeHDF(entry['sample/sample_name'][0])
    if pathExists(entry, 'sample/sample_changer_position'.split('/')):
        sample['sample_changer position'] = decodeHDF(
            entry['sample/sample_changer_position'][0])
    else:
        sample['sample_changer position'] = 'UNKNOWN'
    sample['sample rotation'] = decodeHDF(
        entry['sample/sample_table_rotation'][0])
    if pathExists(entry, 'sample/temperature'.split('/')):
        sample['temperature'] = decodeHDF(entry['sample/temperature'][0])
    else:
        sample['temperature'] = 'UNKNOWN'
    if pathExists(entry, 'sample/magnet'.split('/')):
        sample['magnet'] = decodeHDF(entry['sample/magnet'][0])
    else:
        sample['magnet'] = 'UNKNOWN'
    meta['sample'] = sample
    meta['user'] = decodeHDF(entry['user/name'][0])
    meta['email'] = decodeHDF(entry['proposal_user/email'][0])
    meta['experiment_identifier'] = decodeHDF(entry['proposal_id'][0])
    f.close()
    return meta
Esempio n. 4
0
def readSANS(filename):
    f = h5py.File(filename, 'r')
    meta = {}
    entry = f['entry1']
    meta['title'] = decodeHDF(entry['title'][0])
    #meta['collection_description'] = decodeHDF(entry['comment'][0]).strip()
    # todo normalize times to RFC format
    meta['start_time'] = decodeHDF(entry['start_time'][0])
    # todo normalize times to RFC format
    meta['end_time'] = decodeHDF(entry['end_time'][0])
    meta['instrument'] = 'SANS'
    source = {}
    source['type'] = 'Spallation Neutron Source'
    source['probe'] = 'neutron'
    source['name'] = 'SINQ at PSI'
    meta['source'] = source
    meta['wavelength'] = decodeHDF(entry['SANS/Dornier-VS/lambda'][0])
    coll = {}
    coll['shape'] = 'nxcylinder'
    coll['size'] = decodeHDF(entry['SANS/collimator/length'][0])
    meta['collimator'] = coll
    detector = {}
    # todo find proper transformation detector['sum'] = np.sum(decodeHDF(entry['SANS/detector/counts']))
    detector['distance'] = decodeHDF(entry['SANS/detector/x_position'][0])
    detector['polar_angle'] = 0.
    detector['azimuthal_angle'] = 0.
    detector['aequatorial_angle'] = 0.
    detector['x_pixel_size'] = 7.5
    detector['y_pixel_size'] = 7.5
    if pathExists(entry, 'SANS/detector/beam_center_x'.split('/')):
        detector['beam_center_x'] = decodeHDF(
            entry['SANS/detector/beam_center_x'][0]) * 7.5
        detector['beam_center_y'] = decodeHDF(
            entry['SANS/detector/beam_center_y'][0]) * 7.5
    meta['detector'] = detector
    sample = {}
    sample['name'] = decodeHDF(entry['sample/name'][0])
    #sample['environment'] = decodeHDF(entry['sample/environment'][0])
    sample['aequatorial_angle'] = 0.
    if pathExists(entry, 'sample/temperature'.split('/')):
        sample['temperature'] = decodeHDF(entry['sample/temperature'][0])
    else:
        sample['temperature'] = 'UNKNOWN'
    if pathExists(entry, 'sample/magnet'.split('/')):
        sample['magnet'] = decodeHDF(entry['sample/magnet'][0])
    else:
        sample['magnet'] = 'UNKNOWN'
    meta['sample'] = sample
    control = {}
    control['mode'] = decodeHDF(entry['SANS/detector/count_mode'][0])
    control['preset'] = decodeHDF(entry['SANS/detector/preset'][0])
    control['time'] = decodeHDF(entry['SANS/detector/counting_time'][0])
    control['integral'] = decodeHDF(entry['SANS/monitor1/counts'][0])
    control['monitor2'] = decodeHDF(entry['SANS/monitor2/counts'][0])
    control['monitor3'] = decodeHDF(entry['SANS/monitor3/counts'][0])
    meta['control'] = control
    meta['user'] = decodeHDF(entry['user/name'][0])
    if pathExists(entry, 'proposal_user/email'.split('/')):
        meta['email'] = decodeHDF(entry['proposal_user/email'][0])
    else:
        meta['email'] = '*****@*****.**'
    meta['proposal_title'] = decodeHDF(entry['proposal_title'][0])
    meta['experiment_identifier'] = decodeHDF(entry['proposal_id'][0])
    # todo: commented because not existing: meta['attenuator'] = decodeHDF(entry['SANS/attenuator/selection'][0])
    f.close()
    return meta
def readPOLDI(filename):
    f = h5py.File(filename, 'r')
    meta = {}
    entry = f['entry1']
    meta['title'] = decodeHDF(entry['title'][0])
    meta['collection_description'] = decodeHDF(entry['comment'][0]).strip()
    # todo normalize times to RFC format
    meta['start_time'] = decodeHDF(entry['start_time'][0])
    # todo normalize times to RFC format
    meta['end_time'] = decodeHDF(entry['end_time'][0])
    meta['instrument'] = 'POLDI'
    sample = {}
    sample['name'] = decodeHDF(entry['sample/name'][0])
    sample['environment'] = decodeHDF(entry['sample/environment'][0])
    if pathExists(entry, 'sample/temperature'.split('/')):
        sample['temperature'] = decodeHDF(entry['sample/temperature'][0])
    else:
        sample['temperature'] = 'UNKNOWN'
    if pathExists(entry, 'sample/magnet'.split('/')):
        sample['magnet'] = decodeHDF(entry['sample/magnet'][0])
    else:
        sample['magnet'] = 'UNKNOWN'
    meta['sample'] = sample
    meta['user'] = decodeHDF(entry['user/name'][0])
    meta['email'] = decodeHDF(entry['proposal_user/email'][0])
    meta['experiment_identifier'] = decodeHDF(entry['proposal_id'][0])
    # todo: commented because not existing: meta['attenuator'] = decodeHDF(entry['SANS/attenuator/selection'][0])
    meta['chopper_speed'] = decodeHDF(entry['POLDI/chopper/rotation_speed'][0])
    f.close()
    return meta
Esempio n. 6
0
def readZEBRA(filename):
    if os.path.exists(filename):
        print('hdf file found')
    else:
        filename = filename.replace(".hdf", ".ccl")
        if os.path.exists(filename):
            print('ccl file found')
        else:
            filename = filename.replace(".ccl", ".dat")
            if os.path.exists(filename):
                print('dat file found')
            else:
                print('datatype unknown')
    cclsuffix = '.ccl'
    datsuffix = '.dat'
    hdfsuffix = '.hdf'
    meta = {}
    if (filename.endswith(cclsuffix) or filename.endswith(datsuffix)):
        f = open(filename, 'r')
        dataset = [
            "date", "instrument", "user", "proposal_email", "title", "sample",
            "temperature", "ProposalID", "stt", "chi", "phi", "om", "nu"
        ]
        for line in f:
            if line.startswith('#data'):
                break
            extractedData = line.split('=')
            if len(extractedData) == 2:
                key = extractedData[0].strip()
                if key in dataset:
                    meta[key] = extractedData[1].strip()
        meta['detector_mode'] = '1d'
        f.close()

    elif (filename.endswith(hdfsuffix)):
        f = h5py.File(filename, 'r')
        entry = f['entry1']
        meta['title'] = decodeHDF(entry['title'][0])
        meta['collection_description'] = decodeHDF(entry['comment'][0]).strip()
        # todo normalize times to RFC format
        meta['date'] = decodeHDF(entry['start_time'][0])
        # todo normalize times to RFC format
        meta['instrument'] = 'ZEBRA'
        meta['sample'] = decodeHDF(entry['sample/name'][0])
        sample = {}
        if pathExists(entry, 'sample/temperature'.split('/')):
            sample['temperature'] = decodeHDF(entry['sample/temperature'][0])
        else:
            sample['temperature'] = 'UNKNOWN'
        if pathExists(entry, 'sample/magnet'.split('/')):
            sample['magnet'] = decodeHDF(entry['sample/magnet'][0])
        else:
            sample['magnet'] = 'UNKNOWN'
        meta['sample_directory'] = sample
        meta['user'] = decodeHDF(entry['proposal_user/name'][0])
        meta['proposal_email'] = decodeHDF(entry['proposal_user/email'][0])
        meta['ProposalID'] = decodeHDF(entry['proposal_id'][0])
        # zebra_mode
        meta['detector_mode'] = '2d'
        meta['stt'] = decodeHDF(entry['sample/stt'][0])
        meta['chi'] = decodeHDF(entry['sample/chi'][0])
        meta['phi'] = decodeHDF(entry['sample/phi'][0])
        meta['om'] = decodeHDF(entry['sample/om'][0])
        meta['nu'] = decodeHDF(entry['sample/nu'][0])
        # om, nu
        f.close()
    return meta, filename
def readFOCUS(filename):
    f = h5py.File(filename, 'r')
    meta = {}
    entry = f['entry1']
    meta['title'] = decodeHDF(entry['title'][0])
    meta['collection_description'] = decodeHDF(entry['comment'][0]).strip()
    # todo normalize times to RFC format
    meta['start_time'] = decodeHDF(entry['start_time'][0])
    # todo normalize times to RFC format
    meta['end_time'] = decodeHDF(entry['end_time'][0])
    meta['instrument'] = 'FOCUS'

    meta['wavelength'] = decodeHDF(entry['FOCUS/monochromator/lambda'][0])
    if pathExists(entry, 'focus2d'):
        meta['2ddetector'] = 'yes'
    else:
        meta['2ddetector'] = 'no'
    sample = {}
    sample['name'] = decodeHDF(entry['sample/name'][0])
    sample['environment'] = decodeHDF(entry['sample/environment'][0])
    sample['distance'] = decodeHDF(entry['sample/distance'][0])
    if pathExists(entry, 'sample/temperature'.split('/')):
        sample['temperature'] = decodeHDF(entry['sample/temperature'][0])
    else:
        sample['temperature'] = 'UNKNOWN'
    # TODO: check a number of files and see if you can find an entry for magnets.
    # It coulkd also be that the name is magnetic_field.
    if pathExists(entry, 'sample/magnet'.split('/')):
        sample['magnet'] = decodeHDF(entry['sample/magnet'][0])
    else:
        sample['magnet'] = 'UNKNOWN'
    meta['sample'] = sample
    meta['monitor'] = decodeHDF(entry['FOCUS/counter/monitor'][0])
    meta['user'] = decodeHDF(entry['user/name'][0])
    meta['email'] = decodeHDF(entry['proposal_user/email'][0])
    meta['experiment_identifier'] = decodeHDF(entry['proposal_id'][0])
    meta['disk_chopper_speed'] = decodeHDF(
        entry['FOCUS/disk_chopper/rotation_speed'][0])
    meta['fermi_chopper_speed'] = decodeHDF(
        entry['FOCUS/fermi_chopper/rotation_speed'][0])
    meta['disk_chopper_ratio'] = decodeHDF(
        entry['FOCUS/disk_chopper/ratio'][0])
    meta['fermi_chopper_phase'] = decodeHDF(
        entry['FOCUS/fermi_chopper/phase'][0])
    f.close()
    return meta