import numpy as np
import matplotlib.pyplot as plt

import lightFunctions as light

dataPath = '12-light/data/'
plotsPath = '12-light/plots/'


########################################
#   Wavelength calibration
########################################

filename = 'white-mercury.png'
brightness = light.readIntensity(dataPath + filename, plotsPath + filename, 'ртутная лампа', 'белый лист')

mercuryPeaks = [435.8328, 546.0735, 578.2]
mercuryPixels = [167, 340, 409]

linearFit = np.polyfit(mercuryPixels, mercuryPeaks, 1)

wavelength = np.polyval(linearFit, np.arange(0, np.size(brightness)))


########################################
#   Photo processing
########################################

# Read intensities

lamp = 'лампа накаливания'

white = ['white-tungsten.png', 'белый лист']
red = ['red-tungsten.png', 'красный лист']
green = ['green-tungsten.png', 'зелёный лист']
blue = ['blue-tungsten.png', 'синий лист']
yellow = ['yellow-tungsten.png', 'жёлтый лист']

whiteBrightness = light.readIntensity(dataPath + white[0], plotsPath + white[0], lamp, white[1])
redBrightness = light.readIntensity(dataPath + red[0], plotsPath + red[0], lamp, red[1])
greenBrightness = light.readIntensity(dataPath + green[0], plotsPath + green[0], lamp, green[1])
blueBrightness = light.readIntensity(dataPath + blue[0], plotsPath + blue[0], lamp, blue[1])
yellowBrightness = light.readIntensity(dataPath + yellow[0], plotsPath + yellow[0], lamp, yellow[1])


# Plot intensites

fig = plt.figure(figsize=(7, 5), dpi=200)

plt.title('Отражённая интенсивность\nизлучения лампы накаливания')
plt.xlabel('Длина волны [нм]')
plt.ylabel('Яркость')

plt.plot(wavelength, whiteBrightness, 'w', label=white[1])
plt.plot(wavelength, redBrightness, 'r', label=red[1])
plt.plot(wavelength, greenBrightness, 'g', label=green[1])
plt.plot(wavelength, blueBrightness, 'b', label=blue[1])
plt.plot(wavelength, yellowBrightness, 'y', label=yellow[1])
plt.legend()

ax = plt.gca()
ax.set_facecolor('lightgrey')

plt.grid(which='major')
plt.grid(which='minor', linestyle='--')
plt.minorticks_on()

plt.savefig(plotsPath + '! intensites.png')


# Plot albedos

albedoOne = whiteBrightness
albedoOne[whiteBrightness < 1] = 1

fig = plt.figure(figsize=(7, 5), dpi=200)

plt.title('Альбедо поверхностей')
plt.xlabel('Длина волны [нм]')
plt.ylabel('Альбедо')

plt.plot(wavelength, whiteBrightness / albedoOne, 'w', label=white[1])
plt.plot(wavelength, redBrightness / albedoOne, 'r', label=red[1])
plt.plot(wavelength, greenBrightness / albedoOne, 'g', label=green[1])
plt.plot(wavelength, blueBrightness / albedoOne, 'b', label=blue[1])
plt.plot(wavelength, yellowBrightness / albedoOne, 'y', label=yellow[1])
plt.legend()

ax = plt.gca()
ax.set_facecolor('lightgrey')

plt.grid(which='major')
plt.grid(which='minor', linestyle='--')
plt.minorticks_on()

plt.savefig(plotsPath + '! albedos.png')
import numpy as np
import matplotlib.pyplot as plt

import lightFunctions as light

dataPath = '12-light/data/'
plotsPath = '12-light/plots/'


########################################
#   Wavelength calibration
########################################

filename = 'white-mercury.png'
brightness = light.readIntensity(dataPath + filename, plotsPath + filename, 'ртутная лампа', 'белый лист')

mercuryPeaks = [435.8328, 546.0735, 578.2]
mercuryPixels = [167, 340, 409]

linearFit = np.polyfit(mercuryPixels, mercuryPeaks, 1)

wavelength = np.polyval(linearFit, np.arange(0, np.size(brightness)))


########################################
#   Photo processing
########################################

# Read intensities

lamp = 'лампа накаливания'

white = ['white-tungsten.png', 'белый лист']
red = ['red-tungsten.png', 'красный лист']
green = ['green-tungsten.png', 'зелёный лист']
blue = ['blue-tungsten.png', 'синий лист']
yellow = ['yellow-tungsten.png', 'жёлтый лист']

whiteBrightness = light.readIntensity(dataPath + white[0], plotsPath + white[0], lamp, white[1])
redBrightness = light.readIntensity(dataPath + red[0], plotsPath + red[0], lamp, red[1])
greenBrightness = light.readIntensity(dataPath + green[0], plotsPath + green[0], lamp, green[1])
blueBrightness = light.readIntensity(dataPath + blue[0], plotsPath + blue[0], lamp, blue[1])
yellowBrightness = light.readIntensity(dataPath + yellow[0], plotsPath + yellow[0], lamp, yellow[1])


# Plot intensites

fig = plt.figure(figsize=(7, 5), dpi=200)

plt.title('Отражённая интенсивность\nизлучения лампы накаливания')
plt.xlabel('Длина волны [нм]')
plt.ylabel('Яркость')

plt.plot(wavelength, whiteBrightness, 'w', label=white[1])
plt.plot(wavelength, redBrightness, 'r', label=red[1])
plt.plot(wavelength, greenBrightness, 'g', label=green[1])
plt.plot(wavelength, blueBrightness, 'b', label=blue[1])
plt.plot(wavelength, yellowBrightness, 'y', label=yellow[1])
plt.legend()

ax = plt.gca()
ax.set_facecolor('lightgrey')

plt.grid(which='major')
plt.grid(which='minor', linestyle='--')
plt.minorticks_on()

plt.savefig(plotsPath + '! intensites.png')


# Plot albedos

albedoOne = whiteBrightness
albedoOne[whiteBrightness < 1] = 1

fig = plt.figure(figsize=(7, 5), dpi=200)

plt.title('Альбедо поверхностей')
plt.xlabel('Длина волны [нм]')
plt.ylabel('Альбедо')

plt.plot(wavelength, whiteBrightness / albedoOne, 'w', label=white[1])
plt.plot(wavelength, redBrightness / albedoOne, 'r', label=red[1])
plt.plot(wavelength, greenBrightness / albedoOne, 'g', label=green[1])
plt.plot(wavelength, blueBrightness / albedoOne, 'b', label=blue[1])
plt.plot(wavelength, yellowBrightness / albedoOne, 'y', label=yellow[1])
plt.legend()

ax = plt.gca()
ax.set_facecolor('lightgrey')

plt.grid(which='major')
plt.grid(which='minor', linestyle='--')
plt.minorticks_on()

plt.savefig(plotsPath + '! albedos.png')
######################################## #   Wavelength calibration ######################################## ######################################## #   Photo processing ######################################## # Read intensities # Plot intensites # Plot albedos