Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
ToolBox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SCS
ToolBox
Merge requests
!146
Improved BOZ analysis
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Improved BOZ analysis
boz-improved
into
master
Overview
0
Commits
11
Pipelines
0
Changes
8
Merged
Loïc Le Guyader
requested to merge
boz-improved
into
master
3 years ago
Overview
0
Commits
11
Pipelines
0
Changes
8
Expand
split BOZ part II into:
II.1 processing and saving DSSC data into xarray small data
II.2 binning:
loading small data
binning multiple runs
plotting results
saving binned dataset
add to BOZ part I.b extension where validity of correction of previous day can be checked on new data (3 broken membranes)
DSSC has 'pulseId' overwritten by BAM 'sa3_pId'
for dark, pedestals is computed as mean, we could compute bounds to find bad pixels as std or percentiles
not sure if that is important
improve finding rois with automatic threshold. In many cases the threshold has to be adjusted
not easy to implement
percentage of shot saturated:
give information on the percentage of saturated shots
save the percentage of saturated shots in small data attributes
plot an histogram of Io intensity over run
save corresponding data of all plots
BOZ part I.a
BOZ part I.b
BOZ part II.1
BOZ part II.2
In addition, adds a plot to check the veto pattern.
Closes
#27 (closed)
Edited
3 years ago
by
Loïc Le Guyader
0
0
Merge request reports
Compare
master
version 8
d5d67bff
3 years ago
version 7
c63a6a96
3 years ago
version 6
15fe7267
3 years ago
version 5
7e6b5bb1
3 years ago
version 4
972dff24
3 years ago
version 3
e4c5c037
3 years ago
version 2
d5c57327
3 years ago
version 1
76392f5e
3 years ago
master (base)
and
latest version
latest version
a1589bac
11 commits,
3 years ago
version 8
d5d67bff
10 commits,
3 years ago
version 7
c63a6a96
9 commits,
3 years ago
version 6
15fe7267
8 commits,
3 years ago
version 5
7e6b5bb1
7 commits,
3 years ago
version 4
972dff24
6 commits,
3 years ago
version 3
e4c5c037
4 commits,
3 years ago
version 2
d5c57327
3 commits,
3 years ago
version 1
76392f5e
1 commit,
3 years ago
8 files
+
5046
−
4865
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
8
Search (e.g. *.vue) (Ctrl+P)
doc/BOZ analysis part I parameters determination.ipynb deleted
100644 → 0
+
0
−
538
Options
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"%matplotlib notebook\n",
"import matplotlib.pyplot as plt\n",
"plt.rcParams['figure.constrained_layout.use'] = True\n",
"\n",
"import dask\n",
"print(f'dask: {dask.__version__}')\n",
"\n",
"from psutil import virtual_memory\n",
"\n",
"mem = virtual_memory()\n",
"print(f'Physical memory: {mem.total/1024/1024/1024:.0f} Gb') # total physical memory available\n",
"\n",
"import logging\n",
"logging.basicConfig(filename='example.log', level=logging.DEBUG)\n",
"\n",
"import toolbox_scs as tb\n",
"print(tb.__file__)\n",
"import toolbox_scs.routines.boz as boz"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Create parameters object"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"parameters"
]
},
"outputs": [],
"source": [
"proposal = 2937\n",
"darkrun = 478\n",
"run = 477\n",
"module = 15\n",
"gain = 0.5\n",
"sat_level = 500\n",
"rois_th = 1"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"params = boz.parameters(proposal=proposal, darkrun=darkrun, run=run, module=module, gain=gain)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from extra_data.read_machinery import find_proposal\n",
"\n",
"root = find_proposal(f'p{proposal:06d}')\n",
"path = root + '/usr/processed_runs/' + f'r{params.run}/'\n",
"print(path)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(params)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### load data persistently"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"params.dask_load()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Dark run inspection"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The aim is to check dark level and extract bad pixel map."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"dark = boz.average_module(params.arr_dark).compute()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pedestal = np.mean(dark)\n",
"pedestal"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"mean_th = (pedestal-25, pedestal+30)\n",
"f = boz.inspect_dark(params.arr_dark, mean_th=mean_th)\n",
"f.savefig(path+f'p{params.proposal}-r{params.run}-d{params.darkrun}-inspect-dark.png', dpi=300)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"params.mean_th = mean_th\n",
"params.set_mask(boz.bad_pixel_map(params))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(params)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Histogram"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"h, f = boz.inspect_histogram(params.arr,\n",
" params.arr_dark,\n",
" mask=params.get_mask() #, extra_lines=True\n",
" )\n",
"f.suptitle(f'p:{params.proposal} r:{params.run} d:{params.darkrun}')\n",
"f.savefig(path+f'p{params.proposal}-r{params.run}-d{params.darkrun}-histogram.png', dpi=300)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"adding guide to the eye"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# ROIs extraction"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"params.rois_th = rois_th\n",
"params.rois = boz.find_rois_from_params(params)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(params)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"data = boz.average_module(params.arr, dark=dark).compute()\n",
"dataM = data.mean(axis=0) # mean over pulseId"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"f = boz.inspect_rois(dataM, params.rois, params.rois_th)\n",
"f.savefig(path+f'p{params.proposal}-r{params.run}-d{params.darkrun}-rois.png', dpi=300)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Flat field extraction"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The first step is to compute a good average image, this mean remove saturated shots and ignoring bad pixels"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"params.sat_level = sat_level\n",
"res = boz.average_module(params.arr, dark=dark,\n",
" ret='mean', mask=params.get_mask(), sat_roi=params.rois['sat'],\n",
" sat_level=params.sat_level)\n",
"avg = res.compute().mean(axis=0)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The second step is from that good average image to fit the plane field on n/0 and p/0 rois. We have to make sure that the rois have same width."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"f = boz.inspect_plane_fitting(avg, params.rois)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"f.savefig(path+f'p{params.proposal}-r{params.run}-d{params.darkrun}-inspect-noflatfield.png', dpi=300)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"fit the plane field correction"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plane = boz.plane_fitting(params)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plane"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"compute the correction and inspect the result of its application"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"params.set_flat_field(plane.x)\n",
"ff = boz.compute_flat_field_correction(params.rois, params.get_flat_field())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"f = boz.inspect_plane_fitting(avg/ff, params.rois)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"f.savefig(path+f'p{params.proposal}-r{params.run}-d{params.darkrun}-inspect-withflatfield.png', dpi=300)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Non-linearities correction extraction"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To speed up online analysis, we save the corrections with a dummy non-linearity correction. The saved file can be used for online analysis as soon as it appears."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"params.set_Fnl(np.arange(2**9))\n",
"params.save(path=path)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"N = 80\n",
"domain = boz.nl_domain(N, 40, 511)\n",
"params.alpha = 0.5\n",
"params.max_iter = 25"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## minimizing"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"res, fit_res = boz.nl_fit(params, domain)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"params.set_Fnl(boz.nl_lut(domain, res.x))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(params)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"f = boz.inspect_correction(params, gain=params.gain)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"f.savefig(path+f'p{params.proposal}-r{params.run}-d{params.darkrun}-inspect-correction.png', dpi=300)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### plotting the fitted correction"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"f = boz.inspect_Fnl(params.get_Fnl())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"f.savefig(path+f'p{params.proposal}-r{params.run}-d{params.darkrun}-inspect-Fnl.png', dpi=300)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### plotting the fit progresion"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"f = boz.inspect_nl_fit(fit_res)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"f.savefig(path+f'p{params.proposal}-r{params.run}-d{params.darkrun}-inspect-nl-fit.png', dpi=300)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Save the analysis parameters"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"params.save(path=path)"
]
}
],
"metadata": {
"celltoolbar": "Tags",
"kernelspec": {
"display_name": "xfel",
"language": "python",
"name": "xfel"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
},
"nbsphinx": {
"execute": "never"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading