def test_filter(self): img = Image.open(open(datafile('test_radar_filter.gif'))) fmt = radar_get_format(3) img2 = filter_radar(img, fmt) self.assertEqual(img2.getpixel((8, 1)), (255, 255, 255)) self.assertEqual(img2.getpixel((4, 5)), (255, 255, 255)) self.assertEqual(img2.getpixel((1, 8)), (0, 120, 254))
def align_radar(request): r = RadarPadavin.objects.all()[0] fmt = radar_get_format(r.format_id) geotiff = annotate_geo_radar(r.pic, fmt, scale=4) img = Image.open(StringIO(geotiff)).convert('RGBA') a = numpy.array(numpy.asarray(img)) d = numpy.zeros(a.shape[:2], dtype=numpy.bool) for c in fmt.COLOR_IGNORE: d |= (a[:,:,0] == c[0]) & (a[:,:,1] == c[1]) & (a[:,:,2] == c[2]) a[d,3] = 200 a[~d,3] = 0 return _png_image_fromarray(a)
def align_radar(request): r = RadarPadavin.objects.all()[0] fmt = radar_get_format(r.format_id) geotiff = annotate_geo_radar(r.pic, fmt, scale=4) img = Image.open(StringIO(geotiff)).convert('RGBA') a = numpy.array(numpy.asarray(img)) d = numpy.zeros(a.shape[:2], dtype=numpy.bool) for c in fmt.COLOR_IGNORE: d |= (a[:, :, 0] == c[0]) & (a[:, :, 1] == c[1]) & (a[:, :, 2] == c[2]) a[d, 3] = 200 a[~d, 3] = 0 return _png_image_fromarray(a)
def _png_image(model): model.processed.open() img = Image.open(model.processed).convert('RGBA') fmt = radar_get_format(model.format_id) a = numpy.array(numpy.asarray(img)) # select white color d = (a[:,:,0] == fmt.COLOR_BG[0]) & \ (a[:,:,1] == fmt.COLOR_BG[1]) & \ (a[:,:,2] == fmt.COLOR_BG[2]) # make white pixels completely transparent a[d,3] = 0 # make non-white pixels partially transparent a[~d,3] = 128 return _png_image_fromarray(a)
def _png_image(model): model.processed.open() img = Image.open(model.processed).convert('RGBA') fmt = radar_get_format(model.format_id) a = numpy.array(numpy.asarray(img)) # select white color d = (a[:,:,0] == fmt.COLOR_BG[0]) & \ (a[:,:,1] == fmt.COLOR_BG[1]) & \ (a[:,:,2] == fmt.COLOR_BG[2]) # make white pixels completely transparent a[d, 3] = 0 # make non-white pixels partially transparent a[~d, 3] = 128 return _png_image_fromarray(a)
def load_from_model(self, instance): if instance.format_id > 0: self.fmt = radar_get_format(instance.format_id) self.load_from_string(instance.processed.read()) self.last_modified = instance.last_modified
def __init__(self): self.bands = {} self.last_modified = None self.fmt = radar_get_format(0) self.clean()