Ticket #11822 (closed: fixed)

Opened 5 years ago

Last modified 5 years ago

ISIS direct inelastic reduction script fails if used without diagnostics but mon-2 normalized.

Reported by: Alex Buts Owned by: Alex Buts
Priority: major Milestone: Release 3.5
Component: Framework Keywords:
Cc: Blocked By:
Blocking: Tester: Federico Montesino Pouzols

Description

The script below fails. Apparently, some combination of input parameters leaves ConvertToEnergy.in_white_normalization property uninitialized.

""" Sample MER reduction script """ 
# Two rows necessary to run script outside of the mantid. You need also set up 
# appropriate python path-es
import os,sys
os.environ["PATH"] = r"c:/Mantid/Code/builds/br_master/bin/Release;"+os.environ["PATH"]
from mantid import *
from Direct.ReductionWrapper import *
# this exact name is necessary for web services to work until we implement factory
class MERLINReduction(ReductionWrapper):
#------------------------------------------------------------------------------------#
   @MainProperties
   def def_main_properties(self):
       """ Define main properties used in reduction. These are the property 
           a user usually wants to change
       """ 
       prop = {}

       ei=[160,50.4,24.3,14.3] #[80.1, 29.6,15.2] #[201, 77, 40.4, 24.8]# [160,50.4,24.3,14.3] #[80.1, 29.6,15.2] #[150,64,36] # multiple energies provided in the data file
       ebin=[-0.25,0.005,0.85]    #binning of the energy for the spe file. 
       # if energy is specified as a list (even with single value e.g. ei=[81])
       # The numbers are treated as a fraction of ei [from ,step, to ]. If energy is 
       # a number, energy binning assumed to be absolute (e_min, e_step,e_max)
       #
       prop['incident_energy'] = ei
       prop['energy_bins'] = ebin
       #
       # the range of files to reduce. This range ignored when deployed from autoreduction,
       # unless you going to sum these files. 
       # The range of numbers or run number is used when you run reduction from PC.
       prop['sample_run'] = [25018]#[25018,25019,25020,25021,25022,25026,25027] #range(25026,25028) # 'MER23700.n001'
       prop['wb_run'] = '23684.raw'
       #
       prop['sum_runs'] = True # set to true to sum everything provided to sample_run
       #                        # list
  
       # Absolute units reduction properties. Set prop['monovan_run']=None to do relative units
       prop['monovan_run'] = None #25082 #None 25079 80meV 300Hz # 25082 160meV 350Hz# 25079, 80meV 300Hz vanadium run in the same configuration as your sample
       prop['sample_mass'] = 6.2 # BaFe2s2 mass of your sample 
       prop['sample_rmm'] = 398.864  # BaFe2As2 molecular weight of scatterers in your sample

       return prop
#------------------------------------------------------------------------------------#
   @AdvancedProperties
   def def_advanced_properties(self):
      """  Set up advanced properties, describing reduction.
           These are the properties, usually provided by an instrument 
           scientist
            
           separation between simple and advanced properties depends
           on scientist, experiment and user.   All are necessary for reduction 
           to work properly
      """
      prop = {}
      prop['map_file'] = 'one2one_143.map'
      prop['det_cal_file'] = 'det_corr_143.dat' #'det_corrected7.nxs - testing'
      prop['bleed'] = False
      prop['norm_method']='monitor-2'
      prop['detector_van_range']=[40,55]
      prop['background_range'] = [18000,19000] # TOF range for the calculating flat background
      prop['hardmaskOnly']='MER23698.msk' # diag does not work well on MER. At present only use a hard mask RIB has created
      #prop['hard_mask_file'] = "Bjorn_mask.msk"

      prop['check_background']=False
      #prop['ei-mon2-spec']=69641
      #prop[fix_ei]=True
      

      prop['save_format'] = 'nxspe' #nxs,nxspe'
       # if two input files with the same name and  different extension found, what to prefer. 
      prop['data_file_ext']='.nxs' # for MER it may be choice between event and histo mode if 
      # raw file is written in histo, and nxs -- in event mode
      # Absolute units: map file to calculate monovan integrals                                                                      
      prop['monovan_mapfile'] = 'rings_143.map'
      prop['vanadium-mass']=7.85 # check this
      # change this to correct value and verify that motor_log_names refers correct and existing 
      # log name for crystal rotation to write correct psi value into nxspe files
      prop['motor_offset']=None
      #
      prop['monovan_lo_frac']=-0.4
      prop['monovan_hi_frac']= 0.4
      #RAE added
      prop['bleed_maxrate']=0.005
      return prop
      #
