def parse_image_processing(self, cfg):
     emf_cfg = cfg["extent_mask_func"]
     if isinstance(emf_cfg, Mapping) or isinstance(emf_cfg, str):
         self.extent_mask_func = [ FunctionWrapper(self, emf_cfg) ]
     else:
         self.extent_mask_func = list([ FunctionWrapper(self, emf) for emf in emf_cfg ])
     raw_afb = cfg.get("always_fetch_bands", [])
     self.always_fetch_bands = list([ self.band_idx.band(b) for b in raw_afb ])
     self.solar_correction = cfg.get("apply_solar_corrections", False)
     self.data_manual_merge = cfg.get("manual_merge", False)
     if cfg.get("fuse_func"):
         self.fuse_func = FunctionWrapper(self, cfg["fuse_func"])
     else:
         self.fuse_func = None
 def parse_flags(self, cfg):
     if cfg:
         self.parse_pq_names(cfg)
         self.pq_band = cfg["band"]
         if "fuse_func" in cfg:
             self.pq_fuse_func = FunctionWrapper(self, cfg["fuse_func"])
         else:
             self.pq_fuse_func = None
         self.pq_ignore_time = cfg.get("ignore_time", False)
         self.ignore_info_flags = cfg.get("ignore_info_flags", [])
         self.pq_manual_merge = cfg.get("manual_merge", False)
     else:
         self.pq_names = []
         self.pq_low_res_names = []
         self.pq_name = None
         self.pq_band = None
         self.pq_ignore_time = False
         self.ignore_info_flags = []
         self.pq_manual_merge = False
     self.declare_unready("pq_products")
     self.declare_unready("pq_product")
     self.declare_unready("flags_def")
     self.declare_unready("info_mask")
     self.pq_products = []
     self.pq_low_res_products = []
示例#3
0
    def __init__(self,
                 product,
                 style_cfg,
                 stand_alone=False,
                 defer_multi_date=False):
        super(ColorRampDef, self).__init__(product,
                                           style_cfg,
                                           stand_alone=stand_alone,
                                           defer_multi_date=defer_multi_date)
        style_cfg = self._raw_cfg
        self.color_ramp = ColorRamp(self, style_cfg)

        for band in style_cfg["needed_bands"]:
            self.raw_needed_bands.add(band)

        self.include_in_feature_info = style_cfg.get("include_in_feature_info",
                                                     True)

        if "index_function" in style_cfg:
            self.index_function = FunctionWrapper(self,
                                                  style_cfg["index_function"],
                                                  stand_alone=self.stand_alone)
        else:
            raise ConfigException(
                "Index function is required for index and hybrid styles. Style %s in layer %s"
                % (self.name, self.product.name))
        if not defer_multi_date:
            self.parse_multi_date(style_cfg)
 def parse_feature_info(self, cfg):
     self.feature_info_include_utc_dates = cfg.get("include_utc_dates",
                                                   False)
     custom = cfg.get("include_custom", {})
     self.feature_info_custom_includes = {
         k: FunctionWrapper(self, v)
         for k, v in custom.items()
     }
示例#5
0
    def __init__(self,
                 product,
                 style_cfg,
                 local_band_map=None,
                 stand_alone=False,
                 defer_multi_date=False):
        super().__init__(product,
                         style_cfg,
                         stand_alone=stand_alone,
                         defer_multi_date=defer_multi_date)
        style_cfg = self._raw_cfg
        self.raw_rgb_components = {}
        for imgband in ["red", "green", "blue", "alpha"]:
            components = style_cfg["components"].get(imgband)
            if components is None:
                if imgband == "alpha":
                    continue
                else:
                    raise ConfigException(
                        f"No components defined for {imgband} band in style {self.name}, layer {product.name}"
                    )
            if "function" in components:
                self.raw_rgb_components[imgband] = FunctionWrapper(
                    self.product, components, stand_alone=self.stand_alone)
                for b in style_cfg["additional_bands"]:
                    self.raw_needed_bands.add(b)
            else:
                self.raw_rgb_components[imgband] = components
                for k in components.keys():
                    if k != "scale_range":
                        self.raw_needed_bands.add(k)
        self.declare_unready("rgb_components")

        self.scale_factor = style_cfg.get("scale_factor")
        if "scale_range" in style_cfg:
            self.scale_min, self.scale_max = style_cfg["scale_range"]
        elif self.scale_factor:
            self.scale_min = 0.0
            self.scale_max = 255.0 * self.scale_factor
        else:
            self.scale_min = None
            self.scale_max = None

        self.component_scale_ranges = {}
        for cn, cd in style_cfg["components"].items():
            if "scale_range" in cd:
                self.component_scale_ranges[cn] = {
                    "min": cd["scale_range"][0],
                    "max": cd["scale_range"][1],
                }
            else:
                self.component_scale_ranges[cn] = {
                    "min": self.scale_min,
                    "max": self.scale_max,
                }
    def parse_image_processing(self, cfg):
        emf_cfg = cfg["extent_mask_func"]
        if isinstance(emf_cfg, Mapping) or isinstance(emf_cfg, str):
            self.extent_mask_func = [FunctionWrapper(self, emf_cfg)]
        else:
            self.extent_mask_func = list(
                [FunctionWrapper(self, emf) for emf in emf_cfg])
        self.raw_afb = cfg.get("always_fetch_bands", [])
        self.declare_unready("always_fetch_bands")
        self.solar_correction = cfg.get("apply_solar_corrections", False)
        self.data_manual_merge = cfg.get("manual_merge", False)
        if self.solar_correction and not self.data_manual_merge:
            raise ConfigException("Solar correction requires manual_merge.")
        if self.data_manual_merge and not self.solar_correction:
            _LOG.warning(
                "Manual merge is only recommended where solar correction is required."
            )

        if cfg.get("fuse_func"):
            self.fuse_func = FunctionWrapper(self, cfg["fuse_func"])
        else:
            self.fuse_func = None
