diff --git a/app.py b/app.py index de774aa..529a9c2 100644 --- a/app.py +++ b/app.py @@ -112,15 +112,17 @@ def available_cogs(sftp_client: SFTPClient = Depends(get_sftp_client)): # # create a POST endpoint for running a burn query with an input geojson, with its associated POST body class class AnaylzeBurnPOSTBody(BaseModel): - geojson: dict + geojson: str date_ranges: dict fire_event_name: str + affiliation: str @app.post("/api/analyze-burn") def analyze_burn(body: AnaylzeBurnPOSTBody, sftp_client: SFTPClient = Depends(get_sftp_client)): - geojson = body.geojson + geojson = json.loads(body.geojson) date_ranges = body.date_ranges fire_event_name = body.fire_event_name + affiliation = body.affiliation logger.log_text(f"Received analyze-burn request for {fire_event_name}") try: @@ -143,6 +145,7 @@ def analyze_burn(body: AnaylzeBurnPOSTBody, sftp_client: SFTPClient = Depends(ge sftp_client.connect() sftp_client.upload_fire_event( metrics_stack=geo_client.metrics_stack, + affiliation=affiliation, fire_event_name=fire_event_name, prefire_date_range=date_ranges["prefire"], postfire_date_range=date_ranges["postfire"] @@ -213,7 +216,7 @@ async def upload_shapefile(fire_event_name: str = Form(...), affiliation: str = with tempfile.NamedTemporaryFile(suffix=".geojson", delete=False) as tmp: tmp_geojson = tmp.name with open(tmp_geojson, "w") as f: - f.write(json.dumps(geojson)) + f.write(geojson) sftp_client.upload( source_local_path=tmp_geojson, remote_path=f"{affiliation}/{fire_event_name}/boundary.geojson" @@ -221,9 +224,8 @@ async def upload_shapefile(fire_event_name: str = Form(...), affiliation: str = sftp_client.disconnect() - remote_geojson_path = f"https://burn-severity-backend.s3.us-east-2.amazonaws.com/public/{affiliation}/{fire_event_name}/boundary.geojson" - return JSONResponse(status_code=200, content={"s3_geojson_url": remote_geojson_path}) + return JSONResponse(status_code=200, content={"geojson": geojson}) except Exception as e: return JSONResponse(status_code=400, content={"error": str(e)}) \ No newline at end of file diff --git a/src/static/map.html b/src/static/map.html index 0b76874..02c1769 100644 --- a/src/static/map.html +++ b/src/static/map.html @@ -322,20 +322,6 @@ // Center map on fire, based on `bounds` metadata map.fitBounds(fireBounds); - // Don't put the basemap over the metric layer, if it exists - // map.on('baselayerchange', function(eventLayer) - // { - // console.log(eventLayer.name); - // console.log(map.hasLayer(continiousTileLayer)); - // if (map.hasLayer(continiousTileLayer)) { - // map.removeLayer(continiousTileLayer); - // continiousTileLayer.addTo(map); - // } - // if (map.hasLayer(classifiedTileLayer)) { - // map.removeLayer(classifiedTileLayer); - // classifiedTileLayer.addTo(map); - // } - // }); diff --git a/src/static/upload.html b/src/static/upload.html index 17543d2..61e71bb 100644 --- a/src/static/upload.html +++ b/src/static/upload.html @@ -24,19 +24,19 @@ + \ No newline at end of file diff --git a/src/util/sftp.py b/src/util/sftp.py index b907ded..fee7ec7 100644 --- a/src/util/sftp.py +++ b/src/util/sftp.py @@ -128,7 +128,7 @@ def update_available_cogs(self): self.available_cogs = self.get_available_cogs() self.disconnect() - def upload_cogs(self, metrics_stack, fire_event_name, prefire_date_range, postfire_date_range): + def upload_cogs(self, metrics_stack, fire_event_name, prefire_date_range, postfire_date_range, affiliation): with tempfile.TemporaryDirectory() as tmpdir: @@ -146,10 +146,10 @@ def upload_cogs(self, metrics_stack, fire_event_name, prefire_date_range, postfi self.upload( source_local_path=local_cog_path, - remote_path=f"{fire_event_name}/{band_name}.tif", + remote_path=f"{affiliation}/{fire_event_name}/{band_name}.tif", ) - def update_manifest(self, fire_event_name, bounds, prefire_date_range, postfire_date_range): + def update_manifest(self, fire_event_name, bounds, prefire_date_range, postfire_date_range, affiliation): with tempfile.TemporaryDirectory() as tmpdir: manifest = self.get_manifest() @@ -162,7 +162,8 @@ def update_manifest(self, fire_event_name, bounds, prefire_date_range, postfire_ 'bounds': bounds, 'prefire_date_range': prefire_date_range, 'postfire_date_range': postfire_date_range, - 'last_updated': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + 'last_updated': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), + 'requester_affiliation': affiliation } # Upload the manifest to our SFTP server @@ -175,14 +176,15 @@ def update_manifest(self, fire_event_name, bounds, prefire_date_range, postfire_ ) self.logger.log_text(f"Uploaded/updated manifest.json") - def upload_fire_event(self, metrics_stack, fire_event_name, prefire_date_range, postfire_date_range): + def upload_fire_event(self, metrics_stack, fire_event_name, prefire_date_range, postfire_date_range, affiliation): self.logger.log_text(f"Uploading fire event {fire_event_name}") self.upload_cogs( metrics_stack=metrics_stack, fire_event_name=fire_event_name, prefire_date_range=prefire_date_range, - postfire_date_range=postfire_date_range + postfire_date_range=postfire_date_range, + affiliation=affiliation ) bounds = [round(pos, 4) for pos in metrics_stack.rio.bounds()] @@ -191,7 +193,8 @@ def upload_fire_event(self, metrics_stack, fire_event_name, prefire_date_range, fire_event_name=fire_event_name, bounds=bounds, prefire_date_range=prefire_date_range, - postfire_date_range=postfire_date_range + postfire_date_range=postfire_date_range, + affiliation=affiliation ) def get_manifest(self):