cecil 0.0.22__tar.gz → 0.0.24__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of cecil might be problematic. Click here for more details.
- {cecil-0.0.22 → cecil-0.0.24}/PKG-INFO +1 -1
- {cecil-0.0.22 → cecil-0.0.24}/src/cecil/client.py +10 -1
- {cecil-0.0.22 → cecil-0.0.24}/src/cecil/models.py +26 -1
- cecil-0.0.24/src/cecil/version.py +1 -0
- cecil-0.0.24/src/cecil/xarray.py +74 -0
- {cecil-0.0.22 → cecil-0.0.24}/tests/test_client.py +6 -0
- cecil-0.0.22/src/cecil/version.py +0 -1
- {cecil-0.0.22 → cecil-0.0.24}/.editorconfig +0 -0
- {cecil-0.0.22 → cecil-0.0.24}/.gitignore +0 -0
- {cecil-0.0.22 → cecil-0.0.24}/CONTRIBUTING.md +0 -0
- {cecil-0.0.22 → cecil-0.0.24}/LICENSE.txt +0 -0
- {cecil-0.0.22 → cecil-0.0.24}/Makefile +0 -0
- {cecil-0.0.22 → cecil-0.0.24}/README.md +0 -0
- {cecil-0.0.22 → cecil-0.0.24}/pyproject.toml +0 -0
- {cecil-0.0.22 → cecil-0.0.24}/src/cecil/__init__.py +0 -0
- {cecil-0.0.22 → cecil-0.0.24}/src/cecil/errors.py +0 -0
- {cecil-0.0.22 → cecil-0.0.24}/tests/__init__.py +0 -0
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import os
|
|
2
|
-
from typing import Dict, List, Optional
|
|
3
2
|
|
|
4
3
|
import pandas as pd
|
|
5
4
|
import requests
|
|
6
5
|
import snowflake.connector
|
|
6
|
+
import xarray
|
|
7
|
+
|
|
7
8
|
from pydantic import BaseModel
|
|
8
9
|
from requests import auth
|
|
9
10
|
from cryptography.hazmat.primitives import serialization
|
|
11
|
+
from typing import Dict, List, Optional
|
|
10
12
|
|
|
11
13
|
from .errors import (
|
|
12
14
|
Error,
|
|
@@ -31,8 +33,10 @@ from .models import (
|
|
|
31
33
|
TransformationCreate,
|
|
32
34
|
User,
|
|
33
35
|
UserCreate,
|
|
36
|
+
DataRequestMetadata,
|
|
34
37
|
)
|
|
35
38
|
from .version import __version__
|
|
39
|
+
from .xarray import load_xarray
|
|
36
40
|
|
|
37
41
|
|
|
38
42
|
class Client:
|
|
@@ -78,6 +82,11 @@ class Client:
|
|
|
78
82
|
res = self._get(url="/v0/data-requests")
|
|
79
83
|
return [DataRequest(**record) for record in res["records"]]
|
|
80
84
|
|
|
85
|
+
def load_xarray(self, data_request_id: str) -> xarray.Dataset:
|
|
86
|
+
res = self._get(url=f"/v0/data-requests/{data_request_id}/metadata")
|
|
87
|
+
metadata = DataRequestMetadata(**res)
|
|
88
|
+
return load_xarray(metadata)
|
|
89
|
+
|
|
81
90
|
def create_transformation(
|
|
82
91
|
self, data_request_id: str, crs: str, spatial_resolution: float
|
|
83
92
|
) -> Transformation:
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import datetime
|
|
2
|
-
from typing import Dict, Optional
|
|
2
|
+
from typing import Dict, Optional, List
|
|
3
3
|
|
|
4
4
|
from pydantic import BaseModel, ConfigDict, SecretStr
|
|
5
5
|
from pydantic.alias_generators import to_camel
|
|
@@ -110,3 +110,28 @@ class UserCreate(BaseModel):
|
|
|
110
110
|
first_name: str
|
|
111
111
|
last_name: str
|
|
112
112
|
email: str
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
class Band(BaseModel):
|
|
116
|
+
model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True)
|
|
117
|
+
variable_name: str
|
|
118
|
+
time: str
|
|
119
|
+
time_pattern: str
|
|
120
|
+
number: int
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
class File(BaseModel):
|
|
124
|
+
model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True)
|
|
125
|
+
url: str
|
|
126
|
+
bands: List[Band]
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
class DataRequestMetadata(BaseModel):
|
|
130
|
+
model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True)
|
|
131
|
+
provider_name: str
|
|
132
|
+
dataset_id: str
|
|
133
|
+
dataset_name: str
|
|
134
|
+
dataset_crs: str
|
|
135
|
+
aoi_id: str
|
|
136
|
+
data_request_id: str
|
|
137
|
+
files: List[File]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.0.24"
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import rioxarray
|
|
3
|
+
import xarray
|
|
4
|
+
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
|
|
7
|
+
from .errors import Error
|
|
8
|
+
from .models import DataRequestMetadata
|
|
9
|
+
|
|
10
|
+
os.environ["GDAL_NUM_THREADS"] = "1"
|
|
11
|
+
os.environ["GDAL_DISABLE_READDIR_ON_OPEN"] = "FALSE"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def align_pixel_grids(time_series):
|
|
15
|
+
# Use the first timestep as reference
|
|
16
|
+
reference_da = time_series[0]
|
|
17
|
+
aligned_series = [reference_da]
|
|
18
|
+
|
|
19
|
+
# Align all other timesteps to the reference grid
|
|
20
|
+
for i, da in enumerate(time_series[1:], 1):
|
|
21
|
+
try:
|
|
22
|
+
aligned_da = da.rio.reproject_match(reference_da)
|
|
23
|
+
aligned_series.append(aligned_da)
|
|
24
|
+
except Exception as e:
|
|
25
|
+
raise Error
|
|
26
|
+
continue
|
|
27
|
+
|
|
28
|
+
return aligned_series
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def load_xarray(metadata: DataRequestMetadata) -> xarray.Dataset:
|
|
32
|
+
data_vars = {}
|
|
33
|
+
|
|
34
|
+
for f in metadata.files:
|
|
35
|
+
dataset = rioxarray.open_rasterio(
|
|
36
|
+
f.url,
|
|
37
|
+
chunks={"x": 2000, "y": 2000},
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
for b in f.bands:
|
|
41
|
+
band = dataset.sel(band=b.number, drop=True)
|
|
42
|
+
|
|
43
|
+
if b.time and b.time_pattern:
|
|
44
|
+
time = datetime.strptime(b.time, b.time_pattern)
|
|
45
|
+
band = band.expand_dims("time")
|
|
46
|
+
band = band.assign_coords(time=[time])
|
|
47
|
+
|
|
48
|
+
band.name = b.variable_name
|
|
49
|
+
|
|
50
|
+
if b.variable_name not in data_vars:
|
|
51
|
+
data_vars[b.variable_name] = []
|
|
52
|
+
|
|
53
|
+
data_vars[b.variable_name].append(band)
|
|
54
|
+
|
|
55
|
+
for variable_name, time_series in data_vars.items():
|
|
56
|
+
if "time" in time_series[0].dims:
|
|
57
|
+
# time_series = align_pixel_grids(time_series)
|
|
58
|
+
data_vars[variable_name] = xarray.concat(
|
|
59
|
+
time_series, dim="time", join="exact"
|
|
60
|
+
)
|
|
61
|
+
else:
|
|
62
|
+
data_vars[variable_name] = time_series[0]
|
|
63
|
+
|
|
64
|
+
return xarray.Dataset(
|
|
65
|
+
data_vars=data_vars,
|
|
66
|
+
attrs={
|
|
67
|
+
"provider_name": metadata.provider_name,
|
|
68
|
+
"dataset_id": metadata.dataset_id,
|
|
69
|
+
"dataset_name": metadata.dataset_name,
|
|
70
|
+
"dataset_crs": metadata.dataset_crs,
|
|
71
|
+
"aoi_id": metadata.aoi_id,
|
|
72
|
+
"data_request_id": metadata.data_request_id,
|
|
73
|
+
},
|
|
74
|
+
)
|
|
@@ -20,6 +20,7 @@ def test_client_create_data_request():
|
|
|
20
20
|
"id": "id",
|
|
21
21
|
"aoiId": "aoi_id",
|
|
22
22
|
"datasetId": "dataset_id",
|
|
23
|
+
"externalRef": "external_ref",
|
|
23
24
|
"created_at": FROZEN_TIME,
|
|
24
25
|
"created_by": "user_id",
|
|
25
26
|
},
|
|
@@ -33,6 +34,7 @@ def test_client_create_data_request():
|
|
|
33
34
|
id="id",
|
|
34
35
|
aoiId="aoi_id",
|
|
35
36
|
datasetId="dataset_id",
|
|
37
|
+
externalRef="external_ref",
|
|
36
38
|
created_at="2024-01-01T00:00:00.000Z",
|
|
37
39
|
created_by="user_id",
|
|
38
40
|
)
|
|
@@ -49,6 +51,7 @@ def test_client_list_data_requests():
|
|
|
49
51
|
"id": "data_request_id_1",
|
|
50
52
|
"aoiId": "aoi_id",
|
|
51
53
|
"datasetId": "dataset_id",
|
|
54
|
+
"externalRef": "external_ref",
|
|
52
55
|
"created_at": "2024-09-19T04:45:57.561Z",
|
|
53
56
|
"created_by": "user_id",
|
|
54
57
|
},
|
|
@@ -56,6 +59,7 @@ def test_client_list_data_requests():
|
|
|
56
59
|
"id": "data_request_id_2",
|
|
57
60
|
"aoiId": "aoi_id",
|
|
58
61
|
"datasetId": "dataset_id",
|
|
62
|
+
"externalRef": "",
|
|
59
63
|
"created_at": "2024-09-19T04:54:38.252Z",
|
|
60
64
|
"created_by": "user_id",
|
|
61
65
|
},
|
|
@@ -71,6 +75,7 @@ def test_client_list_data_requests():
|
|
|
71
75
|
id="data_request_id_1",
|
|
72
76
|
aoiId="aoi_id",
|
|
73
77
|
datasetId="dataset_id",
|
|
78
|
+
externalRef="external_ref",
|
|
74
79
|
created_at="2024-09-19T04:45:57.561Z",
|
|
75
80
|
created_by="user_id",
|
|
76
81
|
),
|
|
@@ -78,6 +83,7 @@ def test_client_list_data_requests():
|
|
|
78
83
|
id="data_request_id_2",
|
|
79
84
|
aoiId="aoi_id",
|
|
80
85
|
datasetId="dataset_id",
|
|
86
|
+
externalRef="",
|
|
81
87
|
created_at="2024-09-19T04:54:38.252Z",
|
|
82
88
|
created_by="user_id",
|
|
83
89
|
),
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.0.22"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|