Commit 07373fc5 authored by myron's avatar myron
Browse files

reorganised volume fit

parent 2a4b7d42
...@@ -3929,6 +3929,9 @@ def superR_recreate_rois(mydata): ...@@ -3929,6 +3929,9 @@ def superR_recreate_rois(mydata):
original_roi_path : None original_roi_path : None
""" """
allowed_keys = ["old_scan_address","original_roi_path","responsefilename","nex","target_filename","filter_rois","recenterings_refined","filter_path",]
check_allowed_keys(mydata, allowed_keys)
foil_scan_address = mydata["old_scan_address"] foil_scan_address = mydata["old_scan_address"]
foil_filename ,foil_groupname = split_hdf5_address(foil_scan_address) foil_filename ,foil_groupname = split_hdf5_address(foil_scan_address)
...@@ -4081,6 +4084,10 @@ def superR_fit_responses(mydata): ...@@ -4081,6 +4084,10 @@ def superR_fit_responses(mydata):
""" """
allowed_keys = ["foil_scan_address","ref_scan_number","response_scan_address","nref","niter_optical","beta_optical","beta_pixel","niter_pixel","niter_global","pixel_dim","simmetrizza","do_refine_trajectory","target_file","trajectory_reference_scansequence_address","trajectory_threshold","reload_trajectories_file","filter_rois","fit_lines",]
check_allowed_keys(mydata, allowed_keys)
if "foil_scan_address" in mydata: if "foil_scan_address" in mydata:
foil_scan_address = mydata["foil_scan_address"] foil_scan_address = mydata["foil_scan_address"]
else: else:
......
...@@ -4,6 +4,7 @@ import glob ...@@ -4,6 +4,7 @@ import glob
import json import json
import os import os
import h5py import h5py
import math
BATCH_PARALLELISM = 4 BATCH_PARALLELISM = 4
...@@ -57,9 +58,11 @@ def main(): ...@@ -57,9 +58,11 @@ def main():
selected_rois = list(range(0,24)) + list( range(36,60) ) selected_rois = list(range(0,24)) + list( range(36,60) )
scal_prod_use_optional_solution = False scal_prod_use_optional_solution = True
scal_prod_load_factors = False
scal_prod_load_factors_from = "factors.json"
volume_retrieval_beta = 6.0e-20
volume_retrieval_niter = 100
scalar_products_and_volume_target_file = "results/scalar_products_and_volume.h5" scalar_products_and_volume_target_file = "results/scalar_products_and_volume.h5"
...@@ -72,7 +75,8 @@ def main(): ...@@ -72,7 +75,8 @@ def main():
"do_step_fit_reference_response": False, "do_step_fit_reference_response": False,
"do_step_resynthetise_reference": False, "do_step_resynthetise_reference": False,
"do_step_scalars" : True "do_step_scalars" : True,
"do_step_volume_retrieval" : False,
} }
...@@ -120,9 +124,12 @@ def main(): ...@@ -120,9 +124,12 @@ def main():
selected_rois = selected_rois, selected_rois = selected_rois,
scal_prod_use_optional_solution = scal_prod_use_optional_solution , scal_prod_use_optional_solution = scal_prod_use_optional_solution ,
scal_prod_load_factors = scal_prod_load_factors , scalar_products_and_volume_target_file = scalar_products_and_volume_target_file ,
scal_prod_load_factors_from = scal_prod_load_factors_from ,
scalar_products_and_volume_target_file = scalar_products_and_volume_target_file volume_retrieval_beta = volume_retrieval_beta ,
volume_retrieval_niter = volume_retrieval_niter
) )
...@@ -494,6 +501,57 @@ def get_scalars( Start = None, Thickness = None , ...@@ -494,6 +501,57 @@ def get_scalars( Start = None, Thickness = None ,
process_input( input_string, exploit_slurm_mpi = 0) process_input( input_string, exploit_slurm_mpi = 0)
def get_volume( Start = None,
Thickness = None,
volumes_file= None,
niter = None,
beta = None,
):
inputstring = """
superR_getVolume :
scalprods_address : {volumes_file}:/_{start}_{end}/scal_prods
target_address : {volumes_file}:/_{start}_{end}/volume
niter : {niter}
beta : {beta}
eps : 2e-07
debin : [1, 1]
"""
s=inputstring.format(start=Start, end=Start+Thickness,
volumes_file = volumes_file, niter = niter, beta = beta )
process_input(s, exploit_slurm_mpi = 0 )
def collect_factors(pattern="factors_*_*", newfile="newfactors.json"):
files = glob.glob(pattern)
indexes = [ int(s.split("_")[1]) for s in files ]
order = np.argsort(indexes)
files = [files[i] for i in order]
print( files)
files = files[1:-1]
result = {}
result2 = {}
Nkeys = None
for f in files:
factors = json.load(open(f,"r"))
if Nkeys is None:
Nkeys = len(list(factors.keys()))
assert(Nkeys == len(list(factors.keys())) )
for k,val in factors.items():
if k not in result:
result[k] = 0.0
result2[k] = 0.0
result[k] += factors[k]/ len(files)
result2[k] += (factors[k]*factors[k])/ len(files)
json.dump(result,open(newfile,"w") )
keys = list(result.keys() )
keys.sort(key=int)
for k in keys:
print( k , " ", result[k] , " " , math.sqrt( result2[k] - result[k]*result[k] ) / result[k] )
...@@ -530,9 +588,10 @@ def tools_sequencer( peaks_shifts = None, ...@@ -530,9 +588,10 @@ def tools_sequencer( peaks_shifts = None,
selected_rois = None, selected_rois = None,
scal_prod_use_optional_solution= False, scal_prod_use_optional_solution= False,
scal_prod_load_factors = False, scalar_products_and_volume_target_file = None,
scal_prod_load_factors_from = None,
scalar_products_and_volume_target_file = None volume_retrieval_beta = None,
volume_retrieval_niter = None
) : ) :
if roi_path is None: if roi_path is None:
...@@ -631,12 +690,38 @@ def tools_sequencer( peaks_shifts = None, ...@@ -631,12 +690,38 @@ def tools_sequencer( peaks_shifts = None,
signals_file = interpolated_signals_file , signals_file = interpolated_signals_file ,
target_file = scalar_products_and_volume_target_file, target_file = scalar_products_and_volume_target_file,
selected_rois = selected_rois , selected_rois = selected_rois ,
scal_prod_use_optional_solution= False, scal_prod_use_optional_solution= scal_prod_use_optional_solution,
scal_prod_load_factors = False, scal_prod_load_factors = False,
scal_prod_load_factors_from = None scal_prod_load_factors_from = None
) )
if(scal_prod_use_optional_solution):
collect_factors(pattern="factors_*_*.json", newfile="newfactors.json")
for start in range( first_scan_num , ( first_scan_num + Edim * Zdim ), Zdim ):
get_scalars( Start = start, Thickness = Zdim ,
reference_address = resynthetised_reference_and_roi_target_file + ":/rois_and_reference/scans/ScansSum" ,
signals_file = interpolated_signals_file ,
target_file = scalar_products_and_volume_target_file,
selected_rois = selected_rois ,
scal_prod_use_optional_solution= False,
scal_prod_load_factors = False,
scal_prod_load_factors_from = "newfactors.json"
)
if(steps_to_do["do_step_volume_retrieval"]):
for start in range( first_scan_num , ( first_scan_num + Edim * Zdim ), Zdim ):
get_volume( Start = start,
Thickness = Zdim,
volumes_file = scalar_products_and_volume_target_file,
beta = volume_retrieval_beta ,
niter = volume_retrieval_niter,
)
main() main()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment