#!/usr/bin/env python3 # -*- coding: utf-8 -*- # I need from glob import glob # Pytroll/SatPy needs from satpy import Scene, MultiScene from satpy.writers import compute_writer_results # Below is my version from PR#2394 where I copied multiscene.py to wd from functools import partial import multiscene from multiscene import stack sat = 'MetopB' reader = 'avhrr_l1b_eps' area = 'eurol' generate = True # Available composites in this script (see .../satpy/etc/composites/visir.yaml): # ******************************************************************************** # ['cloud_phase_distinction', 'cloud_phase_distinction_raw', 'cloudtop', 'green_snow', # 'ir108_3d', 'ir_cloud_day', 'natural_color', 'natural_color_raw', 'natural_enh', # 'natural_with_night_fog', 'night_fog', 'night_microphysics', 'overview', 'overview_raw'] composites = ['natural_color', 'ir108_3d'] outdir = './images' # Use blend_type one of 'select_with_weights', 'blend_with_weights', 'stack_no_weights' or None #blend_type = 'stack_no_weights' #blend_type = 'select_with_weights' blend_type = 'blend_with_weights' scenes = [] for passnum in ['1', '2', '3']: passfiles = glob('./pass'+passnum+'/AVHR_xxx*Z') scenes.append(Scene(filenames=passfiles, reader=reader)) mscn = MultiScene(scenes) mscn.load(composites, generate=generate) if blend_type in ['select_with_weights', 'blend_with_weights']: composites.append('satellite_zenith_angle') weights = True else: weights = False new_mscn = mscn.resample(area, resampler='nearest', reduce_data=False) if weights: weights = [] for scn in new_mscn.scenes: w = scn['satellite_zenith_angle'] w = w / w.max(dim = ['x', 'y']) w = (1 - w * w) weights.append(w * w) composites.remove('satellite_zenith_angle') stack_with_weights = partial(stack, weights=weights, blend_type=blend_type) new_scn = new_mscn.blend(blend_function=stack_with_weights) else: new_scn = new_mscn.blend() if generate: for composite in composites: new_scn.save_dataset(composite, outdir+'/'+sat+'-'+composite+'-'+area+'-'+blend_type+'.png', fill_value=0) else: save_objects = [] for composite in composites: save_objects.append(new_scn.save_dataset(composite, base_dir='.', filename=outdir+'/'+sat+'-{name}-'+area+'-'+blend_type+'.png', compute=False, fill_value=0)) compute_writer_results(save_objects)