
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples\plot_jph_from_spec.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_auto_examples_plot_jph_from_spec.py>`
        to download the full example code

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_auto_examples_plot_jph_from_spec.py:


Modeling Photocurrent Density for Tandem Solar Cells
====================================================
Using spectral on-demand data from NREL and simulated EQE data from GENPRO4.

.. GENERATED FROM PYTHON SOURCE LINES 8-11

.. code-block:: default


    # sphinx_gallery_thumbnail_number = 3








.. GENERATED FROM PYTHON SOURCE LINES 12-23

This example shows how to calculate the photocurrent density in the subcells
of a tandem solar cell. It uses "spectral-on-demand" data from the NSRDB
providded by NREL.
For the absorptances of the subcells GENPRO4 simulated EQE curves are used
originally createf for the following publication:
Reference
----------
.. [1] P. Tillmann, K. Jäger, A. Karsenti, L. Kreinin, C. Becker (2022)
   “Model-Chain Validation for Estimating the Energy Yield of Bifacial
   Perovskite/Silicon Tandem Solar Cells,” Solar RRL 2200079,
   DOI: 10.1002/solr.202200079

.. GENERATED FROM PYTHON SOURCE LINES 23-32

.. code-block:: default



    import pandas as pd
    import numpy as np
    import matplotlib.pyplot as plt
    from pv_tandem import utils

    plt.rcParams["figure.dpi"] = 140








.. GENERATED FROM PYTHON SOURCE LINES 33-38

First, the simulated EQE data for the perovskite on silicon 2 terminal tandem
is loaded from the corresponding csv-file. In order to work with pv_tandem
the EQE data needs to be stored as a pandas DataFrame with the column names
specific to the subcell names and the wavelengthsin nm as index. The EQE data
has to be between 0 and 1.

.. GENERATED FROM PYTHON SOURCE LINES 38-46

.. code-block:: default


    example_eqe = pd.read_csv("./data/eqe_tandem_2t.csv", index_col=0)
    ax = (example_eqe * 100).plot()
    ax.set_xlabel("Wavelength (nm)")
    ax.set_ylabel("Absorptance (%)")
    ax.legend(["Perovskite cell", "Silicon cell"], loc="lower right")
    plt.show()




.. image-sg:: /auto_examples/images/sphx_glr_plot_jph_from_spec_001.png
   :alt: plot jph from spec
   :srcset: /auto_examples/images/sphx_glr_plot_jph_from_spec_001.png
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 47-50

Next, the spectral data is loaded. The spectral data has to be stored as a
pandas DataFrame, with the column names corresponding to the wavelengths in
nm and should have the unit W/m²/nm

.. GENERATED FROM PYTHON SOURCE LINES 50-59

.. code-block:: default


    spec_irrad_ts = pd.read_csv(
        "./data/spec_poa_dallas_2020.csv", index_col=0, parse_dates=True
    )
    spec_irrad_ts.columns = spec_irrad_ts.columns.astype(float)
    # converting to W/m²/nm from W/m²/µm and clipping negative values to zero
    spec_irrad_ts = spec_irrad_ts.clip(lower=0) / 1000









.. GENERATED FROM PYTHON SOURCE LINES 60-64

In order to calculate the photocurrent from the EQE and spectral irradiance
both need to be specified for the same wavelengths. pv_tandem provides a
convinice function to transform either the spectral data at the same wavelength
grid as the EQE or vice versa.

.. GENERATED FROM PYTHON SOURCE LINES 64-72

.. code-block:: default


    eqe = utils.interp_eqe_to_spec(example_eqe, spec_irrad_ts)
    ax = (eqe * 100).plot()
    ax.set_xlabel("Wavelength (nm)")
    ax.set_ylabel("Absorptance (%)")
    ax.legend(["Perovskite cell", "Silicon cell"], loc="lower right")
    plt.show()




.. image-sg:: /auto_examples/images/sphx_glr_plot_jph_from_spec_002.png
   :alt: plot jph from spec
   :srcset: /auto_examples/images/sphx_glr_plot_jph_from_spec_002.png
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 73-77

Finally the photocurrent density is calculated. This has to be done seperatly
for each subcell. In this example we aggrgate the generated charge density
(time integrated curent) for each day of the year for the purpose of visulizing
the small differences between the perovskite and silicon subcell.

.. GENERATED FROM PYTHON SOURCE LINES 77-91

.. code-block:: default


    j_ph = pd.concat(
        [
            utils.calc_current(spec_irrad_ts, eqe["pero"]),
            utils.calc_current(spec_irrad_ts, eqe["si"]),
        ],
        axis=1,
    )

    ax = (j_ph.groupby(j_ph.index.dayofyear).sum() * 3.6 / 1000).plot()
    ax.set_xlabel("Day of year")
    ax.set_ylabel("Daily generated Charge (MC/day)")
    ax.legend(["Perovskite cell", "Silicon cell"], loc="upper right")
    plt.show()



.. image-sg:: /auto_examples/images/sphx_glr_plot_jph_from_spec_003.png
   :alt: plot jph from spec
   :srcset: /auto_examples/images/sphx_glr_plot_jph_from_spec_003.png
   :class: sphx-glr-single-img






.. rst-class:: sphx-glr-timing

   **Total running time of the script:** ( 0 minutes  0.357 seconds)


.. _sphx_glr_download_auto_examples_plot_jph_from_spec.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example




    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: plot_jph_from_spec.py <plot_jph_from_spec.py>`

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: plot_jph_from_spec.ipynb <plot_jph_from_spec.ipynb>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
