def __call__(self, projectables, nonprojectables=None, **info): if len(projectables) != 3: raise ValueError("Expected 3 datasets, got %d" % (len(projectables), )) try: the_data = np.rollaxis( np.ma.dstack([projectable for projectable in projectables]), axis=2) except ValueError: raise IncompatibleAreas # info = projectables[0].info.copy() # info.update(projectables[1].info) # info.update(projectables[2].info) info = combine_info(*projectables) info.update(self.info) info['id'] = DatasetID(self.info['name']) # FIXME: should this be done here ? info["wavelength_range"] = None info.pop("units", None) sensor = set() for projectable in projectables: current_sensor = projectable.info.get("sensor", None) if current_sensor: if isinstance(current_sensor, (str, bytes, six.text_type)): sensor.add(current_sensor) else: sensor |= current_sensor if len(sensor) == 0: sensor = None elif len(sensor) == 1: sensor = list(sensor)[0] info["sensor"] = sensor info["mode"] = "RGB" return Projectable(data=the_data, **info)
def __call__(self, projectables, nonprojectables=None, **info): if len(projectables) != 3: raise ValueError("Expected 3 datasets, got %d" % (len(projectables), )) # Collect information that is the same between the projectables info = combine_info(*projectables) # Update that information with configured information (including name) info.update(self.info) # Force certain pieces of metadata that we *know* to be true info["wavelength"] = None info["mode"] = self.info.get("mode", "RGB") return Projectable(data=np.rollaxis(np.ma.dstack( [projectable for projectable in projectables]), axis=2), **info)
def __call__(self, projectables, nonprojectables=None, **info): if len(projectables) != 3: raise ValueError("Expected 3 datasets, got %d" % (len(projectables), )) # Collect information that is the same between the projectables info = combine_info(*projectables) # Update that information with configured information (including name) info.update(self.info) # Force certain pieces of metadata that we *know* to be true info["wavelength"] = None info["mode"] = self.info.get("mode", "RGB") return Projectable(data=np.rollaxis( np.ma.dstack([projectable for projectable in projectables]), axis=2), **info)
def combine_info(self, all_infos): """Combine metadata for multiple datasets. When loading data from multiple files it can be non-trivial to combine things like start_time, end_time, start_orbit, end_orbit, etc. By default this method will produce a dictionary containing all values that were equal across **all** provided info dictionaries. Additionally it performs the logical comparisons to produce the following if they exist: - start_time - end_time - start_orbit - end_orbit Also, concatenate the areas. """ combined_info = combine_info(*all_infos) if 'start_time' not in combined_info and 'start_time' in all_infos[0]: combined_info['start_time'] = min(i['start_time'] for i in all_infos) if 'end_time' not in combined_info and 'end_time' in all_infos[0]: combined_info['end_time'] = max(i['end_time'] for i in all_infos) if 'start_orbit' not in combined_info and 'start_orbit' in all_infos[0]: combined_info['start_orbit'] = min(i['start_orbit'] for i in all_infos) if 'end_orbit' not in combined_info and 'end_orbit' in all_infos[0]: combined_info['end_orbit'] = max(i['end_orbit'] for i in all_infos) try: area = SwathDefinition( lons=np.ma.vstack([info['area'].lons for info in all_infos]), lats=np.ma.vstack([info['area'].lats for info in all_infos])) area.name = '_'.join([info['area'].name for info in all_infos]) combined_info['area'] = area except KeyError: pass return combined_info
def __call__(self, datasets, optional_datasets=[], **info): if len(datasets) != 3: raise ValueError("Expected 3 datasets, got %d" % (len(datasets), )) area = None # raise IncompatibleAreas p1, p2, p3 = datasets if optional_datasets: high_res = optional_datasets[0] low_res = datasets[["red", "green", "blue"].index(self.high_resolution_band)] if high_res.info["area"] != low_res.info["area"]: if np.mod(high_res.shape[0], low_res.shape[0]) or \ np.mod(high_res.shape[1], low_res.shape[1]): raise IncompatibleAreas( "High resolution band is not mapped the same area as the low resolution bands" ) else: f0 = high_res.shape[0] / low_res.shape[0] f1 = high_res.shape[1] / low_res.shape[1] if p1.shape != high_res.shape: p1 = np.ma.repeat(np.ma.repeat(p1, f0, axis=0), f1, axis=1) p1.info["area"] = high_res.info["area"] if p2.shape != high_res.shape: p2 = np.ma.repeat(np.ma.repeat(p2, f0, axis=0), f1, axis=1) p2.info["area"] = high_res.info["area"] if p3.shape != high_res.shape: p3 = np.ma.repeat(np.ma.repeat(p3, f0, axis=0), f1, axis=1) p3.info["area"] = high_res.info["area"] area = high_res.info["area"] if self.high_resolution_band == "red": LOG.debug("Sharpening image with high resolution red band") ratio = high_res.data / p1.data r = high_res.data g = p2.data * ratio b = p3.data * ratio elif self.high_resolution_band == "green": LOG.debug("Sharpening image with high resolution green band") ratio = high_res.data / p2.data r = p1.data * ratio g = high_res.data b = p3.data * ratio elif self.high_resolution_band == "blue": LOG.debug("Sharpening image with high resolution blue band") ratio = high_res.data / p3.data r = p1.data * ratio g = p2.data * ratio b = high_res.data else: # no sharpening r = p1.data g = p2.data b = p3.data mask = p1.mask | p2.mask | p3.mask | high_res.mask else: r, g, b = p1.data, p2.data, p3.data mask = p1.mask | p2.mask | p3.mask # Collect information that is the same between the projectables info = combine_info(*datasets) # Update that information with configured information (including name) info.update(self.info) # Force certain pieces of metadata that we *know* to be true info["wavelength"] = None info.setdefault("standard_name", "true_color") info["mode"] = self.info.get("mode", "RGB") if area is not None: info['area'] = area return Projectable(data=np.concatenate(([r], [g], [b]), axis=0), mask=np.array([[mask, mask, mask]]), **info)
def __call__(self, datasets, optional_datasets=[], **info): if len(datasets) != 3: raise ValueError("Expected 3 datasets, got %d" % (len(datasets), )) area = None # raise IncompatibleAreas p1, p2, p3 = datasets if optional_datasets: high_res = optional_datasets[0] low_res = datasets[["red", "green", "blue"].index(self.high_resolution_band)] if high_res.info["area"] != low_res.info["area"]: if np.mod(high_res.shape[0], low_res.shape[0]) or \ np.mod(high_res.shape[1], low_res.shape[1]): raise IncompatibleAreas( "High resolution band is not mapped the same area as the low resolution bands") else: f0 = high_res.shape[0] / low_res.shape[0] f1 = high_res.shape[1] / low_res.shape[1] if p1.shape != high_res.shape: p1 = np.ma.repeat(np.ma.repeat(p1, f0, axis=0), f1, axis=1) p1.info["area"] = high_res.info["area"] if p2.shape != high_res.shape: p2 = np.ma.repeat(np.ma.repeat(p2, f0, axis=0), f1, axis=1) p2.info["area"] = high_res.info["area"] if p3.shape != high_res.shape: p3 = np.ma.repeat(np.ma.repeat(p3, f0, axis=0), f1, axis=1) p3.info["area"] = high_res.info["area"] area = high_res.info["area"] if self.high_resolution_band == "red": LOG.debug("Sharpening image with high resolution red band") ratio = high_res.data / p1.data r = high_res.data g = p2.data * ratio b = p3.data * ratio elif self.high_resolution_band == "green": LOG.debug("Sharpening image with high resolution green band") ratio = high_res.data / p2.data r = p1.data * ratio g = high_res.data b = p3.data * ratio elif self.high_resolution_band == "blue": LOG.debug("Sharpening image with high resolution blue band") ratio = high_res.data / p3.data r = p1.data * ratio g = p2.data * ratio b = high_res.data else: # no sharpening r = p1.data g = p2.data b = p3.data mask = p1.mask | p2.mask | p3.mask | high_res.mask else: r, g, b = p1.data, p2.data, p3.data mask = p1.mask | p2.mask | p3.mask # Collect information that is the same between the projectables info = combine_info(*datasets) # Update that information with configured information (including name) info.update(self.info) # Force certain pieces of metadata that we *know* to be true info["wavelength"] = None info.setdefault("standard_name", "true_color") info["mode"] = self.info.get("mode", "RGB") if area is not None: info['area'] = area return Projectable(data=np.concatenate( ([r], [g], [b]), axis=0), mask=np.array([[mask, mask, mask]]), **info)