Skip to content
Snippets Groups Projects
Commit 0e1d9ebb authored by Carsten Hinz's avatar Carsten Hinz
Browse files

worked on documentation.

removed manual creation of request from get_sample_data.ipynb
this is handled in a different example (get_sample_data_manual.ipynb)
parent 7e96d44c
Branches
Tags
1 merge request!11Creation of first beta release version
...@@ -22,6 +22,7 @@ TBD, see pyproject.toml ...@@ -22,6 +22,7 @@ TBD, see pyproject.toml
Move to the folder you want to create download this project to. Move to the folder you want to create download this project to.
We now need to download the source code (https://gitlab.jsc.fz-juelich.de/esde/toar-public/toargridding/-/tree/dev?ref_type=heads). Either as ZIP folder or via git: We now need to download the source code (https://gitlab.jsc.fz-juelich.de/esde/toar-public/toargridding/-/tree/dev?ref_type=heads). Either as ZIP folder or via git:
## Download with GIT
Clone the project from its git repository: Clone the project from its git repository:
``` ```
git clone https://gitlab.jsc.fz-juelich.de/esde/toar-public/toargridding.git git clone https://gitlab.jsc.fz-juelich.de/esde/toar-public/toargridding.git
...@@ -32,6 +33,7 @@ cd toargridding ...@@ -32,6 +33,7 @@ cd toargridding
git checkout dev git checkout dev
``` ```
## Installing Dependencies
The handling of required packages is done with poetry. So run poetry in the project directory: The handling of required packages is done with poetry. So run poetry in the project directory:
``` ```
...@@ -46,17 +48,21 @@ There are at the moment three example provided as jupyter notebooks (https://jup ...@@ -46,17 +48,21 @@ There are at the moment three example provided as jupyter notebooks (https://jup
tests/produce_data.ipynb tests/produce_data.ipynb
``` ```
Provides an example on how to download data, apply gridding and save the results as netCDF files. Provides an example on how to download data, apply gridding and save the results as netCDF files.
A possible improvement for is the exchange of the AnalysisService with AnalysisServiceDownload, which caches requests from the TOARDB.
This allows different griddings without the necessity to repeat the request to the TOARDB and subsequent download.
## Retrieving data ## Retrieving data
``` ```
get_sample_data.ipynb get_sample_data.ipynb
``` ```
Downloads data from the TOAR database. Downloads data from the TOAR database. The extracted data are written to disc. No further processing or gridding is done.
## Retrieving data ## Retrieving data
``` ```
get_sample_data_manual.ipynb get_sample_data_manual.ipynb
``` ```
Downloads data from the TOAR database with a manual creation of the request to the TOAR database. Downloads data from the TOAR database with a manual creation of the request to the TOAR database.
This example does not perform any gridding.
## Retriving data and visualization ## Retriving data and visualization
``` ```
......
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
from datetime import datetime, timedelta from datetime import datetime, timedelta
from toargridding.metadata import TimeSample, Metadata from toargridding.metadata import TimeSample, Metadata
sampling = "daily" # FIXME check monthly !!! sampling = "daily" # FIXME check monthly !!!
start = datetime(2010, 1, 1) start = datetime(2010, 1, 1)
end = datetime(2011, 1, 1) end = datetime(2011, 1, 1)
statistics_endpoint = "https://toar-data.fz-juelich.de/api/v2/analysis/statistics/" statistics_endpoint = "https://toar-data.fz-juelich.de/api/v2/analysis/statistics/"
statistic = "mean" statistic = "mean"
time = TimeSample(start, end, sampling=sampling) time = TimeSample(start, end, sampling=sampling)
metadata = Metadata.construct("mole_fraction_of_ozone_in_air", statistic, time) metadata = Metadata.construct("mole_fraction_of_ozone_in_air", statistic, time)
start_time = datetime.now() start_time = datetime.now()
print(start_time) print(start_time)
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
from pathlib import Path from pathlib import Path
from toargridding.toar_rest_client import AnalysisServiceDownload from toargridding.toar_rest_client import AnalysisServiceDownload
#creation of output directories #creation of output directories
toargridding_base_path = Path(".") toargridding_base_path = Path(".")
cache_dir = toargridding_base_path / "results" cache_dir = toargridding_base_path / "results"
download_dir = toargridding_base_path / "data" download_dir = toargridding_base_path / "data"
cache_dir.mkdir(parents=True, exist_ok=True) cache_dir.mkdir(parents=True, exist_ok=True)
download_dir.mkdir(parents=True, exist_ok=True) download_dir.mkdir(parents=True, exist_ok=True)
analysis_service = AnalysisServiceDownload(statistics_endpoint, cache_dir, download_dir) analysis_service = AnalysisServiceDownload(statistics_endpoint, cache_dir, download_dir)
analysis_service.get_data(metadata) results = analysis_service.get_data(metadata)
end_time = datetime.now() end_time = datetime.now()
print(end_time-start_time) print(end_time-start_time)
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
# %%script false --no-error
# manual access to data
import requests
end_with_padding = end + timedelta(1)
response = requests.get(
statistics_endpoint,
params={
"daterange": f"{start.isoformat()},{end_with_padding.isoformat()}", # 1-year
"variable_id": 5,
"statistics": statistic,
"sampling": sampling,
"min_data_capture": 0,
"limit": "None", # get all timeseries
"format": "by_statistic",
"metadata_scheme": "basic",
},
)
print(response)
print(response.headers)
print(response.json())
```
%% Cell type:code id: tags:
``` python
print(response.headers["Content-Type"] == "application/json")
```
%% Cell type:code id: tags:
``` python
import requests
#this hard coded link does not work.
#status_endpoint = "https://toar-data.fz-juelich.de/api/v2/analysis/status/5ec3a54c-322c-4bce-a3f5-fdf485a56514"
#response = requests.get(status_endpoint)
#print(response.headers)
#print(response.json())
```
%% Cell type:code id: tags:
``` python
``` ```
......
...@@ -267,6 +267,8 @@ class AnalysisService: ...@@ -267,6 +267,8 @@ class AnalysisService:
---------- ----------
metadata: metadata:
meta data for the request. meta data for the request.
return:
Requested data and statistics, station coordinates and metadata of the request
""" """
timeseries, timeseries_metadata = self.get_timeseries_and_metadata(metadata) timeseries, timeseries_metadata = self.get_timeseries_and_metadata(metadata)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment