Skip to content

Commit

Permalink
Re #7469 moving some API v1 calls to API v2
Browse files Browse the repository at this point in the history
  • Loading branch information
mdoucet committed Jul 17, 2013
1 parent 364fbc4 commit 8715990
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 29 deletions.
28 changes: 14 additions & 14 deletions Code/Mantid/scripts/reduction/instrument.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import MantidFramework
import mantidsimple
MantidFramework.mtd.initialise()
import mantid.simpleapi as api
from mantid.kernel import *
from mantid.api import *

def instrument_factory(name):
"""
Expand All @@ -21,16 +21,16 @@ def __init__(self, instr_filen=None):
"""
if instr_filen is None:
instr_filen = self._NAME+'_Definition.xml'

self._definition_file = MantidFramework.mtd.getConfigProperty(
'instrumentDefinition.directory')+'/'+instr_filen
config = ConfigService.Instance()
self._definition_file = config["instrumentDefinition.directory"]+'/'+instr_filen

self.definition = self.load_instrument()

def get_default_instrument(self):
instr_filen = self._NAME+'_Definition.xml'
self._definition_file = MantidFramework.mtd.getConfigProperty(
'instrumentDefinition.directory')+'/'+instr_filen
config = ConfigService.Instance()
self._definition_file =config["instrumentDefinition.directory"]+'/'+instr_filen
return self.load_instrument()

def load_instrument(self):
Expand All @@ -39,12 +39,12 @@ def load_instrument(self):
@return the instrument parameter data
"""
wrksp = '__'+self._NAME+'instrument_definition'
if not MantidFramework.mtd.workspaceExists(wrksp):
mantidsimple.CreateWorkspace(wrksp,"1","1","1")
if not AnalysisDataService.doesExist(wrksp):
api.CreateWorkspace(OutputWorkspace=wrksp,DataX="1",DataY="1",DataE="1")
#read the information about the instrument that stored in its xml
mantidsimple.LoadInstrument(wrksp, InstrumentName=self._NAME)
api.LoadInstrument(Workspace=wrksp, InstrumentName=self._NAME)

return MantidFramework.mtd[wrksp].getInstrument()
return AnalysisDataService.retrieve(wrksp).getInstrument()

def name(self):
"""
Expand All @@ -70,7 +70,7 @@ def view(self, workspace_name = None):
if workspace_name is None:
workspace_name = self._NAME+'_instrument_view'
self.load_empty(workspace_name)
elif not MantidFramework.mtd.workspaceExists(workspace_name):
elif not AnalysisDataService.doesExist(workspace_name):
self.load_empty(workspace_name)

import mantidplot
Expand All @@ -89,7 +89,7 @@ def load_empty(self, workspace_name = None):
if workspace_name is None:
workspace_name = '__'+self._NAME+'_empty'

mantidsimple.LoadEmptyInstrument(self._definition_file, workspace_name)
api.LoadEmptyInstrument(Filename=self._definition_file, OutputWorkspace=workspace_name)

return workspace_name

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import sans_reduction_steps
import hfir_load
import absolute_scale
import mantidsimple
import mantid.simpleapi as api
import warnings
import inspect

Expand Down Expand Up @@ -91,10 +91,10 @@ def __init__(self):
self._mask = sans_reduction_steps.Mask()

# Default dark current subtracter class
self._dark_current_subtracter_class = mantidsimple.HFIRDarkCurrentSubtraction
self._dark_current_subtracter_class = api.HFIRDarkCurrentSubtraction

# Resolution calculator
self._resolution_calculator = mantidsimple.ReactorSANSResolution
self._resolution_calculator = api.ReactorSANSResolution

# Sample geometry correction
self.geometry_correcter = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

# Define a SANS specific logger
from mantid.kernel import Logger
import mantid.simpleapi as api
from mantid.api import AnalysisDataService
sanslog = Logger.get("SANS")

