Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DART-WRF
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
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
DataAssimilation
DART-WRF
Commits
633dcc58
Commit
633dcc58
authored
2 years ago
by
lkugler
Browse files
Options
Downloads
Patches
Plain Diff
clean
parent
fb089fa3
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dartwrf/link_dart_rttov.py
+1
-1
1 addition, 1 deletion
dartwrf/link_dart_rttov.py
dartwrf/utils.py
+40
-10
40 additions, 10 deletions
dartwrf/utils.py
with
41 additions
and
11 deletions
dartwrf/link_dart_rttov.py
+
1
−
1
View file @
633dcc58
import
os
import
os
from
config.cfg
import
exp
from
config.cfg
import
exp
from
config.cluster
import
cluster
from
config.cluster
import
cluster
from
dartwrf.utils
import
symlink
,
copy_scp_srvx8
,
copy
,
sed_inplace
from
dartwrf.utils
import
symlink
,
copy
,
sed_inplace
joinp
=
os
.
path
.
join
joinp
=
os
.
path
.
join
...
...
This diff is collapsed.
Click to expand it.
dartwrf/utils.py
+
40
−
10
View file @
633dcc58
...
@@ -22,7 +22,7 @@ class ClusterConfig(object):
...
@@ -22,7 +22,7 @@ class ClusterConfig(object):
Example:
Example:
`/users/abcd/data/sim_archive/experiment1/`
`/users/abcd/data/sim_archive/experiment1/`
"""
"""
return
self
.
archive_base
+
'
/
'
+
self
.
exp
.
expname
return
self
.
archive_base
+
'
/
'
+
self
.
exp
.
expname
+
'
/
'
@property
@property
def
scripts_rundir
(
self
):
def
scripts_rundir
(
self
):
...
@@ -44,7 +44,7 @@ class ClusterConfig(object):
...
@@ -44,7 +44,7 @@ class ClusterConfig(object):
"""
Path to the directory where an ensemble member will run WRF
"""
Path to the directory where an ensemble member will run WRF
Includes the experiment name and the ensemble member index
Includes the experiment name and the ensemble member index
"""
"""
return
self
.
wrf_rundir_base
+
'
/
'
+
self
.
exp
.
expname
+
'
/
'
+
str
(
iens
)
return
self
.
wrf_rundir_base
+
'
/
'
+
self
.
exp
.
expname
+
'
/
'
+
str
(
iens
)
+
'
/
'
def
run_job
(
self
,
cmd
,
jobname
=
''
,
cfg_update
=
dict
(),
depends_on
=
None
):
def
run_job
(
self
,
cmd
,
jobname
=
''
,
cfg_update
=
dict
(),
depends_on
=
None
):
"""
Run scripts in a shell
"""
Run scripts in a shell
...
@@ -63,10 +63,9 @@ class ClusterConfig(object):
...
@@ -63,10 +63,9 @@ class ClusterConfig(object):
"""
"""
if
self
.
use_slurm
:
if
self
.
use_slurm
:
from
slurmpy
import
Slurm
from
slurmpy
import
Slurm
Slurm
(
jobname
,
slurm_kwargs
=
dict
(
self
.
slurm_cfg
,
**
cfg_update
),
return
Slurm
(
jobname
,
slurm_kwargs
=
dict
(
self
.
slurm_cfg
,
**
cfg_update
),
log_dir
=
self
.
log_dir
,
log_dir
=
self
.
log_dir
,
scripts_dir
=
self
.
slurm_scripts_dir
,
scripts_dir
=
self
.
slurm_scripts_dir
,
**
kwargs
).
run
(
cmd
,
depends_on
=
depends_on
)
).
run
(
cmd
,
depends_on
=
depends_on
)
else
:
else
:
print
(
cmd
)
print
(
cmd
)
...
@@ -109,7 +108,8 @@ def clean_wrfdir(dir):
...
@@ -109,7 +108,8 @@ def clean_wrfdir(dir):
os
.
remove
(
f
)
os
.
remove
(
f
)
def
symlink
(
src
,
dst
):
def
symlink
(
src
,
dst
):
# Create a symbolic link pointing to src named dst.
"""
Create a symbolic link from src to dst
"""
try
:
try
:
os
.
symlink
(
src
,
dst
)
os
.
symlink
(
src
,
dst
)
except
FileExistsError
:
except
FileExistsError
:
...
@@ -123,12 +123,18 @@ def symlink(src, dst):
...
@@ -123,12 +123,18 @@ def symlink(src, dst):
raise
e
raise
e
def
link_contents
(
src
,
dst
):
def
link_contents
(
src
,
dst
):
"""
Create symbolic links for all files in src to dst
Args:
src (str): Path to source directory
dst (str): Path to destination directory
Returns:
None
"""
for
f
in
os
.
listdir
(
src
):
for
f
in
os
.
listdir
(
src
):
symlink
(
src
+
'
/
'
+
f
,
dst
+
'
/
'
+
f
)
symlink
(
src
+
'
/
'
+
f
,
dst
+
'
/
'
+
f
)
def
copy_scp_srvx8
(
src
,
dst
):
os
.
system
(
'
scp
'
+
src
+
'
a1254888@srvx8.img.univie.ac.at:
'
+
dst
)
def
sed_inplace
(
filename
,
pattern
,
repl
):
def
sed_inplace
(
filename
,
pattern
,
repl
):
'''
Perform the pure-Python equivalent of in-place `sed` substitution
'''
Perform the pure-Python equivalent of in-place `sed` substitution
Like `sed -i -e
'
s/
'
${pattern}
'
/
'
${repl}
'
"
${filename}
"
`.
Like `sed -i -e
'
s/
'
${pattern}
'
/
'
${repl}
'
"
${filename}
"
`.
...
@@ -162,4 +168,28 @@ def sed_inplace(filename, pattern, repl):
...
@@ -162,4 +168,28 @@ def sed_inplace(filename, pattern, repl):
shutil
.
move
(
tmp_file
.
name
,
filename
)
shutil
.
move
(
tmp_file
.
name
,
filename
)
def
append_file
(
f_main
,
f_gets_appended
):
def
append_file
(
f_main
,
f_gets_appended
):
os
.
system
(
'
cat
'
+
f_gets_appended
+
'
>>
'
+
f_main
)
"""
Append the contents of one file to another
\ No newline at end of file
Args:
f_main (str): Path to file that will be appended
f_gets_appended (str): Path to file that will be appended to f_main
Returns:
None
"""
os
.
system
(
'
cat
'
+
f_gets_appended
+
'
>>
'
+
f_main
)
def
write_txt
(
lines
,
fpath
):
"""
Write a list of strings to a text file
Args:
lines (list): List of strings
fpath (str): Path to file
Returns:
None
"""
try_remove
(
fpath
)
with
open
(
fpath
,
"
w
"
)
as
file
:
for
line
in
lines
:
file
.
write
(
line
+
'
\n
'
)
\ No newline at end of file
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