-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackend.py
More file actions
27 lines (20 loc) · 869 Bytes
/
backend.py
File metadata and controls
27 lines (20 loc) · 869 Bytes
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
from typing import List
from pydantic import BaseModel
import xarray as xr
from dask.distributed import Client, Future
DASK_CLUSTER = "localhost:8786"
class Item(BaseModel):
latitude: List[float] = []
longitude: List[float] = []
async def get_data(locs: Item):
async with Client(DASK_CLUSTER, asynchronous=True) as client:
zarr_store = r"data/air_rechunked_consolid.zarr"
da_zr = xr.open_zarr(zarr_store, consolidated=True)['air']
sel_lats = locs.latitude
sel_lons = locs.longitude
da_sel = da_zr.sel(lat=xr.DataArray(sel_lats, dims='points'),
lon=xr.DataArray(sel_lons, dims='points'),
method='nearest'
).to_dask_dataframe()
future: Future = client.compute(da_sel)
return await future