Skip to content

Commit

Permalink
Refs #11229 option for nexus output added
Browse files Browse the repository at this point in the history
  • Loading branch information
VickieLynch committed Mar 25, 2015
1 parent 3a62204 commit 6e80c54
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 15 deletions.
2 changes: 2 additions & 0 deletions Code/Mantid/scripts/SCD_Reduction/ReduceSCD.config
Expand Up @@ -43,6 +43,8 @@ calibration_file_2 None
#
data_directory None
output_directory /SNS/TOPAZ/IPTS-9890/shared/SPAnH
# Change to true for data with lots of peaks. Use False for ISAW ASCII output
output_nexus False

#
# If use_monitor_counts is True, then the integrated beam monitor
Expand Down
27 changes: 22 additions & 5 deletions Code/Mantid/scripts/SCD_Reduction/ReduceSCD_OneRun.py
Expand Up @@ -72,6 +72,7 @@
calibration_file_2 = params_dictionary.get('calibration_file_2', None)
data_directory = params_dictionary[ "data_directory" ]
output_directory = params_dictionary[ "output_directory" ]
output_nexus = params_dictionary.get( "output_nexus", False)
min_tof = params_dictionary[ "min_tof" ]
max_tof = params_dictionary[ "max_tof" ]
use_monitor_counts = params_dictionary[ "use_monitor_counts" ]
Expand Down Expand Up @@ -145,7 +146,10 @@
# Name the files to write for this run
#
run_niggli_matrix_file = output_directory + "/" + run + "_Niggli.mat"
run_niggli_integrate_file = output_directory + "/" + run + "_Niggli.integrate"
if output_nexus:
run_niggli_integrate_file = output_directory + "/" + run + "_Niggli.nxs"
else:
run_niggli_integrate_file = output_directory + "/" + run + "_Niggli.integrate"

