- prediction/image/ FastAPI 서버 Docker 환경 구성 - Dockerfile: PyTorch 2.1 + CUDA 12.1 기반 GPU 이미지 - docker-compose.yml: GPU 할당 + 데이터 볼륨 마운트 - requirements.txt: 서버 의존성 목록 - .env.example: 환경변수 템플릿 - DOCKER_USAGE.md: 빌드/실행/API 사용법 문서 - Dockerfile에 .dockerignore 제외 폴더 mkdir -p 추가 - .gitignore: prediction/image 결과물 및 모델 가중치(.pth) 제외 추가 - dbInsert_csv.py, dbInsert_shp.py 삭제 (미사용 DB 로직) - api.py: dbInsert import 및 주석 처리된 DB 호출 코드 제거 - aerialRouter.ts: req.params 타입 오류 수정
97 lines
2.9 KiB
Python
97 lines
2.9 KiB
Python
import csv
|
|
from datetime import datetime
|
|
from pathlib import Path
|
|
import geopandas as gpd
|
|
import json
|
|
|
|
def get_metadata(camTy: str, fileId: str):
|
|
|
|
# CSV 파일 경로 설정
|
|
# base_dir = "mx15hdi" if pollId == "1" else "starsafire"
|
|
if camTy == "mx15hdi":
|
|
csv_path = f"{camTy}/Metadata/CSV/{fileId}/mx15hdi_interpolation.csv"
|
|
elif camTy == "starsafire":
|
|
csv_path = f"{camTy}/Metadata/CSV/{fileId}/Metadata_Extracted.csv"
|
|
|
|
try:
|
|
# CSV 파일 읽기
|
|
with open(csv_path, 'r', newline='', encoding='utf-8-sig') as csvfile:
|
|
reader = csv.reader(csvfile)
|
|
next(reader, None)
|
|
row = next(reader, None)
|
|
return ','.join(row)
|
|
|
|
except FileNotFoundError:
|
|
print(f"CSV file not found: {csv_path}")
|
|
raise
|
|
except ValueError as e:
|
|
print(f"Value error: {str(e)}")
|
|
raise
|
|
except Exception as e:
|
|
print(f"Error processing CSV: {e}")
|
|
raise
|
|
|
|
|
|
def get_oil_type(camTy: str, fileId: str):
|
|
# Shapefile 경로 설정
|
|
path = f"{camTy}/Polygon/Shp/{fileId}"
|
|
shp_file = list(Path(path).glob("*.shp"))
|
|
if not shp_file:
|
|
return []
|
|
shp_path = f"{camTy}/Polygon/Shp/{fileId}/{shp_file[0].name}"
|
|
print(shp_path)
|
|
# if camTy == "mx15hdi":
|
|
# fileSub = f"{Path(fileName).stem}_gsd"
|
|
# elif camTy == "starsafire":
|
|
# fileSub = f"{Path(fileName).stem}"
|
|
|
|
# shp_path = f"{camTy}/Polygon/Shp/{fileId}/{fileSub}.shp"
|
|
|
|
# 두께 정보
|
|
class_thickness_mm = {
|
|
1: 1.0, # Black oil (Emulsion)
|
|
2: 0.1, # Brown oil (Crude)
|
|
3: 0.0003, # Rainbow oil (Slick)
|
|
4: 0.0001 # Silver oil (Slick)
|
|
}
|
|
# 알고리즘 정보
|
|
algorithm = {
|
|
1: "검정",
|
|
2: "갈색",
|
|
3: "무지개",
|
|
4: "은색"
|
|
}
|
|
|
|
try:
|
|
# Shapefile 읽기
|
|
gdf = gpd.read_file(shp_path)
|
|
if gdf.crs != "epsg:4326":
|
|
gdf = gdf.to_crs("epsg:4326")
|
|
|
|
# 데이터 준비
|
|
data = []
|
|
for _, row in gdf.iterrows():
|
|
class_id = row.get('class_id', None)
|
|
area_m2 = row.get('area_m2', None)
|
|
volume_m3 = row.get('volume_m3', None)
|
|
note = row.get('note', None)
|
|
thickness_m = class_thickness_mm.get(class_id, 0) / 1000.0
|
|
geom_wkt = row.geometry.wkt if row.geometry else None
|
|
result = {
|
|
"classId": algorithm.get(class_id, 0),
|
|
"area": area_m2,
|
|
"volume": volume_m3,
|
|
"note": note,
|
|
"thickness": thickness_m,
|
|
"wkt": geom_wkt
|
|
}
|
|
data.append(result)
|
|
|
|
return data
|
|
|
|
except FileNotFoundError:
|
|
print(f"Shapefile not found: {shp_path}")
|
|
raise
|
|
except Exception as e:
|
|
print(f"Error processing shapefile or database: {str(e)}")
|
|
raise |