示例#7
0
    def __init__(self, product, style_cfg):
        super(ComponentStyleDef, self).__init__(product, style_cfg)
        self.rgb_components = {}
        for imgband in ["red", "green", "blue", "alpha"]:
            components = style_cfg["components"].get(imgband)
            if components is None:
                if imgband == "alpha":
                    continue
                else:
                    raise ConfigException("No components defined for %s band" %
                                          imgband)
            if "function" in components:
                self.rgb_components[imgband] = FunctionWrapper(
                    self.product, components)
                for b in style_cfg["additional_bands"]:
                    self.needed_bands.add(b)
            else:
                self.rgb_components[imgband] = self.dealias_components(
                    components)

        self.scale_factor = style_cfg.get("scale_factor")
        if "scale_range" in style_cfg:
            self.scale_min, self.scale_max = style_cfg["scale_range"]
        elif self.scale_factor:
            self.scale_min = 0.0
            self.scale_max = 255.0 * self.scale_factor
        else:
            self.scale_min = None
            self.scale_max = None

        self.component_scale_ranges = {}
        for cn, cd in style_cfg["components"].items():
            if "scale_range" in cd:
                self.component_scale_ranges[cn] = {
                    "min": cd["scale_range"][0],
                    "max": cd["scale_range"][1],
                }
            else:
                self.component_scale_ranges[cn] = {
                    "min": self.scale_min,
                    "max": self.scale_max,
                }

        for imgband in ["red", "green", "blue", "alpha"]:
            if imgband in self.rgb_components and not callable(
                    self.rgb_components[imgband]):
                for band in self.rgb_components[imgband].keys():
                    self.needed_bands.add(band)
 def __init__(self, name, mime, extension, renderers, multi_time):
     self.name = name
     self.mime = mime
     self.extension = extension
     self.multi_time = multi_time
     self.renderers = {
         int(ver): FunctionWrapper(None, renderer)
         for ver, renderer in renderers.items()
     }
     if 1 not in self.renderers:
         _LOG.warning("No renderer supplied for WCS 1.x for format %s",
                      self.name)
     if 2 not in self.renderers:
         _LOG.warning(
             "Warning: No renderer supplied for WCS 2.x for format %s",
             self.name)
 def __init__(self, cfg, product_cfg, **kwargs):
     super().__init__(cfg, **kwargs)
     cfg = self._raw_cfg
     self.product = product_cfg
     pq_names = self.product.parse_pq_names(cfg)
     self.pq_names = pq_names["pq_names"]
     self.pq_low_res_names = pq_names["pq_low_res_names"]
     self.pq_band = cfg["band"]
     if "fuse_func" in cfg:
         self.pq_fuse_func = FunctionWrapper(self, cfg["fuse_func"])
     else:
         self.pq_fuse_func = None
     self.pq_ignore_time = cfg.get("ignore_time", False)
     self.ignore_info_flags = cfg.get("ignore_info_flags", [])
     self.pq_manual_merge = cfg.get("manual_merge", False)
     self.declare_unready("pq_products")
     self.declare_unready("flags_def")
     self.declare_unready("info_mask")
