Implement automatic splitting of polarization states
This commit is contained in:
@@ -7,3 +7,5 @@ lamdaCut = 2.5 # Aa
|
||||
lamdaMax = 15.0 # Aa
|
||||
|
||||
polarizationConfigs = ['unpolarized', 'unpolarized', 'po', 'mo', 'op', 'pp', 'mp', 'om', 'pm', 'mm']
|
||||
polarizationLabels = ['undetermined', 'unpolarized', 'spin-up', 'spin-down', 'op',
|
||||
'up-up', 'down-up', 'om', 'up-down', 'down-down']
|
||||
|
||||
@@ -5,6 +5,8 @@ import sys
|
||||
import numpy as np
|
||||
from orsopy import fileio
|
||||
|
||||
from .event_analysis import FilterByLog
|
||||
from .event_handling import ApplyMask
|
||||
from .file_reader import AmorEventData
|
||||
from .header import Header
|
||||
from .path_handling import PathResolver
|
||||
@@ -165,7 +167,31 @@ class ReflectivityReduction:
|
||||
self.header.measurement_data_files.append(fileio.File( file=os.path.basename(fileName),
|
||||
timestamp=self.dataset.fileDate))
|
||||
|
||||
|
||||
if 'polarization_config_label' in self.dataset.data.device_logs:
|
||||
pols = np.unique(self.dataset.data.device_logs['polarization_config_label'].value)
|
||||
pols = pols[pols>0]
|
||||
if len(pols)>1:
|
||||
logging.warning(f' found {len(pols)} polarization configurations, splitting dataset accordingly')
|
||||
from copy import deepcopy
|
||||
from . import const
|
||||
full_ds = deepcopy(self.dataset)
|
||||
for pi in pols:
|
||||
plabel = const.polarizationLabels[pi]
|
||||
pol_filter = FilterByLog(f'polarization_config_label=={pi}',
|
||||
remove_sitchpulse=True) | ApplyMask()
|
||||
logging.info(f' filter {plabel} using polarization_config_label=={pi}')
|
||||
pol_filter(self.dataset)
|
||||
self.dataset.update_header(self.header)
|
||||
pol_filter.update_header(self.header)
|
||||
if self.config.reduction.timeSlize:
|
||||
if i>0:
|
||||
logging.warning(
|
||||
" time slizing should only be used for one set of datafiles, check parameters")
|
||||
self.analyze_timeslices(i, polstr=f' : polarization = {plabel}')
|
||||
else:
|
||||
self.analyze_unsliced(i, polstr=f' : polarization = {plabel}')
|
||||
self.dataset = deepcopy(full_ds)
|
||||
return
|
||||
if self.config.reduction.timeSlize:
|
||||
if i>0:
|
||||
logging.warning(" time slizing should only be used for one set of datafiles, check parameters")
|
||||
@@ -173,7 +199,7 @@ class ReflectivityReduction:
|
||||
else:
|
||||
self.analyze_unsliced(i)
|
||||
|
||||
def analyze_unsliced(self, i):
|
||||
def analyze_unsliced(self, i, polstr=''):
|
||||
self.monitor = self.dataset.data.pulses.monitor.sum()
|
||||
logging.info(f' monitor = {self.monitor:8.2f} {MONITOR_UNITS[self.config.experiment.monitorType]}')
|
||||
|
||||
@@ -186,7 +212,7 @@ class ReflectivityReduction:
|
||||
|
||||
if 'Rqz.ort' in self.config.output.outputFormats:
|
||||
headerRqz = self.header.orso_header()
|
||||
headerRqz.data_set = f'Nr {i} : mu = {self.dataset.geometry.mu:6.3f} deg'
|
||||
headerRqz.data_set = f'Nr {i} : mu = {self.dataset.geometry.mu:6.3f} deg{polstr}'
|
||||
|
||||
# projection on qz-grid
|
||||
result = proj.project_on_qz()
|
||||
@@ -261,7 +287,7 @@ class ReflectivityReduction:
|
||||
proj.plot(colorbar=True, cmap=str(self.config.output.plot_colormap))
|
||||
plt.title(f'{self.config.reduction.fileIdentifier[i]}')
|
||||
|
||||
def analyze_timeslices(self, i):
|
||||
def analyze_timeslices(self, i, polstr=''):
|
||||
wallTime_e = np.float64(self.dataset.data.events.wallTime)/1e9
|
||||
pulseTimeS = np.float64(self.dataset.data.pulses.time)/1e9
|
||||
interval = self.config.reduction.timeSlize[0]
|
||||
@@ -311,7 +337,7 @@ class ReflectivityReduction:
|
||||
|
||||
headerRqz = self.header.orso_header(
|
||||
extra_columns=[fileio.Column('time', 's', 'time relative to start of measurement series')])
|
||||
headerRqz.data_set = f'{i}_{ti}: time = {time:8.1f} s to {time+interval:8.1f} s'
|
||||
headerRqz.data_set = f'{i}_{ti}: time = {time:8.1f} s to {time+interval:8.1f} s{polstr}'
|
||||
orso_data = fileio.OrsoDataset(headerRqz, result.data_for_time(time))
|
||||
self.datasetsRqz.append(orso_data)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user