Testing Utilities (pyart.testing)

Utilities helpful when writing and running unit tests.

Testing functions

make_empty_ppi_radar(ngates, rays_per_sweep, …) Return an Radar object, representing a PPI scan.
make_target_radar() Return a PPI radar with a target like reflectivity field.
make_single_ray_radar() Return a PPI radar with a single ray taken from a ARM C-SAPR Radar.
make_velocity_aliased_radar([alias]) Return a PPI radar with a target like reflectivity field.
make_empty_grid(grid_shape, grid_limits) Make an empty grid object without any fields or metadata.
make_target_grid() Make a sample Grid with a rectangular target.
make_storm_grid() Make a sample Grid with a rectangular storm target.
make_normal_storm(sigma, mu) Make a sample Grid with a gaussian storm target.

Testing classes

InTemporaryDirectory([suffix, prefix, dir]) Create, return, and change directory to a temporary directory.
class pyart.testing.InTemporaryDirectory(suffix='', prefix='tmp', dir=None)[source]

Bases: pyart.testing.tmpdirs.TemporaryDirectory

Create, return, and change directory to a temporary directory.

Examples

>>> import os
>>> my_cwd = os.getcwd()
>>> with InTemporaryDirectory() as tmpdir:
...     _ = open('test.txt', 'wt').write('some text')
...     assert os.path.isfile('test.txt')
...     assert os.path.isfile(os.path.join(tmpdir, 'test.txt'))
>>> os.path.exists(tmpdir)
False
>>> os.getcwd() == my_cwd
True

Methods

cleanup  
__class__

alias of builtins.type

__delattr__(self, name, /)

Implement delattr(self, name).

__dict__ = mappingproxy({'__module__': 'pyart.testing.tmpdirs', '__doc__': " Create, return, and change directory to a temporary directory.\n\n Examples\n --------\n >>> import os\n >>> my_cwd = os.getcwd()\n >>> with InTemporaryDirectory() as tmpdir:\n ... _ = open('test.txt', 'wt').write('some text')\n ... assert os.path.isfile('test.txt')\n ... assert os.path.isfile(os.path.join(tmpdir, 'test.txt'))\n >>> os.path.exists(tmpdir)\n False\n >>> os.getcwd() == my_cwd\n True\n ", '__enter__': <function InTemporaryDirectory.__enter__>, '__exit__': <function InTemporaryDirectory.__exit__>})
__dir__(self, /)

Default dir() implementation.

__enter__(self)[source]
__eq__(self, value, /)

Return self==value.

__exit__(self, exc, value, tb)[source]
__format__(self, format_spec, /)

Default object formatter.

__ge__(self, value, /)

Return self>=value.

__getattribute__(self, name, /)

Return getattr(self, name).

__gt__(self, value, /)

Return self>value.

__hash__(self, /)

Return hash(self).

__init__(self, suffix='', prefix='tmp', dir=None)

Initialize self. See help(type(self)) for accurate signature.

__init_subclass__()

This method is called when a class is subclassed.

The default implementation does nothing. It may be overridden to extend subclasses.

__le__(self, value, /)

Return self<=value.

__lt__(self, value, /)

Return self<value.

__module__ = 'pyart.testing.tmpdirs'
__ne__(self, value, /)

Return self!=value.

__new__(*args, **kwargs)

Create and return a new object. See help(type) for accurate signature.

__reduce__(self, /)

Helper for pickle.

__reduce_ex__(self, protocol, /)

Helper for pickle.

__repr__(self, /)

Return repr(self).

__setattr__(self, name, value, /)

Implement setattr(self, name, value).

__sizeof__(self, /)

Size of object in memory, in bytes.

__str__(self, /)

Return str(self).

__subclasshook__()

Abstract classes can override this to customize issubclass().

This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).

__weakref__

list of weak references to the object (if defined)

cleanup(self)
pyart.testing.make_empty_grid(grid_shape, grid_limits)[source]

Make an empty grid object without any fields or metadata.

Parameters:
grid_shape : 3-tuple of floats

Number of points in the grid (z, y, x).

grid_limits : 3-tuple of 2-tuples

Minimum and maximum grid location (inclusive) in meters for the z, y, x coordinates.

Returns:
grid : Grid

Empty Grid object, centered near the ARM SGP site (Oklahoma).

pyart.testing.make_empty_ppi_radar(ngates, rays_per_sweep, nsweeps)[source]

Return an Radar object, representing a PPI scan.

Parameters:
ngates : int

Number of gates per ray.

rays_per_sweep : int

Number of rays in each PPI sweep.

nsweeps : int

Number of sweeps.

Returns:
radar : Radar

Radar object with no fields, other parameters are set to default values.

pyart.testing.make_empty_rhi_radar(ngates, rays_per_sweep, nsweeps)[source]

Return an Radar object, representing a RHI scan.

Parameters:
ngates : int

Number of gates per ray.

rays_per_sweep : int

Number of rays in each PPI sweep.

nsweeps : int

Number of sweeps.

Returns:
radar : Radar

Radar object with no fields, other parameters are set to default values.

pyart.testing.make_normal_storm(sigma, mu)[source]

Make a sample Grid with a gaussian storm target.

pyart.testing.make_single_ray_radar()[source]

Return a PPI radar with a single ray taken from a ARM C-SAPR Radar.

Radar object returned has ‘reflectivity_horizontal’, ‘norm_coherent_power’, ‘copol_coeff’, ‘dp_phase_shift’, ‘diff_phase’, and ‘differential_reflectivity’ fields with no metadata but a ‘data’ key. This radar is used for unit tests in correct modules.

pyart.testing.make_storm_grid()[source]

Make a sample Grid with a rectangular storm target.

pyart.testing.make_target_grid()[source]

Make a sample Grid with a rectangular target.

pyart.testing.make_target_radar()[source]

Return a PPI radar with a target like reflectivity field.

pyart.testing.make_velocity_aliased_radar(alias=True)[source]

Return a PPI radar with a target like reflectivity field.

Set alias to False to return a de-aliased radar.

pyart.testing.make_velocity_aliased_rhi_radar(alias=True)[source]

Return a RHI radar with a target like reflectivity field.

Set alias to False to return a de-aliased radar.