root = io.find_root_folder(folder)

# Load Camera object
camera = io.load_camera(root)
print(f"Loaded Camera object: {camera}")

# Save location based on camera name
save_to_normalised = camera.filename_calibration("dark_current_normalised.npy")

# Get the ISO speed at which the data were taken from the folder name
ISO = io.split_iso(folder)
save_to_ADU = camera.filename_intermediaries(
    "dark_current/dark_current_iso{ISO}.npy", makefolders=True)

# Load the data
times, means = io.load_means(folder, retrieve_value=io.split_exposure_time)
print(f"Loaded data at {len(times)} exposure times")

# Fit a linear trend to each pixel
dark_current, bias_fit = dark.fit_dark_current_linear(times, means)
print("Fitted dark current to each pixel")

# Save the dark current map at this ISO
np.save(save_to_ADU, dark_current)
print(f"Saved dark current map at ISO {ISO} to '{save_to_ADU}'")

# ISO normalisation
dark_current_normalised = camera.normalise_iso(ISO, dark_current)

# Save the normalised dark current map
np.save(save_to_normalised, dark_current_normalised)
Beispiel #2
0
import numpy as np
from sys import argv
from matplotlib import pyplot as plt
from spectacle import io, raw
from spectacle.gain import malus
from scipy.optimize import curve_fit

folder = argv[1]

angles, means = io.load_means(f"{folder}/stacks/linearity/",
                              retrieve_value=io.split_pol_angle)
angles, stds = io.load_stds(f"{folder}/stacks/linearity/",
                            retrieve_value=io.split_pol_angle)
colours = np.load(f"{folder}/stacks/colour.npy")

mean_reshaped = np.moveaxis(means, 0, 2)
stds_reshaped = np.moveaxis(stds, 0, 2)


def malus_amp(angles, amplitude, offset_angle, offset_intensity):
    I = offset_intensity + amplitude * malus(angles, offset_angle)
    return I


def fit(data):
    popt, pcov = curve_fit(malus_amp, angles, data, p0=[1000, 74, 1000])
    return popt[1]


x = np.arange(means.shape[2])
y = np.arange(means.shape[1])
To do:
    * Save maps for all ISOs and use these in the calibration process.
"""

import numpy as np
from sys import argv
from spectacle import io

# Get the data folder from the command line
folder = io.path_from_input(argv)
root = io.find_root_folder(folder)

# Load Camera object
camera = io.load_camera(root)
print(f"Loaded Camera object: {camera}")

# Save location based on camera name
save_to = camera.filename_calibration("bias.npy")

# Load the mean stacks for each ISO value
isos, means = io.load_means(folder, retrieve_value=io.split_iso)
print(f"Loaded bias data for {len(isos)} ISO values from '{folder}'")

# Find the lowest ISO value in the data and select the respective bias map
lowest_iso_index = isos.argmin()
bias_map = means[lowest_iso_index]

# Save the bias map for calibration purposes
np.save(save_to, bias_map)
print(f"Saved bias map at ISO {isos[lowest_iso_index]} to '{save_to}'")
folder = io.path_from_input(argv)
root = io.find_root_folder(folder)

# Load Camera object
camera = io.load_camera(root)
print(f"Loaded Camera object: {camera}")

# Save location based on camera name
save_to_normalised_map = camera.filename_calibration("gain.npy")

# Get the ISO speed of these data from the folder name
ISO = io.split_iso(folder)
save_to_original_map = camera.filename_intermediaries(f"gain/gain_map_iso{ISO}.npy", makefolders=True)

# Load the data
names, means = io.load_means(folder)
names, stds = io.load_stds(folder)
print("Loaded data")

# Find pixels near saturation to mask later
fit_max = 0.95 * camera.saturation
mask = (means >= fit_max)

# Bias correction
means = camera.correct_bias(means)

# Use variance instead of standard deviation
variance = stds**2

# Make masked arrays that don't include non-linear values (near saturation)
means = np.ma.array(means, mask=mask)
camera = io.load_camera(root)
print(f"Loaded Camera object: {camera}")

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

# Find the indices of the central pixels
array_size = np.array(camera.image_shape)
mid1, mid2 = array_size // 2
center = np.s_[mid1:mid1 + 2, mid2:mid2 + 2]

# Bayer channels of the central pixels
colours_here = camera.bayer_map[center].ravel()

# Load the RAW data
intensities_with_errors, means = io.load_means(
    folder, retrieve_value=lin.filename_to_intensity, selection=center)
intensities, intensity_errors = intensities_with_errors.T
means = means.reshape((len(means), -1))
print("Loaded RAW data")

# Load the JPEG data, if available
try:
    intensities_with_errors, jmeans = io.load_jmeans(
        folder, retrieve_value=lin.filename_to_intensity, selection=center)
except ValueError:
    jpeg = False
else:
    intensities, intensity_errors = intensities_with_errors.T
    jpeg = True
    jmeans = jmeans.reshape((len(jmeans), -1, 3))
    print("Loaded JPEG data")