def _get_regions_geojson(region_counts: Counter[str], region_info: RegionInfo) -> Optional[Dict]: if not region_info: # Regions are unsupported for product return None if region_counts: low, high = min(region_counts.values()), max(region_counts.values()) else: low, high = 0, 0 return { "type": "FeatureCollection", "properties": { "region_type": region_info.name, "region_unit_label": region_info.unit_label, "min_count": low, "max_count": high, }, "features": [{ "type": "Feature", "geometry": region_info.region(region_code).footprint_wgs84.__geo_interface__, "properties": { "region_code": region_code, "label": region_info.region_label(region_code), "count": region_counts[region_code], }, } for region_code in (region_counts or []) if region_info.region(region_code) is not None], }
def get_regions_geojson( product_name: str, year: Optional[int] = None, month: Optional[int] = None, day: Optional[int] = None, ) -> Optional[Dict]: product = STORE.get_dataset_type(product_name) region_info = RegionInfo.for_product(product) if not region_info: return None product_summary = STORE.get_product_summary(product.name) if not product_summary: # Valid product, but no summary generated. return None period = get_time_summary(product_name, year, month, day) if not period: # Valid product, but no summary generated. return None footprint_wrs84 = _get_footprint(period) start = time.time() regions = _get_regions_geojson(period.region_dataset_counts, footprint_wrs84, region_info) _LOG.debug("overview.region_gen", time_sec=time.time() - start) return regions
def _get_regions_geojson(region_counts: Counter[str], footprint: MultiPolygon, region_info: RegionInfo) -> Optional[Dict]: region_geometry = _region_geometry_function(region_info, footprint) if not region_geometry: # Regions are unsupported for product return None if region_counts: low, high = min(region_counts.values()), max(region_counts.values()) else: low, high = 0, 0 return { 'type': 'FeatureCollection', 'properties': { 'region_type': region_info.name, 'region_unit_label': region_info.unit_label, 'min_count': low, 'max_count': high, }, 'features': [{ 'type': 'Feature', 'geometry': region_geometry(region_code).__geo_interface__, 'properties': { 'region_code': region_code, 'label': region_info.region_label(region_code), 'count': region_counts[region_code] } } for region_code in (region_counts or [])] }