Skip to content
Snippets Groups Projects

[AGIPD] [CORRECT] Fix / Correcting AGIPD run with no images.

Merged Karim Ahmed requested to merge fix/use_correct_module_idx into master
5 unresolved threads
Files
2
%% Cell type:markdown id: tags:
# Summary of the AGIPD offline correction #
%% Cell type:code id: tags:
``` python
run = 11 # runs to process, required
out_folder = "/gpfs/exfel/data/scratch/ahmedk/test/AGIPD_Corr" # path to output to, required
karabo_id = "SPB_DET_AGIPD1M-1" # karabo karabo_id
modules = [-1]
karabo_da = ['-1'] # a list of data aggregators names, Default [-1] for selecting all data aggregators
```
%% Cell type:code id: tags:
``` python
import re
import warnings
from pathlib import Path
import dateutil.parser
import numpy as np
import yaml
warnings.filterwarnings('ignore')
import matplotlib.pyplot as plt
%matplotlib inline
import tabulate
from cal_tools.tools import CalibrationMetadata
from IPython.display import Latex, Markdown, display
```
%% Cell type:code id: tags:
``` python
out_folder = Path(out_folder)
metadata = CalibrationMetadata(out_folder)
const_dict = metadata.setdefault("retrieved-constants", {})
time_dict = const_dict.setdefault("time-summary", {})
# Extracting Instrument string
instrument = karabo_id.split("_")[0]
# Evaluate detector instance for mapping
if instrument == "SPB":
dinstance = "AGIPD1M1"
nmods = 16
elif instrument == "MID":
dinstance = "AGIPD1M2"
nmods = 16
elif instrument == "HED":
dinstance = "AGIPD500K"
nmods = 8
if karabo_da[0] == '-1':
if modules[0] == -1:
modules = list(range(nmods))
karabo_da = ["AGIPD{:02d}".format(i) for i in modules]
else:
modules = [int(x[-2:]) for x in karabo_da]
# This is needed only if AGIPD Correction notebook had no precorrection notebooks for retrieving constants
# gather all generated sequence yml files for time summary of retrieved constant under retrieved-constants in metadata.yml
for fn in sorted(out_folder.glob("retrieved_constants_*.yml")):
with fn.open("r") as fd:
fdict = yaml.safe_load(fd)
# append different sequences' time summary to the main yaml
time_dict.update(fdict["time-summary"])
fn.unlink()
metadata.save()
```
%% Cell type:code id: tags:
``` python
def print_const_table(const):
print(f"{const} constants were injected on:")
table_data = {}
for seq, mod_data in time_dict.items():
for mod, const_data in mod_data.items():
timestamp = const_data[const]
table_data.setdefault(timestamp, []).append(f"{seq}:{mod}")
table = []
if len(table_data) == 1:
if not len(table_data):
table.append(["No constants retrieved"])
elif len(table_data) == 1:
    • This part prevented the report to be created with a latex bug.

      Chapter 3.
      (/software/opt/texlive/2019/texmf-dist/tex/latex/psnfss/t1pcr.fd)
      
      ! Package array Error: Empty preamble: `l' used.
      
      See the array package documentation for explanation.
      Type  H <return>  for immediate help.
       ...                                              
                                                        
      l.196 \end{tabular}\end{split}
                                    
      ? 
      ! Emergency stop.
       ...                                              
                                                        
      l.196 \end{tabular}\end{split}
                                    
      !  ==> Fatal error occurred, no output PDF file produced!
      Transcript written on AGIPDOfflineCorrection.log.
      Latexmk: Index file 'AGIPDOfflineCorrection.idx' was written
      Latexmk: Use the -f option to force complete processing,
       unless error was exceeding maximum runs, or warnings treated as errors.
      === TeX engine is 'pdfTeX'
      
Please register or sign in to reply
table.append([[*table_data][0], "All modules"])
else:
for timestamp, seqmod in table_data.items():
table.append([timestamp, seqmod[0]])
for further_module in seqmod[1:]:
table.append(["", further_module])
display(Latex(tabulate.tabulate(table,
tablefmt="latex",
headers=["Timestamps", "Modules and sequences"])))
for const in ['Offset', 'SlopesPC', 'SlopesFF']:
print_const_table(const)
```
%% Cell type:code id: tags:
``` python
```
Loading