<jupyter_start><jupyter_text>Planck's lawLet's briefly introduce the main aspects of the theory combining some Wikipedia articles. Links below.Planck's law describes the spectral density of electromagnetic radiation emitted by a black body in thermal equilibrium at a given temperature, when there is no net flow of matter or energy between the body and its environment.Planck's law can be written in terms of the spectral energy density. These distributions have units of energy per volume per spectral unit.\begin{equation}\rho (\lambda, T) = \frac{8 \pi h c}{\lambda^5 \left(e^{\frac{hc}{\lambda k_B T}} - 1\right)}\label{eq:planck}\end{equation}where $k_B$ is the Boltzmann constant, $h$ is the Planck constant, and $c$ is the speed of light in the medium, whether material or vacuum.Black-body radiation is the thermal electromagnetic radiation within or surrounding a body in thermodynamic equilibrium with its environment, emitted by a black body (an idealized opaque, non-reflective body). It has a specific spectrum of wavelengths, inversely related to intensity that depend only on the body's temperature, which is assumed for the sake of calculations and theory to be uniform and constant.References: [Planck's law](https://en.wikipedia.org/wiki/Planck%27s_law), [Black-body radiation](https://en.wikipedia.org/wiki/Black-body_radiation), [Energy density](https://en.wikipedia.org/wiki/Energy_density)  About this piece of softwareA simple script to plot the Planck's law. Please, run the following cell so that the script can be imported (the notebook must be in the same folder as the script). Then, run each code cell after reading their meaning.<jupyter_code>import planck<jupyter_output><empty_output><jupyter_text>The following must be imported so that we can use them in the examples.<jupyter_code>import matplotlib.pyplot as plt
import numpy as np

# the following must be imported for interactive plots
from ipywidgets import interact, interactive, fixed<jupyter_output><empty_output><jupyter_text>Now let's test the methods of the planck module.We can use the `planck_energy_density` function to calculate the energy density at a given wavelength at a given temperature. Remember that the module uses SI units. For example, at 500 nm and 7000 K:<jupyter_code>planck.planck_energy_density(500.0e-9, 7000)<jupyter_output><empty_output><jupyter_text>Usually we want the energy density at a given wavelength _range_ in order to plot a distribution. The function accepts wavelengths arrays.Let's create a wavelength array with 10 values between 400 and 800 nm and calculate the energy density values at 5000 K:<jupyter_code>lambda_example = np.linspace(400e-9, 800e-9, 10)

energy_density_5000K_example = planck.planck_energy_density(lambda_example, 5000)
energy_density_5000K_example<jupyter_output><empty_output><jupyter_text>Great. Now we have data points that can be plotted. Let's create a figure and uses Matplotlib to draft a plot.<jupyter_code># plot draft

fig_ex1 = plt.figure(figsize=(8,4))
ax_ex1 = fig_ex1.add_subplot(111)

ax_ex1.plot(lambda_example, energy_density_5000K_example)
plt.show()<jupyter_output><empty_output><jupyter_text>Yeah, it resembles a Planck distribution. You can modify the plot using Matplotlib's methods to be more suitable for presentation (axes labels, wavelengths in nanometers etc). You probably should increase the number of points to get a smoother plot.However, the planck module has a function for plots that can do all this! The function receives a wavelength array and a temperature array/list. So, let's plot the same range again but using it and increasing the number of data points to 1000 (probably overkill but hey it's a computer doing math).The function always get the current axis to plot, so we are going to create a figure with axes before calling the function.<jupyter_code>lambda_example = np.linspace(400e-9, 800e-9, 1000)

fig_ex2 = plt.figure(figsize=(8,4))
ax_ex2 = fig_ex2.add_subplot(111)

planck.plot_planck(lambda_example,[5000])<jupyter_output><empty_output><jupyter_text>The function generates the labels and a decent scale. The wavelength unit is nanometers by default.Since the function receives a temperature _list_, more than one value can be passed. Let's test this feature passing 5000 and 6000 K.<jupyter_code>fig_ex3 = plt.figure(figsize=(8,4))
ax_ex3 = fig_ex3.add_subplot(111)

planck.plot_planck(lambda_example,[5000, 6000])<jupyter_output><empty_output><jupyter_text>Great. Let's increase the wavelength range and pass more temperatures using a numpy array:<jupyter_code>lambda_array = np.linspace(1.0e-9, 2.0e-6, 1000) 
temperature_array = np.arange(1000, 7001, 500)

fig1 = plt.figure(figsize=(10, 6))
ax = fig1.add_subplot(111)
planck.plot_planck(lambda_array, temperature_array)<jupyter_output><empty_output><jupyter_text>By default, the method uses the coolwarm [colormap](https://matplotlib.org/3.1.1/gallery/color/colormap_reference.html). Let's change it to gist_rainbow:<jupyter_code>fig2 = plt.figure(figsize=(10, 6))
ax = fig2.add_subplot(111)

planck.plot_planck(lambda_array, temperature_array, colors=plt.cm.gist_rainbow)<jupyter_output><empty_output><jupyter_text>The planck module also has a function that can be called _before_ the plot. It's the `plot visible` one and it adds a visible spectrum in the plot background so that we can see lower temperatures bodies with maximum wavelength emission near the red (or even before, infrared) and higher ones towards the violet and beyond (ultraviolet):<jupyter_code>fig3 = plt.figure(figsize=(10, 6))
ax = fig3.add_subplot(111)

planck.plot_visible()
planck.plot_planck(lambda_array, temperature_array)<jupyter_output><empty_output><jupyter_text>Last but not the least, the module has a function to  interactive plots: `plot_planck_interactive`. This function must be passed to the `interactive` method from ipywidgets package. A wavelength array must also be passed as a fixed argument. The temperature must be passed as follows with a initial value (500 in the example), a final value (8000) and a step (500).<jupyter_code>lambda_array = np.linspace(1.0e-9, 3.0e-6, 1000) 
graph = interactive(planck.plot_planck_interactive,
                    wavelength_array=fixed(lambda_array),
                    temperature=(500,8000,500))
display(graph)<jupyter_output><empty_output><jupyter_text>Let's change the values to see the effects.<jupyter_code>lambda_array = np.linspace(200e-9, 900e-9, 1000) 
graph = interactive(planck.plot_planck_interactive,
                    wavelength_array=fixed(lambda_array),
                    temperature=(3000,9000,400))
display(graph)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07775442809966977, 'fraction_numerical': 0.03317322125487841, 'mean_word_length': 5.81985670419652, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 49, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '52544', 'license': 'MIT', 'n_tokens_mistral': 2145, 'n_tokens_neox': 1922, 'n_words': 725, 'path': 'tutorial.ipynb', 'repo_name': 'chicolucio/planck', 'size': '6662'}