def create_png(products, **kwargs): """ Create image for products. This is a kind of sandbox version. """ utils.makedir(config.IMG_DIR) # Load some images img_shape = shape_image() img_blue = plain_image(color=(0, 0, 127)) img_shape_filled = shape_image_filled() # Get dutch time label tz_amsterdam = pytz.timezone('Europe/Amsterdam') tz_utc = pytz.timezone('UTC') # Loop products for product in products: utc = tz_utc.localize(product.datetime) amsterdam = utc.astimezone(tz_amsterdam) label = amsterdam.strftime('%Y-%m-%d %H:%M') label_from_kwargs = kwargs.get('label', '') if label_from_kwargs: label += ' ' + label_from_kwargs offset = 0.1, 0.9 # Get data image try: with product.get() as h5: array = h5['precipitation'][...] / h5.attrs['composite_count'] mask = np.equal(array, h5.attrs['fill_value']) img_radars = radars_image(h5=h5, label=label, offset=offset) except IOError: logging.debug('Does not exist: {}'.format(product.path)) continue masked_array = np.ma.array(array, mask=mask) img_rain = data_image(masked_array, max_rain=2, threshold=0.008) timestamp = utils.datetime2timestamp(product.datetime) filename = '{}{}.{}'.format( timestamp, kwargs.get('postfix', ''), kwargs.get('format', 'png'), ) # Merge and save path = os.path.join(config.IMG_DIR, filename) utils.merge([ img_radars, img_rain, img_shape, img_shape_filled, img_blue, ]).save(path) logging.info('saved {}.'.format(os.path.basename(path))) logging.debug('saved {}.'.format(path))
def create_png_for_animated_gif(products, **kwargs): """ Create image for products. This is the tweaked version that creates the pngs for use in the animated gif. """ utils.makedir(config.IMG_DIR) # Load some images img_mapbox = mapbox_image() img_osm = osm_image() img_shape = shape_image() img_blue = plain_image(color=(0, 0, 127)) img_shape_filled = shape_image_filled() # Get dutch time label tz_amsterdam = pytz.timezone('Europe/Amsterdam') tz_utc = pytz.timezone('UTC') # Loop products for product in products: utc = tz_utc.localize(product.datetime) amsterdam = utc.astimezone(tz_amsterdam) #label = amsterdam.strftime('%Y-%m-%d %H:%M') label = amsterdam.strftime('%H:%M') offset = 0.25, 0.82 # Get data image with product.get() as h5: array = h5['precipitation'][...] / h5.attrs['composite_count'] mask = np.equal(array, h5.attrs['fill_value']) img_radars = radars_image(h5=h5, label=label, offset=offset) masked_array = np.ma.array(array, mask=mask) img_rain = data_image(masked_array, max_rain=2, threshold=0.008) timestamp = utils.datetime2timestamp(product.datetime) filename = '{}{}.{}'.format( timestamp, kwargs.get('postfix', ''), kwargs.get('format', 'png'), ) # Merge and save path = os.path.join(config.IMG_DIR, filename) utils.merge([ img_radars, img_rain, img_mapbox, img_shape, img_shape_filled, img_blue, ]).save(path) logging.info('saved {}.'.format(os.path.basename(path))) logging.debug('saved {}.'.format(path))