Quick start examples¶
We will now show how can we compute a spectrum using pyrh. The user should be familiar with RH code in general. The basic usage is done through *.input files of RH and user should use these as he would use them when calling RH from a shell.
Open now the examples/synth.py script in your favourite editor.
We will first load in the atmospheric model. Here we will use FAL C atmosheric model:
1import numpy as np
2import matplotlib.pyplot as plt
3import pyrh
4
5def spinor2multi(atm):
6 """
7 Casting from SPINOR type atmosphere structure to MULTI type structure.
8 """
9 from scipy.constants import k
10 new = np.empty(atm.shape, dtype=np.float64)
11
12 new[0] = atm[0]
13 new[1] = atm[2]
14 # electron number dnesity
15 new[2] = atm[4]/10/k/atm[2] / 1e6 # [1/cm3]
16 new[3] = atm[9]/1e5
17 new[4] = atm[8]/1e5
18 # magnetic field vector: strength, inclination and azimuth
19 new[5] = atm[7]
20 new[6] = atm[-2]
21 new[7] = atm[-1]
22 # total hydrogen number density
23 new[8] = (atm[3] - atm[4])/10/k/atm[2] / 1e6 / 1.26 # [1/cm3]
24
25 return new
26
27atmos = np.loadtxt("falc.dat", skiprows=1)
28atmos = np.array(atmos.T, dtype=np.float64)
29atmos= spinor2multi(atmos)
Since the atmospheric model is given in SPINOR like format, first we had to convert it into MULTI type format (more about atmospheric model structure in …).
Now, we define couple of variables to configure RH setup:
1# path to the *.input files
2cwd = "."
3
4# mu angle for which to compute the spectrum
5mu = 1.0
6
7# type of atmosphere stratification:
8# 0 -- optical depth @ 500nm
9# 1 -- mass density [cm2/g]
10# 2 -- height [km]
11atm_scale = 0
Parameter cwd describes the relative path to a location where .*input files are stored. These are going to be read by RH.
Further, we set up the wavelength grid for which we are synthesizing the spectrum. We will synthesize Fe I 6301 and 6302 line pair, therefore:
1# wavelength samples for which to compute the spectrum (in nm) in vacuum
2wave = np.linspace(630.0, 630.35, num=251) + 0.2
To compute a spectrum, we will invoke a method pyrh.compute1d() for given set of input parameters as:
1spec = pyrh.compute1d(cwd, mu, atm_scale, atmos, wave)
2spec = np.array(spec, dtype=np.float64)
And the final product is:
1plt.plot(wave, spec[0]*1e8)
2plt.xlabel("Wavelength in vacuum [nm]")
3plt.ylabel(r"Intensity [10$^{-8}$ W/Hz/srad/m$^2$]")
4plt.xlim([wave[0], wave[-1]])
5plt.show()
Voila!