batch_extraction_interp.py 5.34 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_interp
10
11
12

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

myron's avatar
myron committed
16
    filter_path = "mask.h5:/FILTER_MASK/filter"
myron's avatar
myron committed
17
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
31

    datadir =  "/data/id20/inhouse/data/run3_20/run3_es949"
32
33
34
35
36
37
38
39
40
41
42

    # 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
43
44
45
46
47
48
49
50
51


    #### 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  ]
    ])
                                 
52
53
54
55

    selected_rois = list(range(0,24)) + list( range(36,60) ) 


myron's avatar
myron committed
56
57
58
59
60
    scal_prod_use_optional_solution = True 


    volume_retrieval_beta  = 6.0e-20
    volume_retrieval_niter = 100 
61
62
63
    

    
64
65
    steps_to_do = {
        "do_step_make_roi":                      False,
myron's avatar
myron committed
66
        "do_step_sample_extraction":             True,
67
        "do_step_interpolation":                 False,
myron's avatar
myron committed
68
        "do_step_extract_reference_scan":             False,
myron's avatar
myron committed
69
                
myron's avatar
myron committed
70
        "do_step_fit_reference_response":               False,
71
        "do_step_resynthetise_reference":               False,
myron's avatar
myron committed
72
73
        "do_step_scalars"               :    True,
        "do_step_volume_retrieval"      :    False,
74
    }
myron's avatar
myron committed
75
76
77

    
    os.system("mkdir results")
myron's avatar
myron committed
78
79
80
81


    scalar_products_and_volume_target_file  = "results/scalar_products_and_volume.h5"

myron's avatar
myron committed
82
83
84
85
86
87
88
    roi_target_path    = "results/myrois.h5:/ROIS"
        
    signals_target_file = "results/signals.h5"
    
    interpolated_signals_target_file = "results/interpolated_signals.h5"

    extracted_reference_target_file = "results/reference.h5"
89
    
myron's avatar
myron committed
90
91
    response_target_file = "results/response.h5"

92
    resynthetised_reference_and_roi_target_file = "results/resynthetised_roi_and_scan.h5"
93

94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
    ###########################################################################################
    ######  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
113
    tools_sequencer_interp.tools_sequencer(  peaks_shifts          = peaks_shifts          ,
114
115
116
117
118
119
120
121
122
123
124
125
126
                      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,
127
128
129
130
131
132
                      signals_target_file = signals_target_file,
                      interpolated_signals_target_file = interpolated_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
133
134
                      isolate_spot_by =  isolate_spot_by,
                      response_target_file = response_target_file,
myron's avatar
myron committed
135
136
                      response_fit_options = response_fit_options,
                      
137
138
139
                      resynthetised_reference_and_roi_target_file = resynthetised_reference_and_roi_target_file,

                      selected_rois = selected_rois,
myron's avatar
myron committed
140
                      
141
                      scal_prod_use_optional_solution = scal_prod_use_optional_solution ,
myron's avatar
myron committed
142
143
144
145
146
                      scalar_products_and_volume_target_file      = scalar_products_and_volume_target_file ,

                      volume_retrieval_beta  = volume_retrieval_beta ,
                      volume_retrieval_niter = volume_retrieval_niter 
                      
147
148
149
150
    )
    
    

myron's avatar
myron committed
151
152
            
            
153
main()
154
155