コード例 #1
0
def write_example(filename):

    # --- prepare data ---

    # Generate fake data
    rawdata = np.ones(180 * 256 * 256, np.uint16).reshape(180, 256, 256)
    rawdata_white = np.ones(2 * 256 * 256, np.uint16).reshape(2, 256, 256)
    rawdata_dark = np.zeros(10 * 256 * 256, np.uint16).reshape(10, 256, 256)
  
    # x, y and z ranges
    x = np.arange(256)
    y = np.arange(256)
    z = np.arange(180);
      
    # --- create file ---

    # Open DataExchangeFile file
    f = DataExchangeFile(filename, mode='w')
    
    # Create core HDF5 dataset in exchange group for 180 deep stack
    # of x,y images /exchange/data
    f.add_entry([
            DataExchangeEntry.data(data={'value':rawdata, 'units':'counts'}),
            DataExchangeEntry.data(data_dark={'value':rawdata_dark, 'units':'counts'}),
            DataExchangeEntry.data(data_white={'value':rawdata_white, 'units':'counts'})
            ]
        )
                      
    # --- All done ---
    f.close()
コード例 #2
0
def write_example(filename):

    # --- prepare data ---

    # Generate fake raw data
    rawdata = np.ones(180 * 256 * 256, np.uint16).reshape(180, 256, 256)
     
    # x, y and z ranges
    x = np.arange(128)
    y = np.arange(128)
    z = np.arange(180);
   
    # --- create file ---

    # Open DataExchange file
    f = DataExchangeFile(filename, mode='w')
    
    # Create core HDF5 dataset in exchange group for 180 deep stack of x,y
    # images /exchange/data
    data_en = DataExchangeEntry.data(data={'value': rawdata, 'units':'counts', 'description': 'Projection Data',
                                            'dataset_opts':  {'compression': 'gzip', 'compression_opts': 4} })
    f.add_entry(data_en)

    # The default location for sample in DataExchangeEntry is /measurement/sample
    # To override the default set e.g 'root'='/measurement_4/sample'
    sample_en = DataExchangeEntry.sample(name={'value': 'Minivirus'}, temperature={'value': 200.0, 'units':'celsius',
                                'dataset_opts': {'dtype': 'd'}})
    f.add_entry(sample_en)

    # --- All done ---
    f.close()
コード例 #3
0
def write_example(filename):

    # --- prepare data ---

    # Generate fake data
    rawdata = np.ones(180 * 256 * 256, np.uint16).reshape(180, 256, 256)
    rawdata_white = np.ones(2 * 256 * 256, np.uint16).reshape(2, 256, 256)
    rawdata_dark = np.zeros(10 * 256 * 256, np.uint16).reshape(10, 256, 256)

    # x, y and z ranges
    x = np.arange(256)
    y = np.arange(256)
    z = np.arange(180)

    # Fabricated theta values
    theta = (z / float(180)) * 180.0
    theta_white = (0.0, 180.0)
    theta_dark = (0.0, 0.0, 0.0, 0.0, 0.0, 180.0, 180.0, 180.0, 180.0, 180.0)

    # --- create file ---

    # Open HDF5 file
    f = DataExchangeFile(filename, mode='w')

    #Create HDF5 dataset in exchange group for data, data_dark & data_white, theta, theta_dark, theta_white under /exchange
    f.add_entry([
        DataExchangeEntry.data(data={
            'value': rawdata,
            'units': 'counts',
            'axes': 'theta:y:x'
        }),
        DataExchangeEntry.data(data_dark={
            'value': rawdata_dark,
            'units': 'counts',
            'axes': 'theta:y:x'
        }),
        DataExchangeEntry.data(data_white={
            'value': rawdata_white,
            'units': 'counts',
            'axes': 'theta:y:x'
        }),
        DataExchangeEntry.data(theta={
            'value': theta,
            'units': 'degrees'
        }),
        DataExchangeEntry.data(theta_dark={
            'value': theta_dark,
            'units': 'degrees'
        }),
        DataExchangeEntry.data(theta_white={
            'value': theta_white,
            'units': 'degrees'
        })
    ])

    # --- All done ---
    f.close()