#------------------------------------------------------------------------------------#
   @iliad
   def reduce(self,input_file=None,output_directory=None):
      """ Method executes reduction over single file

          Overload only if custom reduction is needed or
          special features are requested
      """
      results = ReductionWrapper.reduce(self,input_file,output_directory)
      #
      #run_num = PropertyManager.sample_run.run_number() 
      #energies = self.reducer.prop_man.incident_energy
      #for ind,res in enumerate(results):
       #     ei = energies[ind]
        #    filename = "MER{0}_{1:<3.2f}meV.nxspe".format(run_num ,ei)
         #   file = os.path.join('/stagingarea',filename)
           # print 'Saving file to {0}'.format(filename)

     #       RenameWorkspace(res,OutputWorkspace=filename)
     #       SaveNXSPE(res,Filename = file)
      #      t_folder = config['defaultsave.directory']
       #     targ_path = os.path.join(t_folder,filename)
       #     shutil.move(file,targ_path)     
       #     DeleteWorkspace(filename)
      return results
   #
   #
   def set_custom_output_filename(self):
      """ define custom name of output files if standard one is not satisfactory 
          In addition to that, example of accessing reduction properties 
          Changing them if necessary
      """ 
      def custom_name(prop_man):
          """ sample function which builds filename from 
              incident energy and run number and adds some auxiliary information 
              to it.
          """ 
          # Note -- properties have the same names  as the list of advanced and 
          # main properties
          ei = PropertyManager.incident_energy.get_current()
          # sample run is more then just list of runs, so we use 
          # the formalization below to access its methods
          run_num = PropertyManager.sample_run.run_number()
          name = "MER{0}atEi{1:<3.2f}meV_One2One".format(run_num ,ei)
          return name
       
      # Uncomment this to use custom filename function
      # Note: the properties are stored in prop_man class accessed as
      # below. 
      return lambda : custom_name(self.reducer.prop_man)
      # use this method to use standard file name generating function
      #return None
   #
   def validation_file_place(self):
      """Redefine this to the place, where validation file, used in conjunction with
         'validate_run' property, located. Here it defines the place to this script folder.
          but if this function is disabled, by default it looks for/places it 
          in a default save directory"""
      return os.path.split(os.path.realpath(__file__))[0]
   
   def __init__(self,web_var=None):
       """ sets properties defaults for the instrument with Name"""
       ReductionWrapper.__init__(self,'MER',web_var)
#
if __name__ == "__main__":
#------------------------------------------------------------------------------------#
# SECTION USED TO RUN REDUCTION FROM MANTID SCRIPT WINDOW #
#------------------------------------------------------------------------------------#
##### Here one sets up folders where to find input data and where to save results ####
    # It can be done here or from Mantid GUI:
    #      File->Manage user directory ->Browse to directory
    # Folder where map and mask files are located:
    map_mask_dir = r'd:\Data\InstrumentFiles\merlin'#'/usr/local/mprogs/InstrumentFiles/merlin'
    #config.appendDataSearchDir(map_mask_dir)
    # folder where input data can be found
    data_dir = 'd:/Data/Mantid_Testing/15_05_01'
    # auxiliary folder with results
    ref_data_dir = data_dir
    # Set input search path to values, specified above
    config.setDataSearchDirs('{0};{1};{2}'.format(data_dir,map_mask_dir,ref_data_dir))
    # use appendDataSearch directory to add more locations to existing Mantid 
    # data search path
    #config.appendDataSearchDir('d:/Data/Mantid_GIT/Test/AutoTestData')
    # folder to save resulting spe/nxspe files.
    config['defaultsave.directory'] = data_dir

