Skip to content

Commit

Permalink
Refs #4333. Switch to mixedCase functions in Python
Browse files Browse the repository at this point in the history
Keep consistency with C++ and the current interface so people's
scripts will not need to many changes.
  • Loading branch information
martyngigg committed Dec 14, 2011
1 parent bcdc2f2 commit 13c1459
Show file tree
Hide file tree
Showing 44 changed files with 268 additions and 271 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
boost::python::class_<Mantid::Kernel::PropertyWithValue< type >, \
boost::python::bases<Mantid::Kernel::Property>, boost::noncopyable>("PropertyWithValue_"#suffix, boost::python::no_init) \
.add_property("value", Mantid::PythonInterface::PropertyMarshal::value) \
.add_property("value_as_declared", make_function(&Mantid::Kernel::PropertyWithValue<type>::operator(), \
.add_property("valueAsDeclared", make_function(&Mantid::Kernel::PropertyWithValue<type>::operator(), \
boost::python::return_value_policy<boost::python::copy_const_reference>())) \
;

Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/PythonInterface/mantid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@
###############################################################################
# Aliases
###############################################################################
mtd = framework_mgr
mtd = AnalysisDataService.Instance()
5 changes: 1 addition & 4 deletions Code/Mantid/Framework/PythonInterface/mantid/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
###############################################################################
# Make the singleton objects available as named variables
###############################################################################
framework_mgr = FrameworkManager.Instance() # This starts the framework
algorithm_mgr = AlgorithmManager.Instance()
algorithm_factory = AlgorithmFactory.Instance()
analysis_data_svc = AnalysisDataService.Instance()
FrameworkManager.Instance() # This starts the framework

###############################################################################
# Starting the FrameworkManager loads the C++ plugin libraries
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,19 @@ void export_algorithm()
.def("alias", &IAlgorithm::alias, "Return the aliases for the algorithm")
.def("version", &IAlgorithm::version, "Returns the version number of the algorithm")
.def("category", &IAlgorithm::category, "Returns the category containing the algorithm")
.def("doc_string", &createDocString, "Returns a doc string for the algorithm")
.def("mandatory_properties",&getInputPropertiesWithMandatoryFirst, "Returns a list of input and in/out property names that is ordered "
.def("docString", &createDocString, "Returns a doc string for the algorithm")
.def("mandatoryProperties",&getInputPropertiesWithMandatoryFirst, "Returns a list of input and in/out property names that is ordered "
"such that the mandatory properties are first followed by the optional ones.")
.def("output_properties",&getOutputProperties, "Returns a list of the output properties on the algorithm")
.def("outputProperties",&getOutputProperties, "Returns a list of the output properties on the algorithm")
.def("initialize", &IAlgorithm::initialize, "Initializes the algorithm")
.def("is_initialized", &IAlgorithm::isInitialized, "Returns True if the algorithm is initialized, False otherwise")
.def("isInitialized", &IAlgorithm::isInitialized, "Returns True if the algorithm is initialized, False otherwise")
.def("execute", &IAlgorithm::execute, "Runs the algorithm")
.def("is_executed", &IAlgorithm::isExecuted, "Returns true if the algorithm has been executed successfully, false otherwise")
.def("set_child", &IAlgorithm::setChild,
.def("isExecuted", &IAlgorithm::isExecuted, "Returns true if the algorithm has been executed successfully, false otherwise")
.def("setChild", &IAlgorithm::setChild,
"If true this algorithm is run as a child algorithm. There will be no logging and nothing is stored in the Analysis Data Service")
.def("is_child", &IAlgorithm::isChild, "Returns True if the algorithm has been marked to run as a child. If True then Output workspaces "
.def("isChild", &IAlgorithm::isChild, "Returns True if the algorithm has been marked to run as a child. If True then Output workspaces "
"are NOT stored in the Analysis Data Service but must be retrieved from the property.")
.def("set_logging", &IAlgorithm::setLogging, "Toggle logging on/off.")
.def("setLogging", &IAlgorithm::setLogging, "Toggle logging on/off.")
;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void export_AlgorithmFactory()
.def("Instance", &AlgorithmFactory::Instance, return_value_policy<reference_existing_object>(), //This policy is really only safe for singletons
"Returns a reference to the AlgorithmFactory singleton")
.staticmethod("Instance")
.def("get_registered_algorithms", &getRegisteredAlgorithms, "Returns a Python dictionary of ")
.def("getRegisteredAlgorithms", &getRegisteredAlgorithms, "Returns a Python dictionary of ")
;

}
Expand Down Expand Up @@ -107,5 +107,5 @@ namespace
void export_RegisterAlgorithm()
{
// The registration function
def("register_algorithm", &registerAlgorithm, "Register an algorithm with Mantid. The class must derive from mantid.api.PythonAlgorithm.");
def("registerAlgorithm", &registerAlgorithm, "Register an algorithm with Mantid. The class must derive from mantid.api.PythonAlgorithm.");
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void export_AlgorithmManager()
"Returns a reference to the AlgorithmManager singleton")
.staticmethod("Instance")
.def("create", &AlgorithmManagerImpl::create, create_overloads(args("name", "version"), "Creates a managed algorithm."))
.def("create_unmanaged", &AlgorithmManagerImpl::createUnmanaged,
.def("createUnmanaged", &AlgorithmManagerImpl::createUnmanaged,
createUnmanaged_overloads(args("name", "version"), "Creates an unmanaged algorithm."))
;
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ namespace
*/
object retrieveUpcastedPtr(object self, const std::string & name)
{
object dataItem = self.attr("retrieve_as_data_item")(name);
object dataItem = self.attr("retrieveAsDataItem")(name);
Mantid::PythonInterface::PropertyMarshal::upcastFromDataItem(dataItem);
return dataItem;
}
Expand All @@ -110,7 +110,7 @@ void export_AnalysisDataService()
.def("Instance", &AnalysisDataService::Instance, return_value_policy<reference_existing_object>(),
"Return a reference to the ADS singleton")
.staticmethod("Instance")
.def("retrieve_as_data_item", &retrieveAsDataItem, "Retrieve the named object as data item. Raises an exception if the name does not exist")
.def("retrieveAsDataItem", &retrieveAsDataItem, "Retrieve the named object as data item. Raises an exception if the name does not exist")
.def("retrieve", &retrieveUpcastedPtr, "Retrieve the named object. Raises an exception if the name does not exist")
.def("remove", &AnalysisDataServiceImpl::remove, "Remove a named object")
.def("clear", &AnalysisDataServiceImpl::clear, "Removes all objects managed by the service.")
Expand All @@ -122,9 +122,5 @@ void export_AnalysisDataService()
.def("__delitem__", &AnalysisDataServiceImpl::remove)
;

// Factory function
def("get_analysis_data_service", &AnalysisDataService::Instance, return_value_policy<reference_existing_object>(),
"Return a reference to the ADS singleton");

}

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using boost::python::no_init;
void export_ExperimentInfo()
{
class_<ExperimentInfo,boost::noncopyable>("ExperimentInfo", no_init)
.def("get_run_number", &ExperimentInfo::getRunNumber, "Returns the run identifier for this run")
.def("getRunNumber", &ExperimentInfo::getRunNumber, "Returns the run identifier for this run")
;
}

Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,14 @@ void export_FrameworkManager()
"Returns a reference to the FrameworkManager singleton")
.staticmethod("Instance")
.def("clear", &FrameworkManagerImpl::clear, "Clear all memory held by Mantid")
.def("clear_algorithms", &FrameworkManagerImpl::clearAlgorithms, "Clear memory held by algorithms (does not include workspaces)")
.def("clear_data", &FrameworkManagerImpl::clearData, "Clear memory held by the data service (essentially all workspaces, including hidden)")
.def("clear_instruments", &FrameworkManagerImpl::clearInstruments, "Clear memory held by the cached instruments")
.def("clearAlgorithms", &FrameworkManagerImpl::clearAlgorithms, "Clear memory held by algorithms (does not include workspaces)")
.def("clearData", &FrameworkManagerImpl::clearData, "Clear memory held by the data service (essentially all workspaces, including hidden)")
.def("clearInstruments", &FrameworkManagerImpl::clearInstruments, "Clear memory held by the cached instruments")
// NOTE: This differs from the C++ FrameworkManager::createAlgorithm to ensure consistency when called within Python
.def("create_algorithm", &createAlgorithm, create_overloads(args("name", "version"), "Creates and initializes an algorithm of the "
"given name and version. If this called from within a Python algorithm an unmanaged algorithm is created otherwise it will "
"be a managed algorithm"))
.def("createAlgorithm", &createAlgorithm,
create_overloads(args("name", "version"), "Creates and initializes an algorithm of the "
"given name and version. If this called from within a Python algorithm "
"an unmanaged algorithm is created otherwise it will be a managed algorithm"))
;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ using namespace boost::python;
void export_IEventWorkspace()
{
class_<IEventWorkspace, bases<Mantid::API::MatrixWorkspace>, boost::noncopyable>("IEventWorkspace", no_init)
.def("get_number_events", &IEventWorkspace::getNumberEvents, "Returns the number of events in the workspace")
.def("get_tof_min", &IEventWorkspace::getTofMin, "Returns the minimum TOF value (in microseconds) held by the workspace")
.def("get_tof_max", &IEventWorkspace::getTofMax, "Returns the maximum TOF value (in microseconds) held by the workspace")
.def("get_event_list", (IEventList*(IEventWorkspace::*)(const int) ) &IEventWorkspace::getEventListPtr,
.def("getNumberEvents", &IEventWorkspace::getNumberEvents,
"Returns the number of events in the workspace")
.def("getTofMin", &IEventWorkspace::getTofMin,
"Returns the minimum TOF value (in microseconds) held by the workspace")
.def("getTofMax", &IEventWorkspace::getTofMax,
"Returns the maximum TOF value (in microseconds) held by the workspace")
.def("getEventList", (IEventList*(IEventWorkspace::*)(const int) ) &IEventWorkspace::getEventListPtr,
return_internal_reference<>(), "Return the event list managing the events at the given workspace index")
.def("clear_mru", &IEventWorkspace::clearMRU, "Clear the most-recently-used lists")

.def("clearMRU", &IEventWorkspace::clearMRU, "Clear the most-recently-used lists")
;

DECLARE_SINGLEVALUETYPEHANDLER(IEventWorkspace, Mantid::Kernel::DataItem_sptr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,26 @@ void export_MatrixWorkspace()
class_<MatrixWorkspace, boost::python::bases<ExperimentInfo,IMDWorkspace>, boost::noncopyable>("MatrixWorkspace", no_init)
//--------------------------------------- Meta information -----------------------------------------------------------------------
.def("blocksize", &MatrixWorkspace::blocksize, "Returns size of the Y data array")
.def("get_number_histograms", &MatrixWorkspace::getNumberHistograms, "Returns the number of spectra in the workspace")
.def("getNumberHistograms", &MatrixWorkspace::getNumberHistograms, "Returns the number of spectra in the workspace")
//--------------------------------------- Array access ---------------------------------------------------------------------------
.def("read_x", &Mantid::PythonInterface::Numpy::wrapX,
.def("readX", &Mantid::PythonInterface::Numpy::wrapX,
"Creates a read-only numpy wrapper around the original X data at the given index")
.def("read_y", &Mantid::PythonInterface::Numpy::wrapY,
.def("readY", &Mantid::PythonInterface::Numpy::wrapY,
"Creates a read-only numpy wrapper around the original Y data at the given index")
.def("read_e", &Mantid::PythonInterface::Numpy::wrapE,
.def("readE", &Mantid::PythonInterface::Numpy::wrapE,
"Creates a read-only numpy wrapper around the original E data at the given index")
.def("extract_x", Mantid::PythonInterface::Numpy::cloneX, "Extracts (copies) the X data from the workspace into a 2D numpy array. "
"Note: This can fail for large workspaces as numpy will require a block of memory free that will fit all of the data.")
.def("extract_y", Mantid::PythonInterface::Numpy::cloneY, "Extracts (copies) the Y data from the workspace into a 2D numpy array. "
"Note: This can fail for large workspaces as numpy will require a block of memory free that will fit all of the data.")
.def("extract_e", Mantid::PythonInterface::Numpy::cloneE, "Extracts (copies) the E data from the workspace into a 2D numpy array. "
"Note: This can fail for large workspaces as numpy will require a block of memory free that will fit all of the data.")
.def("extractX", Mantid::PythonInterface::Numpy::cloneX,
"Extracts (copies) the X data from the workspace into a 2D numpy array. "
"Note: This can fail for large workspaces as numpy will require a block "
"of memory free that will fit all of the data.")
.def("extractY", Mantid::PythonInterface::Numpy::cloneY,
"Extracts (copies) the Y data from the workspace into a 2D numpy array. "
"Note: This can fail for large workspaces as numpy will require a block "
"of memory free that will fit all of the data.")
.def("extractE", Mantid::PythonInterface::Numpy::cloneE,
"Extracts (copies) the E data from the workspace into a 2D numpy array. "
"Note: This can fail for large workspaces as numpy will require a block "
"of memory free that will fit all of the data.")
;

DECLARE_SINGLEVALUETYPEHANDLER(MatrixWorkspace, DataItem_sptr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ void export_Workspace()
register_ptr_to_python<Workspace_sptr>();

class_<Workspace, bases<DataItem>, boost::noncopyable>("Workspace", no_init)
.def("get_title", &Workspace::getTitle, "Returns the title of the workspace")
.def("get_comment", &Workspace::getComment, return_value_policy<copy_const_reference>(), "Returns the comment field on the workspace")
.def("is_dirty", &Workspace::isDirty, Workspace_isDirtyOverloads(args("n"), "True if the workspace has run more than n algorithms (Default=1)"))
.def("get_memory_size", &Workspace::getMemorySize, "Returns the memory footprint of the workspace in KB")
.def("get_history", &Workspace::getHistory, return_value_policy<copy_const_reference>(),
.def("getTitle", &Workspace::getTitle, "Returns the title of the workspace")
.def("getComment", &Workspace::getComment, return_value_policy<copy_const_reference>(), "Returns the comment field on the workspace")
.def("isDirty", &Workspace::isDirty, Workspace_isDirtyOverloads(args("n"), "True if the workspace has run more than n algorithms (Default=1)"))
.def("getMemorySize", &Workspace::getMemorySize, "Returns the memory footprint of the workspace in KB")
.def("getHistory", &Workspace::getHistory, return_value_policy<copy_const_reference>(),
"Return read-only access to the workspace history")
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ namespace
void export_Component()
{
class_<Component, bases<IComponent>, boost::noncopyable>("Component", no_init)
.def("get_parameter_names", &Component::getParameterNames, Component_getParameterNames())
.def("has_parameter", &Component::hasParameter, Component_hasParameter())
.def("get_number_parameter", &Component::getNumberParameter, Component_getNumberParameter())
.def("get_position_parameter", &Component::getPositionParameter, Component_getPositionParameter())
.def("get_rotation_parameter", &Component::getRotationParameter, Component_getRotationParameter())
.def("get_string_parameter", &Component::getStringParameter, Component_getStringParameter())
.def("getParameterNames", &Component::getParameterNames, Component_getParameterNames())
.def("hasParameter", &Component::hasParameter, Component_hasParameter())
.def("getNumberParameter", &Component::getNumberParameter, Component_getNumberParameter())
.def("getPositionParameter", &Component::getPositionParameter, Component_getPositionParameter())
.def("getRotationParameter", &Component::getRotationParameter, Component_getRotationParameter())
.def("getStringParameter", &Component::getStringParameter, Component_getStringParameter())
;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using namespace boost::python;
void export_DetectorGroup()
{
class_<DetectorGroup, bases<IDetector>, boost::noncopyable>("DetectorGroup", no_init)
.def("get_detector_ids", &DetectorGroup::getDetectorIDs, "Returns the list of detector IDs within this group")
.def("getDetectorIds", &DetectorGroup::getDetectorIDs, "Returns the list of detector IDs within this group")
;
}

Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ void export_IComponent()
register_ptr_to_python<boost::shared_ptr<IComponent> >();

class_<IComponent, boost::noncopyable>("IComponent", no_init)
.def("get_pos", &IComponent::getPos, "Returns the absolute position of the component")
.def("get_distance", &IComponent::getDistance, "Returns the distance, in metres, between this and the given component")
.def("get_name", &IComponent::getName, "Returns the name of the component")
.def("getPos", &IComponent::getPos, "Returns the absolute position of the component")
.def("getDistance", &IComponent::getDistance, "Returns the distance, in metres, between this and the given component")
.def("getName", &IComponent::getName, "Returns the name of the component")
.def("type", &IComponent::type, "Returns the type of the component represented as a string")
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ void export_IDetector()

class_<IDetector, bases<IObjComponent>, boost::noncopyable>("IDetector", no_init)
.def("getID", &IDetector::getID, "Returns the detector ID")
.def("is_masked", &IDetector::isMasked, "Returns the value of the masked flag. True means ignore this detector")
.def("is_monitor", &IDetector::isMonitor, "Returns True if the detector is marked as a monitor in the IDF")
.def("solid_angle", &IDetector::solidAngle, "Return the solid angle in steradians between this detector and an observer")
.def("get_twotheta", &IDetector::getTwoTheta, "Calculate the angle between this detector, another component and an axis")
.def("get_phi", &IDetector::getPhi, "Returns the azimuthal angle of this detector")
.def("isMasked", &IDetector::isMasked, "Returns the value of the masked flag. True means ignore this detector")
.def("isMonitor", &IDetector::isMonitor, "Returns True if the detector is marked as a monitor in the IDF")
.def("solidAngle", &IDetector::solidAngle, "Return the solid angle in steradians between this detector and an observer")
.def("getTwotheta", &IDetector::getTwoTheta, "Calculate the angle between this detector, another component and an axis")
.def("getPhi", &IDetector::getPhi, "Returns the azimuthal angle of this detector")
;
}

Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ void export_ObjCompAssembly()
register_ptr_to_python<boost::shared_ptr<ObjCompAssembly> >();

class_<ObjCompAssembly, boost::python::bases<ICompAssembly, ObjComponent>, boost::noncopyable>("IObjCompAssembly", no_init)
.def("nelements", &ObjCompAssembly::nelements)
.def("__getitem__", &ObjCompAssembly::operator[])
;
}

0 comments on commit 13c1459

Please sign in to comment.