コード例 #4
0
def main():

    file_name = '/local/data/databank/Diamond/projections_13429.hdf'
    hdf5_file_name = '/local/data/databank/dataExchange/microCT/Diamond_2bin.h5'

    mydata = Convert()
    # Create minimal hdf5 file
    if verbose: print "Reading data ... "
    mydata.nexus(file_name,
                        hdf5_file_name = hdf5_file_name,
                        projections_start=20,
                        projections_end=1820,
                        projections_step=2,
                        white_start=11,
                        white_end=20,
                        dark_start=1,
                        dark_end=3,
                        sample_name = 'unknown'
                   )
    
    # Add extra metadata if available / desired

    # Open DataExchange file
    f = DataExchangeFile(hdf5_file_name, mode='a') 

    # Create HDF5 subgroup
    # /measurement/instrument
    f.add_entry( DataExchangeEntry.instrument(name={'value': 'Diamond I12'}) )

    ### Create HDF5 subgroup
    ### /measurement/instrument/source
    f.add_entry( DataExchangeEntry.source(name={'value': "Diamond Light Source"},
                                        date_time={'value': "2013-11-30T19:17:04+0100"},
                                        beamline={'value': "JEEP I12"},
                                        )
    )

    # Create HDF5 subgroup
    # /measurement/experimenter
    f.add_entry( DataExchangeEntry.experimenter(name={'value':"Michael Drakopoulos"},
                                                role={'value':"Project PI"},
                    )
        )

    f.close()
    print "Done creating data exchange file: ", hdf5_file_name
コード例 #5
0
def write_example(filename):

    # --- prepare data ---

    # Generate fake raw data
    rawdata = np.ones(180 * 256 * 256, np.uint16).reshape(180, 256, 256)

    # x, y and z ranges
    x = np.arange(128)
    y = np.arange(128)
    z = np.arange(180)

    # --- create file ---

    # Open HDF5 file
    f = DataExchangeFile(filename, mode='w')

    # Create core HDF5 dataset in exchange group for 180 deep stack of x,y
    # images /exchange/data
    f.add_entry(
        DataExchangeEntry.data(
            data={
                'value': rawdata,
                'units': 'counts',
                'description': 'Projection Data',
                'dataset_opts': {
                    'compression': 'gzip',
                    'compression_opts': 4
                }
            }))

    # Create HDF5 subgroup
    # /measurement/sample
    f.add_entry(
        DataExchangeEntry.sample(name={'value': 'Minivirus'},
                                 temperature={
                                     'value': 200.0,
                                     'units': 'celsius',
                                     'dataset_opts': {
                                         'dtype': 'd'
                                     }
                                 }))

    # Create HDF5 subgroup
    # /measurement/instrument
    f.add_entry(DataExchangeEntry.instrument(name={'value': 'APS 2-BM'}))

    # Create HDF5 subgroup
    # /measurement/instrument/monochromator
    f.add_entry(
        DataExchangeEntry.monochromator(name={'value': 'DMM'},
                                        energy={
                                            'value': 10.00,
                                            'units': 'keV',
                                            'dataset_opts': {
                                                'dtype': 'd'
                                            }
                                        }))

    # --- All done ---
    f.close()
