From 18a1f28a134caa482fd8f45dfcb1bc13d5737174 Mon Sep 17 00:00:00 2001 From: Philip J Clark <Philip.Clark@cern.ch> Date: Thu, 26 Oct 2023 13:37:02 +0100 Subject: [PATCH] adding back in PlanckPlot code --- CodeExamples/PlanckPlot.ipynb | 59 ++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/CodeExamples/PlanckPlot.ipynb b/CodeExamples/PlanckPlot.ipynb index 3f52bfd..69fabde 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()" ] } -- GitLab