def snow(self): """Make a 'Snow' RGB as suggested in the MSG interpretation guide (rgbpart04.ppt). It is kind of special as it requires the derivation of the daytime component of the mixed Terrestrial/Solar 3.9 micron channel. Furthermore the sun zenith angle is used. """ self.refl39_chan() self.check_channels("_IR39Refl", 0.8, 1.63, 3.75) # We calculate the sun zenith angle again. Should be reused if already # calculated/available... # FIXME! lonlats = self[3.9].area.get_lonlats() sunz = sza(self.time_slot, lonlats[0], lonlats[1]) sunz = np.ma.masked_outside(sunz, 0.0, 88.0) sunzmask = sunz.mask sunz = sunz.filled(88.0) costheta = np.cos(np.deg2rad(sunz)) red = np.ma.masked_where(sunzmask, self[0.8].data / costheta) green = np.ma.masked_where(sunzmask, self[1.6].data / costheta) img = geo_image.GeoImage( (red, green, self["_IR39Refl"].data), self.area, self.time_slot, crange=((0, 100), (0, 70), (0, 30)), fill_value=None, mode="RGB", ) img.gamma((1.7, 1.7, 1.7)) return img
def get_reflectance(self, tb11, sun_zenith=None, tb13_4=None): """Get the reflectance part of an NIR channel""" try: from pyspectral.near_infrared_reflectance import Calculator except ImportError: LOG.info("Couldn't load pyspectral") # Check the wavelength, and if outside 3-4 microns this functionality # doesn't give any meaning and should not be supported if (self.wavelength_range[1] < 3.0 or self.wavelength_range[1] > 4.0): LOG.warning("Deriving the near infrared reflectance" + " of a band that is outside the 3-4 micron range" + " is not supported!\n\tWill do nothing...") return # Check if the sun-zenith angle was provided: if sun_zenith is None: lonlats = self.area.get_lonlats() sun_zenith = sza(self.info['time'], lonlats[0], lonlats[1]) try: refl39 = Calculator(self.info['satname'] + self.info['satnumber'], self.info['instrument_name'], self.name) except NameError: LOG.warning("pyspectral missing!") return return refl39.reflectance_from_tbs(sun_zenith, self.data, tb11, tb_ir_co2=tb13_4)
def overview_sun(self, stretch="crude", gamma=1.6): """Make an overview RGB image composite normalising with cosine to the sun zenith angle. """ self.check_channels(0.635, 0.85, 10.8) lonlats = self[10.8].area.get_lonlats() sunz = sza(self.time_slot, lonlats[0], lonlats[1]) sunz = np.ma.masked_outside(sunz, 0.0, 88.0) sunzmask = sunz.mask sunz = sunz.filled(88.0) costheta = np.cos(np.deg2rad(sunz)) red = np.ma.masked_where(sunzmask, self[0.635].data / costheta) green = np.ma.masked_where(sunzmask, self[0.85].data / costheta) blue = -self[10.8].data img = geo_image.GeoImage((red, green, blue), self.area, self.time_slot, fill_value=(0, 0, 0), mode="RGB") if stretch: img.enhance(stretch=stretch) if gamma: img.enhance(gamma=gamma) return img
def dnb_overview(self, stretch='linear'): """Make a nighttime overview RGB image composite from VIIRS DNB and M bands. """ self.check_channels('DNB', 'M15') lonlats = self['M15'].area.get_lonlats() if sza: sunz = sza(self.time_slot, lonlats[0], lonlats[1]) sunz = np.ma.masked_outside(sunz, 103, 180) sunzmask = sunz.mask red = np.ma.masked_where(sunzmask, self['DNB'].data) green = np.ma.masked_where(sunzmask, self['DNB'].data) blue = np.ma.masked_where(sunzmask, -self['M15'].data) else: LOG.warning("No masking of solar contaminated pixels performed!") red = self['DNB'].data green = self['DNB'].data blue = -self['M15'].data img = geo_image.GeoImage((red, green, blue), self.area, self.time_slot, fill_value=None, mode="RGB") img.enhance(stretch=stretch) return img
def snow(self): """Make a 'Snow' RGB as suggested in the MSG interpretation guide (rgbpart04.ppt). It is kind of special as it requires the derivation of the daytime component of the mixed Terrestrial/Solar 3.9 micron channel. Furthermore the sun zenith angle is used. """ self.refl39_chan() self.check_channels("_IR39Refl", 0.8, 1.63, 3.75) # We calculate the sun zenith angle again. Should be reused if already # calculated/available... # FIXME! lonlats = self[3.9].area.get_lonlats() sunz = sza(self.time_slot, lonlats[0], lonlats[1]) sunz = np.ma.masked_outside(sunz, 0.0, 88.0) sunzmask = sunz.mask sunz = sunz.filled(88.) costheta = np.cos(np.deg2rad(sunz)) red = np.ma.masked_where(sunzmask, self[0.8].data / costheta) green = np.ma.masked_where(sunzmask, self[1.6].data / costheta) img = geo_image.GeoImage((red, green, self['_IR39Refl'].data), self.area, self.time_slot, crange=((0, 100), (0, 70), (0, 30)), fill_value=None, mode="RGB") img.gamma((1.7, 1.7, 1.7)) return img
def _get_reflectance(self, projectables, optional_datasets): """Calculate 3.x reflectance with pyspectral""" _nir, _tb11 = projectables LOG.info('Getting reflective part of %s', _nir.attrs['name']) sun_zenith = None tb13_4 = None for dataset in optional_datasets: wavelengths = dataset.attrs.get('wavelength', [100., 0, 0]) if (dataset.attrs.get('units') == 'K' and wavelengths[0] <= 13.4 <= wavelengths[2]): tb13_4 = dataset elif ("standard_name" in dataset.attrs and dataset.attrs["standard_name"] == "solar_zenith_angle"): sun_zenith = dataset # Check if the sun-zenith angle was provided: if sun_zenith is None: from pyorbital.astronomy import sun_zenith_angle as sza lons, lats = _nir.attrs["area"].get_lonlats_dask(CHUNK_SIZE) sun_zenith = sza(_nir.attrs['start_time'], lons, lats) return self._refl3x.reflectance_from_tbs(sun_zenith, _nir, _tb11, tb_ir_co2=tb13_4)
def overview_sun(self, stretch='crude', gamma=1.6): """Make an overview RGB image composite normalising with cosine to the sun zenith angle. """ self.check_channels(0.635, 0.85, 10.8) lonlats = self[10.8].area.get_lonlats() sunz = sza(self.time_slot, lonlats[0], lonlats[1]) sunz = np.ma.masked_outside(sunz, 0.0, 88.0) sunzmask = sunz.mask sunz = sunz.filled(88.) costheta = np.cos(np.deg2rad(sunz)) red = np.ma.masked_where(sunzmask, self[0.635].data / costheta) green = np.ma.masked_where(sunzmask, self[0.85].data / costheta) blue = -self[10.8].data img = geo_image.GeoImage((red, green, blue), self.area, self.time_slot, fill_value=(0, 0, 0), mode="RGB") if stretch: img.enhance(stretch=stretch) if gamma: img.enhance(gamma=gamma) return img
def _get_reflectance(self, projectables, optional_datasets): """Calculate 3.x reflectance with pyspectral""" _nir, _tb11 = projectables LOG.info('Getting reflective part of %s', _nir.info['name']) sun_zenith = None tb13_4 = None for dataset in optional_datasets: if (dataset.info['units'] == 'K' and "wavelengh" in dataset.info and dataset.info["wavelength"][0] <= 13.4 <= dataset.info["wavelength"][2]): tb13_4 = dataset elif dataset.info["standard_name"] == "solar_zenith_angle": sun_zenith = dataset # Check if the sun-zenith angle was provided: if sun_zenith is None: from pyorbital.astronomy import sun_zenith_angle as sza lons, lats = _nir.info["area"].get_lonlats() sun_zenith = sza(_nir.info['start_time'], lons, lats) return self._refl3x.reflectance_from_tbs(sun_zenith, _nir, _tb11, tb_ir_co2=tb13_4)
def day_microphysics(self, wintertime=False): """Make a 'Day Microphysics' RGB as suggested in the MSG interpretation guide (rgbpart04.ppt). It is kind of special as it requires the derivation of the daytime component of the mixed Terrestrial/Solar 3.9 micron channel. Furthermore the sun zenith angle is used. """ self.refl39_chan() self.check_channels(0.8, "_IR39Refl", 10.8) # We calculate the sun zenith angle again. Should be reused if already # calculated/available... # FIXME! lonlats = self[3.9].area.get_lonlats() sunz = sza(self.time_slot, lonlats[0], lonlats[1]) sunz = np.ma.masked_outside(sunz, 0.0, 88.0) sunzmask = sunz.mask sunz = sunz.filled(88.) costheta = np.cos(np.deg2rad(sunz)) if wintertime: crange = ((0, 100), (0, 25), (203, 323)) else: crange = ((0, 100), (0, 60), (203, 323)) red = np.ma.masked_where(sunzmask, self[0.8].data / costheta) green = np.ma.masked_where(sunzmask, self['_IR39Refl'].data) blue = np.ma.masked_where(sunzmask, self[10.8].data) img = geo_image.GeoImage((red, green, blue), self.area, self.time_slot, crange=crange, fill_value=None, mode="RGB") if wintertime: img.gamma((1.0, 1.5, 1.0)) else: img.gamma((1.0, 2.5, 1.0)) # Summertime settings.... return img
def day_microphysics(self, wintertime=False, fill_value=None): """Make a 'Day Microphysics' RGB as suggested in the MSG interpretation guide (rgbpart04.ppt). It is kind of special as it requires the derivation of the daytime component of the mixed Terrestrial/Solar 3.9 micron channel. Furthermore the sun zenith angle is used. for black backgroup specify: fill_value=(0,0,0) """ self.refl39_chan() self.check_channels(0.8, "_IR39Refl", 10.8) # We calculate the sun zenith angle again. Should be reused if already # calculated/available... # FIXME! lonlats = self[3.9].area.get_lonlats() sunz = sza(self.time_slot, lonlats[0], lonlats[1]) sunz = np.ma.masked_outside(sunz, 0.0, 88.0) sunzmask = sunz.mask sunz = sunz.filled(88.) costheta = np.cos(np.deg2rad(sunz)) if wintertime: crange = ((0, 100), (0, 25), (203, 323)) else: crange = ((0, 100), (0, 60), (203, 323)) red = np.ma.masked_where(sunzmask, self[0.8].data / costheta) green = np.ma.masked_where(sunzmask, self['_IR39Refl'].data) blue = np.ma.masked_where(sunzmask, self[10.8].data) img = geo_image.GeoImage((red, green, blue), self.area, self.time_slot, crange=crange, fill_value=fill_value, mode="RGB") if wintertime: img.gamma((1.0, 1.5, 1.0)) else: img.gamma((1.0, 2.5, 1.0)) # Summertime settings.... return img
def __call__(self, projectables, optional_datasets=None, **info): """Get the reflectance part of an NIR channel. Not supposed to be used for wavelength outside [3, 4] µm. """ try: from pyspectral.near_infrared_reflectance import Calculator except ImportError: LOG.info("Couldn't load pyspectral") raise nir, tb11 = projectables LOG.info('Getting reflective part of %s', nir.info['name']) sun_zenith = None tb13_4 = None for dataset in optional_datasets: if (dataset.info['units'] == 'K' and "wavelengh" in dataset.info and dataset.info["wavelength"][0] <= 13.4 <= dataset.info["wavelength"][2]): tb13_4 = dataset elif dataset.info["standard_name"] == "solar_zenith_angle": sun_zenith = dataset # Check if the sun-zenith angle was provided: if sun_zenith is None: from pyorbital.astronomy import sun_zenith_angle as sza lons, lats = nir.info["area"].get_lonlats() sun_zenith = sza(nir.info['start_time'], lons, lats) refl39 = Calculator(nir.info['platform_name'], nir.info['sensor'], nir.id.wavelength[1]) proj = Dataset( refl39.reflectance_from_tbs(sun_zenith, nir, tb11, tb13_4) * 100, **nir.info) proj.info['units'] = '%' self.apply_modifier_info(nir, proj) return proj
def __call__(self, projectables, optional_datasets=None, **info): """Get the reflectance part of an NIR channel. Not supposed to be used for wavelength outside [3, 4] µm. """ try: from pyspectral.near_infrared_reflectance import Calculator except ImportError: LOG.info("Couldn't load pyspectral") raise nir, tb11 = projectables LOG.info('Getting reflective part of %s', nir.info['name']) sun_zenith = None tb13_4 = None for dataset in optional_datasets: if dataset.info["standard_name"] == "solar_zenith_angle": sun_zenith = dataset elif (dataset.info['units'] == 'K' and "wavelengh" in dataset.info and dataset.info["wavelength"][0] <= 13.4 <= dataset.info["wavelength"][2]): tb13_4 = dataset # Check if the sun-zenith angle was provided: if sun_zenith is None: from pyorbital.astronomy import sun_zenith_angle as sza lons, lats = nir.info["area"].get_lonlats() sun_zenith = sza(nir.info['start_time'], lons, lats) refl39 = Calculator(nir.info['platform_name'], nir.info['sensor'], nir.info['name']) proj = Projectable(refl39.reflectance_from_tbs(sun_zenith, nir, tb11, tb13_4), **nir.info) self.apply_modifier_info(nir, proj) return proj
def _dwd_get_sun_zenith_angles_channel(self): """Returns the sun zenith angles for the area of interest as a channel. """ LOGGER.info('Retrieve sun zenith angles') try: self.check_channels("SUN_ZEN_CHN") if self["SUN_ZEN_CHN"].data.shape != self.area.shape: self._data_holder.channels.remove(self["SUN_ZEN_CHN"]) raise Exception() except: if self.area.lons is None or self.area.lats is None: self.area.lons, self.area.lats = self.area.get_lonlats() sun_zen_chn_data = np.zeros(shape=self.area.lons.shape) q = 500 for start in xrange(0, sun_zen_chn_data.shape[1], q): sun_zen_chn_data[:, start:start + q] = sza( get_first(self.time_slot), self.area.lons[:, start:start + q], self.area.lats[:, start:start + q]) sun_zen_chn = Channel(name="SUN_ZEN_CHN", data=sun_zen_chn_data) self._data_holder.channels.append(sun_zen_chn) return self["SUN_ZEN_CHN"]
def _get_reflectance(self, projectables, optional_datasets): """Calculate 3.x reflectance with pyspectral""" _nir, _tb11 = projectables LOG.info('Getting reflective part of %s', _nir.attrs['name']) sun_zenith = None tb13_4 = None for dataset in optional_datasets: if (dataset.attrs['units'] == 'K' and "wavelengh" in dataset.attrs and dataset.attrs["wavelength"][0] <= 13.4 <= dataset.attrs["wavelength"][2]): tb13_4 = dataset elif dataset.attrs["standard_name"] == "solar_zenith_angle": sun_zenith = dataset # Check if the sun-zenith angle was provided: if sun_zenith is None: from pyorbital.astronomy import sun_zenith_angle as sza lons, lats = _nir.attrs["area"].get_lonlats_dask(CHUNK_SIZE) sun_zenith = sza(_nir.attrs['start_time'], lons, lats) return self._refl3x.reflectance_from_tbs(sun_zenith, _nir, _tb11, tb_ir_co2=tb13_4)
def _dwd_get_sun_zenith_angles_channel(self): """Returns the sun zenith angles for the area of interest as a channel. """ LOGGER.info('Retrieve sun zenith angles') try: self.check_channels("SUN_ZEN_CHN") if self["SUN_ZEN_CHN"].data.shape != self.area.shape: self._data_holder.channels.remove(self["SUN_ZEN_CHN"]) raise Exception() except: if self.area.lons is None or self.area.lats is None: self.area.lons, self.area.lats = self.area.get_lonlats() sun_zen_chn_data = np.zeros(shape=self.area.lons.shape) q = 500 for start in xrange(0, sun_zen_chn_data.shape[1], q): sun_zen_chn_data[ :, start: start + q] = sza( get_first(self.time_slot), self.area.lons[:, start: start + q], self.area.lats[:, start: start + q]) sun_zen_chn = Channel(name="SUN_ZEN_CHN", data=sun_zen_chn_data) self._data_holder.channels.append(sun_zen_chn) return self["SUN_ZEN_CHN"]