コード例 #6
0
ファイル: CXSimulate.py プロジェクト: necroen/cxphasing
def pack_data_exchange():
    f = DataExchangeFile(CXP.io.data_exchange_filename, mode='w')
    sim = DataExchangeEntry.simulation(
        name={'value': 'Simulated Ptycho Data.'},
        energy={
            'value': CXP.experiment.energy,
            'units': 'keV'
        },
        focusing_optic={'value': CXP.experiment.optic},
        probe_modes={'value': CXP.reconstruction.probe_modes},
        noise_model={'value': CXP.simulation.noise_model},
        gaussian_noise_level={'value': CXP.simulation.gaussian_noise_level},
        total_photons={'value': CXP.simulation.total_photons},
        beam_stop={'value': CXP.simulation.beam_stop},
        beam_stop_size={'value': CXP.simulation.beam_stop_size},
        beam_stop_attenuation={'value': CXP.simulation.beam_stop_attenuation},
        defocus={'value': CXP.simulation.defocus},
        position_jitter={
            'value': CXP.reconstruction.initial_position_jitter_radius,
            'units': 'pixels'
        })
    f.add_entry(sim)
    sample = DataExchangeEntry.sample(
        root='/simulation',
        name={'value': 'ground truth sample complex amplitude'},
        data={
            'value': cxph.sample.data[0],
            'units': 'sqrt(counts)'
        },
    )
    f.add_entry(sample)
    probe = DataExchangeEntry.sample(
        root='/simulation',
        entry_name='probe',
    )
    for mode in range(CXP.reconstruction.probe_modes):
        setattr(probe, 'mode_{:d}'.format(mode), {
            'value': cxph.input_probe.modes[mode].data[0],
            'units': 'counts'
        })

    f.add_entry(probe)
    detector = DataExchangeEntry.detector(
        root='/simulation',
        x_pixel_size={'value': CXP.experiment.dx_d},
        y_pixel_size={'value': CXP.experiment.dx_d},
        x_dimension={'value': CXP.experiment.px},
        y_dimension={'value': CXP.experiment.py},
        distance={'value': CXP.experiment.z},
        basis_vectors={
            'value': [[0, -CXP.experiment.dx_d, 0],
                      [-CXP.experiment.dx_d, 0, 0]]
        },
        corner_position={'value': [0, 0, 0]})
    f.add_entry(detector)
    data = DataExchangeEntry.data(
        name={'value': 'simulated_data'},
        data={
            'value': sp.array(cxph.det_mod.data),
            'axes': 'translation:y:x',
            'units': 'counts',
            'dataset_opts': {
                'compression': 'gzip',
                'compression_opts': 4
            }
        },
        translation={'value': '/exchange/sample/geometry/translation'})
    f.add_entry(data)
    # Get scan positions into dex format
    pos = sp.zeros((cxph.positions.total, 3))
    y, x = cxph.positions.correct
    for i in range(cxph.positions.total):
        pos[i, 0], pos[i, 1] = x[i] * CXP.dx_s, y[i] * CXP.dx_s

    positions = DataExchangeEntry.translation(
        root='/exchange/sample/geometry',
        name={'value': 'ptychography scan positions'},
        scan_type={'value': CXP.measurement.ptycho_scan_type},
        data={
            'value': pos,
            'units': 'm'
        })

    f.add_entry(positions)
    f.close()
コード例 #7
0
def main():

    file_name = '/local/data/databank/TXM_26ID/20130731_004_Stripe_Solder_Sample_Tip1_TomoScript_181imgs_p1s_b1.txrm'
    white_file_name = '/local/data/databank/TXM_26ID/20130731_001_Background_Reference_20imgs_p5s_b1.xrm'
    hdf5_file_name = '/local/data/databank/dataExchange/TXM/20130731_004_Stripe_Solder_Sample_Tip1_nx.h5'
    log_file = '/local/data/databank/dataExchange/TXM/20130731_004_Stripe_Solder_Sample_Tip1.log'

    mydata = Convert()
    # Create minimal hdf5 file
    if verbose: print "Reading data ... "
    mydata.stack(file_name,
                 hdf5_file_name=hdf5_file_name,
                 white_file_name=white_file_name,
                 sample_name='Stripe_Solder_Sample_Tip1')

    # Add extra metadata if available / desired

    reader = xradia.xrm()
    array = dstruct
    reader.read_txrm(file_name, array)

    # Read angles
    n_angles = np.shape(array.exchange.angles)
    if verbose: print "Done reading ", n_angles, " angles"
    theta = np.zeros(n_angles)
    theta = array.exchange.angles[:]

    # Save any other available metadata in a log file
    f = open(log_file, 'w')
    f.write('Data creation date: \n')
    f.write(str(array.information.file_creation_datetime))
    f.write('\n')
    f.write('=======================================\n')
    f.write('Sample name: \n')
    f.write(str(array.information.sample.name))
    f.write('\n')
    f.write('=======================================\n')
    f.write('Experimenter name: \n')
    f.write(str(array.information.experimenter.name))
    f.write('\n')
    f.write('=======================================\n')
    f.write('X-ray energy: \n')
    f.write(str(array.exchange.energy))
    f.write(str(array.exchange.energy_units))
    f.write('\n')
    f.write('=======================================\n')
    f.write('Angles: \n')
    f.write(str(array.exchange.angles))
    f.write('\n')
    f.write('=======================================\n')
    f.write('Data axes: \n')
    f.write(str(array.exchange.data_axes))
    f.write('\n')
    f.write('=======================================\n')
    f.write('x distance: \n')
    f.write(str(array.exchange.x))
    f.write('\n')
    f.write('=======================================\n')
    f.write('x units: \n')
    f.write(str(array.exchange.x_units))
    f.write('\n')
    f.write('=======================================\n')
    f.write('y distance: \n')
    f.write(str(array.exchange.y))
    f.write('\n')
    f.write('=======================================\n')
    f.write('y units: \n')
    f.write(str(array.exchange.y_units))
    f.write('\n')
    f.close()

    # Open DataExchange file
    f = DataExchangeFile(hdf5_file_name, mode='a')

    # Create HDF5 subgroup
    # /measurement/instrument
    f.add_entry(DataExchangeEntry.instrument(name={'value': 'APS-CNM 26-ID'}))

    ### Create HDF5 subgroup
    ### /measurement/instrument/source
    f.add_entry(
        DataExchangeEntry.source(
            name={'value': "Advanced Photon Source"},
            date_time={'value': "2013-07-31T19:42:13+0100"},
            beamline={'value': "26-ID"},
        ))

    # Create HDF5 subgroup
    # /measurement/instrument/monochromator
    f.add_entry(
        DataExchangeEntry.monochromator(
            type={'value': 'Unknown'},
            energy={
                'value': float(array.exchange.energy[0]),
                'units': 'keV',
                'dataset_opts': {
                    'dtype': 'd'
                }
            },
            mono_stripe={'value': 'Unknown'},
        ))

    # Create HDF5 subgroup
    # /measurement/experimenter
    f.add_entry(
        DataExchangeEntry.experimenter(
            name={'value': "Robert Winarski"},
            role={'value': "Project PI"},
        ))

    # Create HDF5 subgroup
    # /measurement/sample
    f.add_entry(
        DataExchangeEntry.data(theta={
            'value': theta,
            'units': 'degrees'
        }))

    f.close()
    print "Done creating data exchange file: ", hdf5_file_name
