Ticket #9331 (closed)

Opened 6 years ago

Last modified 5 years ago

Export Geometry::Object to Python

Reported by: Martyn Gigg Owned by: Nick Draper
Priority: major Milestone: Release 3.2
Component: Python Keywords:
Cc: Blocked By:
Blocking: Tester:

Description

This should allow, at minimum, access to the shapeXML & bounding box of a particular ObjComponent.

Change History

comment:1 Changed 6 years ago by Martyn Gigg

  • Status changed from new to assigned

comment:2 Changed 6 years ago by Martyn Gigg

  • Status changed from assigned to inprogress

Export Object class to Python

Also add shape() method to the IObjComponent interface export. Refs #9331

Changeset: 0ff794bfe715aadf173a1a877398de0b5039ff5a

comment:3 Changed 6 years ago by Martyn Gigg

Export BoundingBox type to python

Refs #9331

Changeset: 8409af29ad7b9da948bd08a618bf4a1bc77aa639

comment:4 Changed 6 years ago by Martyn Gigg

  • Owner changed from Martyn Gigg to Nick Draper

Branch: feature/9331_access_geometry_shape_from_python

Tester: This script demonstrates the use of the XML and bounding box to access the radius value of the instrument component's shape.

import mantid
import xml.etree.ElementTree as ET

w = mantid.simpleapi.Load("MAR11001.raw")
inst = w.getInstrument()
p = inst.getComponentByName("tall He3 element")
he3_shape = p.shape()

#------- By XML -------------
xml = he3_shape.getShapeXML()
# Define the namespace lookup in the XML
namespaces = {"ns1" : "http://www.mantidproject.org/IDF/1.0"}

root = ET.fromstring(xml)
cyl_elem = root.find("ns1:cylinder", namespaces=namespaces)
radius_elem = cyl_elem.find("ns1:radius", namespaces=namespaces)
radius = radius_elem.get("val", None)
print "Cylinder radius from XML:",radius

#------- By BoundingBox -------------
bounding_box = he3_shape.getBoundingBox()
widths = bounding_box.width()
# box is axis-aligned with shape and Y-axis is assumed "up"
radius = 0.5*widths.X()
print "Cylinder radius from bounding box:",radius

comment:5 Changed 6 years ago by Nick Draper

  • Status changed from inprogress to closed

Merge remote-tracking branch 'origin/feature/9331_access_geometry_shape_from_python'

Full changeset: 983616e2d2d497bdb458e40d3b796d13159efbc7

comment:6 Changed 5 years ago by Stuart Campbell

This ticket has been transferred to github issue 10174

Note: See TracTickets for help on using tickets.