File size: 1,026 Bytes
fc192b7 e80b519 99befaf fc192b7 1834e41 464bbf7 fc192b7 1834e41 fc192b7 c73b96a fc192b7 c73b96a fc192b7 9706359 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
from fastapi import FastAPI, HTTPException
from argopy import DataFetcher
import matplotlib.pyplot as plt
from fastapi.responses import StreamingResponse
import io
app = FastAPI()
@app.get("/plot_trajectory")
def plot_trajectory(lon_min: float, lon_max: float, lat_min: float, lat_max: float,
depth_min: float, depth_max: float,
date_start: str, date_end: str):
try:
# Create data fetcher with user inputs
f = DataFetcher().region([lon_min, lon_max, lat_min, lat_max, depth_min, depth_max, date_start, date_end])
# Plotting
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)
|