コード例 #8
0
    def xtomo_exchange(self,
                       data,
                       data_white=None,
                       data_dark=None,
                       theta=None,
                       sample_name=None,
                       data_exchange_type=None,
                       hdf5_file_name=None,
                       log='INFO'):
        """ 
        Write 3-D data to a data-exchange file.

        Parameters
        ----------            
        data : ndarray
            3-D X-ray absorption tomography raw data.
            Size of the dimensions should be:
            [projections, slices, pixels].
            
        data_white, data_dark : ndarray, optional
            3-D white-field/dark_field data. Multiple
            projections are stacked together to obtain
            a 3-D matrix. 2nd and 3rd dimensions should
            be the same as data: [shots, slices, pixels].
            
        theta : ndarray, optional
            Data acquisition angles corresponding
            to each projection.

        data_excahnge_type : str
            label defyining the type of data contained in data exchange file
            for raw data tomography data use 'tomography_raw_projections'

        hd5_file_name : str
            Output file.

        Notes
        -----
        If file exists, does nothing
                
        Examples
        --------
        - Convert tomographic projection series (raw, dark, white)  of tiff in data exchange:
            
            >>> from dataexchange import xtomo_importer as dx
            >>> from dataexchange import xtomo_exporter as ex

            >>> file_name = '/local/dataraid/databank/Anka/radios/image_.tif'
            >>> dark_file_name = '/local/dataraid/databank/Anka/darks/image_.tif'
            >>> white_file_name = '/local/dataraid/databank/Anka/flats/image_.tif'

            >>> hdf5_file_name = '/local/dataraid/databank/dataExchange/tmp/Anka.h5'

            >>> projections_start = 0
            >>> projections_end = 3167
            >>> white_start = 0
            >>> white_end = 100
            >>> dark_start = 0
            >>> dark_end = 100

            >>> sample_name = 'Anka'
            >>> 
            >>> mydata = dx.Import()
            >>> # Read series of images
            >>> data, white, dark, theta = mydata.xtomo_raw(file_name,
            >>>                                                    projections_start = projections_start,
            >>>                                                    projections_end = projections_end,
            >>>                                                    white_file_name = white_file_name,
            >>>                                                    white_start = white_start,
            >>>                                                    white_end = white_end,
            >>>                                                    dark_file_name = dark_file_name,
            >>>                                                    dark_start = dark_start,
            >>>                                                    dark_end = dark_end,
            >>>                                                    projections_digits = 5,
            >>>                                                    log='INFO'
            >>>                                                    )

            >>> mydata = ex.Export()
            >>> # Create minimal data exchange hdf5 file
            >>> mydata.xtomo_exchange(data = data,
            >>>                       data_white = white,
            >>>                       data_dark = dark,
            >>>                       theta = theta,
            >>>                       hdf5_file_name = hdf5_file_name,
            >>>                       data_exchange_type = 'tomography_raw_projections',
            >>>                       sample_name = sample_name
            >>>                       )

        """

        if (hdf5_file_name != None):
            if os.path.isfile(hdf5_file_name):
                self.logger.error("Data Exchange file: [%s] already exists",
                                  hdf5_file_name)
            else:
                # Create new folder.
                dirPath = os.path.dirname(hdf5_file_name)
                if not os.path.exists(dirPath):
                    os.makedirs(dirPath)

                # Get the file_name in lower case.
                lFn = hdf5_file_name.lower()

                # Split the string with the delimeter '.'
                end = lFn.split('.')

                # Write the Data Exchange HDF5 file.
                # Open DataExchange file
                f = DataExchangeFile(hdf5_file_name, mode='w')

                self.logger.info("Creating Data Exchange File [%s]",
                                 hdf5_file_name)

                # Create core HDF5 dataset in exchange group for projections_theta_range
                # deep stack of x,y images /exchange/data
                self.logger.info(
                    "Adding projections to Data Exchange File [%s]",
                    hdf5_file_name)
                f.add_entry(
                    DataExchangeEntry.data(
                        data={
                            'value': data,
                            'units': 'counts',
                            'description': 'transmission',
                            'axes': 'theta:y:x'
                        }))
                #                f.add_entry( DataExchangeEntry.data(data={'value': data, 'units':'counts', 'description': 'transmission', 'axes':'theta:y:x', 'dataset_opts':  {'compression': 'gzip', 'compression_opts': 4} }))
                if (theta != None):
                    f.add_entry(
                        DataExchangeEntry.data(theta={
                            'value': theta,
                            'units': 'degrees'
                        }))
                    self.logger.info("Adding theta to Data Exchange File [%s]",
                                     hdf5_file_name)
                else:
                    self.logger.warning("theta is not defined")
                if (data_dark != None):
                    self.logger.info(
                        "Adding dark fields to  Data Exchange File [%s]",
                        hdf5_file_name)
                    f.add_entry(
                        DataExchangeEntry.data(
                            data_dark={
                                'value': data_dark,
                                'units': 'counts',
                                'axes': 'theta_dark:y:x'
                            }))
