100 likes | 119 Views
The ESMF Python Interface (ESMP) facilitates access to ESMF Field Regridding by combining ESMF and Python features like unstructured mesh support, parallel regridding, and error handling. The interface allows seamless data representation through Numpy arrays in Python, enabling users to work with unstructured meshes, perform field regridding operations, and benefit from features like automatic documentation via Pydoc. Despite being in an early BETA stage, ESMP offers scalable parallel processing, different regridding methods, and file-based regridding functionalities. Visit the provided link for more on the SCRIP file format and limitations. Automatic documentation generation is possible using the 'pydoc' command, offering insights into ESMP functions like ESMP_FieldCreate. To download ESMP, access the esmfcontrib Sourceforge CVS repository and make sure to meet the specified dependencies, including Python 2.6 or higher, ctypes, Numpy, and ESMF installation. Optional dependencies such as NetCDF, LAPACK, and GNUMake can enhance functionality. The interface introduces coding standards and conventions for optimal utilization, such as handling return arguments and Numpy array input type forcing.
E N D
Earth System Modeling FrameworkPython Interface (ESMP)October 2011 Ryan O’KuinghttonsRobert OehmkeCecelia DeLuca
Architecture • ESMF provides a superstructure for assembling geophysical components into applications. • ESMF also provides an infrastructure that modelers use to • Generate and apply interpolation weights • Handle metadata, time management, data I/O and communications, and other functions • Access third party libraries Components Layer Gridded Components Coupler Components ESMF Superstructure User Code Model Layer ESMF Infrastructure Fields and Grids Layer Low Level Utilities External Libraries MPI, NetCDF, … The purpose of the ESMF Python interface (ESMP) is to provide access to ESMF Field Regridding.
Python Interface Features ESMF related features: • Unstructured Mesh • Field built on Mesh • Parallel regridding (bilinear, higher order, or conservative) Python related features: • Numpy arrays for data representation in Python • Pythonic approach to error handling and multiple return values • Automatic documentation via Pydoc Other neat features: • Open source and freely available!
Limitations • Data structure related: • No logically rectangular grid representation • No FieldBundle class, only single Fields • No access to Mesh coordinates • No access to Field bounds • Testing related: • Only tested on Darwin/gfortran platform • Parallel implementation is not fully tested • Does not undergo nightly ESMF regression testing ESMP is in an early BETA stage! The Python interface is currently not on the ESMF task list. If you would like to see more functionality included, please contact ESMF support so this can be made a priority with the ESMF Change Review Board.
Data Representation – Numpy Numpy – scientific computing with Python, a piece of Scipy • Used to represent data arrays on the Python front-end • Numpy arrays are passed in and out of ESMP interfaces • Input parameters in Numpy arrays are copied into internal ESMP data structures, but referenced out of internal ESMP data structures. Sample Code: Declare a Numpy array ungriddedLBoundN = Numpy.array([1,1]) Create an ESMP_Field, copy data from Numpy array field = ESMP_FieldCreate(...ungriddedLBoundN, ...) Get a pointer to Field data as a Numpy array fieldPtr = ESMP_FieldGetPtr(field, 0) Access Field data as a Numpy array, referencing the internal data for i in range(num_node): fieldPtr[i] = 10
ESMP Field regridding Functions in much the same way as Field regridding in ESMF routehandle = ESMP_FieldRegridStore (srcfield, dstfield, ESMP_REGRIDMETHOD_BILINEAR, ESMP_UNMAPPEDACTION_ERROR) ESMP_FieldRegrid(srcfield, dstfield, routehandle) ESMP_FieldRegridRelease(routehandle) Features: • Fully parallel, and highly scalable • Bilinear, higher order, or conservative • 2D or 3D unstructured Meshes • Optional error handling of unmapped destination points File based regridding: • ‘remap’ module (from ESMP import remap) • Drives the ESMF_RegridWeightGen application • Inputs: NetCDF grid files • Output: NetCDF weights file • Supports: ESMF and SCRIP file format http://climate.lanl.gov/Software/SCRIP/ • Limitations: Serial NetCDF file IO
Automatic documentation Documentation can be generated with the ‘pydoc’ command at terminal prompt: $: pydoc ESMP Help on module ESMP: NAME ESMP - The ESMF Python API ... FUNCTIONS ESMP_FieldCreate(mesh, typekind, gridToFieldMap, ungriddedLBound, ungriddedUBound, name) RETURN ESMP_Field :: field ESMP_TypeKind :: typekind Numpy.array :: gridToFieldMap Numpy.array :: ungriddedLBound Numpy.array :: ungriddedUBound string :: name ...
Software access and dependencies The software is available for download from the esmfcontrib Sourceforge cvs repository: cvs -z3 -d:pserver:anonymous@esmfcontrib.cvs.sourceforge.net:/cvsroot/esmfcontrib co -P -rESMF_5_3_0_beta_snapshot_09 python Dependencies: • Python 2.6 or higher – add top level ESMP directory to PYTHONPATH • Ctypes • http://docs.python.org/library/ctypes.html • Not supported on AIX • Numpy • http://numpy.scipy.org/ • ESMF installation • ESMF_5_3_0_beta_snapshot_09 or higher! • Shared libraries not supported on some platforms (notably Darwin), see the supported platforms table from ESMF for more information: • http://www.earthsystemmodeling.org/download/platforms/ • ESMFMKFILE environment variable pointing to installation esmf.mk file Optional dependencies: • NetCDF - 'remap' interface to ESMF_RegridWeightGen • LAPACK - higher order patch regridding • GNUMake - terminal helper commands
Specific Questions on ESMP Style and Conventions • Argument returns in ESMP_XXXGet() routines: • Could receive arguments in a tuple of multiple return values • Could receive each piece of info in a single Get call • Could also use Python class structures to pass allocated memory into a Get routine to fill with data • Type forcing of Numpy array input arguments • Could force a specific type for these array inputs • Could cast input array to type needed by ESMF • Error handling • No return codes in ESMP -> Abort on bad ESMF return code • Backtrace from Python -> Send to stdout or ESMF logs? • Any other issues of style or convention?
Future work proposal • Add support for the following: • Get bounds information from a Field • Get coordinate information from a Mesh • Structured grids • Output of numerical results • Mesh and Field information in vtk file format using ESMP_MeshWrite(plot with Visit or Paraview) • NetCDF format? • Support for NetCDF IO of Field data? Serial or Parallel? • Add support for Components and States? • Anything else?