Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions docs/source/examples/fe.mf
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
4.5000000e+01 4.6000024e-02 NaN
4.5250000e+01 5.1828579e-02 3.4839262e-02
4.5500000e+01 5.7532098e-02 3.4486162e-02
4.5750000e+01 6.2614204e-02 3.4737634e-02
4.6000000e+01 6.7562494e-02 3.3784025e-02
4.6250000e+01 6.8650093e-02 3.4384982e-02
4.6500000e+01 7.4414324e-02 3.6399182e-02
4.6750000e+01 8.6101630e-02 3.5510966e-02
4.7000000e+01 1.0643828e-01 3.7251029e-02
4.7250000e+01 1.2190662e-01 4.1295010e-02
4.7500000e+01 1.2162338e-01 4.3263565e-02
4.7750000e+01 1.1238736e-01 4.2454540e-02
4.8000000e+01 1.0814969e-01 3.9752814e-02
4.8250000e+01 1.0993911e-01 4.6283662e-02
4.8500000e+01 1.1492749e-01 4.8465858e-02
4.8750000e+01 1.1283758e-01 4.7295931e-02
4.9000000e+01 1.0516644e-01 4.8774548e-02
4.9250000e+01 1.0373928e-01 5.1196426e-02
4.9500000e+01 1.1200213e-01 5.4240833e-02
4.9750000e+01 1.2812411e-01 5.5963875e-02
5.0000000e+01 1.4626389e-01 5.7016800e-02
5.0250000e+01 1.6193214e-01 5.7648619e-02
5.0500000e+01 1.7773063e-01 5.8914288e-02
5.0750000e+01 1.9641535e-01 6.0971633e-02
5.1000000e+01 2.2238499e-01 6.3365213e-02
5.1250000e+01 2.5561264e-01 6.3867594e-02
5.1500000e+01 2.9295103e-01 5.9603027e-02
5.1750000e+01 3.3225748e-01 4.9568833e-02
5.2000000e+01 3.6866729e-01 1.9800161e-02
5.2250000e+01 4.0053272e-01 -1.7180283e-02
5.2500000e+01 4.2909290e-01 -5.7969758e-02
5.2750000e+01 4.5683601e-01 -9.3440972e-02
5.3000000e+01 4.8744250e-01 -1.4416752e-01
5.3250000e+01 5.1465017e-01 -2.0699470e-01
5.3500000e+01 5.2557693e-01 -2.8771292e-01
5.3750000e+01 5.1304845e-01 -3.6862576e-01
5.4000000e+01 4.7243485e-01 -4.4847091e-01
5.4250000e+01 4.0547015e-01 -5.1993418e-01
5.4500000e+01 3.1194550e-01 -5.8773649e-01
5.4750000e+01 1.9024465e-01 -6.4715015e-01
5.5000000e+01 5.1082169e-02 -6.7323748e-01
5.5250000e+01 -9.4197060e-02 -6.6737551e-01
5.5500000e+01 -2.3121942e-01 -6.3875926e-01
5.5750000e+01 -3.5184712e-01 -5.7826383e-01
5.6000000e+01 -4.5510734e-01 -5.1229209e-01
5.6250000e+01 -5.2865017e-01 -4.4317177e-01
5.6500000e+01 -5.5916657e-01 -3.7292663e-01
5.6750000e+01 -5.5387444e-01 -2.9378329e-01
5.7000000e+01 -5.2794361e-01 -2.1616325e-01
5.7250000e+01 -4.9613618e-01 -1.6018768e-01
5.7500000e+01 -4.6663651e-01 -1.0738405e-01
5.7750000e+01 -4.3204046e-01 -5.8587866e-02
5.8000000e+01 -3.9273742e-01 -2.0437189e-02
5.8250000e+01 -3.5392701e-01 6.1952847e-03
5.8500000e+01 -3.1465227e-01 2.7284773e-02
5.8750000e+01 -2.7141522e-01 4.4106965e-02
5.9000000e+01 -2.2934538e-01 5.7701034e-02
5.9250000e+01 -1.9720631e-01 6.6414895e-02
5.9500000e+01 -1.7651794e-01 6.3571669e-02
5.9750000e+01 -1.6402393e-01 6.3691885e-02
6.0000000e+01 -1.5043751e-01 6.4997267e-02
6.0250000e+01 -1.3361777e-01 6.6913581e-02
6.0500000e+01 -1.1700118e-01 6.6228219e-02
6.0750000e+01 -1.0147659e-01 6.4262989e-02
6.1000000e+01 -8.6701720e-02 6.1012488e-02
6.1250000e+01 -7.3355143e-02 6.0961009e-02
6.1500000e+01 -6.2283737e-02 6.0909279e-02
6.1750000e+01 -5.3999562e-02 5.8661704e-02
6.2000000e+01 -4.8297653e-02 5.3332284e-02
6.2250000e+01 -4.3827886e-02 4.7179123e-02
6.2500000e+01 -4.0106277e-02 4.0996597e-02
6.2750000e+01 -3.7578736e-02 3.8335181e-02
6.3000000e+01 -3.6447758e-02 3.5967045e-02
6.3250000e+01 -3.5679709e-02 3.2461956e-02
6.3500000e+01 -3.2837051e-02 2.8138768e-02
6.3750000e+01 -2.6585766e-02 2.4859183e-02
6.4000000e+01 -1.8827651e-02 2.4096859e-02
6.4250000e+01 -1.2934336e-02 2.1828189e-02
6.4500000e+01 -1.1788731e-02 1.8817215e-02
6.4750000e+01 -1.3968126e-02 1.4961087e-02
6.5000000e+01 -1.6268746e-02 1.2143072e-02
6.5250000e+01 -1.7345941e-02 9.5270998e-03
6.5500000e+01 -1.9464399e-02 6.9639314e-03
6.5750000e+01 -2.5607594e-02 5.7242356e-03
6.6000000e+01 -3.3390029e-02 2.9980872e-03
6.6250000e+01 -3.5789993e-02 -2.6199406e-03
6.6500000e+01 -3.3113404e-02 -2.4280481e-03
6.6750000e+01 -2.7916505e-02 -3.6679899e-03
6.7000000e+01 -2.4366066e-02 -8.6146999e-03
6.7250000e+01 -2.3577006e-02 -2.6181950e-03
6.7500000e+01 -2.3772712e-02 4.2230389e-04
6.7750000e+01 -2.7119929e-02 -3.1670011e-03
6.8000000e+01 -3.0173743e-02 -2.9030927e-03
6.8250000e+01 -3.1176302e-02 -1.8970679e-03
6.8500000e+01 -3.1589026e-02 -4.0038896e-04
6.8750000e+01 -3.2479661e-02 -1.6242967e-03
6.9000000e+01 -3.6497468e-02 -2.1805595e-03
6.9250000e+01 -3.9167274e-02 -1.4724472e-03
6.9500000e+01 -4.1390053e-02 5.8494618e-04
6.9750000e+01 -4.4225467e-02 1.4443758e-03
7.0000000e+01 -4.7192867e-02 6.0872013e-04
101 changes: 101 additions & 0 deletions docs/source/examples/fe.nff
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
4.5000000e+01 -4.0523329e-01 NaN
4.5250000e+01 -4.4867918e-01 2.9786293e+00
4.5500000e+01 -4.9301281e-01 2.9149078e+00
4.5750000e+01 -5.4098426e-01 2.8585454e+00
4.6000000e+01 -5.8991783e-01 2.7503837e+00
4.6250000e+01 -6.4223173e-01 2.6527957e+00
4.6500000e+01 -6.9557526e-01 2.5661284e+00
4.6750000e+01 -7.4949206e-01 2.5119422e+00
4.7000000e+01 -8.0444461e-01 2.4467219e+00
4.7250000e+01 -8.7963490e-01 2.3724873e+00
4.7500000e+01 -9.5628416e-01 2.3263161e+00
4.7750000e+01 -1.0558340e+00 2.2735981e+00
4.8000000e+01 -1.1573151e+00 2.2160562e+00
4.8250000e+01 -1.2696799e+00 2.1760589e+00
4.8500000e+01 -1.3841911e+00 2.1369764e+00
4.8750000e+01 -1.5081903e+00 2.0986353e+00
4.9000000e+01 -1.6345189e+00 2.0623213e+00
4.9250000e+01 -1.7812378e+00 2.0201315e+00
4.9500000e+01 -1.9306879e+00 1.9758284e+00
4.9750000e+01 -2.0921308e+00 1.9625525e+00
5.0000000e+01 -2.2565314e+00 1.9396017e+00
5.0250000e+01 -2.4356823e+00 1.9106289e+00
5.0500000e+01 -2.6180689e+00 1.8930523e+00
5.0750000e+01 -2.8464880e+00 1.8518010e+00
5.1000000e+01 -3.0790341e+00 1.7961530e+00
5.1250000e+01 -3.3801883e+00 1.7596302e+00
5.1500000e+01 -3.6867891e+00 1.7319535e+00
5.1750000e+01 -4.0815996e+00 1.7188844e+00
5.2000000e+01 -4.4835365e+00 1.7732291e+00
5.2250000e+01 -4.8914216e+00 1.9832688e+00
5.2500000e+01 -5.3065101e+00 2.3035200e+00
5.2750000e+01 -5.6387635e+00 2.7126785e+00
5.3000000e+01 -5.9766085e+00 3.2046266e+00
5.3250000e+01 -6.1938992e+00 3.7598652e+00
5.3500000e+01 -6.4144823e+00 4.3922891e+00
5.3750000e+01 -6.4969583e+00 5.0686800e+00
5.4000000e+01 -6.5801320e+00 5.7816770e+00
5.4250000e+01 -6.4896402e+00 6.5442552e+00
5.4500000e+01 -6.3966302e+00 7.3828103e+00
5.4750000e+01 -6.0605621e+00 8.2608599e+00
5.5000000e+01 -5.7175342e+00 9.1206351e+00
5.5250000e+01 -5.1516243e+00 9.8658813e+00
5.5500000e+01 -4.5747397e+00 1.0508117e+01
5.5750000e+01 -3.9180624e+00 1.0923544e+01
5.6000000e+01 -3.2490228e+00 1.1234500e+01
5.6250000e+01 -2.6119677e+00 1.1449664e+01
5.6500000e+01 -1.9631735e+00 1.1461279e+01
5.6750000e+01 -1.4240778e+00 1.1363384e+01
5.7000000e+01 -8.7523119e-01 1.1200310e+01
5.7250000e+01 -4.7227022e-01 1.0972462e+01
5.7500000e+01 -6.2154242e-02 1.0714338e+01
5.7750000e+01 2.0482634e-01 1.0430934e+01
5.8000000e+01 4.7644702e-01 1.0107737e+01
5.8250000e+01 6.3738534e-01 9.8310952e+00
5.8500000e+01 8.0103937e-01 9.5665937e+00
5.8750000e+01 8.7791514e-01 9.2904332e+00
5.9000000e+01 9.5601444e-01 9.0410025e+00
5.9250000e+01 9.7351054e-01 8.8210806e+00
5.9500000e+01 9.9119958e-01 8.6671802e+00
5.9750000e+01 9.8871472e-01 8.5363324e+00
6.0000000e+01 9.8608320e-01 8.4144357e+00
6.0250000e+01 9.7272480e-01 8.2992839e+00
6.0500000e+01 9.5904150e-01 8.2132859e+00
6.0750000e+01 9.4448467e-01 8.1460156e+00
6.1000000e+01 9.2958948e-01 8.1066670e+00
6.1250000e+01 9.2323049e-01 8.0670668e+00
6.1500000e+01 9.1667379e-01 8.0281749e+00
6.1750000e+01 9.1237585e-01 7.9923541e+00
6.2000000e+01 9.0791729e-01 7.9631548e+00
6.2250000e+01 9.0219120e-01 7.9384695e+00
6.2500000e+01 8.9628436e-01 7.9212048e+00
6.2750000e+01 8.9898158e-01 7.9266738e+00
6.3000000e+01 9.0163582e-01 7.9325495e+00
6.3250000e+01 9.1527940e-01 7.9281004e+00
6.3500000e+01 9.2905391e-01 7.9268768e+00
6.3750000e+01 9.4606056e-01 7.9256297e+00
6.4000000e+01 9.6324810e-01 7.9233535e+00
6.4250000e+01 9.8279005e-01 7.9199555e+00
6.4500000e+01 1.0025486e+00 7.9162958e+00
6.4750000e+01 1.0252848e+00 7.9129831e+00
6.5000000e+01 1.0482825e+00 7.9136213e+00
6.5250000e+01 1.0727753e+00 7.9087567e+00
6.5500000e+01 1.0975512e+00 7.8929438e+00
6.5750000e+01 1.1158640e+00 7.8744458e+00
6.6000000e+01 1.1343600e+00 7.8563599e+00
6.6250000e+01 1.1482869e+00 7.8401263e+00
6.6500000e+01 1.1623268e+00 7.8459996e+00
6.6750000e+01 1.1774298e+00 7.8466151e+00
6.7000000e+01 1.1926610e+00 7.8336760e+00
6.7250000e+01 1.2072265e+00 7.8300721e+00
6.7500000e+01 1.2219094e+00 7.8248090e+00
6.7750000e+01 1.2358591e+00 7.8154641e+00
6.8000000e+01 1.2499145e+00 7.8164370e+00
6.8250000e+01 1.2615136e+00 7.8150461e+00
6.8500000e+01 1.2731816e+00 7.8088103e+00
6.8750000e+01 1.2848791e+00 7.8155106e+00
6.9000000e+01 1.2966454e+00 7.8218059e+00
6.9250000e+01 1.3129338e+00 7.8260567e+00
6.9500000e+01 1.3293558e+00 7.8369980e+00
6.9750000e+01 1.3510740e+00 7.8469427e+00
7.0000000e+01 1.3730008e+00 7.8550255e+00
908 changes: 908 additions & 0 deletions docs/source/examples/test_elliptical_polarization.ipynb

