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

tests/quality_controll.ipynb

- fixed bug in plotting of station positions

README.md
- started rework of documentation of examples

.gitignore added directory used for examples
parent 867581bb
No related branches found
No related tags found
1 merge request!11Creation of first beta release version
......@@ -7,3 +7,4 @@ tests/cache/
*/.ipynb_checkpoints/
tests/data/
data/
tests/results
......@@ -4,7 +4,7 @@ TOAR Gridding Tool
# About
The TOARgridding projects data from the TOAD database (https://toar-data.fz-juelich.de/) onto a grid.
The stations within one cell of the grid are averaged.
The mean and standard deviation of all stations within a cell are computed.
The tool handels the request to the database over the REST API and the subsequent processing.
The results are provided as xarray objects for subsequent processing by the user.
......@@ -33,8 +33,14 @@ poetry install
# Example
There are at the moment three example provided as jupyter notebooks:
tests/procude_data.ipynb provides an example on how the high level interface can be used.
## High level function
```
tests/procude_data.ipynb
```
Provides an example on how to download data and save them as netCDF files.
## Retrieving data
get_sample_data.ipynb downloads already sampled data from the TOAR database.
## Retriving data and visualization
quality_controll.ipynb processes the data of obtained with get_sample_data.ipynb.
# Supported Grids
......@@ -43,6 +49,6 @@ The first supported grid is the Cartesian grid.
# Supported Variables
at the moment only a limited number of variables from the TOAR database is supported.
At the moment only a limited number of variables from the TOAR database is supported.
%% Cell type:markdown id: tags:
### Get Dataset from request
%% Cell type:code id: tags:
``` python
from datetime import datetime as dt
from pathlib import Path
import pandas as pd
import numpy as np
from toargridding.grids import RegularGrid
from toargridding.toar_rest_client import (
AnalysisServiceDownload,
STATION_LAT,
STATION_LON,
)
from toargridding.metadata import Metadata, TimeSample, AnalysisRequestResult, Coordinates
from toargridding.variables import Coordinate
endpoint = "https://toar-data.fz-juelich.de/api/v2/analysis/statistics/"
#starts in diretory [path/to/toargridding]/tests
#maybe adopt the toargridding_base_path for your machine.
toargridding_base_path = Path(".")
cache_dir = toargridding_base_path / "cache"
data_download_dir = toargridding_base_path / "data"
analysis_service = AnalysisServiceDownload(endpoint, cache_dir, data_download_dir)
my_grid = RegularGrid(1.9, 2.5)
time = TimeSample(dt(2016,1,1), dt(2016,12,31), "daily")
metadata = Metadata.construct("mole_fraction_of_ozone_in_air", "mean", time)
#not used in this notebook
#with open("data/daily_2010-01-01_2011-01-01.zip", "r+b") as sample_file:
# response_content = sample_file.read()
```
%% Cell type:code id: tags:
``` python
# this cell can runs longer than 30minutes
data = analysis_service.get_data(metadata)
ds = my_grid.as_xarray(data)
```
%% Cell type:markdown id: tags:
### Visual inspection
%% Cell type:code id: tags:
``` python
#calculation of coordinates for plotting
#especially separation of coordinates with results and without results.
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
mean_data = ds["mean"]
clean_coords = data.stations_coords
all_na = data.stations_data.isna().all(axis=1)
clean_coords = all_na.to_frame().join(clean_coords)[["latitude", "longitude"]]
all_na_coords = clean_coords[all_na]
not_na_coords = clean_coords[~all_na]
```
%% Cell type:code id: tags:
``` python
import matplotlib as mpl
#definition of plot function
#definition of plotting function
def plot_cells(data, stations, na_stations, discrete=True, plot_stations=False):
fig = plt.figure(figsize=(9, 18))
ax = plt.axes(projection=ccrs.PlateCarree())
ax.coastlines()
gl = ax.gridlines(draw_labels=True)
gl.top_labels = False
gl.left_labels = False
gl.xlocator = mticker.FixedLocator(data.longitude.values)
gl.ylocator = mticker.FixedLocator(data.latitude.values)
cmap = mpl.cm.viridis
if discrete:
print(np.unique(data.values))
bounds = np.arange(8)
norm = mpl.colors.BoundaryNorm(bounds, cmap.N, extend="both")
ticks = np.arange(bounds.size + 1)[:-1] + 0.5
ticklables = bounds
im = plt.pcolormesh(
data.longitude,
data.latitude,
data,
transform=ccrs.PlateCarree(),
cmap=cmap,
shading="nearest",
norm=norm,
)
cb = fig.colorbar(im, ax=ax, shrink=0.2, aspect=25)
cb.set_ticks(ticks)
cb.set_ticklabels(ticklables)
im = plt.pcolormesh(
data.longitude,
data.latitude,
data,
transform=ccrs.PlateCarree(),
cmap=cmap,
shading="nearest",
norm=norm,
)
else:
im = plt.pcolormesh(
data.longitude,
data.latitude,
data,
transform=ccrs.PlateCarree(),
cmap=cmap,
shading="nearest",
)
cb = fig.colorbar(im, ax=ax, shrink=0.2, aspect=25)
if plot_stations:
plt.scatter(na_stations[STATION_LON], na_stations[STATION_LAT], s=1, c="k")
plt.scatter(stations[STATION_LON], stations[STATION_LAT], s=1, c="r")
plt.scatter(na_stations["longitude"], na_stations["latitude"], s=1, c="k")
plt.scatter(stations["longitude"], stations["latitude"], s=1, c="r")
plt.tight_layout()
plt.title(f"global ozon at {data.time.values}")
plt.title(f"global ozon at {data.time.values} {data.time.units}")
```
%% Cell type:code id: tags:
``` python
#example visualization for two timepoints
print(not_na_coords)
timestep = 2
time = ds.time[timestep]
data = ds.sel(time=time)
plot_cells(data["mean"], not_na_coords, all_na_coords, discrete=False)
plot_cells(data["mean"], not_na_coords, all_na_coords, discrete=False, plot_stations=True)
plt.show()
plot_cells(data["n"], not_na_coords, all_na_coords, discrete=True)
plt.show()
n_observations = ds["n"].sum(["latitude", "longitude"])
plt.plot(ds.time, n_observations)
print(np.unique(ds["n"]))
```
%% Cell type:code id: tags:
``` python
print(data)
```
......
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