Skip to content
Snippets Groups Projects
Commit ae84d05a authored by Simon Grasse's avatar Simon Grasse
Browse files

wip status of unit testing, various notebooks

parent 623f9362
No related branches found
No related tags found
1 merge request!11Creation of first beta release version
from toargridding.grids import GridDefinition, GridType
from toargridding.toar_rest_client import AnalysisService
from toargridding.metadata import TimeSample, Metadata
from toargridding.gridding import get_gridded_toar_data
from itertools import product
from datetime import datetime
from pathlib import Path
import pytest
from toargridding.grids import RegularGrid
from toargridding.metadata import TimeSample
from toargridding.metadata import TimeSample, Metadata, TOARVariable
from toargridding.toar_rest_client import AnalysisService
test_data = list((Path(__file__).parent / "data").iterdir())
TEST_SAMPLINGS = ["daily"]
TEST_STATS = ["mean"]
@pytest.fixture
def regular_grid():
......@@ -16,15 +20,33 @@ def regular_grid():
# TODO investigate -1 day discrepancy in time index
@pytest.fixture
def time():
@pytest.fixture(params=TEST_SAMPLINGS)
def time(request):
start = datetime(2009, 12, 31)
end = datetime(2011, 1, 1)
sampling = "daily"
sampling = request.param
return TimeSample(start, end, sampling)
@pytest.fixture
def toar_variable_ozon():
return TOARVariable(
"o3",
"ozone",
"Ozone",
"mole_fraction_of_ozone_in_air",
"nmol mol-1",
"O3",
5,
)
@pytest.fixture
def metadata_ozone_mean(toar_variable_ozon, time):
return Metadata(toar_variable_ozon, "mean", time)
def load_local_data(*args, **kwargs):
with open(test_data[2], "r+b") as f:
return f.read()
......
%% Cell type:code id: tags:
``` python
from datetime import datetime
from datetime import datetime, timedelta
sampling = "monthly"
start = datetime(2010,1,1)
end = datetime(2011,1,1)
from toargridding.metadata import TimeSample, Metadata
print(start.date(), end.date())
print(start.isoformat(), end.isoformat())
sampling = "daily" # FIXME check monthly !!!
start = datetime(2016, 3, 1)
end = datetime(2016, 3, 3)
statistics_endpoint = "https://toar-data.fz-juelich.de/api/v2/analysis/statistics/"
statistic = "mean"
time = TimeSample(start, end, sampling=sampling)
metadata = Metadata.construct("mole_fraction_of_ozone_in_air", statistic, time)
start_time = datetime.now()
print(start_time)
```
%% Cell type:code id: tags:
``` python
from pathlib import Path
from toargridding.toar_rest_client import AnalysisServiceDownload
toargridding_base_path = Path("/home/simon/Projects/toar/toargridding/")
cache_dir = toargridding_base_path / "tests" / "results"
download_dir = toargridding_base_path / "tests" / "data"
analysis_service = AnalysisServiceDownload(statistics_endpoint, cache_dir, download_dir)
analysis_service.get_data(metadata)
end_time = datetime.now()
print(end_time-start_time)
```
%% Cell type:code id: tags:
``` python
# %%script false --no-error
import requests
end_with_padding = end + timedelta(1)
response = requests.get(
"https://toar-data.fz-juelich.de/api/v2/analysis/statistics/",
statistics_endpoint,
params={
"daterange": f"{start.isoformat()},{end.isoformat()}", # 1-year
"daterange": f"{start.isoformat()},{end_with_padding.isoformat()}", # 1-year
"variable_id": 5,
"statistics": "mean",
"sampling": sampling, # daily sampling
"statistics": statistic,
"sampling": sampling,
"min_data_capture": 0,
"limit": "None", # get all timeseries
"limit": "None", # get all timeseries
"format": "by_statistic",
"metadata_scheme": "basic"
}
"metadata_scheme": "basic",
},
)
print(response)
print(response.headers)
print(response.json())
```
%% Cell type:code id: tags:
``` python
print(response.status_code)
status_endpoint = response.json()["status"]
print(status_endpoint)
response.headers["Content-Type"] == "application/json"
```
%% Cell type:code id: tags:
``` python
import time
waiting_for_data = True
start_time = time.time()
while waiting_for_data:
time.sleep(30)
response = requests.get(status_endpoint)
waiting_for_data = (response.headers["Content-Type"] == "application/json")
import requests
response_time = time.time() - start_time
print(response_time)
```
status_endpoint = "https://toar-data.fz-juelich.de/api/v2/analysis/status/5ec3a54c-322c-4bce-a3f5-fdf485a56514"
%% Cell type:code id: tags:
``` python
response.headers["Content-Type"], response.headers["Content-Length"]
response = requests.get(status_endpoint)
print(response.headers)
print(response.json())
```
%% Cell type:code id: tags:
``` python
with open(f"data/{sampling}_{start.date()}_{end.date()}.zip", "w+b") as sample_file:
sample_file.write(response.content)
```
......
from unittest import mock
from pytest import fixture
from toargridding.toar_rest_client import AnalysisService, QueryOptions
def test_query_options_cache_key(metadata_ozone_mean):
q1 = QueryOptions.from_metadata(metadata_ozone_mean)
q2 = QueryOptions.from_metadata(metadata_ozone_mean)
assert q1.cache_key == q2.cache_key
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment