Exemplo n.º 1
0
the system time and an increasing number. This ensures the subfolders are
in the same order as the original data.

Command line arguments:
    * `folder_main`: folder containing RAW (and JPEG, if available) files which
    should be split into subfolders.
    * `blocksize`: the number of files to put in each folder (e.g. 10, 15).
"""

from sys import argv
from shutil import move
import os
from time import time
from spectacle import io

folder_main = io.path_from_input(argv[:2])
root = io.find_root_folder(folder_main)
camera = io.load_metadata(root)
raw_pattern = f"*{camera.image.raw_extension}"

blocksize = int(argv[2])
files = list(folder_main.glob(raw_pattern))
files = sorted(files)
blocks = len(files) // blocksize
for i in range(blocks):
    foldername = str(int(time() * 10000)) + str(i % 10)
    total_path = folder_main / foldername
    print(total_path)
    os.mkdir(total_path)
    files_block = files[blocksize * i:blocksize * (i + 1)]
    for file in files_block:
Exemplo n.º 2
0
Command line arguments:
    * `folder`: folder containing NPY stacks of dark-current data taken at
    different exposure times.

To do:
    * Save maps for all ISOs and use these in the calibration process.
    * Generic filenames, if data are not labelled by ISO.
"""

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

# 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_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
Exemplo n.º 3
0
import numpy as np
from sys import argv
from spectacle import io, calibrate
from matplotlib import pyplot as plt

folder, wvl = io.path_from_input(argv)
wvl = wvl.stem
root = io.find_root_folder(folder)
camera = io.load_metadata(root)

m = np.load(folder / f"{wvl}_mean.npy")
m = calibrate.correct_bias(root, m)
s = np.load(folder / f"{wvl}_stds.npy")

s[s < 0.001] = -1  # prevent infinities

SNR = m / s

m_RGBG, s_RGBG, SNR_RGBG = camera.demosaick(m, s, SNR)

mean_stack = m_RGBG.mean(axis=(1, 2))
std_stack = m_RGBG.std(axis=(1, 2))
SNR_stack = mean_stack / std_stack

for j, c in enumerate("RGBG"):
    SNR_here = SNR_RGBG[j].ravel()
    mean_here = m_RGBG[j].ravel()
    plt.figure(figsize=(10, 3))
    plt.hist(SNR_here, bins=np.arange(0, 100, 1), color=c)
    plt.xlabel("SNR")
    plt.axvline(3, c='k', ls="--")
Analyse dark current maps (in normalised ADU/s) generated using the calibration
functions. The dark current is converted from normalised ADU/s to electrons/s
using a gain map.

Command line arguments:
    * `file`: the location of the dark current map to be analysed. This map
    should be an NPY file generated using ../calibration/dark_current.py.
"""


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

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

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

# Save locations
savefolder = camera.filename_analysis("dark_current", makefolders=True)
save_to_maps = savefolder/"dark_current_map_electrons.pdf"
save_to_histogram = savefolder/"dark_current_histogram_electrons.pdf"

# Load the data
dark_current_normADU = np.load(file)
print("Loaded data")
Exemplo n.º 5
0
These calculations are all done for each individual pixel.

Command line arguments:
    * `folder`: the folder containing linearity data stacks. These should be
    NPY stacks taken at different exposure conditions, with the same ISO speed.
    * `gamma`: the gamma value of the sRGB model to compare to the data. Any
    number of gamma values can be provided.
"""

import numpy as np
from sys import argv
from spectacle import io, linearity as lin

# Get the data folder from the command line
folder, *gammas = io.path_from_input(argv)
gammas = [float(str(gamma)) for gamma in gammas]
root = io.find_root_folder(folder)

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

# Save locations
savefolder = camera.filename_intermediaries("flatfield", makefolders=True)

