Skip to content
Snippets Groups Projects
Commit 4ec603ad authored by Markus Kuehbach's avatar Markus Kuehbach
Browse files

Merge branch '41-sample-data-for-xps' into 'develop'

Resolve "Sample data for XPS"

Closes #41

See merge request !31
parents 3e8fe29c 91ffc0c8
Branches
Tags
1 merge request!31Resolve "Sample data for XPS"
Pipeline #113960 passed
%% Cell type:markdown id: tags:
# Exemplar visualization of XPS spectra
%% Cell type:code id: tags:
``` python
import numpy as np
import matplotlib.pyplot as plt
import os, sys
import json
import shutil
```
%% Cell type:markdown id: tags:
### Get a dataset
%% Cell type:code id: tags:
``` python
shutil.unpack_archive('XPSDataExample.zip')
! ls
```
%% Cell type:markdown id: tags:
### Link to Mark Greiner's parser for reading metadata and numerical data from SPECS Prodigy *.xy files.
%% Cell type:code id: tags:
``` python
import os, sys
sys.path.append('nomad_xps_parser_specsxy')
```
%% Cell type:code id: tags:
``` python
from prodigy_parser_xy import ProdigyParserXY
```
%% Cell type:markdown id: tags:
### Use the parser to extract (meta)data.
%% Cell type:code id: tags:
``` python
MYDATASET = 'XPS data example'
```
%% Cell type:code id: tags:
``` python
parser = ProdigyParserXY( author='Mark Greiner' )
#parser.convertToJson(MYDATASET+'.xy')
parser.parseFile(MYDATASET+'.xy')
#the next two methods are some cleaning steps that we typically do in XPS
parser.removeAlign()
parser.extractAllTags()
#the dataset is a list of dictionaries, where each spectrum is one item in the list
data_set = parser.dataset
```
%% Cell type:markdown id: tags:
### Display selected spectra.
%% Cell type:markdown id: tags:
Starting with Mark Greiner's example code that comes with the parser how to visualize data.
%% Cell type:code id: tags:
``` python
#fig, xy = plt.figure(figsize=[20, 10])
spectrum_types = list(set([d['metadata']['spectrum_region'] for d in data_set]))
print('Number of spectra_types:')
print(np.shape(spectrum_types))
#dataset contains 5 spectra, the zeroth one is an overview, the rest specific ones
for selection in spectrum_types:
#selection = spectrum_types[4]
channel_nr = 1
for data in data_set:
if data['metadata']['spectrum_region'] == selection:
axis_id = data['metadata']['axis_id']
plt.plot(data['data'][axis_id], data['data'][channel_nr])
plt.xlabel(data['metadata']['data_labels'][axis_id]['label']
+ ' [' + data['metadata']['data_labels'][axis_id]['unit']
+ ']', fontsize=14)
plt.ylabel(data['metadata']['data_labels'][channel_nr]['label'] +
' [' + data['metadata']['data_labels'][channel_nr]['unit']
+ ']', fontsize=14)
#plt.yscale('log')
plt.legend(range(5))
plt.show()
```
%% Cell type:markdown id: tags:
### Next steps
%% Cell type:markdown id: tags:
* Reorganize/rewrite plotting functions
* Interface with nomad xpsparser
* Parse from XPS NeXus application definition
* Have a parser from xy/sle/vms to this NeXus application definition
* Thus, split the expertise which is needed for parser development<br>
between domain-format specialists and nomad development specialists
* Let nomad maintain a NeXus for XPS app def parser
* Use widgets (e.g. bokeh or ipywidgets) to make figure interactive
* Use widgets to make spectra selectable
* Make spectrum ranges clickable/selectable to define
* Interface with auto-indexing tool
%% Cell type:code id: tags:
``` python
```
File added
# -*- coding: utf-8 -*-
"""
Created on Mon Feb 1 08:25:00 2021
@author: Mark
"""
class MetaData:
def __init__(self):
self.timestamp = ''
self.dwell_time = ''
self.n_scans = ''
self.excitation_energy = ''
self.method_type = ''
self.data_labels = []
self.device_settings = []
self.spectrum_region = ''
self.source_label = ''
self.primary_channel_id = 1
self.axis_id = 0
self.group_name = ''
class DeviceSettings():
def __init__(self):
self.device_name = ''
self.channel_id = ''
class AnalyzerSettings(DeviceSettings):
def __init__(self):
super().__init__()
self.pass_energy = ''
self.lens_modes = ''
self.detector_voltage = ''
class DataChannel:
def __init__(self):
pass
class MeasurementData:
def __init__(self):
self.metadata = MetaData()
self.data = []
def addDataChannel(self, data_channel):
self.data += [data_channel]
def appendDataChannel(self, data_channel):
channel_id = len(self.data)
self.metadata.data_labels += [{'channel_id':channel_id,
'label':data_channel['label'],
'unit':data_channel['unit']}
]
if 'device_settings' in data_channel.keys():
device_settings = data_channel['device_settings']
if not isinstance(device_settings, DeviceSettings):
print('The device settings should be an instance of DeviceSettings')
else:
device_settings = DeviceSettings()
device_settings.device_name = 'unknown device'
device_settings.channel_id = channel_id
self.metadata.device_settings += [device_settings]
self.data += [data_channel['data']]
\ No newline at end of file
This diff is collapsed.
# -*- coding: utf-8 -*-
"""
Created on Wed Jan 13 14:15:11 2021
@author: Mark
"""
class Spectrum():
def __init__(self):
self.settings = Settings()
self.meta = Meta()
self.measurement_data = [MeasurementData()]
class MeasurementData():
def __init__(self):
self.name = ''
self.units = ''
self.shape = []
self.values = []
class RegularMeasurementData(MeasurementData):
def __init__(self):
super().__init__()
self.start = ''
self.stop = ''
self.step = []
def generate_values(self):
self.values = [self.start, self.stop, self.step]
class IrregularMeasurementData(MeasurementData):
def __init__(self):
super().__init__()
class MeasurementDataArray():
def __init__(self):
self.name = []
self.units = []
self.shape = []
self.values = []
class Settings():
def __init__(self):
self.dwell_time = ''
self.emission_current = ''
self.excitation_energy = ''
self.entrance_slit = ''
self.exit_slit = ''
self.pass_energy = ''
self.source_voltage = ''
self.voltage_range = ''
self.workfunction = ''
self.iris_diameter = ''
self.lens_mode = ''
self.calibration_file = ''
self.scans = ''
self.transmission_function
class Meta():
def __init__(self):
self.method = ''
self.users = ''
self.sample = ''
self.group_name = ''
self.group_id = ''
self.spectrum_id = ''
self.time_stamp = ''
self.devices = ''
self.spectrum_type = ''
reg = RegularMeasurementData()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment