Ejemplo n.º 1
0
def noisy_r(i, d):
    """
    Calculate the Pearson r value for a noisy image with noisy intensities.
    """

    i_o = i + np.random.normal(0, intensity_typical_error, size=len(i)) * i
    n = np.array([
        np.random.normal(
            0,
            np.sqrt(D / number_of_measurements_per_stack) + read_noise)
        for D in d
    ])
    d_n = d + n
    r = lin.pearson_r_single(i_o, d_n, saturate)
    return r
Ejemplo n.º 2
0
    # Loop over the cameras and their associated data
    for camera, ax_column, intensities, intensity_errors, means_raw, means_jpeg in zip(
            cameras, axs.T, intensities_all, intensities_error_all,
            mean_raw_all, mean_jpeg_all):
        # Select the mean data from the relevant channel only
        # This is very clunky (double for-loop and still using an index anyway)
        # It might be better to change the way data are loaded (e.g. per
        # channel instead of per camera) reverse the order of these for-loops
        mean_raw_c = means_raw[:, j]
        mean_jpeg_c = means_jpeg[:, j]

        # Calculate Pearson r values of the RAW and JPEG data
        # These are added to the plot titles
        r_raw = lin.pearson_r_single(intensities,
                                     mean_raw_c,
                                     saturate=0.95 * camera.saturation)
        r_jpeg = lin.pearson_r_single(intensities, mean_jpeg_c, saturate=240)

        # Plot title, including device name and r values calculated above
        title = camera.name + "\n" + "$r_{JPEG} = " + f"{r_jpeg:.3f}" + "$   $r_{RAW} = " + f"{r_raw:.3f}" + "$"

        # Fit a linear function to the RAW response and an sRGB function to the
        # JPEG response, to plot as lines
        x = np.linspace(0, 1, 250)

        non_saturated_indices_raw = np.where(
            mean_raw_c < 0.95 * camera.saturation)
        fit_raw = np.polyfit(intensities[non_saturated_indices_raw],
                             mean_raw_c[non_saturated_indices_raw], 1)
        line_raw = np.clip(np.polyval(fit_raw, x), 0, camera.saturation)
Ejemplo n.º 3
0
bit_number = 12
max_value = 2**bit_number - 1
saturate = 0.95 * max_value

# Bias and read noise characteristics
bias = 528
read_noise = 10  # ADU

intensity_typical_error = 0.05  # %

# Camera response under perfect, noiseless conditions
intensities_real = np.linspace(0, 1, number_of_intensities)
digital_values = bias + intensities_real * (max_value - bias)

# Observed r under perfect, noiseless conditions
r_pure = lin.pearson_r_single(intensities_real, digital_values, saturate)
print(f"Pearson r on pure  I, M:      {r_pure:.3f}")

# Add an observation error to the intensity (e.g. uncertainty in exposure time
# or in polariser angle)
intensities_observed = intensities_real + np.random.normal(
    0, intensity_typical_error, size=len(intensities_real)) * intensities_real
r_noisyI = lin.pearson_r_single(intensities_observed, digital_values, saturate)
print(f"Pearson r on noisy I, pure M: {r_noisyI:.3f}")

# Add a measurement error in the camera response
noise_ADU = np.array([
    np.random.normal(
        0,
        np.sqrt(D / number_of_measurements_per_stack) + read_noise)
    for D in digital_values