| import gradio as gr |
| import numpy as np |
| from pykrige.ok import OrdinaryKriging |
|
|
|
|
| def fonction_api(lat, lon, debit_min, date): |
| |
| echelle = 10 |
| x = np.array(x) |
| y = np.array(y) |
| z = np.array(z) |
| grid_x_min = x.min() |
| grid_x_max = x.max() |
| grid_y_min = y.min() |
| grid_y_max = y.max() |
| delta_x, delta_y = (grid_x_max - grid_x_min) / \ |
| echelle, (grid_y_max - grid_y_min)/echelle |
| grid_x = np.linspace(grid_x_min, grid_x_max, echelle, dtype="float64") |
| grid_y = np.linspace(grid_y_min, grid_y_max, echelle, dtype="float64") |
| OK = OrdinaryKriging(x, y, z, variogram_model="exponential",) |
| zstar, ss = OK.execute("grid", grid_x, grid_y) |
| mask = zstar > debit_min |
| lat_pred = [] |
| lon_pred = [] |
| debit_pred = [] |
| for i in range(echelle): |
| for j in range(echelle): |
| if mask[i, j] == True: |
| lat_pred.append( |
| ((grid_x_min + (i-1)*delta_x)+(grid_x_min + i*delta_x))/2) |
| lon_pred.append( |
| ((grid_y_min + (j-1)*delta_y)+(grid_y_min + j*delta_y))/2) |
| debit_pred.append(zstar[i, j]) |
| data = {} |
| for i in range(len(lat_pred)): |
| data["point " + str(i)] = [lat_pred[i], lon_pred[i], debit_pred[i]] |
| return data |
|
|
|
|
| demo = gr.Interface(fn=fonction_api, inputs=[ |
| "number", "number", "number", "text"], outputs="json") |
| demo.launch() |
|
|