Large diffs are not rendered by default.

106 changes: 76 additions & 30 deletions udkm1Dsim/simulations/xrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,18 @@ class Xray(Simulation):

def __init__(self, S, force_recalc, **kwargs):
super().__init__(S, force_recalc, **kwargs)
self._energy = np.array([])
self._wl = np.array([])
self._k = np.array([])
self._energy = np.array([0])
self._wl = np.array([0])
self._k = np.array([0])
self._theta = np.zeros([1, 1])
self._qz = np.zeros([1, 1])

self.polarizations = {0: 'unpolarized',
1: 'circ +',
2: 'circ -',
3: 'sigma',
4: 'pi'}
4: 'pi',
5: 'elliptical'}

self.pol_in_state = 3 # sigma
self.pol_out_state = 0 # no-analyzer
Expand Down Expand Up @@ -354,12 +355,7 @@ def set_incoming_polarization(self, pol_in_state):

"""
self.pol_in_state = pol_in_state
if (self.pol_in_state == 1): # circ +
self.disp_message('incoming polarizations {:s} not implemented'.format(
self.polarizations[self.pol_in_state]))
self.set_incoming_polarization(3)
return
elif (self.pol_in_state == 2): # circ-
if self.pol_in_state in [1, 2, 5]: # circ +,-, elliptical
self.disp_message('incoming polarizations {:s} not implemented'.format(
self.polarizations[self.pol_in_state]))
self.set_incoming_polarization(3)
Expand Down Expand Up @@ -722,12 +718,7 @@ def set_incoming_polarization(self, pol_in_state):

"""
self.pol_in_state = pol_in_state
if (self.pol_in_state == 1): # circ +
self.disp_message('incoming polarizations {:s} not implemented'.format(
self.polarizations[self.pol_in_state]))
self.set_incoming_polarization(3)
return
elif (self.pol_in_state == 2): # circ-
if self.pol_in_state in [1, 2, 5]: # circ +,-, elliptical
self.disp_message('incoming polarizations {:s} not implemented'.format(
self.polarizations[self.pol_in_state]))
self.set_incoming_polarization(3)
Expand Down Expand Up @@ -1621,14 +1612,22 @@ def get_hash(self, **kwargs):