#                    f.add_entry( DataExchangeEntry.data(data_dark={'value': data_dark, 'units':'counts', 'axes':'theta_dark:y:x', 'dataset_opts':  {'compression': 'gzip', 'compression_opts': 4} }))
                else:
                    self.logger.warning("data dark is not defined")
                if (data_white != None):
                    self.logger.info(
                        "Adding white fields to  Data Exchange File [%s]",
                        hdf5_file_name)
                    f.add_entry(
                        DataExchangeEntry.data(
                            data_white={
                                'value': data_white,
                                'units': 'counts',
                                'axes': 'theta_white:y:x'
                            }))
#                    f.add_entry( DataExchangeEntry.data(data_white={'value': data_white, 'units':'counts', 'axes':'theta_white:y:x', 'dataset_opts':  {'compression': 'gzip', 'compression_opts': 4} }))
                else:
                    self.logger.warning("data white is not defined")
                if (data_exchange_type != None):
                    self.logger.info(
                        "Adding data type to  Data Exchange File [%s]",
                        hdf5_file_name)
                    f.add_entry(
                        DataExchangeEntry.data(
                            title={'value': data_exchange_type}))
                if (sample_name == None):
                    sample_name = end[0]
                    f.add_entry(
                        DataExchangeEntry.sample(
                            name={'value': sample_name},
                            description={
                                'value':
                                'Sample name was assigned by the HDF5 converter and based on the HDF5 file name'
                            }))
                else:
                    f.add_entry(
                        DataExchangeEntry.sample(
                            name={'value': sample_name},
                            description={
                                'value':
                                'Sample name was read from the user log file'
                            }))
                f.close()
                self.logger.info("DONE!!!!. Created Data Exchange File [%s]",
                                 hdf5_file_name)
        else:
            self.logger.warning("Nothing to do ...")
