示例#1
0
def determine_spot_diff(self, row, column, auto_sum=True):
    """Determines the diffraction pattern for a given x and y location
    
    :param self: the SXDMFrameset
    :param row: the row value
    :param column: the column value
    :param auto_sum: (bool) would you like to summ all the diffraction patterns? True = yes
    :return: the diffraction pattern(s)
    """

    pix = grab_pix(array=self.image_array,
                   row=row,
                   column=column,
                   int_convert=True)
    destination = h5get_image_destination(self=self, pixel=pix)
    each_scan_diffraction = sum_pixel(self=self, images_loc=destination)

    # Background Correction
    backgrounds = scan_background_finder(destination=destination,
                                         background_dic=self.background_dic)
    each_scan_diffraction_post = np.subtract(each_scan_diffraction,
                                             backgrounds)

    if auto_sum:
        summed_dif = np.sum(each_scan_diffraction_post, axis=0)
    elif not auto_sum:
        summed_dif = each_scan_diffraction_post

    return summed_dif
示例#2
0
def summed2d_all_data(self, bkg_multiplier=0):
    """Loads the summed diffraction patter without using a large amount of RAM

    Parameters
    ==========
    self (SXDMFrameset)
        the sxdmframeset object
    bkg_multiplier (int)
        the multiplier for the background images

    Returns
    =======
    the 2D summed diffraction pattern
    """
    # Grab the fov dimensions
    dims = grab_fov_dimensions(self)

    # Determining the rows and columns
    rows = dims[1] - 1
    columns = dims[2] - 1
    image_array = self.image_array

    self.background_dic = scan_background(self=self, multiplier=bkg_multiplier)

    # open the hdf file

    for column in tqdm(range(0, columns), desc='Loading 2D'):
        for row in range(0, rows):

            # Getting scan locations
            pix = grab_pix(array=image_array, row=row, column=column, int_convert=True)
            destination = h5get_image_destination(self=self, pixel=pix)

            # Getting diffraction images
            each_scan_diffraction = sum_pixel(self=self, images_loc=destination)

            if bkg_multiplier != 0:
                # Background Correction
                backgrounds = scan_background_finder(destination=destination, background_dic=self.background_dic)

                each_scan_diffraction_post = np.subtract(each_scan_diffraction, backgrounds)
            else:
                # If bkg is set to zero no need for background correction
                each_scan_diffraction_post = each_scan_diffraction

            summed_dif = np.sum(each_scan_diffraction_post, axis=0)

            try:
                total2 = np.add(total2, summed_dif)
            except:
                total2 = summed_dif

    return total2
示例#3
0
def general_pixel_analysis_multi(row, column, image_array, scan_numbers, background_dic, file, analysis_function, analysis_input):
    """The analysis done on a single pixel

    Parameters
    ==========
    row: (int)
        the row the User wants to do analysis on
    column: (int)
        the column the User wants to do analysis on
    image_array: (nd.array)
        the image location array - can be created with create_imagearray(self)
    scan_numbers: (nd.array)
        the list of scan numbers used
    background_dic: (dic)
        the background scan dictionary entry - can be made with scan_backgrounnd(self)
    file: (str)
        the hdf5 file location
    analysis_function: (func)
        a function to be passed into the analysis. the program will find the summed diffraction pattern for each pixel,
        for each scan number of the dataset, background subtract, and pass the summed diffraction into the first
        analysis_function argument.
    analysis_input: (user defined)
        an static input array, value, etc passed into the second argument in the analysis_function.

    Returns
    =======
    the analysis results as an nd.array

    """
    if column == 0 and row % 2 == 0:
        if ram_check() > 90:
            return False

    # This grabs the pixel diffraction information
    pix = grab_pix(array=image_array, row=row, column=column, int_convert=True)

    # This grabs the locations of all of those images it just grabbed
    destination = h5get_image_destination_multi(scan_numbers=scan_numbers, pixel=pix)

    # This will sum together all of those diffraction images
    each_scan_diffraction = sum_pixel_multi(file=file, images_loc=destination)


    # This finds the background
    backgrounds = scan_background_finder(destination=destination, background_dic=background_dic)

    # This subtracts the background
    each_scan_diffraction_post = np.subtract(each_scan_diffraction, backgrounds)

    # This sums together all the background corrected images for that single pixel
    #summed_dif = np.sum(each_scan_diffraction_post, axis=0)


    analysis_output = analysis_function(each_scan_diffraction_post, analysis_input)

    results = [(row, column)]

    for array in analysis_output:
        results.append(array)

    return results
