Create main.py
Browse files
main.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException
|
| 2 |
+
from argopy import DataFetcher
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
from fastapi.responses import FileResponse
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
app = FastAPI()
|
| 8 |
+
|
| 9 |
+
@app.get("/plot_trajectory")
|
| 10 |
+
def plot_trajectory(lon_min: float, lon_max: float, lat_min: float, lat_max: float,
|
| 11 |
+
depth_min: int, depth_max: int,
|
| 12 |
+
date_start: str, date_end: str):
|
| 13 |
+
try:
|
| 14 |
+
# Create data fetcher with user inputs
|
| 15 |
+
f = DataFetcher().region([lon_min, lon_max, lat_min, lat_max, depth_min, depth_max, date_start, date_end])
|
| 16 |
+
|
| 17 |
+
# Plotting
|
| 18 |
+
plt.figure()
|
| 19 |
+
f.plot('trajectory', add_legend=False)
|
| 20 |
+
plot_path = "trajectory_plot.png"
|
| 21 |
+
plt.savefig(plot_path)
|
| 22 |
+
plt.close()
|
| 23 |
+
|
| 24 |
+
return FileResponse(plot_path)
|
| 25 |
+
except Exception as e:
|
| 26 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 27 |
+
|
| 28 |
+
if __name__ == "__main__":
|
| 29 |
+
import uvicorn
|
| 30 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|