def IR_039c_CO2(self): """ IR_039 channel, but compensated for the CO2 absorption """ from trollimage.image import Image as trollimage self.co2corr_chan() self.check_channels("_IR39Corr") img = GeoImage(self["_IR39Corr"].data, self.area, self.time_slot, fill_value=(0, 0, 0), mode="L") #min_data = prop.min() #max_data = prop.max() min_data = 210 # same as for IR_039 in get_input_msg.py max_data = 340 # same as for IR_039 in get_input_msg.py colorize = True if colorize: # use trollimage to create a color map cm = deepcopy(rainbow) cm.set_range(min_data, max_data) # colorize the image img.colorize(cm) return img
def ndvi(self): """Make a normalized vegitation index image from Seviri channels. """ from trollimage.image import Image as trollimage from trollimage.colormap import rdylgn self.check_channels('VIS006', 'VIS008') colorize = True ndvi = (self['VIS008'] - self['VIS006']) / (self['VIS008'] + self['VIS006']) ## use trollimage to create black white image ## black and white version img = GeoImage(ndvi.data, self.area, self.time_slot, fill_value=(0, 0, 0), mode="L") if colorize: # use trollimage to create a color map rdylgn.set_range(-1., +1.) # colorize the image img.colorize(rdylgn) return img
def sza(self): #self.check_channels("VIS006", "HRV", "IR_108") import numpy as np # calculate longitude/latitude and solar zenith angle from pyorbital.astronomy import sun_zenith_angle lonlats = self.area.get_lonlats() #lonlats = self["IR_108"].area.get_lonlats() sza = sun_zenith_angle(self.time_slot, lonlats[0], lonlats[1]) ### stupid numbers for outside disk!!! #import numpy.ma as ma #sza=ma.masked_equal(sza, 8.24905797976) #sza=ma.masked_equal(sza, 8.25871138053) img = GeoImage(sza, self.area, self.time_slot, fill_value=(0, 0, 0), mode="L") from trollimage.colormap import rainbow cm = deepcopy(rainbow) cm.set_range(0, 90) img.colorize(cm) return img
def sandwich(self): """Make a colored 10.8 RGB image with HRV resolution enhacement from Seviri channels. """ from trollimage.image import Image as trollimage self.check_channels('IR_108', "HRV") ## use trollimage to create black white image #img = trollimage(self['IR_108'].data, mode="L") img = GeoImage(self["IR_108"].data, self.area, self.time_slot, mode="L") #, fill_value=0 # use trollimage to create a color map greys.set_range(-30 + 273.15, 30 + 273.15) cm2 = deepcopy(rainbow) cm2.set_range(-73 + 273.15, -30.00001 + 273.15) cm2.reverse() my_cm = cm2 + greys #luminance = GeoImage((self["HRV"].data), self.area, self.time_slot, # crange=(0, 100), mode="L") #luminance.enhance(gamma=2.0) #img.replace_luminance(luminance.channels[0]) ## colorize the image img.colorize(my_cm) return img
def daynight_background(self, cos_scaled=True, use_HRV=False, smooth=False, stretch=False, colorscale='greys', fixed_minmax=False, white_clouds=True): import numpy as np # threshold sza sza1 = 80. # calculate longitude/latitude and solar zenith angle from pyorbital.astronomy import sun_zenith_angle lonlats = self["IR_108"].area.get_lonlats() sza = sun_zenith_angle(self.time_slot, lonlats[0], lonlats[1]) if not smooth: mask = np.array(sza > sza1) else: mask = np.zeros(ir108.shape) mask[np.where(sza > sza1)] = 1 # select, if you want HRV or VIS006 if use_HRV: vis = self["HRV"].data # fill remaining area with VIS006 vis[vis.mask == True] = self["VIS006"].data[vis.mask == True] else: vis = self["VIS006"].data # sceen out data at night/day part of the disk ir108 = self["IR_108"].data * mask # ... and apply cos scaling to mitigate effect of solar zenith angle if not cos_scaled: vis = vis * (1 - mask) else: vis = vis * (1 - mask) / (np.cos(np.radians(sza)) + 0.05) # normilize vis reflectivity and ir brightness temperature # to comparable range between 0 and 1 if fixed_minmax: # minimum and maximum for ir108 ir1 = 190. ir2 = 290. # minimum and maximum for HRV (or VIS006) scale vis1 = 0. if not cos_scaled: vis2 = 75. #for pure vis/hrv else: vis2 = 110. #for scaling with cos(sza) else: # linear stretch from p1 percentile to p2 percentile #import matplotlib.pyplot as plt #plt.hist(ir108[np.where(ir108 > 100)], bins='auto') #plt.title("Histogram with 'auto' bins") #plt.show() #print " min/max(1) IR:", ir108.min(), ir108.max() #print " min/max(1) VIS:", vis.min(), vis.max() # percentile limits p1 = 5 p2 = 95 # ind_ir108 = np.where(ir108 > 100) if len(ind_ir108) > 5: ir1 = np.percentile(ir108[ind_ir108], p1) ir2 = np.percentile(ir108[ind_ir108], p2) else: ir1 = 190. ir2 = 290. ind_vis = np.where(vis > 0) if len(ind_vis) > 5: vis1 = np.percentile(vis[np.where(vis > 0)], p1) vis2 = np.percentile(vis[np.where(vis > 0)], p2) else: vis1 = 5. if not cos_scaled: vis2 = 75. else: vis2 = 110. #print " min/max(2) IR:", ir1, ir2 #print " min/max(2) VIS:", vis1, vis2 # scale the vis and ir channel to the range [0,1] # multiply with mask to keep the zeros for day/night area ir108 = (ir108 - ir1) / (ir2 - ir1) * mask vis = (vis - vis1) / (vis2 - vis1) * (1 - mask) #print " min/max scaled ir: ", ir108.min(), ir108.max() #print " min/max scaled vis:", vis.min(), vis.max() # invert ir108 ir108 = (1 - ir108) * mask img = GeoImage(vis + ir108, self.area, self.time_slot, fill_value=(0, 0, 0), mode="L") print(colorscale, white_clouds) if colorscale == 'rainbow': from trollimage.colormap import rainbow cm = deepcopy(rainbow) elif colorscale == 'greys': from trollimage.colormap import greys cm = deepcopy(greys) if white_clouds: #cm.reverse() # UH (my change in trollimage/colormap.py): color table is not any more changed, but changed one is returned. cm = cm.reverse() cm.set_range(0, 1) img.colorize(cm) if stretch: print("... use streching ", stretch) img.enhance(stretch=stretch) return img