Skip to content

Commit

Permalink
fix bug with b8_fname not defined and tmp_dir.cleanup not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
favyen2 committed Oct 21, 2024
1 parent 3a9cad1 commit ee16650
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions rslp/landsat_vessels/predict_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"]:
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit ee16650

Please sign in to comment.