grib2io_interp
Introduction
grib2io_interp is a component package to the parent package, grib2io.
This package provides interfaces to the Fortran-based NCEPLIBS-ip
general interpolation library. The interface supports performing scalar and vector interpolation. grib2io_interp.interpolate
is a F2PY extension module that contains 2 subroutines: interpolate_scalar
and interpolate_vector
. These
subroutines serve as wrappers to the NCEPLIBS-ip subroutines ipolates_grib2
and ipolatev_grib2
respectively.
It is recommended that you access these interpolation subroutines via grib2io.interpolate()
.
OpenMP Support
NCEPLIBS-ip can be built with support for OpenMP threading. This is also supported in grib2io-interp. The
F2PY signatures for interpolate_scalar
and interpolate_vector
subroutines contain the keyword threadsafe
which unlocks Python's global interpretor lock (gil) and allows for threading. grib2io-interp contains a
second F2PY extension module, grib2io_interp.openmp_handler
, that allows the user to get and set the number
of OpenMP threads. These functions are made public by get_openmp_threads()
and
set_openmp_threads()
.
1""" 2Introduction 3============ 4 5grib2io_interp is a component package to the parent package, [grib2io](https://github.com/NOAA-MDL/grib2io). 6This package provides interfaces to the Fortran-based [NCEPLIBS-ip](https://github.com/NOAA-EMC/NCEPLIBS-ip) 7general interpolation library. The interface supports performing scalar and vector interpolation. `grib2io_interp.interpolate` 8is a F2PY extension module that contains 2 subroutines: `interpolate_scalar` and `interpolate_vector`. These 9subroutines serve as wrappers to the NCEPLIBS-ip subroutines `ipolates_grib2` and `ipolatev_grib2` respectively. 10 11It is **recommended** that you access these interpolation subroutines via [`grib2io.interpolate()`](https://noaa-mdl.github.io/grib2io/grib2io.html#interpolate). 12 13OpenMP Support 14============== 15 16NCEPLIBS-ip can be built with support for OpenMP threading. This is also supported in grib2io-interp. The 17F2PY signatures for `interpolate_scalar` and `interpolate_vector` subroutines contain the keyword `threadsafe` 18which unlocks Python's global interpretor lock (gil) and allows for threading. grib2io-interp contains a 19second F2PY extension module, `grib2io_interp.openmp_handler`, that allows the user to get and set the number 20of OpenMP threads. These functions are made public by `grib2io_interp.get_openmp_threads()` and 21`grib2io_interp.set_openmp_threads()`. 22""" 23 24from .__config__ import grib2io_interp_version as __version__ 25from .__config__ import has_openmp_support 26 27def get_openmp_threads(): 28 """ 29 Return the number of OpenMP threads. 30 31 Returns 32 ------- 33 int 34 The number of OpenMP threads. 35 """ 36 try: 37 from . import openmp_handler 38 return openmp_handler.get_openmp_threads() 39 except(ImportError): 40 pass 41 42def set_openmp_threads(n: int): 43 """ 44 Set the number of OpenMP threads. 45 46 Parameters 47 ---------- 48 n 49 The number of OpenMP threads. 50 """ 51 if n < 1: 52 raise ValueError(f'Number of threads must be > 0.') 53 try: 54 from . import openmp_handler 55 openmp_handler.set_openmp_threads(n) 56 except(ImportError): 57 pass
28def get_openmp_threads(): 29 """ 30 Return the number of OpenMP threads. 31 32 Returns 33 ------- 34 int 35 The number of OpenMP threads. 36 """ 37 try: 38 from . import openmp_handler 39 return openmp_handler.get_openmp_threads() 40 except(ImportError): 41 pass
Return the number of OpenMP threads.
Returns
- int: The number of OpenMP threads.
43def set_openmp_threads(n: int): 44 """ 45 Set the number of OpenMP threads. 46 47 Parameters 48 ---------- 49 n 50 The number of OpenMP threads. 51 """ 52 if n < 1: 53 raise ValueError(f'Number of threads must be > 0.') 54 try: 55 from . import openmp_handler 56 openmp_handler.set_openmp_threads(n) 57 except(ImportError): 58 pass
Set the number of OpenMP threads.
Parameters
- n: The number of OpenMP threads.