diff --git a/CodeExamples/PlanckPlot.ipynb b/CodeExamples/PlanckPlot.ipynb index 3f52bfd421e3d4b3f1df12686b64b49425ed9d98..69fabdea612e412176489d4244b8270fab6f2e47 100644 --- a/CodeExamples/PlanckPlot.ipynb +++ b/CodeExamples/PlanckPlot.ipynb @@ -16,18 +16,67 @@ "outputs": [], "source": [ "\"\"\"\n", - " Example to append two strings and print\n", + " Program to plot the Plack radiation spectrum with the Plank radiation\n", + " spectrun as a function.\n", "\"\"\"\n", + "import math\n", + "import matplotlib.pyplot as plt\n", + "\n", + "\n", + "def planck_spectrum(temperature,wave_length):\n", + " \"\"\"\n", + " Function to calcualte the black body plank spectrum with parameters:\n", + " param: temperature float the temperature in Kelvin \n", + " param: wave_length float the wave_length in microns\n", + " return float the planks spectrum value\n", + " \"\"\"\n", + " c_one = 5.029e6 # 2hc^2 \n", + " c_two = 1.44e4 # hc/k\n", + "\n", + " val = c_one/math.pow(wave_length,5)*(1.0/(math.exp(c_two/(wave_length*temperature)) - 1.0))\n", + " return val\n", + " \n", + "def planck_data(temperature,wave_list):\n", + " \"\"\"\n", + " Function to return a list of plank spectrum values for the specified temperature values and the wavelengths supplied in the list.\n", + " param: temperature float temperature in Kelvin\n", + " param: wave_list, list of floats, the wavelengths\n", + " return: float list of planck spectrum values the same length as wave_list\n", + " \"\"\"\n", + " data = []\n", + " for wavelength in wave_list:\n", + " planck = planck_spectrum(temperature,wavelength)\n", + " data.append(planck)\n", + "\n", + " return data\n", "\n", "def main():\n", - " a = [1,2,3,4]\n", - " b = [5,6,7,8]\n", + " \"\"\"\n", + " Plot out the Planck spectrum for a specified temperature\n", + " \"\"\"\n", + "\n", + " temperature = float(input(\"Temperature : \"))\n", + " npoints = 100\n", + " short_wavelength = 0.25\n", + " long_wavelength = 2.0\n", + " delta_wavelength = (long_wavelength - short_wavelength)/npoints\n", "\n", - " a.extend(b)\n", "\n", - " print(str(a))\n", + " # Make the wavelength list\n", + " wavelength = short_wavelength\n", + " wave_list = []\n", + " while wavelength <= long_wavelength:\n", + " wave_list.append(wavelength)\n", + " wavelength += delta_wavelength\n", + " \n", + " # Get the planck values in a list \n", + " planck_list = planck_data(temperature,wave_list)\n", "\n", + " # Do a baic plot\n", + " plt.plot(wave_list,planck_list,\"r\")\n", + " plt.show()\n", "\n", + " \n", "main()" ] }