Skip to content
Snippets Groups Projects
Commit ccc4d803 authored by Lionel GUEZ's avatar Lionel GUEZ
Browse files

Create function `process_1_file`

Preparing for another call to this function.
parent a9d728ae
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,33 @@ import sys
import time
import csv
def process_1_file(bbox, nco_instance, nc_file, cropped_fname, unpacked_fname,
inst_eddies_exe, d, my_slice, writer):
my_pc = time.perf_counter()
if bbox:
xmin, xmax, ymin, ymax = bbox
try:
nco_instance.ncks(nc_file, output = cropped_fname,
options= [f"--dimension=longitude,{xmin},{xmax}",
f"--dimension=latitude,{ymin},{ymax}"])
except nco.NCOException as err:
print(err.stdout)
raise
nc_file = cropped_fname
nco_instance.ncpdq(nc_file, output = unpacked_fname, options = ["--unpack"])
elapsed_NCO = time.perf_counter() - my_pc
my_pc = time.perf_counter()
subprocess.run([inst_eddies_exe, unpacked_fname, unpacked_fname],
check = True, input = f"&dates_nml date = {d}, "
f"slice = {my_slice}/\n", text = True)
elapsed_Fortran = time.perf_counter() - my_pc
writer.writerow([d, elapsed_NCO, elapsed_Fortran])
def loop_inst_eddies(files, bbox, d, my_slice):
"""files is a sequence or iterator of file paths. The first file must
exist, others can be missing. bbox is a tuple of four real
......@@ -63,31 +90,8 @@ def loop_inst_eddies(files, bbox, d, my_slice):
flush = True)
if os.access(nc_file, os.F_OK):
my_pc = time.perf_counter()
if bbox:
xmin, xmax, ymin, ymax = bbox
try:
nco_instance.ncks(nc_file, output = cropped_fname,
options
= [f"--dimension=longitude,{xmin},{xmax}",
f"--dimension=latitude,{ymin},{ymax}"])
except nco.NCOException as err:
print(err.stdout)
raise
nc_file = cropped_fname
nco_instance.ncpdq(nc_file, output = unpacked_fname,
options = ["--unpack"])
elapsed_NCO = time.perf_counter() - my_pc
my_pc = time.perf_counter()
subprocess.run([inst_eddies_exe, unpacked_fname, unpacked_fname],
check = True, input = f"&dates_nml date = {d}, "
f"slice = {my_slice}/\n", text = True)
elapsed_Fortran = time.perf_counter() - my_pc
writer.writerow([d, elapsed_NCO, elapsed_Fortran])
process_1_file(bbox, nco_instance, nc_file, cropped_fname,
unpacked_fname, inst_eddies_exe, d, my_slice, writer)
else:
print("inst_eddies.loop_inst_eddies: Missing file:", nc_file)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment