You are on page 1of 27

Python Programming

at Canadian Natural
March 2012

THE PREMIUM VALUE DEFINED GROWTH INDEPENDENT


Agenda
• Who is Canadian Natural
• MineSight & Python
• Creating scripts
–that automate repetitive tasks
–with other available Python libraries
• WIN32
• PIL
• Reportlab

CNQ
Slide 2
Who is Canadian Natural?
• Canadian based E&P company
with international exposure
• ~US$50 billion enterprise value
• 594-604 MBOE/d – 2011F
– ~65% crude oil weighted
• 675-726 MBOE/d – 2012B
– ~70% crude oil weighted
• Returns focused
• Major oil sands player
– Major thermal in situ producer
with several projects in
inventory
– Major mining project with
110,000 bbl/d of SCO
production capacity
Information taken from the November 2011 Investor Presentation

CNQ
Slide 3
Horizon Oil Sands Operation
• Horizon Oil Sands Operation
– First Synthetic Crude Oil (SCO) was delivered on February 28, 2009
– Large open pit mining operation
– 2 tons of oil sands to produce 1 barrel SCO
– Bitumen extraction and upgrading facilities
– Current production capacity (Phase 1): 110,000 bbl/d
• Future expansions up to 500,000 bbl/d

CNQ
Slide 4
MineSight & Python
• Mintec’s Grail library
– Provides access to the core of MineSight.
– Modify and create geometry objects and model files
– Use the CAD Engines to calculate volumes, create partials files, intersect
surfaces, polygons, verify surfaces, and more.
– Access to Compass Multiruns

• Think outside of the box!


– Use available Python libraries to enhance your scripts
– WIN32 API adds the functionally to interact with Windows
– PIL Library adds image processing capabilities
– Reportlab Library adds document conversion

• Reasons to use Python


– Simplifies the task for the user
– Saves time
– Standardizes geometry naming convention for a task

CNQ
Slide 5
Repetitive Tasks & Python
• Time consuming tasks:
– Intersecting surfaces
– Creating/Intersecting solids
– Calculating volumes
– When a user has to click the mouse, create an object, and repeat the
process multiple times

• Workflow for Python


– Get geometry objects from Data Manager or active selection
– Sort geometry objects into items to be looped through
– Execute ‘Run Once’ tasks prior to the main loop
• Eg. Create solid using a surface for future solid intersections
– Main Loop
• Create new object for result of operation
• Perform tasks on geometry objects
• Save results
– End Loop
– Exit Script
CNQ
Slide 6
The Repetitive Task
• Create OB & Ore Solids from End of Period shells
End of Periods Surface Intersection Tool Intersect Solids Tool

Overburden

Ore

Ore Solids

Overburden Solids

CNQ
Slide 7
Select Objects with the Data Manager
• Highlighted objects in the datamanager can be accessed with
the grail.ms3d.datamanager module

Variable contains list of all


highlighted geometry objects
from data manager

CNQ
Slide 8
Sort objects with loops
• Loop through the objects to sort the geometry objects into
categories for the script.

Loop through
geometry objects

Loop through object list


and sort into additional
variables as needed

CNQ
Slide 9
Run tasks prior to main loop
• Execute ‘Run once’ tasks prior to the main loop
–Eg. Create a solid to intersect with future solids

Get surface data from


geometry object

Create surface at zero elevation with


grail.engines.dtb

Create Total Ore Solid from ore top


surface and zero elevation surface with
grail.engines.sit

Save result to variable for future use

CNQ
Slide 10
Main loop
• Loop through the objects while performing tasks on them
–Eg. Get data from EOPs.
Loop through
surfaces

Get EOP1 surface data


from geometry object

Get EOP2 surface data


from geometry object

Create geometry
object to store result

CNQ
Slide 11
Main loop – Continued
• Continue performing tasks on the geometry objects
–Eg. Intersect and create excavation solid, and intersect newly
created EOP solid against the Ore solid

Create cut solid using grail.engines.sit

Save result to geometry object

Intersect Excavation Solid and Ore Solid using