コード例 #9
0
def main():

    file_name = '/local/data/databank/TXM_26ID/Miller1/ABR_1SP_.tif'
    #dark_file_name = '/local/data/databank/AS/Mayo_tooth_AS/BG__AFTER_.tif'
    #white_file_name = '/local/data/databank/AS/Mayo_tooth_AS/BG__BEFORE_.tif'
    hdf5_file_name = '/local/data/databank/dataExchange/TXM/TXM_APS26IDMiller1.h5'
    sample_name = 'Teeth'

    projections_start = 0
    projections_end = 361
    white_start = 0
    white_end = 0
    white_step = 1
    dark_start = 0
    dark_end = 0
    dark_step = 1

    verbose = True

    if verbose: print "Input projection base name: ", file_name
    #if verbose: print "Input white base name: ", white_file_name
    #if verbose: print "Input dark base name: ", dark_file_name
    if verbose: print "Output data exchange file name: ", hdf5_file_name

    mydata = Convert()
    # Create minimal hdf5 file
    mydata.series_of_images(
        file_name,
        hdf5_file_name,
        projections_start,
        projections_end,
        #white_file_name = white_file_name,
        white_start=white_start,
        white_end=white_end,
        white_step=white_step,
        #dark_file_name = dark_file_name,
        #dark_start = dark_start,
        #dark_end = dark_end,
        #dark_step = dark_step,
        #sample_name = sample_name,
        projections_digits=4,
        #white_digits = 2,
        #dark_digits = 2,
        projections_zeros=True,
        verbose=False)
    if verbose: print "Done reading data ... "

    # Add extra metadata if available

    # Open DataExchange file
    f = DataExchangeFile(hdf5_file_name, mode='a')

    # Create HDF5 subgroup
    # /measurement/instrument
    f.add_entry(
        DataExchangeEntry.instrument(
            name={'value': 'Australian Synchrotron Facility'}))

    # Create HDF5 subgroup
    # /measurement/instrument/source
    f.add_entry(
        DataExchangeEntry.source(
            name={'value': 'Australian Synchrotron FacilityI'},
            date_time={'value': "2013-10-19T22:22:13+0100"},
            beamline={'value': "Tomography"},
        ))

    # /measurement/experimenter
    f.add_entry(
        DataExchangeEntry.experimenter(
            name={'value': "Sherry Mayo"},
            role={'value': "Project PI"},
        ))

    f.close()
    if verbose: print "Done creating data exchange file: ", hdf5_file_name