###### Initialize reduction class above and set up reduction properties.        ######
######  Note no web_var in constructor.(will be irrelevant if factory is implemented)
    rd = MERLINReduction()
    # set up advanced and main properties
    rd.def_advanced_properties()
    rd.def_main_properties()
#### uncomment rows below to generate web variables and save then to transfer to   ###
    ## web services.
    run_dir = os.path.dirname(os.path.realpath(__file__))
    file = os.path.join(run_dir,'reduce_vars.py')
    rd.save_web_variables(file)

#### Set up time interval (sec) for reducer to check for input data file.         ####
    #  If data file is not present and this value is 0,reduction fails 
    #  if this value >0 the reduction wait until file appears on the data 
    #  search path checking regularly after time interval specified below.
    rd.wait_for_file = 0  # waiting time interval (in sec)
   
### Define a run number to validate reduction against future changes    #############
    # After reduction works well and all settings are done and verified, 
    # take a run number with good reduced results and build validation
    # for this result. 
    # Then place the validation run together with this reduction script.
    # Next time, the script will run reduction and compare the reduction results against
    # the results obtained earlier.
    #rd.validate_run_number = 21968  # Enabling this property disables normal reduction
    # and forces reduction to reduce run specified here and compares results against
    # validation file, processed earlier or calculate this file if run for the first time.
    #This would ensure that reduction script have not changed,
    #allow to identify the reason for changes if it was changed 
    # and would allow to recover the script,used to produce initial reduction
    #if changes are unacceptable.

####get reduction parameters from properties above, override what you want locally ###
   # and run reduction. Overriding would have form:
   # rd.reducer.prop_man.property_name (from the dictionary above) = new value e.g. 
   # rd.reducer.prop_man.energy_bins = [-40,2,40]
   # or 
   ## rd.reducer.prop_man.sum_runs = False
   # 
    
    rd.run_reduction()



Change History

comment:1 Changed 5 years ago by Alex Buts

  • Status changed from new to inprogress

Re #11822 This should fix the issue.

Changeset: 20d7203201f7a54fd44dfa56f861bdb7e5c9743d

comment:2 Changed 5 years ago by Alex Buts

  • Status changed from inprogress to verify
  • Priority changed from critical to major
  • Resolution set to fixed

fixed as PR https://github.com/mantidproject/mantid/pull/789. look there for changes and how to test.

comment:3 Changed 5 years ago by Federico Montesino Pouzols

  • Status changed from verify to verifying
  • Tester set to Federico Montesino Pouzols

comment:4 Changed 5 years ago by Federico Montesino Pouzols

This looks good, except that it seems that a commit that changes the release patch number to 0, inVersionNumber.cmake, was included here accidentally. I guess that this branch was created from the v3.4.0 release branch instead of master. Is this bugfix meant to go into a 3.4.1 patch release? Otherwise I think that you have to undo or revert that commit from this branch.

comment:5 Changed 5 years ago by Federico Montesino Pouzols

Oh, and also if this bug was visible to some users and annoying them, you could add a small bug fix note to the 3.5 / 3.4.1 release notes, depending on whether there's a patch release.

comment:6 Changed 5 years ago by Alex Buts

Re #11822 This should fix the issue.

Changeset: 51e807072c241d67bc16068b9e893f33fb1118a7

comment:7 Changed 5 years ago by Federico Montesino Pouzols

  • Status changed from verifying to closed

Merge pull request #789 from mantidproject/11822_ISISDirect_InvalidProperty

Minor bug in ISIS direct inelastic reduction

Full changeset: 81573937be8dbb50b94d70d5cafa85c3ead2417d

comment:8 Changed 5 years ago by Stuart Campbell

This ticket has been transferred to github issue 12660

Note: See TracTickets for help on using tickets.