Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions oper/utils/grib2writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,23 +145,12 @@ def save_grib2(self, xarray_ds, outdir):
grib2_out_sfc.close()
grib2_out_pres.close()

# Use wgrib2 to generate index files
for outfile in [outfile_sfc, outfile_pres]:
output_idx_file = f"{outfile}.idx"

# Construct the wgrib2 command
wgrib2_command = ['wgrib2', '-s', outfile]

try:
# Open the output file for writing
with open(output_idx_file, "w") as f_out:
# Execute the wgrib2 command and redirect stdout to the output file
subprocess.run(wgrib2_command, stdout=f_out, check=True)

print(f"Index file created successfully: {output_idx_file}")

except subprocess.CalledProcessError as e:
print(f"Error running wgrib2 command: {e}")
# Release post job to create index files and copy files to COM
if os.getenv("envir") is not None:
DATA = os.getenv("DATA")
cmd = [f"{DATA}/set_event.sh", f"{lead:03d}"]
print(f"Running shell subprocess {cmd}")
subprocess.run(cmd, check=True)

if __name__ == "__main__":

Expand Down