Converters and Visualizer
About the Converter API
The Converter API is a new feature in the v0.12.x release of SpectraFit
with major focus on:
- Data Validation
- Settings Management
In general, input and data files are converted to the internal data format, which are dictionaries for the input data and pandas dataframes for the data files. The Converter API is realized by using the ABC
-class and the @abstractmethod
decorator, while the File API is using the pydantic library.
Meta Data Converter Class¶
Abstract base class for the converter plugins.
Converter
¶
Bases: ABC
Abstract base class for the converter plugin.
The abstract base class is used to define the interface for the converter plugins:
- get_args: Get the arguments from the command line.
- convert: Convert the input file to the output file.
- call: Call the converter plugin.
Currently used for:
- Convertion of the input file.
- Convertion of the output file.
Source code in spectrafit/plugins/converter.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
|
__call__()
abstractmethod
¶
Call the converter plugin.
Source code in spectrafit/plugins/converter.py
62 63 64 |
|
convert(infile, file_format)
abstractmethod
staticmethod
¶
Convert the input file to the target file format.
It is an abstract method and must be implemented in the derived class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
infile | Path | Input file as a path object. | required |
file_format | str | Target file format. | required |
Returns:
Type | Description |
---|---|
MutableMapping[str, Any] | MutableMapping[str, Any]: Converted file as a dictionary. |
Source code in spectrafit/plugins/converter.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
get_args()
abstractmethod
¶
Get the arguments from the command line.
Returns:
Type | Description |
---|---|
Dict[str, Any] | Dict[str, Any]: Return the input file arguments as a dictionary without additional information beyond the command line arguments. |
Raises:
Type | Description |
---|---|
ValueError | If the output file format is not supported. |
Source code in spectrafit/plugins/converter.py
25 26 27 28 29 30 31 32 33 34 35 |
|
save(data, fname, export_format)
abstractmethod
¶
Save the data to the target file format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data | Any | Data to save. | required |
fname | Path | Filename of the target file. | required |
export_format | str | Target file format. | required |
Source code in spectrafit/plugins/converter.py
52 53 54 55 56 57 58 59 60 |
|
Input and Output File Converter for object-oriented formats¶
Convert the input and output files to the preferred file format.
FileConverter
¶
Bases: Converter
Convert the input and output file to the preferred file format.
Supported file formats
Currently supported file formats:
-[x] JSON -[x] YAML (YML) -[x] TOML (LOCK for the lock file)
Source code in spectrafit/plugins/file_converter.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
__call__()
¶
Run the converter via cmd commands.
Source code in spectrafit/plugins/file_converter.py
124 125 126 127 128 129 130 131 |
|
convert(infile, file_format)
staticmethod
¶
Convert the input file to the output file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
infile | Path | The input file as a path object. | required |
file_format | str | The output file format. | required |
Raises:
Type | Description |
---|---|
ValueError | If the input file format is not supported. |
Returns:
Type | Description |
---|---|
MutableMapping[str, Any] | MutableMapping[str, Any] : The converted file as a dictionary. |
Source code in spectrafit/plugins/file_converter.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
|
get_args()
¶
Get the arguments from the command line.
Returns:
Type | Description |
---|---|
Dict[str, Any] | Dict[str, Any]: Return the input file arguments as a dictionary without additional information beyond the command line arguments. |
Source code in spectrafit/plugins/file_converter.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
save(data, fname, export_format)
¶
Save the converted file.
Raises:
Type | Description |
---|---|
ValueError | If the input file format is identical with the output format. |
ValueError | If the output file format is not supported. |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data | Any | The converted file as a dictionary. | required |
fname | Path | The input file as a path object. | required |
export_format | str | The output file format. | required |
Source code in spectrafit/plugins/file_converter.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
command_line_runner()
¶
Run the converter from the command line.
Source code in spectrafit/plugins/file_converter.py
134 135 136 |
|
Data Converter for rational data formats like CSV, Excel, etc.¶
Transform the input data to a CSV file.
DataConverter
¶
Bases: Converter
Convert the data files to a CSV file.
Supported file formats
Currently supported file formats:
-[x] ATHENA -[x] TXT -[ ] more to come
DataConverter
class can be also used in the Jupyter notebook.
Source code in spectrafit/plugins/data_converter.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
|
__call__()
¶
Run the converter.
Source code in spectrafit/plugins/data_converter.py
166 167 168 169 170 171 172 173 174 175 176 |
|
convert(infile, file_format)
staticmethod
¶
Convert the input file to the target file format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
infile | Path | Input file as a path object. | required |
file_format | str | Target file format. | required |
Raises:
Type | Description |
---|---|
ValueError | If the file format is not supported. |
Returns:
Type | Description |
---|---|
pd.DataFrame | pd.DataFrame: The converted data as a pandas DataFrame. |
Source code in spectrafit/plugins/data_converter.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
|
get_args()
¶
Get the arguments from the command line.
Returns:
Type | Description |
---|---|
Dict[str, Any] | Dict[str, Any]: Return the input file arguments as a dictionary without additional information beyond the command line arguments. |
Source code in spectrafit/plugins/data_converter.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
save(data, fname, export_format)
¶
Save the converted data to a CSV file.
Raises:
Type | Description |
---|---|
ValueError | If the export format is not supported. |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data | Any | The converted data, which is a pandas DataFrame. | required |
fname | Path | The file name of the data file. | required |
export_format | str | The file format of the exported file. | required |
Source code in spectrafit/plugins/data_converter.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
|
DataFormats
dataclass
¶
Data formats.
Source code in spectrafit/plugins/data_converter.py
62 63 64 65 66 67 |
|
command_line_runner()
¶
Run the converter from the command line.
Source code in spectrafit/plugins/data_converter.py
179 180 181 |
|
get_athena_column(fname, comment='#')
¶
Get the header of the file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fname | Path | The file name of the data file. | required |
comment | str | The comment marker. Defaults to "#". | '#' |
Returns:
Type | Description |
---|---|
Optional[List[str]] | Optional[List[str]]: The column names of the data file as a list. |
Source code in spectrafit/plugins/data_converter.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|
Pkl Converter for pickle files¶
Transform the raw pkl data into a CSV files.
ExportData
¶
Export the data to a file.
General information
The data is exported to a file. The file format is determined by the file extension of the output file. The supported file formats are:
-[x] npy -[x] npz -[x] pkl -[x] pkl.gz
Classical file formats like CSV
, JSON
, TOML
, etc. are not supported. In case of CSV
, the conversion from unstructured data to a structured format is not trivial. In case of JSON
and TOML
, the data is not the conversion from numpy arrays to lists is very costly. Therefore, the data is exported to a pickly file as the preferred format.
About NumPy
The data is exported to a NumPy file can cause some challenge for the loading of the data. The data is exported as a dictionary with numpy as numpy arrays. The data can be loaded with the following code:
import numpy as np
data = np.load("data.npy", allow_pickle=True).item()
Source code in spectrafit/plugins/pkl_converter.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
|
__call__()
¶
Export the data to a file.
Source code in spectrafit/plugins/pkl_converter.py
69 70 71 72 73 74 |
|
__init__(data, fname, export_format)
¶
Export the data to a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data | Dict[str, Any] | The data to export. | required |
fname | Path | The filename of the output file. | required |
export_format | str | The file format of the output file. | required |
Source code in spectrafit/plugins/pkl_converter.py
57 58 59 60 61 62 63 64 65 66 67 |
|
numpy2list(data)
staticmethod
¶
Convert the arrays of list dictionaries to a list of dictionaries with list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data | List[Dict[str, Any]] | The data to convert. | required |
Returns:
Type | Description |
---|---|
List[Dict[str, Any]] | List[Dict[str, Any]]: The converted data. |
Source code in spectrafit/plugins/pkl_converter.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
|
to_numpy()
¶
Export the data to a numpy file.
Source code in spectrafit/plugins/pkl_converter.py
76 77 78 79 80 81 82 |
|
to_pickle()
¶
Export the data to a pickle file.
Source code in spectrafit/plugins/pkl_converter.py
84 85 86 87 88 89 90 91 |
|
PklConverter
¶
Bases: Converter
Convert pkl data to a CSV files.
General information
The pkl data is converted to a CSV file. The CSV file is saved in the same directory as the input file. The name of the CSV file is the same as the input file with the suffix .csv
and prefixed with the name of the 'major' keys in the pkl file. Furthermore, a graph of the data is optionally saved as a PDF file to have a visual representation of the data structure.
Supported file formats
Currently supported file formats:
-[x] pkl -[x] pkl.gz -[x] ...
Source code in spectrafit/plugins/pkl_converter.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
|
__call__()
¶
Run the converter.
Source code in spectrafit/plugins/pkl_converter.py
236 237 238 239 240 |
|
convert(infile, file_format)
staticmethod
¶
Convert the input file to the output file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
infile | Path | The input file of the as a path object. | required |
file_format | str | The output file format. | required |
Returns:
Type | Description |
---|---|
Dict[str, Any] | Dict[str, Any]: The data as a dictionary, which can be a nested dictionary |
Source code in spectrafit/plugins/pkl_converter.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
|
get_args()
¶
Get the arguments from the command line.
Returns:
Type | Description |
---|---|
Dict[str, Any] | Dict[str, Any]: Return the input file arguments as a dictionary without additional information beyond the command line arguments. |
Source code in spectrafit/plugins/pkl_converter.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
|
save(data, fname, export_format)
¶
Save the converted pickle data to a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data | Any | The converted nested dictionary of the pkl data. | required |
fname | Path | The filename of the output file. | required |
export_format | str | The file format of the output file. | required |
Raises:
Type | Description |
---|---|
ValueError | If the export format is not supported. |
Source code in spectrafit/plugins/pkl_converter.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
|
command_line_runner()
¶
Run the command line script.
Source code in spectrafit/plugins/pkl_converter.py
243 244 245 |
|
About pickle file and the PklVisualizer
In addition to exploring the nested structure of the Python's pickle file, the PklVisualizer
provides two methods to visualize the data:
- As graph via
networkx
andmatplotlib
- As json file with used types
Visualize the pkl file as a graph.
PklVisualizer
¶
Bases: Converter
Visualize the pkl data as a graph.
Source code in spectrafit/plugins/pkl_visualizer.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
|
__call__()
¶
Create the graph and save it as a PDF file.
Source code in spectrafit/plugins/pkl_visualizer.py
173 174 175 176 177 178 179 180 181 |
|
add_nodes(graph, data_dict)
¶
Add nodes to the graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
graph | nx.DiGraph | The graph to add nodes to. | required |
data_dict | Dict[str, Any] | The data dictionary to get the nodes from. | required |
Source code in spectrafit/plugins/pkl_visualizer.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
|
convert(infile, file_format)
staticmethod
¶
Convert the input file to the output file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
infile | Path | The input file of the as a path object. | required |
file_format | str | The encoding of the pickle file. | required |
Raises:
Type | Description |
---|---|
ValueError | If the data is not a dictionary. |
Returns:
Type | Description |
---|---|
Dict[str, Any] | Dict[str, Any]: The data as a dictionary, which can be a nested dictionary. |
Source code in spectrafit/plugins/pkl_visualizer.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|
create_graph(fname, data_dict)
¶
Create the graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fname | Path | The filename of the file to create the graph from. | required |
data_dict | Dict[str, Any] | The data dictionary to create the graph from. | required |
Returns:
Type | Description |
---|---|
nx.DiGraph | nx.DiGraph: The graph created from the data dictionary. |
Source code in spectrafit/plugins/pkl_visualizer.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
|
get_args()
¶
Get the arguments from the command line.
Returns:
Type | Description |
---|---|
Dict[str, Any] | Dict[str, Any]: Return the input file arguments as a dictionary without additional information beyond the command line arguments. |
Source code in spectrafit/plugins/pkl_visualizer.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
|
get_type(value)
¶
Get the type of the value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value | Any | The value to get the type from. | required |
Returns:
Type | Description |
---|---|
Union[Dict[str, Any], str] | Union[Dict[str, Any], str]: The type of the value. |
Source code in spectrafit/plugins/pkl_visualizer.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
save(data, fname, export_format)
¶
Save the graph to a file and the data and their types to a json file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data | Any | The data to save, which can be a nested dictionary. | required |
fname | Path | The filename of the file to save. | required |
export_format | str | The file format to save the graph to. | required |
Raises:
Type | Description |
---|---|
ValueError | If the export format is not supported. |
Source code in spectrafit/plugins/pkl_visualizer.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
|
command_line_runner()
¶
Run the converter from the command line.
Source code in spectrafit/plugins/pkl_visualizer.py
184 185 186 |
|
RIXS Converter for RIXS data¶
Transform the raw pkl data into a JSON, TOML, or numpy file for RIXS.
RIXSConverter
¶
Bases: Converter
Transform the raw pkl data into a JSON, TOML, or numpy file for RIXS.
Source code in spectrafit/plugins/rixs_converter.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
|
__call__()
¶
Run the converter.
Source code in spectrafit/plugins/rixs_converter.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
|
convert(infile, file_format)
staticmethod
¶
Convert the pkl file to a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
infile | Path | The input file. | required |
file_format | str | The file format for the optional encoding of the pickle file. | required |
Returns:
Type | Description |
---|---|
MutableMapping[str, Any] | MutableMapping[str, Any]: The data dictionary from the pkl file. |
Source code in spectrafit/plugins/rixs_converter.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
create_rixs(data, incident_energy, emission_energy, rixs_map, mode)
¶
Create the RIXS map from the pkl file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data | MutableMapping[str, Any] | The data dictionary from the pkl file. | required |
incident_energy | str | The name of the incident energy. | required |
emission_energy | str | The name of the emitted energy. | required |
rixs_map | str | The name of the RIXS map. | required |
mode | str | The mode of the RIXS map post-processing, e.g. 'sum' or 'max'. | required |
Raises:
Type | Description |
---|---|
ValueError | If the mode is not in the choices. |
KeyError | If the incident energy, emission energy, or RIXS map is not in the data. |
Returns:
Name | Type | Description |
---|---|---|
RIXSModelAPI | RIXSModelAPI | The RIXS map as a RIXSModelAPI pydantic object. |
Source code in spectrafit/plugins/rixs_converter.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
get_args()
¶
Get the arguments from the command line.
Returns:
Type | Description |
---|---|
Dict[str, Any] | Dict[str, Any]: Return the input file arguments as a dictionary without additional information beyond the command line arguments. |
Source code in spectrafit/plugins/rixs_converter.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
numpydict2listdict(data)
staticmethod
¶
Convert a dictionary with numpy arrays to a dictionary with lists.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data | MutableMapping[str, Any] | The data dictionary. | required |
Returns:
Type | Description |
---|---|
MutableMapping[str, Any] | MutableMapping[str, Any]: The data dictionary with lists. |
Source code in spectrafit/plugins/rixs_converter.py
200 201 202 203 204 205 206 207 208 209 210 |
|
raise_error(wrong_key, data)
staticmethod
¶
Raise an error if the key is not in the data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
wrong_key | str | The key which is not in the data. | required |
data | Any | The data dictionary from the pkl file. | required |
Raises:
Type | Description |
---|---|
KeyError | If the key is not in the data. |
Source code in spectrafit/plugins/rixs_converter.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
|
save(data, fname, export_format)
¶
Save the data to a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data | Any | The data to save. | required |
fname | Path | The filename. | required |
export_format | str | The file extension for the export. | required |
Raises:
Type | Description |
---|---|
ValueError | If the export format is not in the choices. |
Source code in spectrafit/plugins/rixs_converter.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
|
command_line_runner()
¶
Run the command line script.
Source code in spectrafit/plugins/rixs_converter.py
228 229 230 |
|
On top of the RIXSConverter
class, the RIXSVisualizer
class is available to visualize the RIXS data and provide a method to take RIXS cuts.
This module contains the RIXS visualizer class.
RIXSApp
¶
Bases: RIXSFigure
Create the RIXS app.
About the RIXS app
The RIXS app is a web application that allows you to visualize the RIXS data. The app is based on the Dash framework. The app is composed of three figures: the RIXS figure, the XES figure and the XAS figure.
The RIXS figure is a 3D surface plot. The XES figure is a line plot showing the XES spectrum. The XAS figure is a line plot showing the XAS spectrum.
The RIXS figure is interactive. You can zoom in and out, rotate the figure, and change the color scale. The XES and XAS figures are not interactive.
Source code in spectrafit/plugins/rixs_visualizer.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 |
|
__init__(incident_energy, emission_energy, rixs_map, size=SizeRatioAPI(size=(500, 500), ratio_rixs=(2, 2), ratio_xas=(3, 1), ratio_xes=(3, 1)), main_title=MainTitleAPI(rixs='RIXS', xes='XES', xas='XAS'), fdir=Path('./'), mode='server', jupyter_dash=False, port=8050, debug=False)
¶
Create the RIXS app.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
incident_energy | NDArray[np.float64] | Incident energy. | required |
emission_energy | NDArray[np.float64] | Emission energy. | required |
rixs_map | NDArray[np.float64] | RIXS data as a 2D array. | required |
size | SizeRatioAPI | Size of the figures. Defaults to SizeRatioAPI(size=(500, 500), ratio_rixs=(2, 2), ratio_xas=(3, 1), ratio_xes=(3, 1)). | SizeRatioAPI(size=(500, 500), ratio_rixs=(2, 2), ratio_xas=(3, 1), ratio_xes=(3, 1)) |
main_title | MainTitleAPI | Main title of the figures. Defaults to MainTitleAPI(rixs="RIXS", xes="XES", xas="XAS"). | MainTitleAPI(rixs='RIXS', xes='XES', xas='XAS') |
fdir | Path | Directory to save the figures. Defaults to Path("./"). | Path('./') |
mode | str | Mode of the app. Defaults to "server". | 'server' |
port | int | Port of the app. Defaults to 8050. | 8050 |
jupyter_dash | bool | Jupyter Dash mode. Defaults to False. | False |
debug | bool | Debug mode. Defaults to False. | False |
Source code in spectrafit/plugins/rixs_visualizer.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
|
app_run()
¶
Run the app.
Source code in spectrafit/plugins/rixs_visualizer.py
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 |
|
body()
¶
Create the body.
Returns:
Type | Description |
---|---|
dbc.Card | dbc.Card: Body as a bootstrap card. |
Source code in spectrafit/plugins/rixs_visualizer.py
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 |
|
colorscale()
¶
Create the color scale dropdown.
Returns:
Type | Description |
---|---|
html.Div | html.Div: Color scale dropdown. |
Source code in spectrafit/plugins/rixs_visualizer.py
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
|
footer()
¶
Create the footer.
Returns:
Type | Description |
---|---|
dbc.Card | dbc.Card: Footer as a bootstrap card. |
Source code in spectrafit/plugins/rixs_visualizer.py
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 |
|
header()
¶
Create the header.
Returns:
Type | Description |
---|---|
dbc.Card | dbc.Card: Header as a bootstrap card. |
Source code in spectrafit/plugins/rixs_visualizer.py
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 |
|
logging_flask()
¶
Set the logging level of the Flask server to ERROR.
Source code in spectrafit/plugins/rixs_visualizer.py
304 305 306 307 |
|
opacity()
¶
Create the opacity slider.
Returns:
Type | Description |
---|---|
html.Div | html.Div: Opacity slider. |
Source code in spectrafit/plugins/rixs_visualizer.py
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
|
pre_body()
¶
Create the body.
Returns:
Type | Description |
---|---|
Tuple[html.Div, html.Div, html.Div] | Tuple[html.Div, html.Div, html.Div]: Body as a tuple of three plot parts. |
Source code in spectrafit/plugins/rixs_visualizer.py
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
|
RIXSFigure
¶
Class to create the RIXS figure.
About the RIXS figure
The RIXS figure is composed of three subplots:
- RIXS -> 3D plot
- XES -> 2D plot
- XAS -> 2D plot
Source code in spectrafit/plugins/rixs_visualizer.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
|
__init__(incident_energy, emission_energy, rixs_map, size=SizeRatioAPI(size=(500, 500), ratio_rixs=(2, 2), ratio_xes=(3, 1), ratio_xas=(3, 1)), x_axis=XAxisAPI(name='Incident Energy', unit='eV'), y_axis=YAxisAPI(name='Emission Energy', unit='eV'), z_axis=ZAxisAPI(name='Intensity', unit='a.u.'))
¶
Initialize the RIXS figure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
incident_energy | NDArray[np.float64] | Incident energy. | required |
emission_energy | NDArray[np.float64] | Emission energy. | required |
rixs_map | NDArray[np.float64] | RIXS data as a 2D array. | required |
size | SizeRatioAPI | Size of the figure. Defaults to SizeRatioAPI(size=(500, 500), ratio_rixs=(2, 2), ratio_xes=(3, 1), ratio_xas=(3, 1)). | SizeRatioAPI(size=(500, 500), ratio_rixs=(2, 2), ratio_xes=(3, 1), ratio_xas=(3, 1)) |
x_axis | XAxisAPI | X-Axis of the figure. Defaults to XAxisAPI(name="Incident Energy", unit="eV"). | XAxisAPI(name='Incident Energy', unit='eV') |
y_axis | YAxisAPI | Y-Axis of the figure. Defaults to YAxisAPI(name="Emission Energy", unit="eV"). | YAxisAPI(name='Emission Energy', unit='eV') |
z_axis | ZAxisAPI | Z-Axis of the figure. Defaults to ZAxisAPI(name="Intensity", unit="a.u."). | ZAxisAPI(name='Intensity', unit='a.u.') |
Source code in spectrafit/plugins/rixs_visualizer.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|
create_rixs(colorscale='Viridis', opacity=0.9, template=None)
¶
Create the RIXS figure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
colorscale | str | Color scale. Defaults to "Viridis". | 'Viridis' |
opacity | float | Opacity of the surface. Defaults to 0.9. | 0.9 |
template | str | Template of the figure. Defaults to None. | None |
Returns:
Type | Description |
---|---|
go.Figure | go.Figure: RIXS figure. |
Source code in spectrafit/plugins/rixs_visualizer.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
|
create_xas(x, y, template=None)
¶
Create the XAS figure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x | NDArray[np.float64] | X-axis of the figure. | required |
y | NDArray[np.float64] | Y-axis of the figure. | required |
template | str | Template of the figure. Defaults to None. | None |
Returns:
Type | Description |
---|---|
go.Figure | go.Figure: XAS figure. |
Source code in spectrafit/plugins/rixs_visualizer.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
|
create_xes(x, y, template=None)
¶
Create the XES figure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x | NDArray[np.float64] | X-axis of the figure. | required |
y | NDArray[np.float64] | Y-axis of the figure. | required |
template | str | Template of the figure. Defaults to None. | None |
Returns:
Type | Description |
---|---|
go.Figure | go.Figure: XES figure. |
Source code in spectrafit/plugins/rixs_visualizer.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
|
initialize_figure_size(size)
¶
Initialize the size of the figure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size | SizeRatioAPI | Size of the figure. | required |
Source code in spectrafit/plugins/rixs_visualizer.py
90 91 92 93 94 95 96 97 98 99 100 101 |
|
RIXSVisualizer
¶
RIXS Visualizer. This class is used to visualize RIXS data.
Source code in spectrafit/plugins/rixs_visualizer.py
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 |
|
__call__()
¶
Run the RIXS Visualizer.
Source code in spectrafit/plugins/rixs_visualizer.py
653 654 655 656 |
|
get_args()
¶
Get the arguments from the command line.
Returns:
Type | Description |
---|---|
Dict[str, Any] | Dict[str, Any]: Return the input file arguments as a dictionary without additional information beyond the command line arguments. |
Source code in spectrafit/plugins/rixs_visualizer.py
600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 |
|
load_data(infile)
staticmethod
¶
Load the data from the input file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
infile | Path | The input file path. This can be a json, toml, npy, or npz file. | required |
Raises:
Type | Description |
---|---|
ValueError | If the file type is not supported. |
Returns:
Name | Type | Description |
---|---|---|
RIXSModelAPI | RIXSModelAPI | The data as a pydantic model object with the following attributes: incident_energy, emission_energy, and rixs_map. The incident_energy and emission_energy are 1D arrays, and the rixs_map is a 2D array. |
Source code in spectrafit/plugins/rixs_visualizer.py
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 |
|
command_line_runner()
¶
Run the RIXS Visualizer from the command line.
Source code in spectrafit/plugins/rixs_visualizer.py
659 660 661 |
|