''' This example creates plots for all silicon properties available in Scarce.
'''

import numpy as np
import matplotlib.pylab as plt

from scarce import silicon


def plot_depletion_depth():
    V_bias = np.linspace(0, 100., 1000.)
    plt.clf()
    # Plot depletion depth for different bias voltages
    for n_eff in [1, 10, 100]:
        for temperature in [300]:
            depletion_depth = silicon.get_depletion_depth(
                V_bias=V_bias,
                n_eff=n_eff,
                temperature=temperature)
            plt.plot(V_bias,
                     depletion_depth,
                     linewidth=2.,
                     label=r'$\mathrm{N_{eff}=%d\cdot10^{12}/cm^3}}$, $T=%d$'
                     % (n_eff, temperature))
    plt.title('Depletion depth in silicon')
    plt.xlabel('Bias voltage [$\mathrm{V}}$]')
    plt.ylabel('Depletion depth [$\mathrm{um}$]')
    plt.legend(loc=0)
    plt.grid()
    plt.savefig('DepletionDepth.pdf', layout='tight')


def plot_depletion_depth_res():
    # Plot depletion depth as a function of the resistivity
    temperature = 300  # [K]
    e_field = 1e3  # [V/cm]
    V_bias = 100  # [V]
    n_eff = np.logspace(0, 3, 1000.)
    resistivity = silicon.get_resistivity(n_eff,
                                          is_n_type=False,
                                          temperature=temperature,
                                          e_field=e_field)
    depletion_depth = silicon.get_depletion_depth(
        V_bias=V_bias,
        n_eff=n_eff,
        temperature=temperature)
    plt.plot(resistivity,
             depletion_depth,
             linewidth=2.,
             label='$\mathrm{p-type, V_{bias}=%d\ V}$, $T=%d$'
             % (V_bias, temperature))
    plt.plot(resistivity,
             0.3 * np.sqrt(V_bias * resistivity),
             '--',
             linewidth=2.,