Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Grid SEPTREFHUM
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
VIPS
Models
GRID
Grid SEPTREFHUM
Commits
271ed505
Commit
271ed505
authored
3 months ago
by
Lene Wasskog
Browse files
Options
Downloads
Patches
Plain Diff
chore: Log output of cdo command
parent
10f2a4e6
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
SEPTREFHUM.py
+26
-6
26 additions, 6 deletions
SEPTREFHUM.py
with
26 additions
and
6 deletions
SEPTREFHUM.py
+
26
−
6
View file @
271ed505
...
...
@@ -32,6 +32,28 @@ import configparser
import
logging
import
shutil
def
run_command
(
command
,
stdout
=
subprocess
.
PIPE
):
logging
.
debug
(
f
"
{
command
}
"
)
try
:
result
=
subprocess
.
run
(
command
,
stdout
=
stdout
,
stderr
=
stdout
,
shell
=
True
,
text
=
True
,
check
=
True
,
)
if
result
.
stdout
:
result_lines
=
result
.
stdout
.
splitlines
()
for
line
in
result_lines
:
logging
.
debug
(
line
.
strip
())
return
result_lines
if
result
.
stderr
:
for
line
in
result
.
stderr
.
splitlines
():
logging
.
error
(
line
.
strip
())
except
subprocess
.
CalledProcessError
as
e
:
logging
.
error
(
f
"
{
e
}
"
)
# Paths config
# Create a .env file from dotenv-sample
load_dotenv
()
...
...
@@ -87,7 +109,7 @@ logging.basicConfig(
start_date
=
None
last_wh_date
=
None
#"""
for
wh_file
in
glob
.
glob
(
f
"
{
tmpfile_path
}
wh_
2[0-9][0-9][0-9]
-[01][0-9]-[0123][0-9].nc
"
):
for
wh_file
in
glob
.
glob
(
f
"
{
tmpfile_path
}
wh_
{
year
}
-[01][0-9]-[0123][0-9].nc
"
):
current_wh_file_date
=
local_timezone
.
localize
(
datetime
.
strptime
(
f
"
{
wh_file
[
12
:
22
]
}
"
,
"
%Y-%m-%d
"
))
if
last_wh_date
is
None
or
last_wh_date
<
current_wh_file_date
:
last_wh_date
=
current_wh_file_date
...
...
@@ -124,11 +146,9 @@ for file_path in sorted(weatherdata_files):
# Produce daily files with WH_SUM, which is the number of "Wet hours" (WH) for a given day
# WH is defined as RR > 0.2 || UM > 88.0
wh_sum_date_str
=
wh_sum_date
.
strftime
(
"
%Y-%m-%d
"
)
wh_sum_hour_str
=
wh_sum_date
.
strftime
(
"
%H
"
)
subprocess
.
run
(
f
'
cdo -s -O -setdate,
{
wh_sum_date_str
}
-settime,
{
wh_sum_hour_str
}
:00:00 -chname,WH,WH_DAYSUM -timsum -selname,WH -aexpr,
"
WH = (
{
TM
}
>=
{
TEMPERATURE_THRESHOLD
}
&& (
{
RR
}
> 0.2 ||
{
UM
}
> 88.0)) ? 1 : 0;
"
{
file_path
}
{
tmpfile_path
}
wh_
{
wh_sum_date_str
}
.nc
'
,
shell
=
True
)
wh_sum_hour_str
=
wh_sum_date
.
strftime
(
"
%H
"
)
logging
.
info
(
"
Run WH calculations for
"
+
wh_sum_date_str
)
run_command
(
command
=
f
'
cdo -s -O -setdate,
{
wh_sum_date_str
}
-settime,
{
wh_sum_hour_str
}
:00:00 -chname,WH,WH_DAYSUM -timsum -selname,WH -aexpr,
"
WH = (
{
TM
}
>=
{
TEMPERATURE_THRESHOLD
}
&& (
{
RR
}
> 0.2 ||
{
UM
}
> 88.0)) ? 1 : 0;
"
{
file_path
}
{
tmpfile_path
}
wh_
{
wh_sum_date_str
}
.nc
'
)
# Concatenate daily files > one file with daily values
# Additive calculation - this file can be stored between calculations
...
...
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