batch_extraction_esynth1.py 5.63 KB
Newer Older
1
2
3
4
5
import numpy as np
import h5py
import glob
import json
import os
6
import h5py
myron's avatar
myron committed
7
import math
8

myron's avatar
myron committed
9
from XRStools import tools_sequencer_esynth
10
from XRStools import xrs_read,  xrs_rois
11
12
13

import os
def main():
myron's avatar
myron committed
14
    
15
    os.system("xz -dk mask.h5.xz --stdout > mask.h5")
16

myron's avatar
myron committed
17
    filter_path = "mask.h5:/FILTER_MASK/filter"
myron's avatar
myron committed
18
19
20

    roi_scan_num   = [245,246,247]
    reference_scan_list = [245, 246, 247]
myron's avatar
myron committed
21
    
myron's avatar
myron committed
22
    monitor_column = "izero/0.000001"
23
24
25
26
27
28
    
    first_scan_num = 651 
    Ydim        = 25
    Zdim        = 10
    Edim        = 7

29
    elastic_scan_for_peaks_shifts = 42
myron's avatar
myron committed
30

myron's avatar
myron committed
31
32
33
34
35
36
    energy_custom_grid = [  2*13.253006- 13.25551 , 13.253006,  13.25551,   13.258008, 13.260506 , 13.263004, 13.268   ]
    
    ### custom_components_file = "abc.h5"
    custom_components_file = None

    
myron's avatar
myron committed
37
    datadir =  "/data/id20/inhouse/data/run3_20/run3_es949"
38
39
40
41
42
43
44
45
46
47
48

    # If reference_clip is not None, then a smaller part of the reference scan is considered
    # This may be usefule to obtain smaller volumes containing the interesting part
    # The used reference scan  will the correspond to the positions from reference_clip[0] to reference_clip[1]-1 included
    ###########
    #    reference_clip = None
    reference_clip = [ 90, 180 ]

    ## in the reference scan for each position there is a spot with a maximum. We set zero the background which is further than
    ## such radius from the maximum
    isolate_spot_by = 6
myron's avatar
myron committed
49
50
51
52
53
54
55
56
57


    #### For the fit of the response function based on reference scans
    response_fit_options = dict( [
        ["niter_optical" , 100],
        ["beta_optical"  , 0.1],
        ["niter_global"  , 3  ]
    ])
                                 
myron's avatar
myron committed
58
    # selected_rois = list(range(0,24)) + list( range(36,60) ) 
myron's avatar
myron committed
59
60
    selected_rois = list( range(24,36) ) + list( range(60,72) ) 
    # selected_rois = list(range(0,72))
myron's avatar
myron committed
61
62
    volume_retrieval_beta  = 6.0e-20
    volume_retrieval_niter = 100 
63
64
    

65
66
67
    steps_to_do = {
        "do_step_make_roi":                      False,
        "do_step_sample_extraction":             False,
68
        "do_step_extract_reference_scan":             False,                
myron's avatar
myron committed
69
        "do_step_fit_reference_response":               False,
70
        "do_step_resynthetise_reference":               False,
71

myron's avatar
myron committed
72
        "do_step_scalars"               :    True,
73
    
myron's avatar
myron committed
74
        "do_step_interpolation_coefficients":    True,
myron's avatar
myron committed
75
76
        
        "do_step_finalise_for_fit":              True
77
    }
myron's avatar
myron committed
78
79
80
81

    
    os.system("mkdir results")
    
myron's avatar
myron committed
82
83
    scalar_products_target_file  = "results/scalar_products.h5"
    
myron's avatar
myron committed
84
85
86
87
88
    roi_target_path    = "results/myrois.h5:/ROIS"
        
    signals_target_file = "results/signals.h5"
    
    extracted_reference_target_file = "results/reference.h5"
89
    
myron's avatar
myron committed
90
91
    response_target_file = "results/response.h5"

myron's avatar
myron committed
92
    resynthetised_reference_and_roi_target_file = "results/resynthetised_roi_and_scan.h5"
93

myron's avatar
myron committed
94
    interpolation_infos_file =  "interpolation_infos.json"
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115

    ###########################################################################################
    ######  LOADING PEAKS SHIFTS
    ###### peaks_shifts = h5py.File("../peaks_positions_for_analysers.h5","r")["peaks_positions"][()]
    ###### assert( len(peaks_shifts) == 72)
    
    roiob = xrs_rois.roi_object()
    roiob.loadH5( roi_target_path  )
    elastic = xrs_read.Hydra( datadir )
    elastic.set_roiObj( roiob )
    elastic.get_compensation_factor( elastic_scan_for_peaks_shifts , method='sum')
    el_dict = elastic.cenom_dict
    Enominal = np.median(  list( el_dict.values() ) )
    peaks_shift = np.array([    el_dict["ROI%02d"%i] if ("ROI%02d"%i) in  el_dict else nan    for i in range 72  ] ) 
    Enominal = np.median(peaks_shifts)
    peaks_shifts-= Enominal
    
    ##############################################################
    ##########################################################################


myron's avatar
myron committed
116
    
myron's avatar
myron committed
117
    tools_sequencer_esynth.tools_sequencer(  peaks_shifts          = peaks_shifts          ,
118
119
120
121
122
123
124
125
126
127
128
129
130
                      datadir               = datadir               ,
                      filter_path           = filter_path           ,
                      roi_scan_num          = roi_scan_num          ,
                      roi_target_path       = roi_target_path       ,
                      
                      steps_to_do = steps_to_do,
                      
                      first_scan_num =  first_scan_num,
                      Ydim        =  Ydim       ,
                      Zdim        =  Zdim       ,
                      Edim        =  Edim       ,

                      monitor_column = monitor_column,
131
132
133
134
135
                      signals_target_file = signals_target_file,

                      reference_scan_list = reference_scan_list,
                      reference_clip = reference_clip,
                      extracted_reference_target_file = extracted_reference_target_file ,
myron's avatar
myron committed
136
137
                      isolate_spot_by =  isolate_spot_by,
                      response_target_file = response_target_file,
myron's avatar
myron committed
138
139
                      response_fit_options = response_fit_options,
                      
140
141
142
                      resynthetised_reference_and_roi_target_file = resynthetised_reference_and_roi_target_file,

                      selected_rois = selected_rois,
myron's avatar
myron committed
143
                      
144
                      scalar_products_target_file      = scalar_products_target_file ,
myron's avatar
myron committed
145
                      
myron's avatar
myron committed
146
                      volume_retrieval_beta  = volume_retrieval_beta ,
myron's avatar
myron committed
147
                      volume_retrieval_niter = volume_retrieval_niter ,
myron's avatar
myron committed
148

myron's avatar
myron committed
149
150
151
152
                      energy_custom_grid =  energy_custom_grid,
                      custom_components_file = custom_components_file,
                      interpolation_infos_file =  interpolation_infos_file
            
myron's avatar
myron committed
153
                      
154
155
156
    )
    
    
157
main()
158
159