return self.S.get_hash(types=['xray', 'magnetic']) + '_' + make_hash_md5(param)

def set_incoming_polarization(self, pol_in_state):
def set_incoming_polarization(self, pol_in_state, polarization=None):
"""set_incoming_polarization

Sets the incoming polarization factor for circular +, circular -, sigma,
pi, and unpolarized polarization.
pi, unpolarized, and elliptical polarization.
In the case of elliptical polarization a single or list of tuple of the
azimuth angle :math:`\alpha` and the ellipticity :math:`e` of the
polarization can be input.
:math:`-180° \leq \alpha \leq +180°`
:math:`-1 \leq e \leq +1`

Args:
pol_in_state (int): incoming polarization state id.
polarization (list[tuple[alpha (Quantity), ellipticity (float)]]):
azimuth angle alpha of polarization (0 -> s; 90 -> pi) [deg]
ellipticity (-+1 -> circular left/right; 0 -> linear)

"""

Expand All @@ -1641,21 +1640,51 @@ def set_incoming_polarization(self, pol_in_state):
self.pol_in = np.array([1, 0], dtype=np.cfloat)
elif (self.pol_in_state == 4): # pi
self.pol_in = np.array([0, 1], dtype=np.cfloat)
elif (self.pol_in_state == 5): # elliptical
if polarization is None:
raise ValueError('For elliptical polarization a list or single tuple of azimuth '
'angle alpha and ellipticity e must be provided.')
if type(polarization) is tuple:
polarization = [polarization]

