Exemplo n.º 1
0
    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])
X, Y = np.meshgrid(x, y)
(x0, y0) = (len(x) / 2, len(y) / 2)
D = np.sqrt((X - x0)**2 + (Y - y0)**2)

meanRGBG, stdsRGBG, D_split = raw.demosaick(colours, mean_reshaped,
                                            stds_reshaped, D)

outer_radii = np.arange(1000, 2000, 75)


def ring_mean(outer_radius, data, distances, width=10):
    ind = np.where((distances < outer_radius)
                   & (distances <= outer_radius - width))
    mean = np.mean(data[ind])
    std = np.std(data[ind])
    return mean, std


allmean = np.zeros((4, len(outer_radii), len(angles)))
allstds = allmean.copy()
Exemplo n.º 2
0
x = np.arange(data_Qp.shape[1])
xp = np.repeat(x[:, np.newaxis], bayer_Qp.shape[0], axis=1).T
xm = np.repeat(x[:, np.newaxis], bayer_Qm.shape[0], axis=1).T
yp = np.arange(data_Qp.shape[0])
ym = np.arange(data_Qm.shape[0])

coefficients_Qp = np.load(
    Path("calibration_data") / "wavelength_calibration_Qp.npy")
coefficients_Qm = np.load(
    Path("calibration_data") / "wavelength_calibration_Qm.npy")

wavelengths_Qp = wavelength.calculate_wavelengths(coefficients_Qp, x, yp)
wavelengths_Qm = wavelength.calculate_wavelengths(coefficients_Qm, x, ym)

wavelengths_split_Qp, RGBG_Qp, xp_split = raw.demosaick(
    bayer_Qp, wavelengths_Qp, data_Qp, xp)
wavelengths_split_Qm, RGBG_Qm, xm_split = raw.demosaick(
    bayer_Qm, wavelengths_Qm, data_Qm, xm)

plt.figure(figsize=(6, 2))
for j, c in enumerate("rgb"):
    plt.plot(xm_split[j, 50], RGBG_Qm[j, 50], c=c)
plt.xlabel("Pixel")
plt.ylabel("Counts [ADU]")
plt.grid(ls="--")
plt.ylim(-5, RGBG_Qm[:, 50, 1000:].max() * 1.05)
plt.xlim(0, x.shape[0])
plt.savefig(Path("results") / f"{file.stem}_row_raw_Qm.pdf",
            bbox_inches="tight")
plt.close()
Exemplo n.º 3
0
wavelength_fits_Qp = wavelength.fit_many_wavelength_relations(yp, lines_fit_Qp)
wavelength_fits_Qm = wavelength.fit_many_wavelength_relations(ym, lines_fit_Qm)

# Fit a polynomial to the coefficients of the previous fit
coefficients_Qp, coefficients_fit_Qp = wavelength.fit_wavelength_coefficients(yp, wavelength_fits_Qp)
coefficients_Qm, coefficients_fit_Qm = wavelength.fit_wavelength_coefficients(ym, wavelength_fits_Qm)

# Plot the polynomial fits to the coefficients
#plot.wavelength_coefficients(yp, wavelength_fits_Qp, coefficients_fit_Qp)
#plot.wavelength_coefficients(ym, wavelength_fits_Qm, coefficients_fit_Qm)

# Save the coefficients to file
wavelength.save_coefficients(coefficients_Qp, saveto=save_to_Qp)
wavelength.save_coefficients(coefficients_Qm, saveto=save_to_Qm)
print(f"Saved wavelength coefficients to '{save_to_Qp}' and '{save_to_Qm}'")

# Convert the input spectrum to wavelengths and plot it, as a sanity check
wavelengths_Qp = wavelength.calculate_wavelengths(coefficients_Qp, x, yp)
wavelengths_Qm = wavelength.calculate_wavelengths(coefficients_Qm, x, ym)

wavelengths_split_Qp, RGBG_Qp = raw.demosaick(bayer_Qp, wavelengths_Qp, data_Qp)
wavelengths_split_Qm, RGBG_Qm = raw.demosaick(bayer_Qm, wavelengths_Qm, data_Qm)

lambdarange, all_interpolated_Qp = wavelength.interpolate_multi(wavelengths_split_Qp, RGBG_Qp)
lambdarange, all_interpolated_Qm = wavelength.interpolate_multi(wavelengths_split_Qm, RGBG_Qm)

stacked_Qp = wavelength.stack(lambdarange, all_interpolated_Qp)
stacked_Qm = wavelength.stack(lambdarange, all_interpolated_Qm)
plot.plot_fluorescent_spectrum(stacked_Qp[0], stacked_Qp[1:])
plot.plot_fluorescent_spectrum(stacked_Qm[0], stacked_Qm[1:])
Exemplo n.º 4
0
# Spectrum edges
xmin, xmax = 1900, 3500
ymin_thin, ymax_thin = 450, 800
ymin_thick, ymax_thick = 900, 1220

