1.2. Warm up#
In this tutorial, you will learn basic use of numpy and matplotlib that are employed in the manipulation of nucleardatapy.
Import numpy library.
# Import numpy
import numpy as np
Generate a numpy array with linspace(). Documentation is there: https://numpy.org/doc/stable/reference/generated/numpy.linspace.html
vec = np.linspace( 0.01, 0.31, num = 5 )
print( vec )
[0.01 0.085 0.16 0.235 0.31 ]
Generate a vector density with logspace() (https://numpy.org/doc/stable/reference/generated/numpy.logspace.html):
logvec = np.logspace(-5, -1, num = 10, base = 10)
print( logvec )
[1.00000000e-05 2.78255940e-05 7.74263683e-05 2.15443469e-04
5.99484250e-04 1.66810054e-03 4.64158883e-03 1.29154967e-02
3.59381366e-02 1.00000000e-01]
Generate a vector with constant asymmetry parameter asy
.
For SM, where asy
is a vector of zeros:
asy = np.zeros( vec.size )
print( asy )
[0. 0. 0. 0. 0.]
For NM, where asy
is a vector of ones:
asy = np.ones( vec.size )
print( asy )
[1. 1. 1. 1. 1.]
For AM, where asy
is any value between 0 and 1:
asy = 0.5 * np.ones( vec.size )
print( asy )
[0.5 0.5 0.5 0.5 0.5]
Now we draw some plots.
Import the matplotlib library as well as nucleardatapy to get some data.
# Import matplotlib package
import matplotlib.pyplot as plt
# Import nucleardatapy package
import nucleardatapy as nuda
Load the energy per particle from APR equation of state and instantiate the object apr
:
apr = nuda.matter.setupMicro( model = '1998-VAR-AM-APR' )
print('den in SM:',apr.sm_den)
print('energy per particle in SM:',apr.sm_e2a)
model -> 1998-VAR-AM-APR
flag_nm: True
flag_sm: True
flag_kf: False
flag_den: True
den in SM: [0.04 0.08 0.12 0.16 0.2 0.24 0.32 0.4 0.48 0.56 0.64 0.8 0.96]
energy per particle in SM: [ 932.4386795 926.7886795 923.8786795 922.9186795 923.8286795
926.0386795 933.8886795 941.0486795 954.3786795 973.3086795
997.2686795 1060.1686795 1142.9386795]
Plot the binding energy as function of the particle density (using plot https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html):
plt.xlabel(r'density $n$ (fm$^{-3}$)')
plt.ylabel(r'energy per particle $E/A$ (MeV)')
plt.plot( apr.sm_den, apr.sm_e2a, label = apr.label )
plt.legend(loc='upper left')
<matplotlib.legend.Legend at 0x7f4f6cbbe9f0>
Now put errorbars in the plot (using errorbar https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.errorbar.html):
plt.errorbar( apr.sm_den, apr.sm_e2a, yerr = apr.sm_e2a_err, label = apr.label )
plt.legend(loc='upper left')
<matplotlib.legend.Legend at 0x7f4f6d261550>