1.5.1.2.5. polar2grid.compare module

Script for comparing writer output.

class polar2grid.compare.ArrayComparisonResult(almost_equal: 'bool', num_diff_pixels: 'int', total_pixels: 'int', different_shape: 'bool')[source]

Bases: object

almost_equal: bool
different_shape: bool
property failed
num_diff_pixels: int
total_pixels: int
class polar2grid.compare.CompareHelper(atol: float = 0.0, rtol: float = 0.0, margin_of_error: float = 0.0, create_plot: bool = False)[source]

Bases: object

Wrapper around various comparison operations.

compare(input1, input2, **kwargs) list[polar2grid.compare.FileComparisonResults][source]
compare_dirs(dir1, dir2, **kwargs) list[polar2grid.compare.FileComparisonResults][source]
compare_files(file1, file2, file_type=None, **kwargs)[source]
class polar2grid.compare.FileComparisonResults(file1: 'str', file2: 'str', files_missing: 'bool', unknown_file_type: 'bool', sub_results: 'list[ArrayComparisonResult]' = <factory>)[source]

Bases: object

property any_failed: bool
file1: str
file2: str
files_missing: bool
sub_results: list[polar2grid.compare.ArrayComparisonResult]
unknown_file_type: bool
class polar2grid.compare.FlatArrayComparisonResult(almost_equal: 'bool', num_diff_pixels: 'int', total_pixels: 'int', different_shape: 'bool', shape1: 'tuple', shape2: 'tuple', dtype1: 'np.dtype', dtype2: 'np.dtype')[source]

Bases: ArrayComparisonResult

dtype1: dtype
dtype2: dtype
shape1: tuple
shape2: tuple
class polar2grid.compare.VariableComparisonResult(almost_equal: 'bool', num_diff_pixels: 'int', total_pixels: 'int', different_shape: 'bool', variable: 'str', variable_missing: 'bool')[source]

Bases: ArrayComparisonResult

property failed
variable: str
variable_missing: bool
polar2grid.compare._compare_gtiff_colormaps(cmap1: dict, cmap2: dict, **kwargs) VariableComparisonResult[source]
polar2grid.compare._file_type(str_val)[source]
polar2grid.compare._generate_html_summary(output_filename, file_comparison_results)[source]
polar2grid.compare._generate_matplotlib_1d_thumbnail(input_arr, output_thumbnail_path, max_width) bool[source]
polar2grid.compare._generate_matplotlib_thumbnail(input_arr, output_thumbnail_path, max_width=512) bool[source]
polar2grid.compare._generate_pillow_thumbnail(input_arr, output_thumbnail_path, max_width=512) bool[source]
polar2grid.compare._generate_subresult_table_row(img_dst_dir: str, file_comparison_result: FileComparisonResults, sub_result: ArrayComparisonResult) str[source]
polar2grid.compare._generate_table_rows(output_filename: str, file_comparison_results: list[polar2grid.compare.FileComparisonResults]) list[str][source]
polar2grid.compare._generate_thumbnail(input_arr, output_thumbnail_path, max_width=512) bool[source]
polar2grid.compare._generate_thumbnail_html(data_pathname: str, variable: Optional[str], img_dst_dir: str, tn_suffix: str, shape: Optional[tuple], dtype: Optional[dtype]) str[source]
polar2grid.compare._get_binary_array(input_filename: str, variable: str, shape: Optional[tuple], dtype: dtype) Optional[ndarray][source]
polar2grid.compare._get_geotiff_array(gtiff_fn, dtype=None)[source]
polar2grid.compare._get_geotiff_colormap(gtiff_fn, band_idx=1)[source]
polar2grid.compare._get_hdf5_array(input_filename: str, variable: str, shape: Optional[tuple], dtype: Optional[dtype]) Optional[ndarray][source]
polar2grid.compare._get_hdf5_variables(variables, name, obj)[source]
polar2grid.compare._get_image_array(img_filename: str, variable: Optional[str] = None, shape: Optional[tuple] = None, dtype: Optional[dtype] = None) Optional[ndarray][source]
polar2grid.compare._get_mpl_figsize(input_shape, max_width) tuple[int, int][source]
polar2grid.compare._get_netcdf_array(input_filename: str, variable: str, shape: Optional[tuple], dtype: Optional[dtype]) Optional[ndarray][source]
polar2grid.compare._get_thumbnail_array(input_data_path: str, variable: Optional[str], shape: Optional[tuple], dtype: Optional[dtype]) Optional[ndarray][source]
polar2grid.compare._tranpose_for_thumbnail_if_multiband_array(arr: ndarray) ndarray[source]
polar2grid.compare.compare_array(array1, array2, plot=False, **kwargs) ArrayComparisonResult[source]
polar2grid.compare.compare_binary(fn1, fn2, shape, dtype, atol=0.0, margin_of_error=0.0, **kwargs) list[polar2grid.compare.ArrayComparisonResult][source]
polar2grid.compare.compare_geotiff(gtiff_fn1, gtiff_fn2, atol=0.0, margin_of_error=0.0, **kwargs) list[polar2grid.compare.ArrayComparisonResult][source]

Compare 2 single banded geotiff files.

Note

The binary arrays will be converted to 32-bit floats before comparison.

polar2grid.compare.compare_hdf5(h1_name, h2_name, variables, atol=0.0, margin_of_error=0.0, **kwargs) list[polar2grid.compare.ArrayComparisonResult][source]
polar2grid.compare.compare_image(im1_name, im2_name, atol=0.0, margin_of_error=0.0, **kwargs) list[polar2grid.compare.ArrayComparisonResult][source]
polar2grid.compare.compare_netcdf(nc1_name, nc2_name, variables, atol=0.0, margin_of_error=0.0, **kwargs) list[polar2grid.compare.VariableComparisonResult][source]
polar2grid.compare.isclose_array(array1, array2, atol=0.0, rtol=0.0, margin_of_error=0.0, **kwargs) ArrayComparisonResult[source]

Compare 2 binary arrays per pixel.

Two pixels are considered different if the absolute value of their difference is greater than 1. This function assumes the arrays are in useful data types, which may cause erroneous results. For example, if both arrays are unsigned integers and the different results in a negative value overflow will occur and the threshold will likely not be met.

Parameters:
  • array1 – numpy array for comparison

  • array2 – numpy array for comparison

Returns:

1 if more than margin_of_error pixels are different, 0 otherwise.

polar2grid.compare.main(argv=['-b', 'html', '-d', 'build/doctrees', 'source', 'build/html'])[source]
polar2grid.compare.num_failed_files(file_comparison_results: list[polar2grid.compare.FileComparisonResults]) int[source]
polar2grid.compare.plot_array(array1, array2, cmap='viridis', vmin=None, vmax=None, **kwargs)[source]

Debug two arrays being different by visually comparing them.