N = len(polarization)
self.pol_in = np.zeros((2, N), dtype=np.cfloat)
for i, (alpha, ellipticity) in enumerate(polarization):
alpha = alpha.to('rad').magnitude
if ellipticity > 1 or ellipticity < -1:
raise ValueError('ellipticity must be -1 <= e <= +1')
else:
epsilon = np.arctan(ellipticity)
self.pol_in[:, i] = np.array([np.cos(alpha)*np.cos(epsilon)
- 1j*np.sin(alpha)*np.sin(epsilon),
np.sin(alpha)*np.cos(epsilon)
+ 1j*np.cos(alpha)*np.sin(epsilon)],
dtype=np.cfloat)

else: # unpolarized
self.pol_in_state = 0 # catch any number and set state to 0
self.pol_in = np.array([np.sqrt(.5), np.sqrt(.5)], dtype=np.cfloat)


self.disp_message('incoming polarizations set to: {:s}'.format(
self.polarizations[self.pol_in_state]))

def set_outgoing_polarization(self, pol_out_state):
def set_outgoing_polarization(self, pol_out_state, polarization=None):
"""set_outgoing_polarization

Sets the outgoing polarization factor for circular +, circular -, sigma,
pi, and unpolarized polarization.
pi, unpolarized, and elliptical polarization.
In the case of elliptical polarization a single or list of tuple of the
azimuth angle :math:`\alpha` and the ellipticity :math:`e` of the
polarization can be input.
:math:`-180° \leq \alpha \leq +180°`
:math:`-1 \leq e \leq +1`

Args:
pol_out_state (int): outgoing polarization state id.
polarization (list[tuple[alpha (Quantity), ellipticity (float)]]):
azimuth angle alpha of polarization (0 -> s; 90 -> pi) [deg]
ellipticity (-+1 -> circular left/right; 0 -> linear)

"""