thin_slit = np.s_[ymin_thin:ymax_thin, xmin:xmax]
thick_slit = np.s_[ymin_thick:ymax_thick, xmin:xmax]

x = np.arange(xmin, xmax)
y_thin = np.arange(ymin_thin, ymax_thin)
y_thick = np.arange(ymin_thick, ymax_thick)

image_thin = values[thin_slit]
colors_thin = img.raw_colors[thin_slit]
RGBG_thin = raw.demosaick(colors_thin, image_thin)
plot.show_RGBG(RGBG_thin)

image_thick = values[thick_slit]
colors_thick = img.raw_colors[thick_slit]
RGBG_thick = raw.demosaick(colors_thick, image_thick)
plot.show_RGBG(RGBG_thick)

# Extract areas slightly above and below the spectrum for noise removal
above_thin = np.s_[350:360, xmin:xmax]
below_thick = np.s_[1400:1410, xmin:xmax]

values_above = values[above_thin]
colors_above = img.raw_colors[above_thin]
values_below = values[below_thick]
colors_below = img.raw_colors[below_thick]
Exemplo n.º 5
0
file = io.path_from_input(argv)
root, images, stacks, products, results = io.folders(file)

img = io.load_raw_file(file)
exif = io.load_exif(file)

values = img.raw_image.astype(np.float32)
values = calibrate.correct_bias(root, values)

image_cut = values[760:1000, 2150:3900]
colors_cut = img.raw_colors[760:1000, 2150:3900]
x = np.arange(2150, 3900)
y = np.arange(760, 1000)

RGBG = raw.demosaick(colors_cut, image_cut)
plot.show_RGBG(RGBG)

coefficients = wavelength.load_coefficients(results /
                                            "ispex/wavelength_solution.npy")
wavelengths_cut = wavelength.calculate_wavelengths(coefficients, x, y)
wavelengths_split = raw.demosaick(colors_cut, wavelengths_cut)

lambdarange, all_interpolated = wavelength.interpolate_multi(
    wavelengths_split, RGBG)
stacked = wavelength.stack(lambdarange, all_interpolated)
plot.plot_spectrum(stacked[0],
                   stacked[1:],
                   saveto=results / "ispex" / (file.stem + ".pdf"))

np.save(results / "ispex" / (file.stem + ".npy"), stacked)
Exemplo n.º 6
0
xp = np.repeat(x[:, np.newaxis], bayer_Qp.shape[0], axis=1).T
xm = np.repeat(x[:, np.newaxis], bayer_Qm.shape[0], axis=1).T
yp = np.arange(mean_grey_Qp.shape[0])
ym = np.arange(mean_grey_Qm.shape[0])

# Load the wavelength calibration
coefficients_Qp = np.load(
    Path("calibration_data") / "wavelength_calibration_Qp.npy")
coefficients_Qm = np.load(
    Path("calibration_data") / "wavelength_calibration_Qm.npy")

wavelengths_Qp = wavelength.calculate_wavelengths(coefficients_Qp, x, yp)
wavelengths_Qm = wavelength.calculate_wavelengths(coefficients_Qm, x, ym)

# Demosaick the data and wavelength calibration data
wavelengths_split_Qp, mean_grey_Qp_RGBG, mean_sky_Qp_RGBG, mean_water_Qp_RGBG, xp_split = raw.demosaick(
    bayer_Qp, wavelengths_Qp, mean_grey_Qp, mean_sky_Qp, mean_water_Qp, xp)
wavelengths_split_Qm, mean_grey_Qm_RGBG, mean_sky_Qm_RGBG, mean_water_Qm_RGBG, xm_split = raw.demosaick(
    bayer_Qm, wavelengths_Qm, mean_grey_Qm, mean_sky_Qm, mean_water_Qm, xm)

# Smooth the data in RGBG space
# 1 pixel in RGBG space = 2 pixels in RGB space
mean_grey_Qp_RGBG, mean_sky_Qp_RGBG, mean_water_Qp_RGBG, mean_grey_Qm_RGBG, mean_sky_Qm_RGBG, mean_water_Qm_RGBG = general.gauss_filter_multidimensional(
    mean_grey_Qp_RGBG,
    mean_sky_Qp_RGBG,
    mean_water_Qp_RGBG,
    mean_grey_Qm_RGBG,
    mean_sky_Qm_RGBG,
    mean_water_Qm_RGBG,
    sigma=(0, 0, 3))

# Plot the Qm data in a single row