diff --git a/rslp/landsat_vessels/predict_pipeline.py b/rslp/landsat_vessels/predict_pipeline.py index 848ab70d..99de4dd2 100644 --- a/rslp/landsat_vessels/predict_pipeline.py +++ b/rslp/landsat_vessels/predict_pipeline.py @@ -210,8 +210,8 @@ def predict_pipeline( # Use temporary directory if scratch_path or crop_path are not specified. if scratch_path is None: - with tempfile.TemporaryDirectory() as tmp_dir: - scratch_path = tmp_dir + tmp_dir = tempfile.TemporaryDirectory() + scratch_path = tmp_dir.name else: tmp_dir = None @@ -296,6 +296,20 @@ def predict_pipeline( json_data = [] for idx, detection in enumerate(detections): + # Get longitude/latitude. + src_geom = STGeometry( + detection.projection, shapely.Point(detection.col, detection.row), None + ) + dst_geom = src_geom.to_projection(WGS84_PROJECTION) + lon = dst_geom.shp.x + lat = dst_geom.shp.y + + json_dict = dict( + longitude=lon, + latitude=lat, + score=detection.score, + ) + # Load crops from the window directory. images = {} for band in ["B2", "B3", "B4", "B8"]: @@ -333,23 +347,10 @@ def predict_pipeline( with b8_fname.open("wb") as f: Image.fromarray(images["B8"]).save(f, format="PNG") - # Get longitude/latitude. - src_geom = STGeometry( - detection.projection, shapely.Point(detection.col, detection.row), None - ) - dst_geom = src_geom.to_projection(WGS84_PROJECTION) - lon = dst_geom.shp.x - lat = dst_geom.shp.y + json_dict["rgb_fname"] = str(rgb_fname) + json_dict["b8_fname"] = str(b8_fname) - json_data.append( - dict( - longitude=lon, - latitude=lat, - score=detection.score, - rgb_fname=str(rgb_fname), - b8_fname=str(b8_fname), - ) - ) + json_data.append(json_dict) time_profile["write_json_and_crops"] = time.time() - step_start_time