コード例 #10
0
    def xtomo_exchange(self,
                       data,
                       data_white=None,
                       data_dark=None,
                       theta=None,
                       data_exchange_type=None,
                       source_name=None,
                       source_mode=None,
                       source_datetime=None,
                       beamline=None,
                       energy=None,
                       current=None,
                       actual_pixel_size=None,
                       experimenter_name=None,
                       experimenter_affiliation=None,
                       experimenter_email=None,
                       instrument_comment=None,
                       sample_name=None,
                       sample_comment=None,
                       acquisition_mode=None,
                       acquisition_comment=None,
                       sample_position_x=None,
                       sample_position_y=None,
                       sample_position_z=None,
                       sample_image_shift_x=None,
                       sample_image_shift_y=None,
                       hdf5_file_name=None,
                       axes='theta:y:x',
                       log='INFO'):
        """ 
        Write 3-D data to a data-exchange file.

        Parameters
                    
        data : ndarray
            3-D X-ray absorption tomography raw data.
            Size of the dimensions should be:
            [projections, slices, pixels].
            
        data_white, data_dark : ndarray, optional
            3-D white-field/dark_field data. Multiple
            projections are stacked together to obtain
            a 3-D matrix. 2nd and 3rd dimensions should
            be the same as data: [shots, slices, pixels].
            
        theta : ndarray, optional
            Data acquisition angles corresponding
            to each projection.

        data_excahnge_type : str, optional
            label defyining the type of data contained in data exchange file
            for raw data tomography data use 'tomography_raw_projections'

        source_name, source_mode, source_datetime : str, optional
            label defining the source name, operation mode and date/time when these values were taken

        beamline : str, optional
            label defining the beamline name
        
        energy, current : float, optional
            X-ray energy and bean current

        actual_pixel_size : float, optional
            pixel size on the sample plane
 
        experimenter_name, experimenter_affiliation, experimenter_email : str, optional
            user name, affiliation and e-mail address

        instrument_comment : str, optional
            instrument comment

        sample_name, sample_comment : str, optional
            sample name and comment
        
        acquisition_mode, acquisition_comment : str, optional
            acquisition mode and comment

        hd5_file_name : str
            Output file.

        Notes
        -----
        If file exists, does nothing
                
        Examples
        
        - Convert tomographic projection series (raw, dark, white)  of tiff in data exchange:
            
            >>> import dataexchange

            >>> file_name = '/local/dataraid/databank/Anka/radios/image_.tif'
            >>> dark_file_name = '/local/dataraid/databank/Anka/darks/image_.tif'
            >>> white_file_name = '/local/dataraid/databank/Anka/flats/image_.tif'

            >>> hdf5_file_name = '/local/dataraid/databank/dataExchange/tmp/Anka.h5'

            >>> projections_start = 0
            >>> projections_end = 3167
            >>> white_start = 0
            >>> white_end = 100
            >>> dark_start = 0
            >>> dark_end = 100

            >>> sample_name = 'Anka'
            >>> 
            >>> # Read raw data
            >>> read = dataexchange.Import()
            >>> data, white, dark, theta = read.xtomo_raw(file_name,
            >>>                                                    projections_start = projections_start,
            >>>                                                    projections_end = projections_end,
            >>>                                                    white_file_name = white_file_name,
            >>>                                                    white_start = white_start,
            >>>                                                    white_end = white_end,
            >>>                                                    dark_file_name = dark_file_name,
            >>>                                                    dark_start = dark_start,
            >>>                                                    dark_end = dark_end,
            >>>                                                    projections_digits = 5,
            >>>                                                    log='INFO'
            >>>                                                    )
            >>>
            >>> # Save data
            >>> write = dataexchange.Export()
            >>> write.xtomo_exchange(data = data,
            >>>                       data_white = white,
            >>>                       data_dark = dark,
            >>>                       theta = theta,
            >>>                       hdf5_file_name = hdf5_file_name,
            >>>                       data_exchange_type = 'tomography_raw_projections',
            >>>                       sample_name = sample_name
            >>>                       )

        """

        if (hdf5_file_name != None):
            if os.path.isfile(hdf5_file_name):
                self.logger.error("Data Exchange file: [%s] already exists",
                                  hdf5_file_name)
            else:
                # Create new folder.
                dirPath = os.path.dirname(hdf5_file_name)
                if not os.path.exists(dirPath):
                    os.makedirs(dirPath)

                # Get the file_name in lower case.
                lFn = hdf5_file_name.lower()

                # Split the string with the delimeter '.'
                end = lFn.split('.')

                # Write the Data Exchange HDF5 file.
                # Open DataExchange file
                f = DataExchangeFile(hdf5_file_name, mode='w')

                self.logger.info("Creating Data Exchange File [%s]",
                                 hdf5_file_name)

                # Create core HDF5 dataset in exchange group for projections_theta_range
                # deep stack of x,y images /exchange/data
                self.logger.info(
                    "Adding projections to Data Exchange File [%s]",
                    hdf5_file_name)
                f.add_entry(
                    DataExchangeEntry.data(
                        data={
                            'value': data,
                            'units': 'counts',
                            'description': 'transmission',
                            'axes': axes
                        }))
                #                f.add_entry( DataExchangeEntry.data(data={'value': data, 'units':'counts', 'description': 'transmission', 'axes':'theta:y:x', 'dataset_opts':  {'compression': 'gzip', 'compression_opts': 4} }))
                if (theta != None):
                    f.add_entry(
                        DataExchangeEntry.data(theta={
                            'value': theta,
                            'units': 'degrees'
                        }))
                    self.logger.info("Adding theta to Data Exchange File [%s]",
                                     hdf5_file_name)
                else:
                    self.logger.warning("theta is not defined")
                if (data_dark != None):
                    self.logger.info(
                        "Adding dark fields to  Data Exchange File [%s]",
                        hdf5_file_name)
                    f.add_entry(
                        DataExchangeEntry.data(
                            data_dark={
                                'value': data_dark,
                                'units': 'counts',
                                'axes': 'theta_dark:y:x'
                            }))
#                    f.add_entry( DataExchangeEntry.data(data_dark={'value': data_dark, 'units':'counts', 'axes':'theta_dark:y:x', 'dataset_opts':  {'compression': 'gzip', 'compression_opts': 4} }))
                else:
                    self.logger.warning("data dark is not defined")
                if (data_white != None):
                    self.logger.info(
                        "Adding white fields to  Data Exchange File [%s]",
                        hdf5_file_name)
                    f.add_entry(
                        DataExchangeEntry.data(
                            data_white={
                                'value': data_white,
                                'units': 'counts',
                                'axes': 'theta_white:y:x'
                            }))
