示例#1
0
# Bias correction
mean_bias_corrected = calibrate.correct_bias(root, mean_raw)

# Normalise the RGBG2 channels to a maximum of 1 each
mean_normalised, stds_normalised = flat.normalise_RGBG2(
    mean_bias_corrected, stds_raw, camera.bayer_map)
print("Normalised data")

# Calculate the signal-to-noise ratio (SNR) per pixel
SNR = mean_normalised / stds_normalised
print("Calculated signal-to-noise-ratio")

# Make a histogram of the SNR
save_to_histogram_SNR = savefolder / f"data_histogram_SNR_{label}.pdf"
SNR_top_percentile = analyse.symmetric_percentiles(SNR)[1]
bins_SNR = np.linspace(0, SNR_top_percentile, 100)

plt.figure(figsize=(4, 2), tight_layout=True)
plt.hist(SNR.ravel(), bins=bins_SNR, color='k')
plt.xlim(bins_SNR[0], bins_SNR[-1])
plt.xlabel("Signal-to-noise ratio")
plt.ylabel("Counts")
plt.savefig(save_to_histogram_SNR)
plt.close()
print(f"Saved histogram of signal-to-noise ratio to '{save_to_histogram_SNR}'")

# Make Gaussian maps of the SNR
save_to_maps_SNR = savefolder / f"data_SNR_{label}.pdf"
camera.plot_gauss_maps(SNR,
                       colorbar_label="Signal-to-noise ratio",
labels = ["Normalisation", "Best fit $\gamma$", "$R^2$"]

# Find the number of non-NaN pixels which will be used in the plot
number_of_pixels = gammas[...,0].size
pixels_not_nan = np.where(~np.isnan(gammas[...,0]))[0]
number_of_pixels_not_nan = pixels_not_nan.size
percentage_not_nan = 100. * number_of_pixels_not_nan / number_of_pixels
print(f"{number_of_pixels_not_nan}/{number_of_pixels} ({percentage_not_nan:.1f}%) of pixels are not NaN.")

# Create a figure to hold the plot
fig, axs = plt.subplots(ncols=3, figsize=(7,2), sharey=True, tight_layout=True, gridspec_kw={"wspace":0, "hspace":0})

# Loop over the results
for ax, result, label in zip(axs, [normalisations, gammas, R2s], labels):
    # Get bins from the range of data
    xmin, xmax = analyse.symmetric_percentiles(result)
    bins = np.linspace(xmin, xmax, 150)

    # Loop over the RGB channels
    for j, c in enumerate(plot.rgb):
        # Flatten the array and remove NaN elements
        result_c = result[...,j].ravel()
        result_c = result_c[~np.isnan(result_c)]
        ax.hist(result_c, bins, color=c, alpha=0.7)

    # Plot parameters
    ax.set_xlabel(label)
    ax.set_xlim(xmin, xmax)

# Plot parameters
axs[0].set_ylabel("Counts")
示例#3
0
# Get metadata
camera = io.load_metadata(root)

# Load the data
dark_current = np.load(file)
print("Loaded data")

# Convolve the map with a Gaussian kernel and plot an image of the result
save_to_maps = save_folder / "dark_current_map_ADU.pdf"
camera.plot_gauss_maps(dark_current,
                       colorbar_label="Dark current (norm. ADU/s)",
                       saveto=save_to_maps)
print(f"Saved Gauss map to '{save_to_maps}'")

# Range on the x axis for the histogram
xmin, xmax = analyse.symmetric_percentiles(dark_current, percent=0.001)

# Split the data into the RGBG2 filters and make histograms (aggregate and per
# filter)
save_to_histogram = save_folder / "dark_current_histogram_ADU.pdf"
camera.plot_histogram_RGB(dark_current,
                          xmin=xmin,
                          xmax=xmax,
                          xlabel="Dark current (norm. ADU/s)",
                          saveto=save_to_histogram)
print(f"Saved RGB histogram to '{save_to_histogram}'")

# Check how many pixels are over some threshold in dark current
threshold = 50
pixels_over_threshold = np.where(np.abs(dark_current) > threshold)
number_over_threshold = len(pixels_over_threshold[0])
示例#4
0
# Load Camera object
cameras = [io.load_camera(root) for root in roots]
print(f"Loaded Camera objects: {cameras}")

# Load the data
data_all = [np.load(path) for path in files]

# Demosaick the data
RGBGs_all = [camera.demosaick(data) for data, camera in zip(data_all, cameras)]

# Convolve the data with a Gaussian kernel
gauss_all = [gaussMd(RGBG, sigma=(0, 5, 5)) for RGBG in RGBGs_all]

# Minimum and maximum of colourbars
vmin, vmax = analyse.symmetric_percentiles(gauss_all)

# Figure to hold the subplots
fig, axs = plt.subplots(ncols=4,
                        nrows=len(files),
                        sharex=True,
                        sharey=True,
                        figsize=(7, 1.695 * len(files)),
                        squeeze=False,
                        tight_layout=True,
                        gridspec_kw={
                            "wspace": 0,
                            "hspace": 0
                        })

# Loop over the data and plot them
savefolder = camera.filename_analysis("readnoise", makefolders=True)

# Load the data
isos, stds = io.load_stds(folder, retrieve_value=io.split_iso)

# Normalise the data using the ISO look-up table
stds_normalised = camera.normalise_iso(isos, stds)

# Print statistics at each ISO
stats = analyse.statistics(stds_normalised,
                           prefix_column=isos,
                           prefix_column_header="ISO")
print(stats)

# Range on the x axis for the histograms
xmin, xmax = 0., analyse.symmetric_percentiles(stds_normalised)[1]

# Loop over the data and make plots at each ISO value
for ISO, std in zip(isos, stds_normalised):
    save_to_histogram = savefolder / f"readnoise_normalised_histogram_iso{ISO}.pdf"
    save_to_maps = savefolder / f"readnoise_normalised_map_iso{ISO}.pdf"

    camera.plot_histogram_RGB(std,
                              xmin=xmin,
                              xmax=xmax,
                              xlabel="Read noise (norm. ADU)",
                              saveto=save_to_histogram)
    camera.plot_gauss_maps(std,
                           colorbar_label="Read noise (norm. ADU)",
                           saveto=save_to_maps)
# Save location based on camera name
savefolder = camera.filename_analysis("bias", makefolders=True)

# Load the data
isos, means = io.load_means(folder, retrieve_value=io.split_iso)
print("Loaded data")

# Print statistics at each ISO
stats = analyse.statistics(means,
                           prefix_column=isos,
                           prefix_column_header="ISO")
print(stats)

# Range on the x axis for the histograms
xmin, xmax = analyse.symmetric_percentiles(means, percent=0.001)

# Loop over the data and make plots at each ISO value
for ISO, mean in zip(isos, means):
    save_to_histogram = savefolder / f"bias_histogram_iso{ISO}.pdf"
    save_to_maps = savefolder / f"bias_map_iso{ISO}.pdf"

    camera.plot_histogram_RGB(mean,
                              xmin=xmin,
                              xmax=xmax,
                              xlabel="Bias (ADU)",
                              saveto=save_to_histogram)
    camera.plot_gauss_maps(mean,
                           colorbar_label="Bias (ADU)",
                           saveto=save_to_maps)
示例#7
0
print(f"Loaded Camera object: {camera}")

# Save locations
savefolder = camera.filename_analysis("readnoise", makefolders=True)

# Load the data
isos, stds = io.load_stds(folder, retrieve_value=io.split_iso)

# Print statistics at each ISO
stats = analyse.statistics(stds,
                           prefix_column=isos,
                           prefix_column_header="ISO")
print(stats)

# Range on the x axis for the histograms
xmin, xmax = 0., analyse.symmetric_percentiles(stds)[1]

# Loop over the data and make plots at each ISO value
for ISO, std in zip(isos, stds):
    save_to_histogram = savefolder / f"readnoise_ADU_histogram_iso{ISO}.pdf"
    save_to_maps = savefolder / f"readnoise_ADU_map_iso{ISO}.pdf"

    camera.plot_histogram_RGB(std,
                              xmin=xmin,
                              xmax=xmax,
                              xlabel="Read noise (ADU)",
                              saveto=save_to_histogram)
    camera.plot_gauss_maps(std,
                           colorbar_label="Read noise (ADU)",
                           saveto=save_to_maps)
示例#8
0
save_to_histogram_RAW_JPEG = savefolder/f"histogram_raw_jpeg.pdf"

# Load the data
r_raw = np.load(file_raw)
print("Loaded RAW Pearson r map")
if jpeg_data_available:
    r_jpeg = np.load(file_jpeg)
    print("Loaded JPEG Pearson r map")

# Make Gaussian maps of the RAW data
camera.plot_gauss_maps(r_raw, colorbar_label="Pearson $r$", saveto=save_to_maps)
print(f"Saved maps of RAW Pearson r to '{save_to_maps}'")

# Make a Gaussian map of the JPEG data, if available
if jpeg_data_available:
    vmin, vmax = analyse.symmetric_percentiles(r_jpeg)
    fig, axs = plt.subplots(ncols=3, sharex=True, sharey=True, figsize=(5,2), tight_layout=True, gridspec_kw={"wspace":0, "hspace":0}, squeeze=True)
    for data, channel, ax in zip(r_jpeg, plot.rgb, axs):
        img = ax.imshow(data, vmin=vmin, vmax=vmax, cmap=plot.cmaps[channel])
        colorbar_here = plot.colorbar(img)
        ax.set_xticks([])
        ax.set_yticks([])
        if ax is axs[1]:
            colorbar_here.set_label("Pearson $r$")
        colorbar_here.locator = plot.ticker.MaxNLocator(nbins=4)
        colorbar_here.update_ticks()
    plt.savefig(save_to_map_JPEG)
    plt.close()
    print(f"Saved map of JPEG Pearson r to '{save_to_map_JPEG}'")

# Print comparative statistics on the RAW and JPEG (R/G/B) Pearson r values
示例#9
0
# Get the data folder from the command line
file = io.path_from_input(argv)
root = io.find_root_folder(file)
savefolder = root / "analysis/gain/"
ISO = io.split_iso(file)

# Get metadata
camera = io.load_metadata(root)
print("Loaded metadata")

# Load the data
gains = np.load(file)
print("Loaded data")

# Plot an RGB histogram of the data
xmin, xmax = 0, analyse.symmetric_percentiles(gains, percent=0.001)[1]
camera.plot_histogram_RGB(gains,
                          xmin=xmin,
                          xmax=xmax,
                          xlabel="Gain (ADU/e$^-$)",
                          saveto=savefolder / f"gain_histogram_iso{ISO}.pdf")
print("Made histogram")

# Plot Gauss-convolved maps of the data
camera.plot_gauss_maps(gains,
                       colorbar_label="Gain (ADU/e$^-$)",
                       saveto=savefolder / f"gain_map_iso{ISO}.pdf")
print("Made maps")

# Demosaick data by splitting the RGBG2 channels into separate arrays
gains_RGBG = camera.demosaick(gains)
示例#10
0
        ax.set_title(label)

        # Include a colorbar
        # Left-most map has a colorbar on the left
        if ax is axs[0]:
            loc = "left"
        # Right-most map has a colorbar on the right
        elif ax is axs[-1]:
            loc = "right"
        # Any other maps have a colorbar on the bottom
        else:
            loc = "bottom"
        cbar = plot.colorbar(im, location=loc, label="Gain (ADU/e$^-$)")

        # Print the range of gain values found in this map
        percentile_low, percentile_high = analyse.symmetric_percentiles(
            data_RGBG)
        print(label)
        print(f"{c_label:>2}: {percentile_low:.2f} -- {percentile_high:.2f}")

    # Save the figure
    save_to_map_c = save_folder / f"gain_map_{c_label}.pdf"
    fig.savefig(save_to_map_c)
    plt.close()
    print(f"Saved gain map for the {c_label} channel to '{save_to_map_c}'")

# Plot a histogram
fig, axs = plt.subplots(ncols=len(files),
                        nrows=4,
                        figsize=(3 * len(files), 3),
                        tight_layout=True,
                        gridspec_kw={