Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
toargridding
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
esde
toar-public
toargridding
Commits
867581bb
Commit
867581bb
authored
1 year ago
by
Carsten Hinz
Browse files
Options
Downloads
Patches
Plain Diff
notebook is now running.
made adoptions to the updates by Simon
parent
0140944b
No related branches found
No related tags found
1 merge request
!11
Creation of first beta release version
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/quality_controll.ipynb
+15
-8
15 additions, 8 deletions
tests/quality_controll.ipynb
with
15 additions
and
8 deletions
tests/quality_controll.ipynb
+
15
−
8
View file @
867581bb
...
@@ -30,9 +30,11 @@
...
@@ -30,9 +30,11 @@
"\n",
"\n",
"\n",
"\n",
"endpoint = \"https://toar-data.fz-juelich.de/api/v2/analysis/statistics/\"\n",
"endpoint = \"https://toar-data.fz-juelich.de/api/v2/analysis/statistics/\"\n",
"toargridding_base_path = Path(\"/home/simon/Projects/toar/toargridding/\")\n",
"#starts in diretory [path/to/toargridding]/tests\n",
"cache_dir = toargridding_base_path / \"tests\" / \"results\"\n",
"#maybe adopt the toargridding_base_path for your machine.\n",
"data_download_dir = toargridding_base_path / \"tests\" / \"data\"\n",
"toargridding_base_path = Path(\".\")\n",
"cache_dir = toargridding_base_path / \"cache\"\n",
"data_download_dir = toargridding_base_path / \"data\"\n",
"\n",
"\n",
"analysis_service = AnalysisServiceDownload(endpoint, cache_dir, data_download_dir)\n",
"analysis_service = AnalysisServiceDownload(endpoint, cache_dir, data_download_dir)\n",
"my_grid = RegularGrid(1.9, 2.5)\n",
"my_grid = RegularGrid(1.9, 2.5)\n",
...
@@ -40,8 +42,9 @@
...
@@ -40,8 +42,9 @@
"time = TimeSample(dt(2016,1,1), dt(2016,12,31), \"daily\")\n",
"time = TimeSample(dt(2016,1,1), dt(2016,12,31), \"daily\")\n",
"metadata = Metadata.construct(\"mole_fraction_of_ozone_in_air\", \"mean\", time)\n",
"metadata = Metadata.construct(\"mole_fraction_of_ozone_in_air\", \"mean\", time)\n",
"\n",
"\n",
"with open(\"data/daily_2010-01-01_2011-01-01.zip\", \"r+b\") as sample_file:\n",
"#not used in this notebook\n",
" response_content = sample_file.read()"
"#with open(\"data/daily_2010-01-01_2011-01-01.zip\", \"r+b\") as sample_file:\n",
"# response_content = sample_file.read()"
]
]
},
},
{
{
...
@@ -50,6 +53,7 @@
...
@@ -50,6 +53,7 @@
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
"# this cell can runs longer than 30minutes\n",
"data = analysis_service.get_data(metadata)\n",
"data = analysis_service.get_data(metadata)\n",
"ds = my_grid.as_xarray(data)"
"ds = my_grid.as_xarray(data)"
]
]
...
@@ -67,13 +71,15 @@
...
@@ -67,13 +71,15 @@
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
"#calculation of coordinates for plotting\n",
"\n",
"import cartopy.crs as ccrs\n",
"import cartopy.crs as ccrs\n",
"import matplotlib.pyplot as plt\n",
"import matplotlib.pyplot as plt\n",
"import matplotlib.ticker as mticker\n",
"import matplotlib.ticker as mticker\n",
"\n",
"\n",
"mean_data = ds[\"mean\"]\n",
"mean_data = ds[\"mean\"]\n",
"clean_coords =
analysis_service.get_clean_coords(timeseries_metadata)
\n",
"clean_coords =
data.stations_coords
\n",
"all_na =
timeseries
.isna().all(axis=1)\n",
"all_na =
data.stations_data
.isna().all(axis=1)\n",
"clean_coords = all_na.to_frame().join(clean_coords)[[\"latitude\", \"longitude\"]]\n",
"clean_coords = all_na.to_frame().join(clean_coords)[[\"latitude\", \"longitude\"]]\n",
"all_na_coords = clean_coords[all_na]\n",
"all_na_coords = clean_coords[all_na]\n",
"not_na_coords = clean_coords[~all_na]"
"not_na_coords = clean_coords[~all_na]"
...
@@ -87,6 +93,7 @@
...
@@ -87,6 +93,7 @@
"source": [
"source": [
"import matplotlib as mpl\n",
"import matplotlib as mpl\n",
"\n",
"\n",
"#definition of plot function\n",
"\n",
"\n",
"def plot_cells(data, stations, na_stations, discrete=True, plot_stations=False):\n",
"def plot_cells(data, stations, na_stations, discrete=True, plot_stations=False):\n",
" fig = plt.figure(figsize=(9, 18))\n",
" fig = plt.figure(figsize=(9, 18))\n",
...
@@ -196,7 +203,7 @@
...
@@ -196,7 +203,7 @@
"name": "python",
"name": "python",
"nbconvert_exporter": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"pygments_lexer": "ipython3",
"version": "3.11.
8
"
"version": "3.11.
5
"
}
}
},
},
"nbformat": 4,
"nbformat": 4,
...
...
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### Get Dataset from request
### Get Dataset from request
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
from
datetime
import
datetime
as
dt
from
datetime
import
datetime
as
dt
from
pathlib
import
Path
from
pathlib
import
Path
import
pandas
as
pd
import
pandas
as
pd
import
numpy
as
np
import
numpy
as
np
from
toargridding.grids
import
RegularGrid
from
toargridding.grids
import
RegularGrid
from
toargridding.toar_rest_client
import
(
from
toargridding.toar_rest_client
import
(
AnalysisServiceDownload
,
AnalysisServiceDownload
,
STATION_LAT
,
STATION_LAT
,
STATION_LON
,
STATION_LON
,
)
)
from
toargridding.metadata
import
Metadata
,
TimeSample
,
AnalysisRequestResult
,
Coordinates
from
toargridding.metadata
import
Metadata
,
TimeSample
,
AnalysisRequestResult
,
Coordinates
from
toargridding.variables
import
Coordinate
from
toargridding.variables
import
Coordinate
endpoint
=
"
https://toar-data.fz-juelich.de/api/v2/analysis/statistics/
"
endpoint
=
"
https://toar-data.fz-juelich.de/api/v2/analysis/statistics/
"
toargridding_base_path
=
Path
(
"
/home/simon/Projects/toar/toargridding/
"
)
#starts in diretory [path/to/toargridding]/tests
cache_dir
=
toargridding_base_path
/
"
tests
"
/
"
results
"
#maybe adopt the toargridding_base_path for your machine.
data_download_dir
=
toargridding_base_path
/
"
tests
"
/
"
data
"
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
)
analysis_service
=
AnalysisServiceDownload
(
endpoint
,
cache_dir
,
data_download_dir
)
my_grid
=
RegularGrid
(
1.9
,
2.5
)
my_grid
=
RegularGrid
(
1.9
,
2.5
)
time
=
TimeSample
(
dt
(
2016
,
1
,
1
),
dt
(
2016
,
12
,
31
),
"
daily
"
)
time
=
TimeSample
(
dt
(
2016
,
1
,
1
),
dt
(
2016
,
12
,
31
),
"
daily
"
)
metadata
=
Metadata
.
construct
(
"
mole_fraction_of_ozone_in_air
"
,
"
mean
"
,
time
)
metadata
=
Metadata
.
construct
(
"
mole_fraction_of_ozone_in_air
"
,
"
mean
"
,
time
)
with
open
(
"
data/daily_2010-01-01_2011-01-01.zip
"
,
"
r+b
"
)
as
sample_file
:
#not used in this notebook
response_content
=
sample_file
.
read
()
#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:
%% Cell type:code id: tags:
```
python
```
python
# this cell can runs longer than 30minutes
data
=
analysis_service
.
get_data
(
metadata
)
data
=
analysis_service
.
get_data
(
metadata
)
ds
=
my_grid
.
as_xarray
(
data
)
ds
=
my_grid
.
as_xarray
(
data
)
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### Visual inspection
### Visual inspection
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
#calculation of coordinates for plotting
import
cartopy.crs
as
ccrs
import
cartopy.crs
as
ccrs
import
matplotlib.pyplot
as
plt
import
matplotlib.pyplot
as
plt
import
matplotlib.ticker
as
mticker
import
matplotlib.ticker
as
mticker
mean_data
=
ds
[
"
mean
"
]
mean_data
=
ds
[
"
mean
"
]
clean_coords
=
analysis_service
.
get_clean_coords
(
timeseries_metadata
)
clean_coords
=
data
.
stations_coords
all_na
=
timeseries
.
isna
().
all
(
axis
=
1
)
all_na
=
data
.
stations_data
.
isna
().
all
(
axis
=
1
)
clean_coords
=
all_na
.
to_frame
().
join
(
clean_coords
)[[
"
latitude
"
,
"
longitude
"
]]
clean_coords
=
all_na
.
to_frame
().
join
(
clean_coords
)[[
"
latitude
"
,
"
longitude
"
]]
all_na_coords
=
clean_coords
[
all_na
]
all_na_coords
=
clean_coords
[
all_na
]
not_na_coords
=
clean_coords
[
~
all_na
]
not_na_coords
=
clean_coords
[
~
all_na
]
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
import
matplotlib
as
mpl
import
matplotlib
as
mpl
#definition of plot function
def
plot_cells
(
data
,
stations
,
na_stations
,
discrete
=
True
,
plot_stations
=
False
):
def
plot_cells
(
data
,
stations
,
na_stations
,
discrete
=
True
,
plot_stations
=
False
):
fig
=
plt
.
figure
(
figsize
=
(
9
,
18
))
fig
=
plt
.
figure
(
figsize
=
(
9
,
18
))
ax
=
plt
.
axes
(
projection
=
ccrs
.
PlateCarree
())
ax
=
plt
.
axes
(
projection
=
ccrs
.
PlateCarree
())
ax
.
coastlines
()
ax
.
coastlines
()
gl
=
ax
.
gridlines
(
draw_labels
=
True
)
gl
=
ax
.
gridlines
(
draw_labels
=
True
)
gl
.
top_labels
=
False
gl
.
top_labels
=
False
gl
.
left_labels
=
False
gl
.
left_labels
=
False
gl
.
xlocator
=
mticker
.
FixedLocator
(
data
.
longitude
.
values
)
gl
.
xlocator
=
mticker
.
FixedLocator
(
data
.
longitude
.
values
)
gl
.
ylocator
=
mticker
.
FixedLocator
(
data
.
latitude
.
values
)
gl
.
ylocator
=
mticker
.
FixedLocator
(
data
.
latitude
.
values
)
cmap
=
mpl
.
cm
.
viridis
cmap
=
mpl
.
cm
.
viridis
if
discrete
:
if
discrete
:
print
(
np
.
unique
(
data
.
values
))
print
(
np
.
unique
(
data
.
values
))
bounds
=
np
.
arange
(
8
)
bounds
=
np
.
arange
(
8
)
norm
=
mpl
.
colors
.
BoundaryNorm
(
bounds
,
cmap
.
N
,
extend
=
"
both
"
)
norm
=
mpl
.
colors
.
BoundaryNorm
(
bounds
,
cmap
.
N
,
extend
=
"
both
"
)
ticks
=
np
.
arange
(
bounds
.
size
+
1
)[:
-
1
]
+
0.5
ticks
=
np
.
arange
(
bounds
.
size
+
1
)[:
-
1
]
+
0.5
ticklables
=
bounds
ticklables
=
bounds
im
=
plt
.
pcolormesh
(
im
=
plt
.
pcolormesh
(
data
.
longitude
,
data
.
longitude
,
data
.
latitude
,
data
.
latitude
,
data
,
data
,
transform
=
ccrs
.
PlateCarree
(),
transform
=
ccrs
.
PlateCarree
(),
cmap
=
cmap
,
cmap
=
cmap
,
shading
=
"
nearest
"
,
shading
=
"
nearest
"
,
norm
=
norm
,
norm
=
norm
,
)
)
cb
=
fig
.
colorbar
(
im
,
ax
=
ax
,
shrink
=
0.2
,
aspect
=
25
)
cb
=
fig
.
colorbar
(
im
,
ax
=
ax
,
shrink
=
0.2
,
aspect
=
25
)
cb
.
set_ticks
(
ticks
)
cb
.
set_ticks
(
ticks
)
cb
.
set_ticklabels
(
ticklables
)
cb
.
set_ticklabels
(
ticklables
)
im
=
plt
.
pcolormesh
(
im
=
plt
.
pcolormesh
(
data
.
longitude
,
data
.
longitude
,
data
.
latitude
,
data
.
latitude
,
data
,
data
,
transform
=
ccrs
.
PlateCarree
(),
transform
=
ccrs
.
PlateCarree
(),
cmap
=
cmap
,
cmap
=
cmap
,
shading
=
"
nearest
"
,
shading
=
"
nearest
"
,
norm
=
norm
,
norm
=
norm
,
)
)
else
:
else
:
im
=
plt
.
pcolormesh
(
im
=
plt
.
pcolormesh
(
data
.
longitude
,
data
.
longitude
,
data
.
latitude
,
data
.
latitude
,
data
,
data
,
transform
=
ccrs
.
PlateCarree
(),
transform
=
ccrs
.
PlateCarree
(),
cmap
=
cmap
,
cmap
=
cmap
,
shading
=
"
nearest
"
,
shading
=
"
nearest
"
,
)
)
cb
=
fig
.
colorbar
(
im
,
ax
=
ax
,
shrink
=
0.2
,
aspect
=
25
)
cb
=
fig
.
colorbar
(
im
,
ax
=
ax
,
shrink
=
0.2
,
aspect
=
25
)
if
plot_stations
:
if
plot_stations
:
plt
.
scatter
(
na_stations
[
STATION_LON
],
na_stations
[
STATION_LAT
],
s
=
1
,
c
=
"
k
"
)
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
(
stations
[
STATION_LON
],
stations
[
STATION_LAT
],
s
=
1
,
c
=
"
r
"
)
plt
.
tight_layout
()
plt
.
tight_layout
()
plt
.
title
(
f
"
global ozon at
{
data
.
time
.
values
}
"
)
plt
.
title
(
f
"
global ozon at
{
data
.
time
.
values
}
"
)
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
timestep
=
2
timestep
=
2
time
=
ds
.
time
[
timestep
]
time
=
ds
.
time
[
timestep
]
data
=
ds
.
sel
(
time
=
time
)
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
)
plt
.
show
()
plt
.
show
()
plot_cells
(
data
[
"
n
"
],
not_na_coords
,
all_na_coords
,
discrete
=
True
)
plot_cells
(
data
[
"
n
"
],
not_na_coords
,
all_na_coords
,
discrete
=
True
)
plt
.
show
()
plt
.
show
()
n_observations
=
ds
[
"
n
"
].
sum
([
"
latitude
"
,
"
longitude
"
])
n_observations
=
ds
[
"
n
"
].
sum
([
"
latitude
"
,
"
longitude
"
])
plt
.
plot
(
ds
.
time
,
n_observations
)
plt
.
plot
(
ds
.
time
,
n_observations
)
print
(
np
.
unique
(
ds
[
"
n
"
]))
print
(
np
.
unique
(
ds
[
"
n
"
]))
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
```
```
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment