io#

Functions for loading and preprocessing raw data from the disk.

tike.ptycho.io.position_units_to_pixels(positions, detector_distance, detector_pixel_count, detector_pixel_width, photon_energy)[source]#

Convert scanning positions units from meters to pixels coordinates.

Parameters
  • positions (array[float] [m]) – Coordinates of the position of the beam when frames were collected.

  • detector_distance (float [m]) – The propagation distance of the beam from the sample to the detector.

  • detector_pixel_count (int) – The number of pixels across one edge of the detector. Assumes a square detector.

  • detector_pixel_width (float [m]) – The width of one detector pixel. Assumes square pixels.

  • photon_energy (float [eV]) – The energy of the incident beam.

Returns

positions – The scanning positions in pixel coordinates.

Return type

float [pixels]

tike.ptycho.io.read_aps_lynx(diffraction_path, position_path, photon_energy, beam_center_x, beam_center_y, detector_dist, xy_columns=(6, 3), trigger_column=0, max_crop=2048, gap_value=4095, binned_pix=1)[source]#

Load ptychography data from Advanced Photon Source LYNX.

Expects one h5 file and one dat file with the following organization:

diffraction_path:
    entry:NXentry
    @NX_class = NXentry
        data:NXdata
        @NX_class = NXdata
        eiger_4:NX_UINT16[12320,1030,1614] =
            @Count_cutoff = 199998
            @Exposure_period = 0.052000000000000005
            @Exposure_time = 0.005
            @Pixel_size = [7.5e-05]

DAT is a space-separated text file with two rows of headers with positions in nanometers.

Parameters
  • diffraction_path (string) – The absolute path to the HDF5 file containing diffraction patterns.

  • position_path (string) – The absolute path to the CSV file containing position information.

  • xy_columns (2-tuple of int) – The columns in the 8 column raw position file to use for x,y positions

  • trigger_column (int) – The column in the 8 column raw position file to use for grouping positions together.

  • max_crop (int) – Crop the diffraction pattern to at most this width.

  • gap_value (int) – The value used to encode detector gaps

  • binned_pix (int) – The number of pixels binned together along each dimension

Returns

  • data ((FRAME, WIDE, HIGH)) – Diffraction patterns; cropped square and peak FFT shifted to corner.

  • scan ((POSI, 2) float32) – Scan positions; rescaled to pixel coordinates but uncentered.

Return type

Tuple[numpy.typing.NDArray, numpy.typing.NDArray]

tike.ptycho.io.read_aps_velociprobe(diffraction_path, position_path, xy_columns=(5, 1), trigger_column=7, max_crop=2048, binned_pix=1)[source]#

Load ptychography data from the Advanced Photon Source Velociprobe.

Expects one HDF5 file and one CSV file with the following organization:

diffraction_path:
    /entry
        /data
            /data_000000:int[FRAME, WIDE, HIGH] {unit: counts}
            /data_000001:int[FRAME, WIDE, HIGH] {unit: counts}
            ...
        /instrument
            /detector
                /beam_center_x:float            {unit: pixel}
                /beam_center_y:float            {unit: pixel}
                /detectorSpecific
                    /photon_energy:float        {unit: eV}
                    /x_pixels_in_detector:int
                    /y_pixels_in_detector:int
                /detector_distance:float        {unit: m}
                /x_pixel_size:float             {unit: m}
        /sample
            /goniometer
                /chi:float[]                    {unit: degree }

Where FRAME is the number of detector frames recorded and WIDE/HIGH is the width and height. The number of data_000000 links may be more than the actual number of files because of some problem where the master file is created before the linked files are created.

We use lz4 to compress the data. In order to open these compressed datasets, you have to install the lz4 filter plugins (nexusformat/HDF5-External-Filter-Plugins).

The CSV position raw data file is a 8 column file with columns corresponding to the following parameters: samz, samx, samy, zpx, zpy, encoder y, encoder x, trigger number. Because the horizontal stage is on top of the rotation, stage, we must use the rotation stage position to correct the horizontal scanning positions. By default we use samx, encoder y for the horizontal and vertical positions.

Parameters
  • diffraction_path (string) – The absolute path to the HDF5 file containing diffraction patterns and other metadata.

  • position_path (string OR List[string]) – The absolute path to the CSV file(s) containing position information.

  • xy_columns (2-tuple of int) – The columns in the 8 column raw position file to use for x,y positions

  • trigger_column (int) – The column in the 8 column raw position file to use for grouping positions together.

  • max_crop (int) – Crop the diffraction pattern to at most this width.

  • binned_pix (int) – The number of pixels binned together along each dimension

Returns

  • data ((FRAME, WIDE, HIGH)) – Diffraction patterns; cropped square and peak FFT shifted to corner.

  • scan ((POSI, 2) float32) – Scan positions; rescaled to pixel coordinates but uncentered.

Return type

Tuple[numpy.typing.NDArray, numpy.typing.NDArray]