Skip to content

Commit

Permalink
fixed a bug for empty files
Browse files Browse the repository at this point in the history
  • Loading branch information
givelberg committed Oct 29, 2024
1 parent 34f894f commit 5e80b3a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
14 changes: 14 additions & 0 deletions ush/ioda/bufr2ioda/marine/b2i/b2iconverter/bufr2ioda_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,22 @@ def run(self):
# process query results and set ioda variables
self.ioda_vars.set_from_query_result(r)

n_obs = self.ioda_vars.number_of_obs()
self.logger.debug(f"Query result has {n_obs} obs")
if (n_obs == 0):
self.logger.warning(f"No obs! Quitting.")
sys.exit(1)

self.ioda_vars.filter()

n_obs = self.ioda_vars.number_of_obs()
self.logger.debug(f"Filtered result has {n_obs} obs")
if (n_obs == 0):
self.logger.warning(f"No obs! Quitting.")
sys.exit(1)
self.logger.debug(f"Number of temperature obs = {self.ioda_vars.number_of_temp_obs()}")
self.logger.debug(f"Number of salinity obs = {self.ioda_vars.number_of_saln_obs()}")

# set seqNum, PreQC, ObsError, OceanBasin
self.ioda_vars.additional_vars.construct()

Expand Down
23 changes: 23 additions & 0 deletions ush/ioda/bufr2ioda/marine/b2i/b2iconverter/ioda_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,29 @@ def set_salinity_range(self, smin, smax):
self.S_min = smin
self.S_max = smax

def number_of_temp_obs(self):
try:
if isinstance(self.temp, np.ma.MaskedArray):
return self.temp.count()
else:
return 0
# except NameError:
except AttributeError:
return 0

def number_of_saln_obs(self):
try:
if isinstance(self.saln, np.ma.MaskedArray):
return self.saln.count()
else:
return 0
# except NameError:
except AttributeError:
return 0

def number_of_obs(self):
return max(self.number_of_temp_obs(), self.number_of_saln_obs())

def build_query(self):
q = bufr.QuerySet()
q.add('year', '*/YEAR')
Expand Down

0 comments on commit 5e80b3a

Please sign in to comment.