Table of Contents
Pyrex is python with C data types. It allows you to mix code that uses python values and C values. This helps in reducing block model access times since it allows direct referencing of the model access library (written in C). The biggest bottleneck in grail.data.model is the translation of data from python to C and back again.
This document outlines the C functions that are available for accessing a block model, and provides some examples.
Note
Pyrex requires Python version 2.5 or higher.
The choice of compiler you will use will be a function of the platform you are building against (32 bit vs. 64 bit), and the python version you are working with. The table below highlights the recommendations,
Python Platform Recommended Compiler 2.5 32 BIT MinGW32 GCC 2.5 64 BIT n/a - not available in MPYTHON. 2.7 32 BIT n/a - not available in MPYTHON. 2.7 64 BIT Visual Studio 2008 Express
For 32 Bit Python 2.5, you can either use the free MinGW32 GCC or pay for an old version of Visual Studio 2003. Since there is good 32 bit support for GCC, and since GCC is free, we often recommened this compiler when working with Python 2.5 and 32 bit code.
For 64 Bit Python 2.7, you have a choice of 64 Bit GCC or a Visual Studio 2008 Express. With the Express edition, you now have access to a Microsoft Visual Studio compiler that is free. With 64 Bit GCC we have found that that state of the compiler on Microsoft platforms is in a state of flux at the moment. Since Visual Studio 2008 Express is free, and since it is operational, and since GCC 64 bit support is limited, we recommend using Visual Studio 2008.
Warning
Block model indices are offset from zero. This is in contrast to grail.data.model in which the indices begin at 1.
Warning
ciMODELGetSlabItemIndexByItemName_Raw is an "expensive” function and should not be called repeatedly within the processing loop. The function assumes the parameters are not NULL, and that a slab has been loaded from the model.
Note
Most functions return either a flag or some kind of pointer. By testing the return value of a function you can determine if an error has occurred. An error message can be accessed using the ciGetError() function.
For 32 Bit, Python 2.5: install MinGW32 GCC compiler suite (ensure 'gcc.exe' is on %PATH%).
For 64 bit, Python 2.7: Install Visual Studio 2008 Express (ensure that 'cl.exe' is on the %PATH%). Typically done by using an installed short cut "Visual Studio 2008 x64 Win64 Command Prompt".
Write Pyrex function (save as 'model_rex.pyx'). Refer to "model_rex_boilerplate.pyx" in the script samples as a guide.
Compile to pyd using "build_model_rex.cmd" (found in %MEDEXE% folder). Pass the full filepath to your model_rex.pyx file as a command-line argument.
In main python script, import grail.data.pyrex_config before importing your new model_rex extension.