Expand All @@ -1668,6 +1697,8 @@ def set_outgoing_polarization(self, pol_out_state):
self.pol_out = np.array([1, 0], dtype=np.cfloat)
elif (self.pol_out_state == 4): # pi
self.pol_out = np.array([0, 1], dtype=np.cfloat)
elif (self.pol_out_state == 5): # elliptical
self.pol_out = np.array([0, 1], dtype=np.cfloat)
else: # no analyzer
self.pol_out_state = 0 # catch any number and set state to 0
self.pol_out = np.array([], dtype=np.cfloat)
Expand Down Expand Up @@ -2665,17 +2696,32 @@ def calc_reflectivity_transmissivity_from_matrix(RT, pol_in, pol_out):
Trans = np.matmul(np.matmul(np.array([[-1, 1], [-1j, -1j]]), Trans),
np.array([[-1, 1j], [1, 1j]])*0.5)

if pol_out.size == 0:
# no analyzer polarization
R = np.real(np.matmul(np.square(np.absolute(np.matmul(Ref, pol_in))),
np.array([1, 1], dtype=np.cfloat)))
T = np.real(np.matmul(np.square(np.absolute(np.matmul(Trans, pol_in))),
np.array([1, 1], dtype=np.cfloat)))
else:
R = np.real(np.square(np.absolute(np.matmul(np.matmul(Ref, pol_in), pol_out))))
T = np.real(np.square(np.absolute(np.matmul(np.matmul(Trans, pol_in), pol_out))))
# enable multiple polarizations
try:
num_pol = pol_in.shape[1]
except IndexError:
num_pol = 1
# add second dimension to polarization vectors for iteration
pol_in = pol_in[:, np.newaxis]

R = np.empty((Ref.shape[0], Ref.shape[1], num_pol))
T = np.empty((Ref.shape[0], Ref.shape[1], num_pol))

for i in range(num_pol):
if pol_out.size == 0:
# no analyzer polarization
R[:, :, i] = np.real(np.matmul(np.square(np.absolute(np.matmul(Ref, pol_in[:, i]))),
np.array([1, 1], dtype=np.cfloat)))
T[:, :, i] = np.real(np.matmul(np.square(np.absolute(np.matmul(Trans, pol_in[:, i]))),
np.array([1, 1], dtype=np.cfloat)))
else:
R[:, :, i] = np.real(np.square(np.absolute(np.matmul(np.matmul(Ref, pol_in[:, i]), pol_out))))
T[:, :, i] = np.real(np.square(np.absolute(np.matmul(np.matmul(Trans, pol_in[:, i]), pol_out))))

return R, T
if num_pol == 1:
return np.squeeze(R, axis=2), np.squeeze(T, axis=2)
else:
return R, T

@staticmethod
def calc_kerr_effect_from_matrix(RT):
Expand Down