Spectrum

Introduction

Spectrum class is designed to simplify the unit conversions, interpolation and arithmetic operations of spectrum data in the form of y(x) or y(x)dx. When modeling solar cells, we often have to deal with spectrum with different units. For example, the x of your EQE is in photon energy (eV), but the x of the illumination spectrum is in wavelength (nm), and you want to multiply them to get Jsc. You then have to convert the x of EQE into wavelength, reverse the sequence of both x and y, interpolate either the EQE or the illumination spectrum, convert y of the illumination spectrum into photon flux, multiply the data and finally run numerical integration to get Jsc. These processes can cause some headache and very error prone. Spectrum class aims to make these calculations robust and easy.

Spectrum class bundles the data of x, y and their associated units together into an object. This design may look clumsy at first sight, but this helps reduce many potential errors that could happen when handling the unit conversions of the data. The reason is that the value of y is often coupled with the unit of x. For example, converting the y data from energy flux into photon flux requires the values of x.

Design of Spectrum class

An instance of Spectrum class bundles the following key properties of a spectrum y(x):

  • x_data: the values of x
  • y_data: the values of y
  • x_unit: the unit of x (strings), e.g. ‘eV’, ‘nm’, ‘J’ and so on.
  • y_area_unit (optional): use this if the spectrum is something per area, such as sun irradiance (W/m^2), e.g., ‘m 2’)
  • is_spec_density: a boolean value to specify whether the spectrum is y(x)dx. In other words, this should be set to True if the integration of y(x)dx is a physical quantity. For example, this should be set to True when dealing with the sun irradiance spectrum because the integration of the sun irradiance spectrum gives the total illumination power. On the other hand, this should be set to False for spectrum like quantum efficiency or absorption spectrum.
  • is_photon_flux: This boolean values specifies whether the spectrum is photon flux.

Access the values in Spectrum

One can use get_spectrum() or get_interp_spectrum() to accessing the values of x and y in a spectrum. When retrieving the values of spectrum data, the user has to specify the unit for x. Both of these functions will handle the unit conversion and rearrange the order of x and y (say, when converting nm to eV).

get_spectrum() returns the 2xL numpy array of the x and y data.

get_interp_spectrum() returns the 2xL numpy array of interpolated x and y data from given x.

Arithmetic operations

Spectrum class supports arithmetic operations between different spectrum, for example:

# Multiplication of two spectrum
s3=s1*s2

If s1 and s2 have different x, the function will interpolate s2 based on the values of x in s1. After that, it does the multiplication of y in s1 and s2.

Spectrum calss also supports arithmetic operations with single float number, for example:

# Multiply a spectrum by a single number
s2=s1*0.5

or

s2=0.5*s1

This operation multiply all the y values in s1 by 0.5 and return the result to s2.

Copyright 2017 Kan-Hua Lee, Toyota Technological Institute

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Spectrum class API

class pypvcell.spectrum.Spectrum(x_data, y_data, x_unit, y_unit=”, is_spec_density=False, is_photon_flux=False)[source]

This class handles the operation of the spectrum y(x), including unit conversion and multiplication.

It can handle unit conversions of different types of spectrum, including:

  • Standard spectrum. The unit of y is independent of x, e.g. quantum efficiency, absorption spectrum, etc.
  • Sepctral density. The unit of y is per [x-unit]. For example, the Black-body radiation spectrum is often in the unit of energy/nm/m^2
  • Photon flux: y is number of photons. When converting y into energy (J), it has to be multiplied by its photon energy.
__init__(x_data, y_data, x_unit, y_unit=”, is_spec_density=False, is_photon_flux=False)[source]

Constructor of the spectrum y(x)

Parameters:
  • is_spec_density
  • x_data – x data of the spectrum (1d numpy array)
  • y_data – y data of the spectrum (1d numpy array)
  • x_unit – the unit of x (string), e.g. ‘nm’, ‘eV’
  • y_unit – (string) If y is per area, put area unit here, e.g. ‘m-2’ or ‘cm-2’. Put null string ” if y does not have area unit
  • is_photon_flux – (boolean). True if y is number of photons.
convert_spectrum_unit(x_data, y_data, from_x_unit, to_x_unit, from_y_area_unit, to_y_area_unit, is_spec_density)[source]

A general method for converting the spectrum y(x) from one set of unit to another. Note that this only supports the conversion of x from: [length]<->[frequency] [length]<-> 1/[length] [length]<->[energy]

This is because Spectrum class converts the units of x to [length] first when initilizing or new spectrum is set. Therefore this function only implments the bi-direction unit conversions that involves [length].

Parameters:
  • x_data – data of x (numpy array)
  • y_data – data of y (numpy array)
  • from_x_unit – the unit of x_data
  • to_x_unit – the unit of x_data to be converted to
  • from_y_area_unit – the unit of area of y_data
  • to_y_area_unit – the unit of area of y_data tobe converted to
  • is_spec_density – True if the data is spectral density.
Returns:

a tuple of 1-d array (new_x_data, new_y_data)

cut(start, end, unit)[source]

Cut a particular band of spectrum y(x), where start<x<end

Parameters:
  • start – the starting x
  • end – the end x
  • unit – the unit of x
Returns:

a new spectrum

get_interp_spectrum(to_x_data, to_x_unit, to_y_area_unit=None, to_photon_flux=False, interp_left=None, interp_right=None, raise_error=True)[source]

Get interpolated spectrum.

Parameters:
  • raise_error – if to_x_data is not within the range of the spectru, raise ValueError
  • to_x_data – (ndarray) x values to be interpolated
  • to_x_unit – (string) unit of x of the output value
  • to_y_area_unit – (string) unit of area of y of the output value.
  • to_photon_flux – (bool) True if converting the value to photon flux as the output
  • interp_left – value to return for x < core_x[0], return core_x[0] if set to be None
  • interp_right – value to return for x> core_x[-1], return core_y[-1] if set to be None
Returns:

a 2xL array

get_spectrum(to_x_unit, to_y_area_unit=None, to_photon_flux=False)[source]

Retrieve the values of the spectrum based on the given units of x and y.

Parameters:
  • to_x_unit – the unit of x
  • to_y_area_unit – the unit of area of y. Default is the y_area_unit of the object.
  • to_photon_flux – True if converting y to photon flux.
Returns:

a 2xL numpy array

rsum()[source]

Integration of the spectrum, i.e., int y(x)dx Internally, it simply does np.trapz(y,x)

Returns:The integrated value.
set_spectrum(x_data, y_data, x_unit, y_area_unit, is_photon_flux, is_spec_density)[source]

This is essentially a constructor method that sets up the attributes of the object. It converts everything to standard MKS unit. x_data: ‘m’, y_data: ‘[]/m^2-m’

Parameters:
  • x_data – x data of the spectrum (1d numpy array)
  • y_data – y data of the spectrum (1d numpy array)
  • x_unit (str) – the unit of x (string), e.g. ‘nm’, ‘eV’
  • y_area_unit (str) – If y is per area, put area unit here, e.g. ‘m**-2’ or ‘cm**-2’. Put null string ” if y does not have area unit
  • is_photon_flux (bool) – True if y is number of photons.
  • is_spec_density (bool) – True if y is spectral density.
Returns:

None