#
# Load the run data and find the total monitor counts
Expand Down Expand Up @@ -219,7 +223,10 @@
# see these partial results
#
SaveIsawUB( InputWorkspace=peaks_ws,Filename=run_niggli_matrix_file )
SaveIsawPeaks( InputWorkspace=peaks_ws, AppendFile=False,
if output_nexus:
SaveNexus( InputWorkspace=peaks_ws, Filename=run_niggli_integrate_file )
else:
SaveIsawPeaks( InputWorkspace=peaks_ws, AppendFile=False,
Filename=run_niggli_integrate_file )

#
Expand Down Expand Up @@ -327,7 +334,10 @@
# This is the only file needed, for the driving script to get a combined
# result.
#
SaveIsawPeaks( InputWorkspace=peaks_ws, AppendFile=False,
if output_nexus:
SaveNexus( InputWorkspace=peaks_ws, Filename=run_niggli_integrate_file )
else:
SaveIsawPeaks( InputWorkspace=peaks_ws, AppendFile=False,
Filename=run_niggli_integrate_file )

# Print warning if user is trying to integrate using the cylindrical method and transorm the cell
Expand All @@ -342,13 +352,20 @@
if (not cell_type is None) and (not centering is None) :
run_conventional_matrix_file = output_directory + "/" + run + "_" + \
cell_type + "_" + centering + ".mat"
run_conventional_integrate_file = output_directory + "/" + run + "_" + \
if output_nexus:
run_conventional_integrate_file = output_directory + "/" + run + "_" + \
cell_type + "_" + centering + ".nxs"
else:
run_conventional_integrate_file = output_directory + "/" + run + "_" + \
cell_type + "_" + centering + ".integrate"
SelectCellOfType( PeaksWorkspace=peaks_ws,\
CellType=cell_type, Centering=centering,\
AllowPermutations=allow_perm,\
Apply=True, Tolerance=tolerance )
SaveIsawPeaks( InputWorkspace=peaks_ws, AppendFile=False,\
if output_nexus:
SaveNexus( InputWorkspace=peaks_ws, Filename=run_conventional_integrate_file )
else:
SaveIsawPeaks( InputWorkspace=peaks_ws, AppendFile=False,\
Filename=run_conventional_integrate_file )
SaveIsawUB( InputWorkspace=peaks_ws, Filename=run_conventional_matrix_file )

Expand Down
71 changes: 61 additions & 10 deletions Code/Mantid/scripts/SCD_Reduction/ReduceSCD_Parallel.py
Expand Up @@ -84,6 +84,7 @@ def run ( self ):

exp_name = params_dictionary[ "exp_name" ]
output_directory = params_dictionary[ "output_directory" ]
output_nexus = params_dictionary.get( "output_nexus", False)
reduce_one_run_script = params_dictionary[ "reduce_one_run_script" ]
slurm_queue_name = params_dictionary[ "slurm_queue_name" ]
max_processes = int(params_dictionary[ "max_processes" ])
Expand All @@ -94,6 +95,7 @@ def run ( self ):
centering = params_dictionary[ "centering" ]
allow_perm = params_dictionary[ "allow_perm" ]
run_nums = params_dictionary[ "run_nums" ]
data_directory = params_dictionary[ "data_directory" ]

use_cylindrical_integration = params_dictionary[ "use_cylindrical_integration" ]
instrument_name = params_dictionary[ "instrument_name" ]
Expand Down Expand Up @@ -153,14 +155,44 @@ def run ( self ):
# appending them to a combined output file.
#
niggli_name = output_directory + "/" + exp_name + "_Niggli"
niggli_integrate_file = niggli_name + ".integrate"
if output_nexus:
niggli_integrate_file = niggli_name + ".nxs"
else:
niggli_integrate_file = niggli_name + ".integrate"
niggli_matrix_file = niggli_name + ".mat"

first_time = True

if output_nexus:
#Only need this for instrument for peaks_total
short_filename = "%s_%s_event.nxs" % (instrument_name, str(run_nums[0]))
if data_directory is not None:
full_name = data_directory + "/" + short_filename
else:
candidates = FileFinder.findRuns(short_filename)
full_name = ""
for item in candidates:
if os.path.exists(item):
full_name = str(item)

if not full_name.endswith('nxs'):
print "Exiting since the data_directory was not specified and"
print "findnexus failed for event NeXus file: " + instrument_name + " " + str(run)
exit(0)
#
# Load the first data file to find instrument
#
wksp = LoadEventNexus( Filename=full_name, FilterByTofMin=0, FilterByTofMax=0 )
peaks_total = CreatePeaksWorkspace(NumberOfPeaks=0, InstrumentWorkspace=wksp)

if not use_cylindrical_integration:
for r_num in run_nums:
one_run_file = output_directory + '/' + str(r_num) + '_Niggli.integrate'
peaks_ws = LoadIsawPeaks( Filename=one_run_file )
if output_nexus:
one_run_file = output_directory + '/' + str(r_num) + '_Niggli.nxs'
peaks_ws = Load( Filename=one_run_file )
else:
one_run_file = output_directory + '/' + str(r_num) + '_Niggli.integrate'
peaks_ws = LoadIsawPeaks( Filename=one_run_file )
if first_time:
if UseFirstLattice and not read_UB:
# Find a UB (using FFT) for the first run to use in the FindUBUsingLatticeParameters
Expand All @@ -171,17 +203,27 @@ def run ( self ):
uc_alpha = peaks_ws.sample().getOrientedLattice().alpha()
uc_beta = peaks_ws.sample().getOrientedLattice().beta()
uc_gamma = peaks_ws.sample().getOrientedLattice().gamma()
SaveIsawPeaks( InputWorkspace=peaks_ws, AppendFile=False, Filename=niggli_integrate_file )

if output_nexus:
peaks_total = CombinePeaksWorkspaces(LHSWorkspace=peaks_total, RHSWorkspace=peaks_ws)
SaveNexus( InputWorkspace=peaks_ws, Filename=niggli_integrate_file )
else:
SaveIsawPeaks( InputWorkspace=peaks_ws, AppendFile=False, Filename=niggli_integrate_file )
first_time = False
else:
SaveIsawPeaks( InputWorkspace=peaks_ws, AppendFile=True, Filename=niggli_integrate_file )
if output_nexus:
peaks_total = CombinePeaksWorkspaces(LHSWorkspace=peaks_total, RHSWorkspace=peaks_ws)
SaveNexus( InputWorkspace=peaks_total, Filename=niggli_integrate_file )
else:
SaveIsawPeaks( InputWorkspace=peaks_ws, AppendFile=True, Filename=niggli_integrate_file )

#
# Load the combined file and re-index all of the peaks together.
# Save them back to the combined Niggli file (Or selcted UB file if in use...)
#
peaks_ws = LoadIsawPeaks( Filename=niggli_integrate_file )
if output_nexus:
peaks_ws = Load( Filename=niggli_integrate_file )
else:
peaks_ws = LoadIsawPeaks( Filename=niggli_integrate_file )

#
# Find a Niggli UB matrix that indexes the peaks in this run
Expand All @@ -206,7 +248,10 @@ def run ( self ):
FindUBUsingFFT( PeaksWorkspace=peaks_ws, MinD=min_d, MaxD=max_d, Tolerance=tolerance )

IndexPeaks( PeaksWorkspace=peaks_ws, Tolerance=tolerance )
SaveIsawPeaks( InputWorkspace=peaks_ws, AppendFile=False, Filename=niggli_integrate_file )
if output_nexus:
SaveNexus( InputWorkspace=peaks_ws, Filename=niggli_integrate_file )
else:
SaveIsawPeaks( InputWorkspace=peaks_ws, AppendFile=False, Filename=niggli_integrate_file )
SaveIsawUB( InputWorkspace=peaks_ws, Filename=niggli_matrix_file )

#
Expand All @@ -216,12 +261,18 @@ def run ( self ):
if not use_cylindrical_integration:
if (not cell_type is None) and (not centering is None) :
conv_name = output_directory + "/" + exp_name + "_" + cell_type + "_" + centering
conventional_integrate_file = conv_name + ".integrate"
if output_nexus:
conventional_integrate_file = conv_name + ".nxs"
else:
conventional_integrate_file = conv_name + ".integrate"
conventional_matrix_file = conv_name + ".mat"

SelectCellOfType( PeaksWorkspace=peaks_ws, CellType=cell_type, Centering=centering,\
AllowPermutations=allow_perm, Apply=True, Tolerance=tolerance )
SaveIsawPeaks( InputWorkspace=peaks_ws, AppendFile=False, Filename=conventional_integrate_file )
if output_nexus:
SaveNexus( InputWorkspace=peaks_ws, Filename=conventional_integrate_file )
else:
SaveIsawPeaks( InputWorkspace=peaks_ws, AppendFile=False, Filename=conventional_integrate_file )
SaveIsawUB( InputWorkspace=peaks_ws, Filename=conventional_matrix_file )

if use_cylindrical_integration:
Expand Down

0 comments on commit 6e80c54

Please sign in to comment.