class HFIRSetup(ReductionStep):
Expand Down Expand Up @@ -850,7 +852,7 @@ def execute(self, reducer, workspace):
mantid.sendLogMessage("Badly defined mask from configuration file: %s" % str(rec))

for shape in self._xml:
MaskDetectorsInShape(workspace, shape)
api.MaskDetectorsInShape(Workspace=workspace, ShapeXML=shape)

instrument = reducer.instrument
# Get a list of detector pixels to mask
Expand All @@ -871,10 +873,10 @@ def execute(self, reducer, workspace):
# Mask the pixels by passing the list of IDs
MaskDetectors(workspace, DetectorList = masked_detectors)

masked_detectors = ExtractMask(InputWorkspace=workspace, OutputWorkspace="__mask")
mantid.sendLogMessage("Mask check %s: %g masked pixels" % (workspace, len(masked_detectors.getPropertyValue("DetectorList"))))
masked_detectors = api.ExtractMask(InputWorkspace=workspace, OutputWorkspace="__mask")
sanslog.notice("Mask check %s: %g masked pixels" % (workspace, len(masked_detectors)))

return "Mask applied %s: %g masked pixels" % (workspace, len(masked_detectors.getPropertyValue("DetectorList")))
return "Mask applied %s: %g masked pixels" % (workspace, len(masked_detectors))

class CorrectToFileStep(ReductionStep):
"""
Expand Down Expand Up @@ -975,14 +977,14 @@ def calculate(self, reducer, wave_wksps=[]):
wave_adj = None
for wksp in wave_wksps:
#before the workspaces can be combined they all need to match
RebinToWorkspace(wksp, reducer.output_wksp, self.TMP_WORKSPACE_NAME)
api.RebinToWorkspace(WorkspaceToRebin=wksp, WorkspaceToMatch=reducer.output_wksp, OutputWorkspace=self.TMP_WORKSPACE_NAME)

if not wave_adj:
#first time around this loop
wave_adj = self.WAVE_CORR_NAME
RenameWorkspace(self.TMP_WORKSPACE_NAME, wave_adj)
api.RenameWorkspace(InputWorkspace=self.TMP_WORKSPACE_NAME, OutputWorkspace=wave_adj)
else:
Multiply(self.TMP_WORKSPACE_NAME, wave_adj, wave_adj)
api.Multiply(LHSWorkspace=self.TMP_WORKSPACE_NAME, RHSWorkspace=wave_adj, OutputWorkspace=wave_adj)

# read pixel correction file
# note the python code below is an attempt to emulate function overloading
Expand All @@ -997,8 +999,8 @@ def calculate(self, reducer, wave_wksps=[]):
load_com += ')'
eval(load_com)

if mtd.workspaceExists(self.TMP_WORKSPACE_NAME):
DeleteWorkspace(self.TMP_WORKSPACE_NAME)
if AnalysisDataService.doesExist(self.TMP_WORKSPACE_NAME):
AnalysisDataService.remove(self.TMP_WORKSPACE_NAME)

return wave_adj, pixel_adj

Expand Down Expand Up @@ -1123,8 +1125,8 @@ def _deleteWorkspaces(self, workspaces):
"""
for wk in workspaces:
try:
if wk and mantid.workspaceExists(wk):
DeleteWorkspace(wk)
if AnalysisDataService.doesExist(wk):
AnalysisDataService.remove(wk)
except:
#if the workspace can't be deleted this function does nothing
pass
Expand Down Expand Up @@ -1530,4 +1532,4 @@ def execute(self, reducer, workspace):
startX = x_vals[start]
# Make sure we're inside the bin that we want to crop
endX = 1.001*x_vals[stop + 1]
CropWorkspace(workspace,workspace,startX,endX)
api.CropWorkspace(InputWorkspace=workspace, OutputWorkspace=workspace, XMin=startX, XMax=endX)

0 comments on commit 8715990

Please sign in to comment.