[vc_row][vc_column][vc_column_text]
Pike Overview
Pike consists of two main subsystems: a conversion cross compiler (pikex) and a runtime Python package (pike) that implements an IDL-like API. Working together these two systems deliver a conversion process that maps IDL functionality to Python, specifically functionality delivered by the NumPy and SciPy (collectively referred to as SciPy) modules.
In general, Pike has support for IDL 4.x language features, currently not implementing IDL Objects or Pointers which were first implemented in IDL 5.0.[/vc_column_text][vc_column_text]
Operational Structure
Pike is delivered as a Python package which encapsulates all the functionality needed to translate IDL source code to Python, and execute the results within a SciPy environment.
The PIKE package provides a complete IDL to Python conversion environment. To accomplish this capability, PIKE consists of two sub-systems: The pikex conversion compiler and the Pike runtime Python package.
PikeX
The PikeX (pikex) conversion compiler reads IDL source code and outputs Python source code that maintains the IDL structure and execution logic. PikeX is a terminal command, pikex, that operates in a fashion similar to a standard compiler.
When pikex executes, in performs the following processing stages:
- Indexing – Index all inputs, resolving any unknown routines and detailing routine signatures.
- Parse – Parse the IDL source code, creating an internal syntax tree.
- Optimize – Re-organize the syntax tree to transpose IDL functionality into Python language patterns.
- Output – Write Python code that implements the input IDL functionality.
When completed, pikex will write out the desired Python code as well as the Python specific files, allowing for the conversion code to be use as a standard Python package. Additionally, a PIKE specific descriptor file is written, which provide the ability of the generated Python package to be used as a reference library by future conversion operation.
The Pike Library
The PIKE library (or package in Python terms) provides the runtime environment to support IDL-like execution patterns within Python, as well as an extensive set of IDL routines.
The runtime functions provided by the Pike library are often just wrappers around a SciPy routines. These wrappers convert data structures and calling patterns to the native SciPy format. The extent of these wrappers varies and is proportional to the difference between the IDL function signature and that of the SciPy offering.
In addition to the deliveries functions, the PIKE runtime library provides support for a set of unique IDL runtime features. These features include:
- Variable argument numbers and _EXTRA support
- Common Blocks
- System Variables
- Structures
- Data types and data conversion
- Multiple output variables
In addition to supporting the execution of pikex converted IDL source code, the Pike Library also provides a robust IDL-like API that transforms the Python interactive environment, bringing familiar commands the the IPython command line.[/vc_column_text][vc_single_image image=”910″ img_size=”large” add_caption=”yes” style=”vc_box_rounded” title=”The Pike Conversion Sequence”][vc_column_text css=”.vc_custom_1475526835972{margin: 0px !important;border-width: 0px !important;padding: 0px !important;}”]
Pike Operation
In general, the conversion of IDL code to Python using Pike follows the process outlined in the preceding graphic. Details of each step are provided in the following sections.
Code Conversion
The code conversion process is performed by the pikex conversion compiler, generating Python code that executes using the Pike runtime library, operating in a SciPy Python environment.
The result of this process is a set of Python files that preserve the structure, logic and operational flow of the original IDL implementation. In addition, the pikex command generates the following files:[/vc_column_text][vc_column_text]
__init__.py | Used to define a Python package out of the contents of the directory parsed. Helpful in the management and execute of large code packages. | |
__pikelib__.pkl | A Pike library file that contains the definitions of all the routines translated and exposed in the created package. These definitions ensure proper calling sequence conversion. |
[/vc_column_text][/vc_column][/vc_row][vc_row][vc_column][vc_column_text]
Code Editing
Ideally the Pike converter could convert all IDL implemented logic and structure into Python, but experience has shown that complex source files do require some manual editing. Pike will assist with this where it can, flagging trouble areas or detected translation errors.
Common areas that require manual editing and review include:
- Unknown routines being called. This is often caused from an IDL library routine missing from Pike, or from a user routine not available during conversion. If a user routine is not discovered, add the routine to Pike’s search path (PIKE_PATH), or include the routines source file to the pikex conversion command.
- Complex memory/array uses in the IDL source code. IDL and Python index arrays differently, specifically IDL uses [X,Y], while Python uses [Y,X]. While Pike attempts to manage these differences, complex use of multiple dimension arrays often require manual review during the conversion process.
- Large, nested uses of array concatenation (square brackets) in IDL often leads to translation errors and incorrect array shapes.
- Indexing of a scalar variable. While this is a valid option in IDL, it is not implemented in Python and it’s use results in an error.
Of note, a helpful command to use in debugging translation issues is the IDL stop command, which is translated into a Python debug session:
[/vc_column_text][/vc_column][/vc_row][vc_row][vc_column][vc_column_text css=”.vc_custom_1475528102270{margin-top: -30px !important;}”]
import pdb pdb.set_trace()
[/vc_column_text][vc_column_text]
Code Execution
The execution of the resultant Python implementation is just as it was in IDL, except Python conversions and syntax is utilized. The general structure of execution is as follows:
- Start an IPython session that has Pike installed.
- Import the translated functionality. Either the translated file, or crated Python package (directory that contains the translated functionality).
import <filename>
or
import <directory name>
- Call the routine using the same calling sequence as IDL
filename.routinename()
Note the following:
- Full keyword names are required in Python.
- All Python routine functions. Procedures are not implemented in Python .
- In Python, all output parameters are returned as the output value of a function.
[/vc_column_text][vc_separator color=”custom” border_width=”2″ accent_color=”#444444″ css=”.vc_custom_1475530398578{margin-bottom: 8px !important;border-bottom-width: 0px !important;padding-bottom: 0px !important;}”][vc_column_text css=”.vc_custom_1475530465533{margin-top: 0px !important;margin-bottom: 0px !important;border-top-width: 0px !important;border-bottom-width: 0px !important;padding-top: 0px !important;padding-bottom: 0px !important;}”]
Additional Pike Details
[/vc_column_text][/vc_column][/vc_row][vc_row][vc_column]
[/vc_column][/vc_row][vc_row][vc_column][/vc_column][/vc_row]