Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Flex Extract
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Flexpart
Flex Extract
Commits
7dc8ede1
Commit
7dc8ede1
authored
4 years ago
by
Andreas Plach
Browse files
Options
Downloads
Patches
Plain Diff
apl: added a script to do a simple integrity check on the downloaded FP input files
parent
3d44ae0d
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
Run/check_integrity_FP_input_grib.py
+65
-0
65 additions, 0 deletions
Run/check_integrity_FP_input_grib.py
with
65 additions
and
0 deletions
Run/check_integrity_FP_input_grib.py
0 → 100644
+
65
−
0
View file @
7dc8ede1
'''
simple integrity check of downloaded FLEXPART input files
just checking if python can read them and if the files contain 845 grib
messages (I had some corrupt files before which had 869 messages and FP
was not able to read them)
counts the files in the provided main directory and its sub-directory
you need a working python environment and the eccodes library
usage: python check_integrity_FP_input_grip.py
Andreas Plach, UniWien, October 2020
'''
import
os
import
datetime
as
dt
import
pygrib
import
fnmatch
import
re
path
=
(
'
/raid61/scratch/aplach/ECMWF_DATA/EA_fields/checked/2001/
'
)
# create a sorted dictionary of all files in main path and
# sub-directories
for
(
dirpath
,
dirnames
,
filenames
)
in
os
.
walk
(
path
):
print
(
dirnames
)
# now loop through the files in sub-directory
# list of patterns to exclude
excludes
=
[
'
*.tmp
'
,
'
*.txt
'
]
excludes
=
r
'
|
'
.
join
([
fnmatch
.
translate
(
x
)
for
x
in
excludes
])
or
r
'
$.
'
files
=
[
f
for
f
in
filenames
if
not
re
.
match
(
excludes
,
f
)]
# create a file which will contain a list of corrupted files
corrfile
=
(
dirpath
[:
-
2
]
+
dirpath
[
-
2
:]
+
'
_list_of_corrupt_files.txt
'
)
# write some basic info into the respective files
corrupt
=
open
(
corrfile
,
'
w
'
)
corrupt
.
write
(
str
(
dt
.
datetime
.
now
())
+
'
\n
'
)
corrupt
.
write
(
'
total number of files in sub-dir:
'
+
str
(
len
(
files
))
+
'
\n
'
)
corrupt
.
write
(
'
list of corrupted files in sub-dir below:
\n
'
)
corrupt
.
write
(
'
-----------------------------------------
\n
'
)
corrupt
.
close
()
for
filename
in
sorted
(
files
):
# if query to ignore some files
if
(
filename
[
-
4
:]
!=
'
.tmp
'
)
and
(
filename
[
-
4
:]
!=
'
.txt
'
):
print
(
filename
)
gr
=
pygrib
.
open
(
dirpath
+
'
/
'
+
filename
)
try
:
gr
[
1
]
if
(
gr
.
messages
!=
845
):
print
(
'
The number of grib messages is not equal to 845;
'
'
there might be problem with the file
'
)
corrupt
=
open
(
corrfile
,
'
a
'
)
corrupt
.
write
(
dirpath
+
'
/
'
+
filename
+
'
\n
'
)
corrupt
.
close
()
except
RuntimeError
as
e
:
print
(
e
)
corrupt
=
open
(
corrfile
,
'
a
'
)
corrupt
.
write
(
dirpath
+
'
/
'
+
filename
+
'
\n
'
)
corrupt
.
close
()
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