Skip to content
Snippets Groups Projects
Commit 647bdea3 authored by Arnaud HEMMERLE's avatar Arnaud HEMMERLE
Browse files

Restore save fluospectrum.mat in XRF.py and remove the correction with ICR/OCR...

Restore save fluospectrum.mat in XRF.py and remove the correction with ICR/OCR in the variable spectrums
parent 0f01eddc
No related branches found
No related tags found
No related merge requests found
# Release notes # Release notes
## v2.12.1
- Restore save fluospectrum.mat in XRF.py
- Remove the tiny correction with ICR/OCR in XRF.py, to have exactly the same numbers in the variable spectrums, and in the saved file fluospectrum.mat
## v2.12 ## v2.12
- New rules for numbering versions: vX.Y.Z with X major, Y minor, Z patch. Each new version increments Z (not used if Z=0). If the file Example.ipynb cannot run with the new libraries, increment Y and restart at Z=0. - New rules for numbering versions: vX.Y.Z with X major, Y minor, Z patch. Each new version increments Z (not used if Z=0). If the file Example.ipynb cannot run with the new libraries, increment Y and restart at Z=0.
......
%% Cell type:markdown id: tags:notPrint %% Cell type:markdown id: tags:notPrint
# JupyLabBook @ SIRIUS # JupyLabBook @ SIRIUS
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
%%latex %%latex
\tableofcontents \tableofcontents
\newpage \newpage
``` ```
%% Output %% Output
\tableofcontents \tableofcontents
\newpage \newpage
%% Cell type:code id: tags:notPrint %% Cell type:code id: tags:notPrint
``` python ``` python
__version__ = '2.12' __version__ = '2.12.1'
print("JupyLabBook version: %s"%__version__) print("JupyLabBook version: %s"%__version__)
print("More info on: %s"%"https://gitlab.com/soleil-data-treatment/soleil-beamlines/soleil-beamline-sirius/JupyLabBook") print("More info on: %s"%"https://gitlab.com/soleil-data-treatment/soleil-beamlines/soleil-beamline-sirius/JupyLabBook")
#import useful libraries #import useful libraries
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from IPython.display import set_matplotlib_formats, Javascript, display from IPython.display import set_matplotlib_formats, Javascript, display
# import custom libraries # import custom libraries
import lib.frontend as FE import lib.frontend as FE
from lib.extraction.common import PyNexus as PN from lib.extraction.common import PyNexus as PN
from lib.extraction import GIXD from lib.extraction import GIXD
from lib.extraction import GIXS from lib.extraction import GIXS
from lib.extraction import DetectorSum from lib.extraction import DetectorSum
from lib.extraction import Isotherm from lib.extraction import Isotherm
from lib.extraction import Sensors1D from lib.extraction import Sensors1D
from lib.extraction import XRF from lib.extraction import XRF
from lib.extraction import XRR_liquid from lib.extraction import XRR_liquid
from lib.extraction import XRR_solid from lib.extraction import XRR_solid
# necessary for plotting in the notebook # necessary for plotting in the notebook
%matplotlib inline %matplotlib inline
# to avoid having a large notebook # to avoid having a large notebook
try: try:
import matplotlib_inline.backend_inline import matplotlib_inline.backend_inline
matplotlib_inline.backend_inline.set_matplotlib_formats('png', 'pdf') matplotlib_inline.backend_inline.set_matplotlib_formats('png', 'pdf')
except: except:
#for IPython<7.23 #for IPython<7.23
set_matplotlib_formats('png', 'pdf') set_matplotlib_formats('png', 'pdf')
# to have all the cells expanded (not collapsed) # to have all the cells expanded (not collapsed)
display(Javascript('IPython.OutputArea.prototype._should_scroll = function(lines) {return false;}')) display(Javascript('IPython.OutputArea.prototype._should_scroll = function(lines) {return false;}'))
# define the class experiment # define the class experiment
class Experiment: class Experiment:
""" """
Class Experiment is used to pass arguments concerning the current experiment only. Class Experiment is used to pass arguments concerning the current experiment only.
""" """
def __init__(self): def __init__(self):
pass pass
# test if the expt already exists (avoid loosing info when reloading this cell) # test if the expt already exists (avoid loosing info when reloading this cell)
if not 'expt' in locals(): if not 'expt' in locals():
expt = Experiment() expt = Experiment()
# necessary for saving in pdf # necessary for saving in pdf
expt.notebook_name = 'JupyLabBook.ipynb' expt.notebook_name = 'JupyLabBook.ipynb'
# directory where the data will be saved # directory where the data will be saved
expt.working_dir = 'working/' expt.working_dir = 'working/'
# directory where the nexus files are # directory where the nexus files are
#expt.recording_dir = "Z:\\com-sirius\\users\\2022\\user\\" #expt.recording_dir = "Z:\\com-sirius\\users\\2022\\user\\"
expt.recording_dir = 'recording/' expt.recording_dir = 'recording/'
# directory where the logs are # directory where the logs are
#expt.logs_dir = "Z:\\com-sirius\\users\\2022\\user\\logs\\" #expt.logs_dir = "Z:\\com-sirius\\users\\2022\\user\\logs\\"
expt.logs_dir = 'logs/' expt.logs_dir = 'logs/'
FE.Action.Check_and_init(expt) FE.Action.Check_and_init(expt)
``` ```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:notPrint
``` python
FE.Action.Choose(expt)
```
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
A Jupyter Notebook used as an interactive lab book on the beamline SIRIUS (SOLEIL Synchrotron). A Jupyter Notebook used as an interactive lab book on the beamline SIRIUS (SOLEIL Synchrotron).
### Latest version ### Latest version
JupyLabBook.ipynb : 2.12 JupyLabBook.ipynb : 2.12.1
# User manual # User manual
See the file JupyLabBook_User_Manual.pdf in the repository. See the file JupyLabBook_User_Manual.pdf in the repository.
......
No preview for this file type
...@@ -4,10 +4,12 @@ Module for extracting, plotting, and saving an XRF scan. ...@@ -4,10 +4,12 @@ Module for extracting, plotting, and saving an XRF scan.
""" """
import os import os
import sys import sys
import io
import datetime import datetime
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from matplotlib import colors from matplotlib import colors
from contextlib import redirect_stdout
from lib.extraction.common import PyNexus as PN from lib.extraction.common import PyNexus as PN
...@@ -214,9 +216,9 @@ def Extract(nxs_filename, recording_dir, ...@@ -214,9 +216,9 @@ def Extract(nxs_filename, recording_dir,
datetime.datetime.fromtimestamp(epoch_time[0]), datetime.datetime.fromtimestamp(epoch_time[0]),
datetime.datetime.fromtimestamp(epoch_time[-1])) datetime.datetime.fromtimestamp(epoch_time[-1]))
def extract_and_correct(ind_spectrum): def extract_and_correct(ind_spectrum, is_correction):
""" """
Extract the requested fluospectrum from the nexus file and correct it with ICR/OCR. Extract the requested fluospectrum from the nexus file and correct it with ICR/OCR, if is_correction is True.
""" """
is_icr_found = False is_icr_found = False
is_ocr_found = False is_ocr_found = False
...@@ -240,8 +242,12 @@ def Extract(nxs_filename, recording_dir, ...@@ -240,8 +242,12 @@ def Extract(nxs_filename, recording_dir,
print(_RED+"OCR not found in data. Taking OCR = spectrum_intensity/counting_time."+_RESET) print(_RED+"OCR not found in data. Taking OCR = spectrum_intensity/counting_time."+_RESET)
OCR = np.array([np.sum(fluospectrum[n])/integration_time[n] for n in range(len(fluospectrum))]) OCR = np.array([np.sum(fluospectrum[n])/integration_time[n] for n in range(len(fluospectrum))])
if is_correction:
ratio = np.array([ICR[n]/OCR[n] if (~np.isclose(OCR[n],0.) & ~np.isnan(OCR[n]) & ~np.isnan(ICR[n])) ratio = np.array([ICR[n]/OCR[n] if (~np.isclose(OCR[n],0.) & ~np.isnan(OCR[n]) & ~np.isnan(ICR[n]))
else 0. for n in range(len(ICR))]) else 0. for n in range(len(ICR))])
else:
ratio = np.array([1. if (~np.isclose(OCR[n],0.) & ~np.isnan(OCR[n]) & ~np.isnan(ICR[n]))
else 0. for n in range(len(ICR))])
spectrums_corr = np.array([fluospectrum[n]*ratio[n] for n in range(len(ratio))]) spectrums_corr = np.array([fluospectrum[n]*ratio[n] for n in range(len(ratio))])
return spectrums_corr return spectrums_corr
...@@ -255,7 +261,7 @@ def Extract(nxs_filename, recording_dir, ...@@ -255,7 +261,7 @@ def Extract(nxs_filename, recording_dir,
allspectrums_corr = np.zeros((nbpts, 2048)) allspectrums_corr = np.zeros((nbpts, 2048))
for i in list_elems: for i in list_elems:
allspectrums_corr += extract_and_correct(str(i)) allspectrums_corr += extract_and_correct(ind_spectrum = str(i), is_correction = False)
ind_non_zero_spectrums = np.where(np.sum(allspectrums_corr, axis = 1)>10.)[0] ind_non_zero_spectrums = np.where(np.sum(allspectrums_corr, axis = 1)>10.)[0]
#list_ranges = np.split(ind_non_zero_spectrums, np.where(np.diff(ind_non_zero_spectrums) != 1)[0]+1) #list_ranges = np.split(ind_non_zero_spectrums, np.where(np.diff(ind_non_zero_spectrums) != 1)[0]+1)
...@@ -447,7 +453,7 @@ def Plot(channels, eVs, spectrums, first_non_zero_spectrum, last_non_zero_spectr ...@@ -447,7 +453,7 @@ def Plot(channels, eVs, spectrums, first_non_zero_spectrum, last_non_zero_spectr
def Save(nxs_filename, stamps0D, data0D, fig_spectrogram, fig_sum, fig_first_last, def Save(nxs_filename, stamps0D, data0D, fig_spectrogram, fig_sum, fig_first_last,
recording_dir, fast, working_dir, verbose): recording_dir, fast, working_dir, verbose):
""" """
Use the PyNexus library to convert the Nexus file into a .dat file. Use the PyNexus library to convert the Nexus file into a .dat and a .mat files.
Parameters Parameters
---------- ----------
...@@ -481,6 +487,22 @@ def Save(nxs_filename, stamps0D, data0D, fig_spectrogram, fig_sum, fig_first_la ...@@ -481,6 +487,22 @@ def Save(nxs_filename, stamps0D, data0D, fig_spectrogram, fig_sum, fig_first_la
np.savetxt(savename+'.dat', np.transpose(data0D), header = header0D, np.savetxt(savename+'.dat', np.transpose(data0D), header = header0D,
comments = '', fmt='%s', delimiter = '\t') comments = '', fmt='%s', delimiter = '\t')
## save non-corrected spectrums
# we assume extraction was already checked with Extract
nxs_path = recording_dir+nxs_filename
nexus = PN.PyNexusFile(nxs_path, fast=fast)
# get stamps and Data
stamps, data = nexus.extractData()
# extract without printing the sensors in the notebook
f = io.StringIO()
with redirect_stdout(f):
old_nexus_filename = nexus.filename
nexus.filename = working_dir + nxs_filename
nexus.saveOneDExtractedData((stamps, data))
nexus.filename = old_nexus_filename
out = f.getvalue()
nexus.close()
# figures in pdf # figures in pdf
if fig_spectrogram is not None: if fig_spectrogram is not None:
plt.figure(fig_spectrogram) plt.figure(fig_spectrogram)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment