Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
Detection eddies
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
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
IPSL
LMD
DPAO
Detection eddies
Commits
a26ee607
Commit
a26ee607
authored
3 years ago
by
Lionel GUEZ
Browse files
Options
Downloads
Patches
Plain Diff
Create a function from the body of the script
So we can call it from another script with a generated list of files.
parent
78045196
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
Inst_eddies/inst_eddies_in.py
+63
-60
63 additions, 60 deletions
Inst_eddies/inst_eddies_in.py
with
63 additions
and
60 deletions
Inst_eddies/inst_eddies_in.py
+
63
−
60
View file @
a26ee607
...
...
@@ -19,6 +19,68 @@ import netCDF4
import
time
import
csv
def
loop_inst_eddies
(
files
,
bbox
,
d
):
inst_eddies_exe
=
"
@CMAKE_CURRENT_BINARY_DIR@/inst_eddies
"
if
not
os
.
access
(
inst_eddies_exe
,
os
.
X_OK
):
sys
.
exit
(
inst_eddies_exe
+
"
not found or not executable
"
)
if
os
.
access
(
"
main_nml.txt
"
,
os
.
R_OK
):
print
(
"
Will use main_nml.txt.
"
)
else
:
sys
.
exit
(
'"
main_nml.txt
"
not found
'
)
nco_instance
=
nco
.
Nco
()
for
orient
in
[
"
cyclo
"
,
"
anti
"
]:
if
os
.
access
(
f
"
SHPC_
{
orient
}
"
,
os
.
F_OK
):
shutil
.
rmtree
(
f
"
SHPC_
{
orient
}
"
)
os
.
mkdir
(
f
"
SHPC_
{
orient
}
"
)
perf_report
=
open
(
"
perf_report.csv
"
,
"
w
"
,
newline
=
''
)
writer
=
csv
.
writer
(
perf_report
,
lineterminator
=
"
\n
"
)
writer
.
writerow
([
"
date
"
,
"
elapsed NCO
"
,
"
elapsed Fortran
"
])
for
nc_file
in
files
:
print
(
"
inst_eddies.py: Date:
"
,
d
)
print
(
"
Input file:
"
,
nc_file
)
if
os
.
access
(
nc_file
,
os
.
F_OK
):
my_pc
=
time
.
perf_counter
()
if
bbox
:
xmin
,
xmax
,
ymin
,
ymax
=
bbox
nco_instance
.
ncks
(
nc_file
,
output
=
"
cropped.nc
"
,
options
=
[
f
"
--dimension=longitude,
{
xmin
}
,
{
xmax
}
"
,
f
"
--dimension=latitude,
{
ymin
}
,
{
ymax
}
"
])
nc_file
=
"
cropped.nc
"
nco_instance
.
ncpdq
(
nc_file
,
output
=
"
unpacked.nc
"
,
options
=
[
"
--unpack
"
])
os
.
symlink
(
"
unpacked.nc
"
,
"
h.nc
"
)
os
.
symlink
(
"
unpacked.nc
"
,
"
uv.nc
"
)
elapsed_NCO
=
time
.
perf_counter
()
-
my_pc
my_pc
=
time
.
perf_counter
()
subprocess
.
run
(
inst_eddies_exe
,
check
=
True
,
input
=
str
(
d
)
+
"
\n
"
,
text
=
True
)
elapsed_Fortran
=
time
.
perf_counter
()
-
my_pc
os
.
remove
(
"
h.nc
"
)
os
.
remove
(
"
uv.nc
"
)
writer
.
writerow
([
d
,
elapsed_NCO
,
elapsed_Fortran
])
else
:
print
(
"
inst_eddies.py: Missing file:
"
,
nc_file
)
for
orient
in
[
"
cyclo
"
,
"
anti
"
]:
with
open
(
f
"
SHPC_
{
orient
}
/ishape_last.txt
"
,
"
a
"
)
as
ishape_last
,
\
shapefile
.
Reader
(
f
"
SHPC_
{
orient
}
/extremum
"
)
as
shpr
:
n_shapes
=
len
(
shpr
)
ishape_last
.
write
(
str
(
n_shapes
-
1
)
+
"
\n
"
)
d
+=
1
perf_report
.
close
()
os
.
remove
(
"
unpacked.nc
"
)
if
bbox
:
os
.
remove
(
"
cropped.nc
"
)
argparser
=
argparse
.
ArgumentParser
()
argparser
.
add_argument
(
"
file
"
,
nargs
=
"
+
"
,
help
=
"
NetCDF file containing SSH and velocity at a
"
...
...
@@ -28,63 +90,4 @@ argparser.add_argument("-b", "--bbox", nargs=4, type = float,
args
=
argparser
.
parse_args
()
d
=
input
(
"
Enter first date (integer value):
"
)
d
=
int
(
d
)
inst_eddies_exe
=
"
@CMAKE_CURRENT_BINARY_DIR@/inst_eddies
"
if
not
os
.
access
(
inst_eddies_exe
,
os
.
X_OK
):
sys
.
exit
(
inst_eddies_exe
+
"
not found or not executable
"
)
if
os
.
access
(
"
main_nml.txt
"
,
os
.
R_OK
):
print
(
"
Will use main_nml.txt.
"
)
else
:
sys
.
exit
(
'"
main_nml.txt
"
not found
'
)
nco_instance
=
nco
.
Nco
()
for
orient
in
[
"
cyclo
"
,
"
anti
"
]:
if
os
.
access
(
f
"
SHPC_
{
orient
}
"
,
os
.
F_OK
):
shutil
.
rmtree
(
f
"
SHPC_
{
orient
}
"
)
os
.
mkdir
(
f
"
SHPC_
{
orient
}
"
)
perf_report
=
open
(
"
perf_report.csv
"
,
"
w
"
,
newline
=
''
)
writer
=
csv
.
writer
(
perf_report
,
lineterminator
=
"
\n
"
)
writer
.
writerow
([
"
date
"
,
"
elapsed NCO
"
,
"
elapsed Fortran
"
])
for
nc_file
in
args
.
file
:
print
(
"
inst_eddies.py: Date:
"
,
d
)
print
(
"
Input file:
"
,
nc_file
)
if
os
.
access
(
nc_file
,
os
.
F_OK
):
my_pc
=
time
.
perf_counter
()
if
args
.
bbox
:
xmin
,
xmax
,
ymin
,
ymax
=
args
.
bbox
nco_instance
.
ncks
(
nc_file
,
output
=
"
cropped.nc
"
,
options
=
[
f
"
--dimension=longitude,
{
xmin
}
,
{
xmax
}
"
,
f
"
--dimension=latitude,
{
ymin
}
,
{
ymax
}
"
])
nc_file
=
"
cropped.nc
"
nco_instance
.
ncpdq
(
nc_file
,
output
=
"
unpacked.nc
"
,
options
=
[
"
--unpack
"
])
os
.
symlink
(
"
unpacked.nc
"
,
"
h.nc
"
)
os
.
symlink
(
"
unpacked.nc
"
,
"
uv.nc
"
)
elapsed_NCO
=
time
.
perf_counter
()
-
my_pc
my_pc
=
time
.
perf_counter
()
subprocess
.
run
(
inst_eddies_exe
,
check
=
True
,
input
=
str
(
d
)
+
"
\n
"
,
text
=
True
)
elapsed_Fortran
=
time
.
perf_counter
()
-
my_pc
os
.
remove
(
"
h.nc
"
)
os
.
remove
(
"
uv.nc
"
)
writer
.
writerow
([
d
,
elapsed_NCO
,
elapsed_Fortran
])
else
:
print
(
"
inst_eddies.py: Missing file:
"
,
nc_file
)
for
orient
in
[
"
cyclo
"
,
"
anti
"
]:
with
open
(
f
"
SHPC_
{
orient
}
/ishape_last.txt
"
,
"
a
"
)
as
ishape_last
,
\
shapefile
.
Reader
(
f
"
SHPC_
{
orient
}
/extremum
"
)
as
shpr
:
n_shapes
=
len
(
shpr
)
ishape_last
.
write
(
str
(
n_shapes
-
1
)
+
"
\n
"
)
d
+=
1
perf_report
.
close
()
os
.
remove
(
"
unpacked.nc
"
)
if
args
.
bbox
:
os
.
remove
(
"
cropped.nc
"
)
loop_inst_eddies
(
args
.
file
,
args
.
bbox
,
d
)
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