示例#4
0
def summed2d_all_data_v2(self, bkg_multiplier=0):
    """Loads the summed diffraction patter without using a large amount of RAM

    Parameters
    ==========
    self (SXDMFrameset)
        the sxdmframeset object
    bkg_multiplier (int)
        the multiplier for the background images

    Returns
    =======
    the 2D summed diffraction pattern
    """
    # Grab the fov dimensions
    #dims = grab_fov_dimensions(self)
    #user_input = input('What Scan Are You Doing? centroid/roi/all ?')

    user_input = 'all'

    if user_input == 'roi':
        rows_pre = self.roi_analysis_total_rows
        columns_pre = self.roi_analysis_total_columns
    elif user_input == 'centroid':
        rows_pre = self.centroid_analysis_total_rows
        columns_pre = self.centroid_analysis_total_columns
    elif user_input == 'all':
        dims = grab_fov_dimensions(self)
        rows_pre = dims[1] - 1
        columns_pre = dims[2] - 1

    # Determining the rows and columns
    if isinstance(rows_pre, int):
        start_row = 0
        end_row = rows_pre
    elif isinstance(rows_pre, tuple):
        start_row = rows_pre[0]
        end_row = rows_pre[1]

    if isinstance(columns_pre, int):
        start_column = 0
        end_column = columns_pre
    elif isinstance(columns_pre, tuple):
        start_column = columns_pre[0]
        end_column = columns_pre[1]


    image_array = self.image_array

    bkg = scan_background(self=self, multiplier=bkg_multiplier)

    # open the hdf file
    with h5py.File(self.file, 'r') as hdf:

        for row in tqdm(range(start_row, end_row), desc='Loading 2D'):
            for column in range(start_column, end_column):

                # Getting scan locations
                pix = grab_pix(array=image_array, row=row, column=column, int_convert=True)
                destination = h5get_image_destination(self=self, pixel=pix)

                # Getting diffraction images
                each_scan_diffraction = sum_pixel_v2(images_loc=destination, file=hdf)


                if bkg_multiplier != 0:
                    # Background Correction
                    backgrounds = scan_background_finder(destination=destination, background_dic=self.background_dic)
                    try:
                        each_scan_diffraction_post = np.subtract(each_scan_diffraction, backgrounds)
                    except Exception as ex:
                        print(ex)
                else:
                    # If bkg is set to zero no need for background correction
                    each_scan_diffraction_post = each_scan_diffraction

                summed_dif = np.sum(each_scan_diffraction_post, axis=0)

                try:
                    total2 = np.add(total2, summed_dif)
                except:
                    total2 = summed_dif

    return total2
示例#5
0
def centroid_pixel_analysis_multi(row, column, median_blur_distance,
                                  median_blur_height, stdev_min, image_array,
                                  scan_numbers, background_dic, file):
    """The analysis done on a single pixel
    Parameters
    ==========
    row: (int)
        the row the User wants to do analysis on
    column: (int)
        the column the User wants to do analysis on
    median_blur_distance: (int)
        the amount of values to scan for median blur
    median_blur_height:  (int)
        the height cut off for the median blur
    stdev_min: (int)
        standard deviation above the mean of signal to ignore
    image_array: (nd.array)
        the image location array - can be created with create_imagearray(self)
    scan_numbers: (nd.array)
        the list of scan numbers used
    background_dic: (dic)
        the background scan dictionary entry - can be made with scan_backgrounnd(self)
    file: (str)
        the hdf5 file location
    Returns
    =======
    the analysis results as an nd.array
    """
    if column == 0 and row % 2 == 0:
        if ram_check() > 90:
            return False

    pix = grab_pix(array=image_array, row=row, column=column, int_convert=True)
    destination = h5get_image_destination_multi(scan_numbers=scan_numbers,
                                                pixel=pix)

    each_scan_diffraction = sum_pixel_multi(file=file, images_loc=destination)

    # Background Correction
    backgrounds = scan_background_finder(destination=destination,
                                         background_dic=background_dic)

    each_scan_diffraction_post = np.subtract(each_scan_diffraction,
                                             backgrounds)
    summed_dif = np.sum(each_scan_diffraction_post, axis=0)

    ttheta, ttheta_centroid, ttheta_centroid_finder, ttheta2 = theta_maths(
        summed_dif, median_blur_distance, median_blur_height, stdev_min)
    chi, chi_centroid, chi_centroid_finder = chi_maths(summed_dif,
                                                       median_blur_distance,
                                                       median_blur_height,
                                                       stdev_min)

    full_roi = np.sum(ttheta2)

    # Setting this to zero to solve high RAM usage
    summed_dif = 0

    results = [(row, column), summed_dif, ttheta, chi, ttheta_centroid_finder,
               ttheta_centroid, chi_centroid_finder, chi_centroid, full_roi]

    return results
