Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ash-seviri
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
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
ash
ash-seviri
Commits
9671ee67
Commit
9671ee67
authored
1 year ago
by
Espen Sollum
Browse files
Options
Downloads
Patches
Plain Diff
Added copy script for hourly SEVIRI files
parent
0b14b0ed
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
AshDetection/copy_hourly.py
+74
-0
74 additions, 0 deletions
AshDetection/copy_hourly.py
with
74 additions
and
0 deletions
AshDetection/copy_hourly.py
0 → 100644
+
74
−
0
View file @
9671ee67
#!/usr/bin/env python3
"""
Copy the SEVIRI files at whole hours to a subdirectory
"""
import
os
import
argparse
import
glob
import
shutil
# Source/destination directories and matching glob patterns
SOURCE_DEST_DIRS
=
{
"
/viper/nadir/nvap/IcelandEurope_1088_0088_1537x494/
"
:
[
"
/viper/nadir/nvap/IcelandEurope_1088_0088_1537x494/HOURLY
"
,
"
*00_flat.nc
"
],
"
/viper/nadir/nvap/IcelandEurope_1088_0088_1537x494/SEVIRI-CLOUDS/
"
:
[
"
/viper/nadir/nvap/IcelandEurope_1088_0088_1537x494/HOURLY/SEVIRI-CLOUDS/
"
,
"
*0000_reg2d.nc
"
]
}
def
copy_files
(
dry_run
=
False
):
"""
Copy files
"""
for
d_key
,
v_val
in
SOURCE_DEST_DIRS
.
items
():
source_files
=
glob
.
glob
(
os
.
path
.
join
(
d_key
,
v_val
[
1
]))
dest_files
=
[
os
.
path
.
join
(
v_val
[
0
],
os
.
path
.
basename
(
f
))
for
f
in
source_files
]
if
dry_run
:
# Print some of the files that would be copied
print
(
"
Copying files from
\n
"
,
source_files
[:
10
],
"
to
\n
"
,
dest_files
[:
10
])
if
not
dry_run
:
for
src
,
dest
in
zip
(
source_files
,
dest_files
):
try
:
shutil
.
copyfile
(
src
,
dest
)
except
Exception
as
e_err
:
# Things that can go wrong: no write permission,
# file has been deleted in the meantime etc.
print
(
"
ERROR: Failed to copy file {} to {}
\n
{}
"
.
format
(
src
,
dest
,
e_err
))
if
__name__
==
"
__main__
"
:
parser
=
argparse
.
ArgumentParser
(
prog
=
"
copy_hourly
"
,
description
=
(
"
Copy SEVIRI files.
"
),
formatter_class
=
argparse
.
ArgumentDefaultsHelpFormatter
)
parser
.
add_argument
(
'
-r
'
,
'
--run_copy
'
,
dest
=
'
run_copy
'
,
help
=
"
Run the copying script
"
,
action
=
'
store_true
'
,
default
=
False
)
parser
.
add_argument
(
'
-d
'
,
'
--dry_run
'
,
dest
=
'
dry_run
'
,
help
=
"
Run the copying script but only show the files that would be copied
"
,
action
=
'
store_true
'
,
default
=
False
)
args
=
parser
.
parse_args
()
if
args
.
run_copy
:
copy_files
(
dry_run
=
args
.
dry_run
)
else
:
print
(
"
\n
Nothing to do, here is some help:
\n
"
)
parser
.
print_help
()
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