grail.engines.union to get OB Solid

Save OB Solid to geometry object

CNQ
Slide 12
Main loop & Exit Script
• Finish performing tasks on the geometry objects
–Eg. Intersect EOP solid against the Ore solid

Intersect EOP solid result and Ore Solid using


grail.engines.union

Save Ore Solid to geometry object

Close all objects and refresh the Data Manager

• Outside of the main loop, close all objects and refresh Data
Manager when complete

CNQ
Slide 13
Results from the Python script
• The script:
– Makes the folders and geometry
objects
– Selects surfaces for surface and
solid intersection
– Stores results to a geometry
object
– Open and close objects as
needed
• Example: 18 EOPs & 1 Ore Top
selected
– 5 minutes 13 seconds later
– 18 Total excavation solids
– 18 Overburden solids
– 18 Ore solids Video clipped to reduce play time

CNQ
Slide 14
Calculate volumes
• Use grail.data.partialsfile & grail.engines.voxel to create partials files for solids and
report volumes
• Example: 1 LGO, 5 Dyke Shells,
and 9 Dyke Zone Solids
– 6 minutes 11 seconds later
– Fill solids for each dyke shell
– Zone solids for each dyke
shell
– Volumes calculated and
saved to CSV

Video clipped to reduce play time

CNQ
Slide 15
Compass MultiRuns
• Pass arguments to the script and execute Multi-run if needed
• When would you do this?
– Using MSEP for inventory calculation and adjustments to RCODE are required

Check variable &


continue if >0
Run RCODE
MultiRun

CNQ
Slide 16
Compass MultiRuns
• Weekly GSM Rebuild multirun
– Multiple tasks – Dump data, Build GSM, Clone GSM, Dilute GSM

Ask user is surface was gridded

Ask user for folder with model

Continue if both prj files exist

Run Dump Data multirun

Run Rebuild GSM multirun

Clone undiluted GSM

Run Dilute GSM multirun

CNQ
Slide 17
WIN32 API
• Interact with Microsoft Outlook
– Send emails with attachments

Create new mail item


with win32API

Get highlighted objects


with datamanager
module

Attach files and show


new mail item

CNQ
Slide 18
WIN32 API – Continued
• Interact with Microsoft Outlook
– Read emails and find MSR attachments

Connect to Outlook and


retrieve messages

Find email with .MSR files

Save .MSR files

Refresh Data Manager

CNQ
Slide 19
OS.Startfile
• Start any file from within MineSight
– Eg. Excel/Word/PowerPoint files, Video capture program, etc

CNQ
Slide 20
Python Imaging Library – Tile Image
• Texturing Surfaces inside MineSight
• Tile images for hardware
rendering (4096px x 4096px)
Load image

Crop image

Save new image


CNQ
Slide 21
File utilities – Copy latest LGO
• Using shutil.copyfile & os.listdir
• Get the latest LGO on the network and copy it to your computer

Get folder contents with os.listdir

Sort contents to find latest year of “Field Surveys”

Get contents of Weekly LGO folder, and sort

Make folder if needed


and copy LGO

CNQ
Slide 22
Convert PNG to PDF
• Convert PNGs to PDFs using reportlab.pdfgen

Get folder contents

Load image

Check orientation
and page size

Save to PDF

Open Windows Explorer

CNQ
Slide 23
Search the Data Manager
• Use os.walk to get the contents of the data manager
folder
• Use grail.project module for the resource directory path

CNQ
Slide 24
Resources
• MineSight Grail Documentation
• Google – Many searches for code tutorials and examples
• http://effbot.org/tkinterbook/ – TKinter reference

CNQ
Slide 25
Questions?

CNQ
Slide 26
THE FUTURE
CLEARLY DEFINED
Canadian Natural Resources Limited
2500, 855 - 2 Street SW
Calgary Alberta
T2P 4J8

phone: 403.517.6700
fax: 403.517.7350
email: ir@cnrl.com
www.cnrl.com

THE PREMIUM VALUE DEFINED GROWTH INDEPENDENT

You might also like