def compare_render(orig_data: ArrayLike, rendered_data: ArrayLike, previous_render: Optional[ArrayLike] = None, atol: Optional[float] = 1.0): """Compare an expected original array with the rendered result. Parameters ---------- orig_data Expected output result array. This will be converted to an RGBA array to be compared against the rendered data. rendered_data Actual rendered result as an RGBA 8-bit unsigned array. previous_render Previous instance of a render that the current render should not be equal to. atol Absolute tolerance to be passed to :func:`numpy.testing.assert_allclose`. """ predicted = make_rgba(orig_data) np.testing.assert_allclose(rendered_data.astype(float), predicted.astype(float), atol=atol) if previous_render is not None: # assert not allclose pytest.raises(AssertionError, np.testing.assert_allclose, rendered_data, previous_render, atol=10)
def set_adiacenta(self, M_adiacenta: npt.ArrayLike): """ :param M_adiacenta: adjacency matrix """ self.M_adiacenta = M_adiacenta.astype('int') self.nodes = self.get_nodes() self.edges = self.get_edges()
def fma(a: ArrayLike, b: ArrayLike, c: ArrayLike) -> np.ndarray: a = np.asarray(a) b = np.asarray(b) c = np.asarray(c) dtype = np.find_common_type([], [a.dtype, b.dtype, c.dtype]) a = a.astype(dtype) b = b.astype(dtype) c = c.astype(dtype) if dtype == np.single: return _pyfma.fmaf(a, b, c) elif dtype == np.double: return _pyfma.fma(a, b, c) assert dtype == np.longdouble return _pyfma.fmal(a, b, c)
def build_thumbnail(image_array: npt.ArrayLike, thumbnail_dir: Path): image_array = image_array - np.min(image_array) + 1.001 image_array = np.log(image_array) image_array = 205 * image_array / (np.max(image_array)) auto_contrast_image = Image.fromarray(image_array.astype("uint8")) auto_contrast_image = ImageOps.autocontrast(auto_contrast_image, cutoff=0.1) filename = str(uuid4()) + ".png" # file = io.BytesIO() file = thumbnail_dir / Path(filename) auto_contrast_image.save(file, format="PNG") return file
def wrap( longitudes: npt.ArrayLike, base: Optional[float] = -180.0, period: Optional[float] = 360.0, decimals: Optional[int] = 8, ) -> np.ndarray: """ Transform the longitude values to be within the closed interval [base, base + period]. Parameters ---------- longitudes : ArrayLike One or more longitude values (degrees) to be wrapped. base : float, default=-180.0 The start limit (degrees) of the closed interval. period : float, default=360.0 The end limit (degrees) of the closed interval expressed as a length from the `base`. Returns ------- ndarray The transformed longitude values. Notes ----- .. versionadded:: 0.1.0 """ # # TODO: support radians # if not isinstance(longitudes, Iterable): longitudes = [longitudes] longitudes = np.round(longitudes, decimals=decimals) result = ((longitudes.astype(np.float64) - base + period * 2) % period) + base return result