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
adbaf2a0
Commit
adbaf2a0
authored
9 months ago
by
Carsten Hinz
Browse files
Options
Downloads
Patches
Plain Diff
added exclusion of N/A from contributors
parent
61b4f45a
No related branches found
No related tags found
3 merge requests
!11
Creation of first beta release version
,
!10
change in metadata of notebook
,
!9
change in metadata of notebook
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/produce_data_withOptional.ipynb
+6
-6
6 additions, 6 deletions
examples/produce_data_withOptional.ipynb
src/toargridding/contributors.py
+2
-1
2 additions, 1 deletion
src/toargridding/contributors.py
with
8 additions
and
7 deletions
examples/produce_data_withOptional.ipynb
+
6
−
6
View file @
adbaf2a0
...
...
@@ -56,12 +56,12 @@
"for year in range(0,19):\n",
" valid_data = Config(\n",
" grid,\n",
"
#
TimeSample( start=dt(2000+year,1,1), end=dt(2000+year,12,31), sampling=\"daily\"),#possibly adopt range:-)\n",
" TimeSample( start=dt(2000+year,1,1), end=dt(2000+year,12,31), sampling=\"monthly\"),#possibly adopt range:-)\n",
" TimeSample( start=dt(2000+year,1,1), end=dt(2000+year,12,31), sampling=\"daily\"),#possibly adopt range:-)\n",
"
#
TimeSample( start=dt(2000+year,1,1), end=dt(2000+year,12,31), sampling=\"monthly\"),#possibly adopt range:-)\n",
" [\"mole_fraction_of_ozone_in_air\"],#variable name\n",
" #[ \"mean\", \"dma8epax\"],# will start one request after another other...\n",
"
#
[ \"dma8epa_strict\" ],\n",
" [ \"mean\" ],\n",
" [ \"dma8epa_strict\" ],\n",
"
#
[ \"mean\" ],\n",
" details4Query\n",
" )\n",
" \n",
...
...
@@ -89,7 +89,7 @@
"\n",
"# maybe adopt the interval for requesting the results and the total duration, before the client pauses the requests.\n",
"# as the requests take about 45min, it is more suitable to wait 60min before timing out the requests than the original 30min.\n",
"analysis_service.connection.set
R
equest
T
imes(interval_min=5, max
W
ait_min=60)\n",
"analysis_service.connection.set
_r
equest
_t
imes(interval_min=5, max
_w
ait_min
utes
=60)\n",
"\n",
"for person, config in configs.items():\n",
" print(f\"\\nProcessing {person}:\")\n",
...
...
@@ -100,7 +100,7 @@
" time=config.time,\n",
" variables=config.variables,\n",
" stats=config.stats,\n",
" contributors_path=result_basepath\n",
" contributors_path=result_basepath
,
\n",
" **config.moreOptions\n",
" )\n",
"\n",
...
...
%% Cell type:code id: tags:
```
python
import
logging
from
datetime
import
datetime
as
dt
from
collections
import
namedtuple
from
pathlib
import
Path
from
toargridding.toar_rest_client
import
AnalysisServiceDownload
,
Connection
from
toargridding.grids
import
RegularGrid
from
toargridding.gridding
import
get_gridded_toar_data
from
toargridding.metadata
import
TimeSample
from
toargridding.defaultLogging
import
toargridding_defaultLogging
#setup of logging
logger
=
toargridding_defaultLogging
()
logger
.
addShellLogger
(
logging
.
DEBUG
)
logger
.
logExceptions
()
logger
.
addRotatingLogFile
(
Path
(
"
log/produce_data_withOptional.log
"
))
#we need to explicitly set a logfile
#logger.addSysLogger(logging.DEBUG)
```
%% Cell type:code id: tags:
```
python
#creation of request.
Config
=
namedtuple
(
"
Config
"
,
[
"
grid
"
,
"
time
"
,
"
variables
"
,
"
stats
"
,
"
moreOptions
"
])
#moreOptions is implemented as a dict to add additional arguments to the query to the REST API
#For example the field toar1_category with its possible values Urban, RuralLowElevation, RuralHighElevation and Unclassified can be added.
#see page 18 in https://toar-data.fz-juelich.de/sphinx/TOAR_UG_Vol03_Database/build/latex/toardatabase--userguide.pdf
#or type_of_area with urban, suburban and rural on page 20 can be used
details4Query
=
{
#"toar1_category" : "Urban" #uncomment if wished:-)
#"toar1_category" : "RuralLowElevation" #uncomment if wished:-)
#"toar1_category" : "RuralHighElevation" #uncomment if wished:-)
#"type_of_area" : "Urban" #also test Rural, Suburban,
"
type_of_area
"
:
"
Rural
"
#also test Rural, Suburban,
#"type_of_area" : "Suburban" #also test Rural, Suburban,
}
grid
=
RegularGrid
(
lat_resolution
=
1.9
,
lon_resolution
=
2.5
,
)
configs
=
dict
()
for
year
in
range
(
0
,
19
):
valid_data
=
Config
(
grid
,
#
TimeSample( start=dt(2000+year,1,1), end=dt(2000+year,12,31), sampling="daily"),#possibly adopt range:-)
TimeSample
(
start
=
dt
(
2000
+
year
,
1
,
1
),
end
=
dt
(
2000
+
year
,
12
,
31
),
sampling
=
"
monthly
"
),
#possibly adopt range:-)
TimeSample
(
start
=
dt
(
2000
+
year
,
1
,
1
),
end
=
dt
(
2000
+
year
,
12
,
31
),
sampling
=
"
daily
"
),
#possibly adopt range:-)
#
TimeSample( start=dt(2000+year,1,1), end=dt(2000+year,12,31), sampling="monthly"),#possibly adopt range:-)
[
"
mole_fraction_of_ozone_in_air
"
],
#variable name
#[ "mean", "dma8epax"],# will start one request after another other...
#
[ "dma8epa_strict" ],
[
"
mean
"
],
[
"
dma8epa_strict
"
],
#
[ "mean" ],
details4Query
)
configs
[
f
"
test_ta
{
year
}
"
]
=
valid_data
```
%% Cell type:code id: tags:
```
python
#CAVE: this cell runs about 45minutes per requested year. therefore we increase the waiting duration to 1h per request.
#the processing is done on the server of the TOAR database.
#a restart of the cell continues the request to the REST API if the requested data are ready for download
# The download can also take a few minutes
stats_endpoint
=
"
https://toar-data.fz-juelich.de/api/v2/analysis/statistics/
"
cache_basepath
=
Path
(
"
cache
"
)
result_basepath
=
Path
(
"
results
"
)
cache_basepath
.
mkdir
(
exist_ok
=
True
)
result_basepath
.
mkdir
(
exist_ok
=
True
)
analysis_service
=
AnalysisServiceDownload
(
stats_endpoint
=
stats_endpoint
,
cache_dir
=
cache_basepath
,
sample_dir
=
result_basepath
,
use_downloaded
=
True
)
# maybe adopt the interval for requesting the results and the total duration, before the client pauses the requests.
# as the requests take about 45min, it is more suitable to wait 60min before timing out the requests than the original 30min.
analysis_service
.
connection
.
set
R
equest
T
imes
(
interval_min
=
5
,
max
W
ait_min
=
60
)
analysis_service
.
connection
.
set
_r
equest
_t
imes
(
interval_min
=
5
,
max
_w
ait_min
utes
=
60
)
for
person
,
config
in
configs
.
items
():
print
(
f
"
\n
Processing
{
person
}
:
"
)
print
(
f
"
--------------------
"
)
datasets
,
metadatas
=
get_gridded_toar_data
(
analysis_service
=
analysis_service
,
grid
=
config
.
grid
,
time
=
config
.
time
,
variables
=
config
.
variables
,
stats
=
config
.
stats
,
contributors_path
=
result_basepath
contributors_path
=
result_basepath
,
**
config
.
moreOptions
)
for
dataset
,
metadata
in
zip
(
datasets
,
metadatas
):
dataset
.
to_netcdf
(
result_basepath
/
f
"
{
metadata
.
get_id
()
}
_
{
config
.
grid
.
get_id
()
}
.nc
"
)
print
(
metadata
.
get_id
())
```
...
...
This diff is collapsed.
Click to expand it.
src/toargridding/contributors.py
+
2
−
1
View file @
adbaf2a0
...
...
@@ -61,7 +61,8 @@ class contributions_manager_by_name(contributionsManager):
for
id
in
ids
:
names
=
self
.
id_to_names
(
id
)
for
name
in
names
:
self
.
timeseriesIDs
.
add
(
name
)
if
name
!=
"
N/A
"
:
self
.
timeseriesIDs
.
add
(
name
)
def
id_to_names
(
self
,
id
:
int
)
->
list
[
str
]:
for
pos
in
range
(
10
):
req_res
=
requests
.
get
(
f
"
https://toar-data.fz-juelich.de/api/v2/timeseries/
{
id
}
"
,
timeout
=
40
)
...
...
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