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

from XRStools import tools_sequencer_interp
10
11
from XRStools import tools_sequencer_esynth
from XRStools import xrs_read,  xrs_rois
myron's avatar
ants  
myron committed
12
13
14
15
16
17
18
19
20

import os
def main():
    
    ## os.system("xz -dk ../mask.h5.xz --stdout > mask.h5 ")

    filter_path = None
    # filter_path = "mask.h5:/FILTER_MASK/filter"

21
22
    roi_scan_num   = list(range(592,600))
    reference_scan_list = list(range(592,600))
myron's avatar
ants  
myron committed
23
24
25
26

    
    monitor_column = "izero/0.000001"
    
27
28
29
30
31
    first_scan_num = 464
    
    Ydim        = None   # not used, it is the scan lenght , it is given by the data, contained in the scan
    Zdim        = 2
    Edim        = 62
myron's avatar
ants  
myron committed
32

33
    rois_are_ready = True
myron's avatar
myron committed
34
    elastic_scan_for_peaks_shifts = 38
myron's avatar
ants  
myron committed
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

    datadir =   "/data/id20/inhouse/data/run5_17/run7_ihr/"

    # 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 = 7

    #### 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  ]
    ])
                                 

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


    scal_prod_use_optional_solution = True 


    volume_retrieval_beta  = 6.0e-20
    volume_retrieval_niter = 100 
    
    
    steps_to_do = {
68
        "do_step_make_roi":                      False,
myron's avatar
myron committed
69
        "do_step_sample_extraction":             False,
myron's avatar
ants  
myron committed
70
71
72
        "do_step_interpolation":                 False,
        "do_step_extract_reference_scan":             False,
                
myron's avatar
myron committed
73
        "do_step_fit_reference_response":               True,
myron's avatar
ants  
myron committed
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
        "do_step_resynthetise_reference":               False,
        "do_step_scalars"               :    False,
        "do_step_volume_retrieval"      :    False,
    }

    
    os.system("mkdir results")


    scalar_products_and_volume_target_file  = "results/scalar_products_and_volume.h5"

    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"
    
    response_target_file = "results/response.h5"

    resynthetised_reference_and_roi_target_file = "results/resynthetised_roi_and_scan.h5"

    ###########################################################################################
    ######  LOADING PEAKS SHIFTS
    ###### peaks_shifts = h5py.File("../peaks_positions_for_analysers.h5","r")["peaks_positions"][()]
    ###### assert( len(peaks_shifts) == 72)

    if rois_are_ready:
        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() ) )
myron's avatar
ants    
myron committed
110
111
        peaks_shifts = np.array([    el_dict["ROI%02d"%i] if ("ROI%02d"%i) in  el_dict else nan    for i in range( 72)  ] )

myron's avatar
ants  
myron committed
112
113
        Enominal = np.median(peaks_shifts)
        peaks_shifts-= Enominal
114
        
myron's avatar
ants  
myron committed
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
    else:
        peaks_shifts = None
    
    ##############################################################
    ##########################################################################
    
    tools_sequencer_interp.tools_sequencer(  peaks_shifts          = peaks_shifts          ,
                      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,
130
                      Ydim        =  Ydim       ,                    # not used 
myron's avatar
ants  
myron committed
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
                      Zdim        =  Zdim       ,
                      Edim        =  Edim       ,

                      monitor_column = monitor_column,
                      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 ,
                      isolate_spot_by =  isolate_spot_by,
                      response_target_file = response_target_file,
                      response_fit_options = response_fit_options,
                      
                      resynthetised_reference_and_roi_target_file = resynthetised_reference_and_roi_target_file,

                      selected_rois = selected_rois,
                      
                      scal_prod_use_optional_solution = scal_prod_use_optional_solution ,
                      scalar_products_and_volume_target_file      = scalar_products_and_volume_target_file ,

                      volume_retrieval_beta  = volume_retrieval_beta ,
                      volume_retrieval_niter = volume_retrieval_niter 
                      
    )
    
    

            
            
main()