-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from CMCC-Foundation/hotfix_v0.1a1
Hotfix v0.1a1
- Loading branch information
Showing
12 changed files
with
153 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,3 +112,4 @@ venv.bak/ | |
_catalogs/ | ||
_old/ | ||
|
||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
ARG REGISTRY=rg.fr-par.scw.cloud/geolake | ||
ARG TAG=latest | ||
FROM $REGISTRY/geolake-datastore:$TAG | ||
|
||
RUN apt update && apt install -y cron curl | ||
|
||
WORKDIR /app | ||
COPY requirements.txt /code/requirements.txt | ||
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt | ||
COPY app /app | ||
EXPOSE 80 | ||
|
||
COPY ./healtcheck.* /opt/ | ||
|
||
RUN chmod +x /opt/healtcheck.sh | ||
RUN crontab -u root /opt/healtcheck.cron | ||
|
||
CMD ["uvicorn", "app.main:app", "--proxy-headers", "--host", "0.0.0.0", "--port", "80"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*/10 * * * * bash -c '/opt/healtcheck.sh' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
curl https://hc-ping.com/$HEALTCHECKS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
"""geokube driver for intake.""" | ||
|
||
from typing import Mapping, Optional | ||
import geokube | ||
import numpy as np | ||
import xarray as xr | ||
from .base import GeokubeSource | ||
from geokube import open_datacube, open_dataset | ||
from geokube.core.datacube import DataCube | ||
|
||
_PROJECTION = {"grid_mapping_name": "latitude_longitude"} | ||
|
||
def postprocess_afm(ds: xr.Dataset, **post_process_chunks): | ||
if isinstance(ds, geokube.core.datacube.DataCube): | ||
ds = ds.to_xarray() | ||
latitude = ds['lat'].values | ||
longitude = ds['lon'].values | ||
# ds = ds.expand_dims(dim={"latitude": latitude, "longitude": longitude}, axis=(1,0)) | ||
ds = ds.drop('lat') | ||
ds = ds.drop('lon') | ||
ds = ds.drop('certainty') | ||
deduplicated = ds.expand_dims(dim={"latitude": latitude, "longitude": longitude}, axis=(1, 0)) | ||
# print(deduplicated.dims) | ||
for dim in deduplicated.dims: | ||
indexes = {dim: ~deduplicated.get_index(dim).duplicated(keep='first')} | ||
deduplicated = deduplicated.isel(indexes) | ||
return DataCube.from_xarray( | ||
deduplicated.sortby('time').sortby('latitude').sortby('longitude').chunk(post_process_chunks)) | ||
|
||
def add_projection(dset: xr.Dataset, **kwargs) -> xr.Dataset: | ||
"""Add projection information to the dataset""" | ||
coords = dset.coords | ||
coords["crs"] = xr.DataArray(data=np.array(1), attrs=_PROJECTION) | ||
for var in dset.data_vars.values(): | ||
enc = var.encoding | ||
enc["grid_mapping"] = "crs" | ||
return dset | ||
|
||
|
||
class CMCCAFMSource(GeokubeSource): | ||
name = "cmcc_afm_geokube" | ||
|
||
def __init__( | ||
self, | ||
path: str, | ||
pattern: str = None, | ||
field_id: str = None, | ||
delay_read_cubes: bool = False, | ||
metadata_caching: bool = False, | ||
metadata_cache_path: str = None, | ||
storage_options: dict = None, | ||
xarray_kwargs: dict = None, | ||
metadata=None, | ||
mapping: Optional[Mapping[str, Mapping[str, str]]] = None, | ||
load_files_on_persistance: Optional[bool] = True, | ||
postprocess_chunk: Optional = None | ||
): | ||
self._kube = None | ||
self.path = path | ||
self.pattern = pattern | ||
self.field_id = field_id | ||
self.delay_read_cubes = delay_read_cubes | ||
self.metadata_caching = metadata_caching | ||
self.metadata_cache_path = metadata_cache_path | ||
self.storage_options = storage_options | ||
self.mapping = mapping | ||
self.xarray_kwargs = {} if xarray_kwargs is None else xarray_kwargs | ||
self.load_files_on_persistance = load_files_on_persistance | ||
self.postprocess_chunk = postprocess_chunk | ||
# self.preprocess = preprocess_afm | ||
super(CMCCAFMSource, self).__init__(metadata=metadata) | ||
|
||
def _open_dataset(self): | ||
if self.pattern is None: | ||
self._kube =\ | ||
postprocess_afm( | ||
open_datacube( | ||
path=self.path, | ||
id_pattern=self.field_id, | ||
metadata_caching=self.metadata_caching, | ||
metadata_cache_path=self.metadata_cache_path, | ||
mapping=self.mapping, | ||
**self.xarray_kwargs, | ||
# preprocess=self.preprocess | ||
), | ||
**self.postprocess_chunk | ||
).resample('maximum', frequency='1H') | ||
else: | ||
self._kube = open_dataset( | ||
path=self.path, | ||
pattern=self.pattern, | ||
id_pattern=self.field_id, | ||
metadata_caching=self.metadata_caching, | ||
metadata_cache_path=self.metadata_cache_path, | ||
mapping=self.mapping, | ||
**self.xarray_kwargs, | ||
# preprocess=self.preprocess | ||
).apply(postprocess_afm,**self.postprocess_chunk).resample('maximum', frequency='1H') | ||
return self._kube |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,18 @@ | ||
ARG REGISTRY=rg.fr-par.scw.cloud/geolake | ||
ARG TAG=latest | ||
FROM $REGISTRY/geolake-datastore:$TAG | ||
|
||
RUN apt update && apt install -y cron curl | ||
|
||
|
||
WORKDIR /app | ||
COPY requirements.txt /code/requirements.txt | ||
RUN pip install --no-cache-dir -r /code/requirements.txt | ||
COPY app /app | ||
|
||
COPY ./healtcheck.* /opt/ | ||
|
||
RUN chmod +x /opt/healtcheck.sh | ||
RUN crontab -u root /opt/healtcheck.cron | ||
|
||
CMD [ "python", "main.py" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*/10 * * * * bash -c '/opt/healtcheck.sh' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
curl https://hc-ping.com/$HEALTCHECKS |