#                    f.add_entry( DataExchangeEntry.data(data_white={'value': data_white, 'units':'counts', 'axes':'theta_white:y:x', 'dataset_opts':  {'compression': 'gzip', 'compression_opts': 4} }))
                else:
                    self.logger.warning("data white is not defined")
                if (data_exchange_type != None):
                    self.logger.info(
                        "Adding data type to  Data Exchange File [%s]",
                        hdf5_file_name)
                    f.add_entry(
                        DataExchangeEntry.data(
                            title={'value': data_exchange_type}))

                if (source_name != None):
                    f.add_entry(
                        DataExchangeEntry.source(name={'value': source_name}))
                if (source_mode != None):
                    f.add_entry(
                        DataExchangeEntry.source(mode={'value': source_mode}))
                if (source_datetime != None):
                    f.add_entry(
                        DataExchangeEntry.source(
                            datetime={'value': source_datetime}))

                if (beamline != None):
                    f.add_entry(
                        DataExchangeEntry.source(beamline={'value': beamline}))
                if (energy != None):
                    f.add_entry(
                        DataExchangeEntry.monochromator(
                            energy={
                                'value': energy,
                                'units': 'keV',
                                'dataset_opts': {
                                    'dtype': 'd'
                                }
                            }))
                if (current != None):
                    f.add_entry(
                        DataExchangeEntry.source(
                            current={
                                'value': current,
                                'units': 'mA',
                                'dataset_opts': {
                                    'dtype': 'd'
                                }
                            }))

                if (actual_pixel_size != None):
                    f.add_entry(
                        DataExchangeEntry.detector(actual_pixel_size_x={
                            'value': actual_pixel_size,
                            'units': 'microns',
                            'dataset_opts': {
                                'dtype': 'd'
                            }
                        },
                                                   actual_pixel_size_y={
                                                       'value':
                                                       actual_pixel_size,
                                                       'units': 'microns',
                                                       'dataset_opts': {
                                                           'dtype': 'd'
                                                       }
                                                   }))

                if (experimenter_name != None):
                    f.add_entry(
                        DataExchangeEntry.experimenter(
                            name={'value': experimenter_name}))
                if (experimenter_affiliation != None):
                    f.add_entry(
                        DataExchangeEntry.experimenter(
                            affiliation={'value': experimenter_affiliation}))
                if (experimenter_email != None):
                    f.add_entry(
                        DataExchangeEntry.experimenter(
                            email={'value': experimenter_email}))

                if (instrument_comment != None):
                    f.add_entry(
                        DataExchangeEntry.instrument(
                            comment={'value': instrument_comment}))
                if (sample_name == None):
                    sample_name = end[0]
                    f.add_entry(
                        DataExchangeEntry.sample(
                            name={'value': sample_name},
                            description={
                                'value':
                                'Sample name assigned by the HDF5 converter and based on the HDF5 file name'
                            }))
                else:
                    f.add_entry(
                        DataExchangeEntry.sample(name={'value': sample_name}))
                if (sample_comment != None):
                    f.add_entry(
                        DataExchangeEntry.sample(
                            comment={'value': sample_comment}))

                if (acquisition_mode != None):
                    f.add_entry(
                        DataExchangeEntry.acquisition(
                            mode={'value': acquisition_mode}))
                if (acquisition_comment != None):
                    f.add_entry(
                        DataExchangeEntry.acquisition(
                            comment={'value': acquisition_comment}))

                if (sample_position_x != None):
                    f.add_entry(
                        DataExchangeEntry.acquisition(
                            sample_position_x={
                                'value': sample_position_x,
                                'units': 'microns',
                                'dataset_opts': {
                                    'dtype': 'd'
                                }
                            }))
                if (sample_position_y != None):
                    f.add_entry(
                        DataExchangeEntry.acquisition(
                            sample_position_y={
                                'value': sample_position_y,
                                'units': 'microns',
                                'dataset_opts': {
                                    'dtype': 'd'
                                }
                            }))
                if (sample_position_z != None):
                    f.add_entry(
                        DataExchangeEntry.acquisition(
                            sample_position_z={
                                'value': sample_position_z,
                                'units': 'microns',
                                'dataset_opts': {
                                    'dtype': 'd'
                                }
                            }))

                if (sample_image_shift_x != None):
                    f.add_entry(
                        DataExchangeEntry.acquisition(
                            sample_image_shift_x={
                                'value': sample_image_shift_x,
                                'units': 'microns',
                                'dataset_opts': {
                                    'dtype': 'd'
                                }
                            }))
                if (sample_image_shift_y != None):
                    f.add_entry(
                        DataExchangeEntry.acquisition(
                            sample_image_shift_y={
                                'value': sample_image_shift_y,
                                'units': 'microns',
                                'dataset_opts': {
                                    'dtype': 'd'
                                }
                            }))

                f.close()
                self.logger.info("DONE!!!!. Created Data Exchange File [%s]",
                                 hdf5_file_name)

        else:
            self.logger.warning("Nothing to do ...")