def _build_standard_products(idaho_id, proj, gsd=None): dn_op = ipe.IdahoRead(bucketName="idaho-images", imageId=idaho_id, objectStore="S3") params = ortho_params(proj, gsd=gsd) ortho_op = ipe.Orthorectify(dn_op, **params) # TODO: Switch to direct metadata access (ie remove this block) idaho_md = requests.get( 'http://idaho.timbr.io/{}.json'.format(idaho_id)).json() meta = idaho_md["properties"] gains_offsets = calc_toa_gain_offset(meta) radiance_scales, reflectance_scales, radiance_offsets = zip( *gains_offsets) # --- toa_reflectance_op = ipe.MultiplyConst(ipe.AddConst( ipe.MultiplyConst(ipe.Format(ortho_op, dataType="4"), constants=radiance_scales), constants=radiance_offsets), constants=reflectance_scales) return { "1b": dn_op, "ortho": ortho_op, "toa_reflectance": toa_reflectance_op }
def _build_standard_products(cls, cat_id, band_type, proj, gsd=None): # TODO: Switch to direct metadata access (ie remove this block) _parts = cls._find_parts(cat_id, band_type) _id = _parts[0]['properties']['attributes']['idahoImageId'] try: idaho_md = requests.get('http://idaho.timbr.io/{}.json'.format(_id)).json() except ValueError: raise MissingMetadata('Metadata not found in S3 for image: {}'.format(_id)) meta = idaho_md["properties"] gains_offsets = calc_toa_gain_offset(meta) radiance_scales, reflectance_scales, radiance_offsets = zip(*gains_offsets) # --- dn_ops = [ipe.IdahoRead(bucketName="idaho-images", imageId=p['properties']['attributes']['idahoImageId'], objectStore="S3") for p in _parts] mosaic_params = {"Dest SRS Code": proj} if gsd is not None: mosaic_params["Requested GSD"] = str(gsd) ortho_op = ipe.GeospatialMosaic(*dn_ops, **mosaic_params) radiance_op = ipe.AddConst( ipe.MultiplyConst( ipe.Format(ortho_op, dataType="4"), constants=radiance_scales), constants=radiance_offsets) toa_reflectance_op = ipe.MultiplyConst(radiance_op, constants=reflectance_scales) return {"ortho": ortho_op, "toa_reflectance": toa_reflectance_op, "radiance": radiance_op}
def _mosaic(self, graph, suffix=''): mosaic = ipe.GeospatialMosaic(*graph.values()) idaho_id = list(graph.keys())[0] meta = requests.get( 'http://idaho.timbr.io/{}.json'.format(idaho_id)).json() gains_offsets = calc_toa_gain_offset(meta['properties']) radiance_scales, reflectance_scales, radiance_offsets = zip( *gains_offsets) radiance = ipe.AddConst(ipe.MultiplyConst(ipe.Format(mosaic, dataType="4"), constants=radiance_scales), constants=radiance_offsets) toa = ipe.MultiplyConst(radiance, constants=reflectance_scales) graph.update({ "mosaic{}".format(suffix): mosaic, "radiance{}".format(suffix): radiance, "toa_reflectance{}".format(suffix): toa }) return graph
def _init_graphs(self): meta = self.idaho_md["properties"] gains_offsets = calc_toa_gain_offset(meta) radiance_scales, reflectance_scales, radiance_offsets = zip( *gains_offsets) ortho = ipe.Orthorectify( ipe.IdahoRead(bucketName="idaho-images", imageId=self._gid, objectStore="S3"), **ortho_params(self._proj)) radiance = ipe.AddConst(ipe.MultiplyConst(ipe.Format(ortho, dataType="4"), constants=radiance_scales), constants=radiance_offsets) toa_reflectance = ipe.MultiplyConst(radiance, constants=reflectance_scales) return { "ortho": ortho, "radiance": radiance, "toa_reflectance": toa_reflectance }
def _build_standard_products(cls, cat_id, band_type, proj): # TODO: Switch to direct metadata access (ie remove this block) _parts = cls._find_parts(cat_id, band_type) _id = _parts[0]['properties']['attributes']['idahoImageId'] idaho_md = requests.get('http://idaho.timbr.io/{}.json'.format(_id)).json() meta = idaho_md["properties"] gains_offsets = calc_toa_gain_offset(meta) radiance_scales, reflectance_scales, radiance_offsets = zip(*gains_offsets) # --- dn_ops = [ipe.IdahoRead(bucketName="idaho-images", imageId=p['properties']['attributes']['idahoImageId'], objectStore="S3") for p in _parts] ortho_op = ipe.GeospatialMosaic(*dn_ops, **{"Dest SRS Code": proj}) toa_reflectance_op = ipe.MultiplyConst( ipe.AddConst( ipe.MultiplyConst( ipe.Format(ortho_op, dataType="4"), constants=radiance_scales), constants=radiance_offsets), constants=reflectance_scales) return {"ortho": ortho_op, "toa_reflectance": toa_reflectance_op}