# Load the data
intensities_with_errors, jmeans = io.load_jmeans(folder, retrieve_value=lin.filename_to_intensity)
intensities, intensity_errors = intensities_with_errors.T
print("Loaded data")
Exemplo n.º 6
0
monochromator. The data are expected to be in subfolders of a main folder, each
subfolder corresponding to a monochromator setting (e.g. filter/grating).

Command line arguments:
    * `folder`: folder containing subfolders with monochromator data. The sub-
    folders correspond to different monochromator settings (e.g. gratings or
    filters). Each subfolder in turn contains NPY stacks of monochromator data
    taken at different wavelengths.
"""

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

# Get the data folder and minimum and maximum wavelengths from the command line
folder, wvl1, wvl2 = io.path_from_input(argv)
wvl1 = float(wvl1.stem)
wvl2 = float(wvl2.stem)
root = io.find_root_folder(folder)

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

# Get the subfolders in the given data folder
folders = io.find_subfolders(folder)

# Load the data from each subfolder
spectra = [
    spectral.load_monochromator_data(root, subfolder) for subfolder in folders
]
    * `file2`: the location of the second flat-field map.
    These flat-field maps should be NPY stacks generated using
    ../calibration/flatfield.py

To do:
    * Input labels for plots
"""

import numpy as np
from sys import argv
from spectacle import io, analyse, plot
from spectacle.general import RMS
from matplotlib import pyplot as plt

# Get the data folder from the command line
file1, file2 = io.path_from_input(argv)
root = io.find_root_folder(file1)
label = "comparison_" + file1.stem + "_X_" + file2.stem

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

# Save locations
savefolder = camera.filename_analysis("flatfield", makefolders=True)
save_to_histogram = savefolder / f"{label}_histogram.pdf"
save_to_histogram_RGB = savefolder / f"{label}_histogram_RGB.pdf"
save_to_maps = savefolder / f"{label}_map.pdf"
save_to_combined_map = savefolder / f"{label}_map_combined.pdf"

# Load the data
Exemplo n.º 8
0
    * `file_raw`: the file containing the Pearson r map to be analysed. This r
    map should be an NPY stack generated using linearity_raw.py.
    Optional:
    * `file_jpeg`: the file containing the JPEG Pearson r map to be analysed.
    This r map should be an NPY stacks generated using linearity_jpeg.py.
"""

import numpy as np
from sys import argv
from matplotlib import pyplot as plt
from spectacle import io, analyse, plot

# Get the data folder from the command line
# Use JPEG data if these are provided
try:
    file_raw, file_jpeg = io.path_from_input(argv)
except TypeError:
    file_raw = io.path_from_input(argv)
    jpeg_data_available = False
else:
    jpeg_data_available = True
root = io.find_root_folder(file_raw)
if jpeg_data_available:
    print("JPEG data have been provided")
else:
    print("JPEG data are not available")

# Load Camera object
camera = io.load_camera(root)
print(f"Loaded Camera object: {camera}")
Exemplo n.º 9
0
"""
Compare stacked images to WISP data.
"""

import numpy as np
from sys import argv
from spectacle import plot, io, wavelength, raw, general, calibrate
from ispex import general as ispex_general, plot as ispex_plot, validation
from matplotlib import pyplot as plt
from pathlib import Path

# Get the filenames from the command line
filename_ispex, filename_wisp = io.path_from_input(argv)

# For iSPEX, get the grey card, sky, and water filenames
# For now, assume the given filename was for the grey card
label_dataset = filename_ispex.parents[1].stem
parent_ispex = filename_ispex.parent
filename_grey = filename_ispex
filename_sky = parent_ispex / (filename_grey.stem.replace("grey", "sky") +
                               filename_grey.suffix)
filename_water = parent_ispex / (filename_grey.stem.replace("grey", "water") +
                                 filename_grey.suffix)
filenames_ispex = [filename_grey, filename_sky, filename_water]

# Get the std filenames from the mean filenames
filenames_ispex_std = [
    parent_ispex / (filename.stem.replace("mean", "stds") + filename.suffix)
    for filename in filenames_ispex
]