示例#6
0
def roi_pixel_analysis_multi(row,
                             column,
                             median_blur_distance,
                             median_blur_height,
                             image_array,
                             scan_numbers,
                             background_dic,
                             file,
                             diff_segments=False):
    """The analysis done on a single pixel - this will get the new roi for each theta
    and be able to segment out diffraction areas and create the roi for them
    Parameters
    ==========
    row: (int)
        the total number of rows you want to iterate through
    column: (int)
        the total number of columns you want to iterate through
    median_blur_distance: (int)
        the amount of values to scan for median blur
    median_blur_height: (int)
        the height cut off for the median blur
    image_array: (nd.array)
        the location for all the pixels - can be created through create_imagearray(self)
    scan_numbers: (array)
        the list of scan numbers
    background_dic: (dic)
        the dictionary for the background images - created through scan_background(self)
    file: (str)
        the location to the hdf5 file
    diff_segments: (array)
        array used for segmenting the diffraction patterns
    Returns
    =======
    the analysis results as an nd.array
    [(row, column), idxs,
               raw_scan_data, corr_scan_data, scan_data_roi_vals,
               summed_data, corr_summed_data, summed_data_roi_vals]
    """

    median_blur = config.median_blur

    if column == 0:
        if ram_check() > 90:
            return False

    pix = grab_pix(array=image_array, row=row, column=column, int_convert=True)
    destination = h5get_image_destination_multi(scan_numbers, pixel=pix)

    each_scan_diffraction = sum_pixel_multi(file, images_loc=destination)

    # Background Correction
    backgrounds = scan_background_finder(destination=destination,
                                         background_dic=background_dic)

    # All diffraction images for the current pixel
    each_scan_diffraction_post = np.subtract(each_scan_diffraction,
                                             backgrounds)

    # Obtain all master array scan_number index values that the diffraction scans correspond to
    idxs = get_idx4roi(pix=pix,
                       destination=destination,
                       scan_numbers=scan_numbers)

    raw_scan_data = []
    corr_scan_data = []
    scan_data_roi_vals = []

    # SCAN DATA
    # For each of the scan_diffraction_post
    for diffraction in each_scan_diffraction_post:

        # sum down an axis
        ttheta = np.sum(diffraction, axis=0)
        ttheta_copy = ttheta.copy()

        # store this to an array
        raw_scan_data.append(ttheta)

        # median blur it and store
        ttheta_copy = median_blur(input_array=ttheta_copy,
                                  median_blur_distance=median_blur_distance,
                                  cut_off_value_above_mean=median_blur_height,
                                  with_low=True)

        corr_scan_data.append(ttheta_copy)

        # sum to single value and store
        scan_roi_val = np.sum(ttheta_copy)
        scan_data_roi_vals.append(scan_roi_val)

    # start roi bounding arrays
    summed_data = []
    corr_summed_data = []
    summed_data_roi_vals = []

    # create the summed diffraction pattern for the selected pixel location
    summed_dif = np.sum(each_scan_diffraction_post, axis=0)

    # only do this is the user wants it done

    if diff_segments != False:

        # for each bounding box
        for segment in diff_segments:
            # segment the summed diffraction pattern
            segmented_diffraction = summed_dif[int(segment[2]):int(segment[3]),
                                               int(segment[0]):int(segment[1])]

            # sum it down an axis and store
            ttheta = np.sum(segmented_diffraction, axis=0)
            ttheta_copy = ttheta.copy()
            summed_data.append(ttheta)

            # median blur it and store
            ttheta_copy = median_blur(
                input_array=ttheta_copy,
                median_blur_distance=median_blur_distance,
                cut_off_value_above_mean=median_blur_height)
            corr_summed_data.append(ttheta_copy)

            # sum to single value and store
            summed_data_roi_val = np.sum(ttheta_copy)
            summed_data_roi_vals.append(summed_data_roi_val)

    results = [(row, column), idxs, raw_scan_data, corr_scan_data,
               scan_data_roi_vals, summed_data, corr_summed_data,
               summed_data_roi_vals]

    return results