Skip to content

Commit

Permalink
remove .nc files found in OUTPUT_DIR depending on config file (#710)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtmims authored Nov 18, 2024
1 parent 6b2408e commit eb4ed79
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/output_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import glob
import io
import shutil
import yaml
from src import util, verify_links

import logging
Expand Down Expand Up @@ -264,6 +265,23 @@ def cleanup_pod_files(self):
for f in util.find_files(self.WORK_DIR, 'model/netCDF/*.nc'):
os.remove(f)

def cleanup_pp_data(self):
"""Removes nc files found in catalog if the ``save_pp_data`` data
is set to false.
This is done by looping through the ``case_info.yml`` file found in each
POD. If the .nc file exists, it is then deleted.
"""
if not self.save_nc:
for f in util.find_files(self.WORK_DIR, 'case_info.yml'):
case_info_yml = yaml.safe_load(open(f))
for case in case_info_yml['CASE_LIST']:
for k in case_info_yml['CASE_LIST'][case]:
if k.endswith('FILE') or k.endswith('FILES'):
v = case_info_yml['CASE_LIST'][case][k]
if v != '' and os.path.exists(v) and v.endswith('.nc'):
os.remove(v)

def make_output(self, config: util.NameSpace):
"""Top-level method to make POD-specific output, post-init. Split off
into its own method to make subclassing easier.
Expand All @@ -281,6 +299,7 @@ def make_output(self, config: util.NameSpace):
self.convert_pod_figures(os.path.join('model', 'PS'), 'model')
self.convert_pod_figures(os.path.join('obs', 'PS'), 'obs')
self.cleanup_pod_files()
self.cleanup_pp_data()


class HTMLOutputManager(AbstractOutputManager,
Expand Down

0 comments on commit eb4ed79

Please sign in to comment.