Esempio n. 1
0
    def update_units_labels_and_values(self) -> None:
        """ Updates the x units labels and fields

        :return: None
        """
        # If x units haven't changed, we do nothing
        new_x = self.units.get().split('_')[-1]
        old_x = self.units_x.get()
        if new_x == old_x:
            return

        self.units_x.set(new_x)

        old_min = self.x_min.get()
        old_max = self.x_max.get()

        if all(t in ('nm', 'eV') for t in (old_x, new_x)):
            new_min = eVnm(old_min)
            new_max = eVnm(old_max)
        elif all(t in ('nm', 'J') for t in (old_x, new_x)):
            new_min = nmJ(old_min)
            new_max = nmJ(old_max)
        elif all(t in ('nm', 'm') for t in (old_x, new_x)):
            factor = 1e-9 if old_x == 'nm' else 1e9
            new_min = factor * old_min
            new_max = factor * old_max
        elif all(t in ('nm', 'hz') for t in (old_x, new_x)):
            new_min = nmHz(old_min)
            new_max = nmHz(old_max)
        elif all(t in ('m', 'J') for t in (old_x, new_x)):
            new_min = mJ(old_min)
            new_max = mJ(old_max)
        elif all(t in ('m', 'eV') for t in (old_x, new_x)):
            factor = h * c / q
            new_min = factor / old_min
            new_max = factor / old_max
        elif all(t in ('m', 'hz') for t in (old_x, new_x)):
            factor = c
            new_min = factor / old_min
            new_max = factor / old_max
        elif all(t in ('J', 'eV') for t in (old_x, new_x)):
            factor = q if old_x == 'eV' else 1 / q
            new_min = factor * old_min
            new_max = factor * old_max
        elif all(t in ('J', 'hz') for t in (old_x, new_x)):
            factor = 1 / h if old_x == 'J' else h
            new_min = factor * old_min
            new_max = factor * old_max
        else:
            # eV <-> hz
            factor = q / h if old_x == 'eV' else h / q
            new_min = factor * old_min
            new_max = factor * old_max

        # Now we have to check if maximum and minimum are in the correct order, reversing them, otherwise
        if new_min > new_max:
            new_min, new_max = new_max, new_min

        self.x_min.set(format(new_min, '.4'))
        self.x_max.set(format(new_max, '.4'))
Esempio n. 2
0
    def _get_photon_flux_per_J(self, energy):
        """ Function that returns the spectrum in photon flux per Joule.

        :param energy: Array with the energies at which to calculate the spectrum (in J)
        :return: The spectrum in the chosen units.
        """
        wavelength = nmJ(energy)[::-1]
        output = self._spectrum(wavelength)
        energy_eV, output = spectral_conversion_nm_ev(wavelength, output)
        output = output / (q * energy)
        return output
Esempio n. 3
0
def photon_flux_per_joule(spectrum: Callable[[np.ndarray], np.ndarray], x: np.ndarray):
    """ Function that returns the spectrum in photon flux per Joule.

    The input spectrum is assumed to be in power density per nanometer.

    :param spectrum: The spectrum to interpolate.
    :param x: Array with the energies (in J)
    :return: The spectrum in the chosen units.
    """
    wavelength = nmJ(x)[::-1]
    output = spectrum(wavelength)
    _, output = spectral_conversion_nm_ev(wavelength, output)
    return output / (q * x)