|
from fastapi import FastAPI, HTTPException |
|
from argopy import DataFetcher |
|
import matplotlib.pyplot as plt |
|
from fastapi.responses import FileResponse |
|
import io |
|
|
|
|
|
app = FastAPI() |
|
|
|
@app.get("/plot_trajectory") |
|
def plot_trajectory(lat_min: float, lat_max: float, lon_min: float, lon_max: float, |
|
depth_min: float, depth_max: float, |
|
date_start: str, date_end: str): |
|
try: |
|
|
|
f = DataFetcher().region([lat_min, lat_max, lon_min, lon_max, depth_min, depth_max, date_start, date_end]) |
|
|
|
|
|
plt.figure() |
|
f.plot('trajectory', add_legend=False) |
|
buf = io.BytesIO() |
|
plt.savefig(buf, format='png') |
|
buf.seek(0) |
|
plt.close() |
|
|
|
return StreamingResponse(buf, media_type="image/png") |
|
|
|
except Exception as e: |
|
raise HTTPException(status_code=500, detail=str(e)) |
|
|
|
if __name__ == "__main__": |
|
import uvicorn |
|
uvicorn.run(app, host="0.0.0.0", port=7860) |
|
|