gavo.utils.imgtools module

Some miscellaneous helpers for making images and such.

As this may turn into a fairly expensive import, this should not be imported by utils.__init__. Hence, none of these functions are in gavo.api or gavo.utils.

gavo.utils.imgtools.colorJpegFromNumpyArrays(rPix: ndarray[Any, dtype[ScalarType]], gPix: ndarray[Any, dtype[ScalarType]], bPix: ndarray[Any, dtype[ScalarType]], gamma: float = 0.25) bytes[source]

as jpegFromNumpyArray, except a color jpeg is built from red, green, and blue pixels.

gavo.utils.imgtools.getScaledPNG(srcFile: str, newWidth: int) bytes[source]

returns PNG bytes that is a scaled version of an image in srcFile.

srcFile must correspond to something that PIL can read. Since scaling really sucks for non-RGB images, we unconditionally convert whatever we get to 3-band RGB.

gavo.utils.imgtools.jpegFromNumpyArray(pixels: ndarray[Any, dtype[ScalarType]], gamma: float = 0.25) bytes[source]

returns a normalized JPEG for numpy pixels.

pixels is assumed to come from FITS arrays, which are flipped wrt to jpeg coordinates, which is why we’re flipping here.

The normalized intensities are scaled by v^gamma; we believe the default helps with many astronomical images

gavo.utils.imgtools.scaleNumpyArray(arr: ndarray[Any, dtype[ScalarType]], destSize: int) ndarray[Any, dtype[ScalarType]][source]

returns the numpy array arr scaled down to approximately destSize.