示例#10
0
    def parse_flags(self, cfg, dc):
        if cfg:
            self.parse_pq_names(cfg)
            self.pq_band = cfg["band"]
            if "fuse_func" in cfg:
                self.pq_fuse_func = FunctionWrapper(self, cfg["fuse_func"])
            else:
                self.pq_fuse_func = None
            self.pq_ignore_time = cfg.get("ignore_time", False)
            self.ignore_info_flags = cfg.get("ignore_info_flags", [])
            self.pq_manual_merge = cfg.get("manual_merge", False)
        else:
            self.pq_names = []
            self.pq_name = None
            self.pq_band = None
            self.pq_ignore_time = False
            self.ignore_info_flags = []
            self.pq_manual_merge = False
        self.pq_products = []

        if self.pq_names:
            for pqn in self.pq_names:
                if pqn is not None:
                    pq_product = dc.index.products.get_by_name(pqn)
                    if pq_product is None:
                        raise ConfigException(
                            "Could not find pq_product %s for %s in database" %
                            (pqn, self.name))
                    self.pq_products.append(pq_product)

        self.info_mask = ~0
        if self.pq_products:
            self.pq_product = self.pq_products[0]
            meas = self.pq_product.lookup_measurements([self.pq_band])
            self.flags_def = meas[self.pq_band]["flags_definition"]
            for bitname in self.ignore_info_flags:
                bit = self.flags_def[bitname]["bits"]
                if not isinstance(bit, int):
                    continue
                flag = 1 << bit
                self.info_mask &= ~flag
        else:
            self.pq_product = None
 def __init__(self, style, cfg):
     self.style = style
     if "allowed_count_range" not in cfg:
         raise ConfigException(
             "multi_date handler must have an allowed_count_range")
     if len(cfg["allowed_count_range"]) > 2:
         raise ConfigException(
             "multi_date handler allowed_count_range must have 2 and only 2 members"
         )
     self.min_count, self.max_count = cfg["allowed_count_range"]
     if self.max_count < self.min_count:
         raise ConfigException(
             "multi_date handler allowed_count_range: minimum must be less than equal to maximum"
         )
     if "aggregator_function" in cfg:
         self.aggregator = FunctionWrapper(style.product,
                                           cfg["aggregator_function"])
     else:
         raise ConfigException(
             "Aggregator function is required for multi-date handlers.")
     self.parse_legend_cfg(cfg.get("legend", {}))
示例#12
0
    def __init__(self, cfg, global_cfg, dc, parent_layer=None):
        super().__init__(cfg, global_cfg, dc, parent_layer)
        self.name = cfg["name"]
        self.hide = False
        try:
            self.parse_product_names(cfg)
            self.products = []
            for prod_name in self.product_names:
                if "__" in prod_name:
                    raise ConfigException(
                        "Product names cannot contain a double underscore '__'."
                    )
                product = dc.index.products.get_by_name(prod_name)
                if not product:
                    raise ConfigException(
                        "Could not find product %s in datacube" % prod_name)
                self.products.append(product)
            self.product = self.products[0]
            self.definition = self.product.definition

            self.time_resolution = cfg.get("time_resolution", TIMERES_RAW)
            if self.time_resolution not in TIMERES_VALS:
                raise ConfigException(
                    "Invalid time resolution value %s in named layer %s" %
                    (self.time_resolution, self.name))
        except KeyError:
            raise ConfigException(
                "Required product names entry missing in named layer %s" %
                self.name)
        self.dynamic = cfg.get("dynamic", False)
        self.force_range_update(dc)
        # TODO: sub-ranges
        self.band_idx = BandIndex(self.product, cfg.get("bands"), dc)
        try:
            self.parse_resource_limits(cfg.get("resource_limits", {}))
        except KeyError:
            raise ConfigException(
                "Missing required config items in resource limits for layer %s"
                % self.name)
        try:
            self.parse_flags(cfg.get("flags", {}), dc)
        except KeyError:
            raise ConfigException(
                "Missing required config items in flags section for layer %s" %
                self.name)
        try:
            self.parse_image_processing(cfg["image_processing"])
        except KeyError:
            raise ConfigException(
                "Missing required config items in image processing section for layer %s"
                % self.name)
        self.identifiers = cfg.get("identifiers", {})
        for auth in self.identifiers.keys():
            if auth not in self.global_cfg.authorities:
                raise ConfigException(
                    "Identifier with non-declared authority: %s" % repr(auth))
        try:
            self.parse_urls(cfg.get("urls", {}))
        except KeyError:
            raise ConfigException(
                "Missing required config items in urls section for layer %s" %
                self.name)
        self.parse_feature_info(cfg.get("feature_info", {}))

        self.feature_info_include_utc_dates = cfg.get("feature_info_url_dates",
                                                      False)
        try:
            self.parse_styling(cfg["styling"])
        except KeyError:
            raise ConfigException(
                "Missing required config items in styling section for layer %s"
                % self.name)

        if self.global_cfg.wcs:
            try:
                self.parse_wcs(cfg.get("wcs"), dc)
            except KeyError:
                raise ConfigException(
                    "Missing required config items in wcs section for layer %s"
                    % self.name)

        sub_prod_cfg = cfg.get("sub_products", {})
        self.sub_product_label = sub_prod_cfg.get("label")
        if "extractor" in sub_prod_cfg:
            self.sub_product_extractor = FunctionWrapper(
                self, sub_prod_cfg["extractor"])
        else:
            self.sub_product_extractor = None

        # And finally, add to the global product index.
        self.global_cfg.product_index[self.name] = self
        if not self.multi_product:
            self.global_cfg.native_product_index[self.product_name] = self