Exemplo n.º 1
0
            temp_array[np.nonzero(temp_mask)] = 1  # enough, numpy array is mutable hence mask will be modified
        del temp_mask, dim, original_data, flag_pause
        gc.collect()

    data[mask == 1] = 0
    flag_mask = False

    #############################################
    # mask or median filter isolated empty pixels
    #############################################
    if flag_medianfilter == 'mask_isolated' or flag_medianfilter == 'interp_isolated':
        print("\nFiltering isolated pixels")
        nb_pix = 0
        for idx in range(pad_width[0], nz-pad_width[1]):  # filter only frames whith data (not padded)
            data[idx, :, :], numb_pix, mask[idx, :, :] = \
                pru.mean_filter(data=data[idx, :, :], nb_neighbours=medfilt_order, mask=mask[idx, :, :],
                                interpolate=flag_medianfilter, min_count=3, debugging=debug)
            nb_pix = nb_pix + numb_pix
            print("Processed image nb: ", idx)
        if flag_medianfilter == 'mask_isolated':
            print("Total number of masked isolated pixels: ", nb_pix)
        if flag_medianfilter == 'interp_isolated':
            print("Total number of interpolated isolated pixels: ", nb_pix)

    elif flag_medianfilter == 'median':  # apply median filter
        for idx in range(pad_width[0], nz-pad_width[1]):  # filter only frames whith data (not padded)
            data[idx, :, :] = scipy.signal.medfilt2d(data[idx, :, :], [3, 3])
        print("Applying median filtering")
    else:
        print("Skipping median filtering")

    #############################################
Exemplo n.º 2
0
                    reciprocal_space=True)

#######################################################################
# interactive interface to check the PRTF along particular directions #
#######################################################################
if flag_interact:
    if interpolate_nans:  # filter out the nan values
        linecut_prtf = np.copy(prtf_matrix)
        print(
            '\nInterpolating the 3D PRTF on nan values, it will take some time ...'
        )
        print(f'nb_nans before interpolation = {np.isnan(linecut_prtf).sum()}')
        linecut_prtf, nb_filtered, _ = pru.mean_filter(
            data=linecut_prtf,
            nb_neighbours=1,
            interpolate='interp_isolated',
            min_count=0,
            extent=1,
            target_val=np.nan,
            debugging=debug)
        print(f'nb_nans after = {np.isnan(linecut_prtf).sum()}')
        gu.multislices_plot(linecut_prtf,
                            sum_frames=False,
                            plot_colorbar=True,
                            cmap=my_cmap,
                            title='prtf_matrix after interpolation',
                            scale='linear',
                            vmin=0,
                            reciprocal_space=True)
        np.savez_compressed(detector.savedir + 'linecut_prtf.npz',
                            data=linecut_prtf)
    else: