Test of the RIXS Map visualization tool¶
For visualization of the RIXS map, we use the RixsMap
class. The class is initialized with the RIXS map data and the energy axis. The energy axis is a list of two elements: the first element is the energy axis of the RIXS map, the second element is the energy axis of the RIXS map after the energy loss correction. The energy axis is in units of eV.
import numpy as np
from spectrafit.plugins.rixs_visualizer import RIXSApp
from spectrafit.api.rixs_model import SizeRatioAPI
Initialization¶
For visualization of a RIXS map, we use the RIXSApp
class. The class only requires the incident and emission energy as 1D arrays. The RIXS map itself has to be stored as a 2D meshgrid of intensities. By default the RIXS map is assumed to be in units of eV.
Information "it is an early version of the RIXS map visualization tool"
Note:
In this example, a reference function is defined, which returns all three required arrays for the RixsMap
class. The first two arrays are the one-dimensional energy ranges of the incident and emission energies. The third array is the two-dimensional RIXS map.
from typing import Tuple
def sin2_as_rixsmap() -> Tuple[np.ndarray, np.ndarray, np.ndarray]:
"""Create a RIXS map with a sinusoidal intensity."""
incident_energy = np.linspace(0, 10, 100)
emission_energy = np.linspace(0, 10, 100)
grid = np.meshgrid(incident_energy, emission_energy)
rixs_map = np.sin(grid[0]) * np.sin(grid[1])
return incident_energy, emission_energy, rixs_map
_app = RIXSApp(
incident_energy=sin2_as_rixsmap()[0],
emission_energy=sin2_as_rixsmap()[1],
rixs_map=sin2_as_rixsmap()[2],
# For avoiding issues with a too large inline visualization, please downsizing the RIXS map size
size=SizeRatioAPI(size=(200, 200)),
mode="inline",
jupyter_dash=True,
)
_app.app_run()
/home/runner/work/spectrafit/spectrafit/.venv/lib/python3.10/site-packages/dash/dash.py:579: UserWarning: JupyterDash is deprecated, use Dash instead. See https://dash.plotly.com/dash-in-jupyter for more details.
What is needed to run similiar example?¶
To run this example, you need to have the following three target arrays:
incident_energy
axis as 1D arrayemission_energy
axis as 1D arrayrixs_map
as 2D array
In the example above, sin2_as_rixsmap
is used as reference function to generate all three arrays, but you can use any other function that returns the three arrays or load them from a file, like:
import pickle
with open('rixs_map.pickle', 'rb') as f:
incident_energy, emission_energy, rixs_map = pickle.load(f)
_app = RIXSApp(incident_energy, emission_energy, rixs_map)
or:
import pandas as pd
_app = RIXSApp(
incident_energy=pd.read_csv('incident_energy.csv', index_col=0).values,
emission_energy=pd.read_csv('emission_energy.csv', index_col=0).values,
# Loaded values has to be reshaped to 2D array
rixs_map=pd.read_csv('rixs_map.csv', index_col=0).values.reshape(100, 100)
)
The example above assumes that the data is stored in the csv
format and the first column is the index column. The index_col=0
argument is used to skip the first column.