Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
thopri
BoBEAS
Commits
b32fd5e7
Commit
b32fd5e7
authored
5 years ago
by
jelt
Browse files
Options
Download
Email Patches
Plain Diff
script to sort restarts and figure out associated dates
parent
1b966a04
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
0 deletions
+46
-0
SCRIPTS/sort_restart_files.py
SCRIPTS/sort_restart_files.py
+46
-0
No files found.
SCRIPTS/sort_restart_files.py
0 → 100644
View file @
b32fd5e7
# sort_restart_files.py
#
# sort restart files
# jelt 31 May 2018
import
re
import
os
import
datetime
# Get a list of files: `ls INDIAN_*_restart_0000.nc`
files
=
[
f
for
f
in
os
.
listdir
(
'.'
)
if
re
.
match
(
r
'INDIAN_[0-9]+_restart_0000\.nc'
,
f
)]
def
getdate
(
time_step_in
):
"""
Usage: [nday, dat ] = getdate( time_step_in )
"""
# Convert timestep to julian day. Initialise list with known values
time_step
=
[
0
]
*
2
nday_year
=
[
0
]
*
2
date
=
[
0
]
*
2
# Time point One
time_step
[
0
]
=
150721
nday_year
[
0
]
=
108.
date
[
0
]
=
datetime
.
datetime
(
2016
,
4
,
17
)
# Time point TWO
time_step
[
1
]
=
269761
date
[
1
]
=
datetime
.
datetime
(
2016
,
8
,
19
)
nday_year
[
1
]
=
232.
nday_year_out
=
(
nday_year
[
1
]
-
nday_year
[
0
])
/
(
time_step
[
1
]
-
time_step
[
0
])
*
(
time_step_in
-
time_step
[
0
])
+
nday_year
[
0
]
date_out
=
(
date
[
1
]
-
date
[
0
])
/
(
time_step
[
1
]
-
time_step
[
0
])
*
(
time_step_in
-
time_step
[
0
])
+
date
[
0
]
return
nday_year_out
,
date_out
# Extract date and day number and move restarts to folder with date structure Y-m-d
for
file
in
files
:
nstep
=
file
.
replace
(
'INDIAN_'
,
''
).
replace
(
'_restart_0000.nc'
,
''
)
[
nday
,
dat
]
=
getdate
(
int
(
nstep
)
+
1
)
# +1 because the restarts were (all but a couple) written 1 timestep before midnight. The 'couple' were written just before notification
print
str
(
nstep
),
nday
,
dat
.
strftime
(
"%Y-%m-%d"
)
os
.
system
(
'mkdir '
+
dat
.
strftime
(
"%Y-%m-%d"
))
os
.
system
(
'mv '
+
file
.
replace
(
'restart_0000.nc'
,
'restart*nc'
)
+
' '
+
dat
.
strftime
(
"%Y-%m-%d"
)
+
'/.'
)
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment