Skip to content

Commit

Permalink
Skip spectral consistency check if missing coefficients
Browse files Browse the repository at this point in the history
  • Loading branch information
tukiains committed Nov 13, 2024
1 parent 0bb1ce4 commit f4d6cc2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions mwrpy/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ class MissingInputData(Exception):

class InvalidFileError(Exception):
pass


class MissingCoefficientsError(Exception):
pass
15 changes: 13 additions & 2 deletions mwrpy/level1/quality_control.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
"""Quality control for level1 data."""

import datetime
import logging

import netCDF4 as nc
import numpy as np
import pandas as pd
import suncalc
from numpy import ma

from mwrpy.exceptions import MissingCoefficientsError
from mwrpy.level1.rpg_bin import RpgBin
from mwrpy.level2.get_ret_coeff import get_mvr_coeff
from mwrpy.level2.write_lev2_nc import retrieval_input
Expand Down Expand Up @@ -66,8 +68,14 @@ def apply_qc(
if params["flag_status"][3] == 1 or "air_pressure" not in data:
data["quality_flag_status"] = setbit(data["quality_flag_status"], 3)
else:
ind = spectral_consistency(data, site, coeff_files)
data["quality_flag"][ind] = setbit(data["quality_flag"][ind], 3)
try:
ind = spectral_consistency(data, site, coeff_files)
data["quality_flag"][ind] = setbit(data["quality_flag"][ind], 3)
except MissingCoefficientsError as e:
logging.error(
f"Error in spectral consistency check: {e}. Proceeding without flagging."
)
data["quality_flag_status"] = setbit(data["quality_flag_status"], 3)

# Bit 5: Receiver sanity
if params["flag_status"][4] == 1:
Expand Down Expand Up @@ -307,6 +315,9 @@ def spectral_consistency(
else:
c_list = get_coeff_list(site, "tbx", coeff_files)

if not c_list:
raise MissingCoefficientsError("No coefficients found")

for ifreq, _ in enumerate(data["frequency"]):
with nc.Dataset(c_list[ifreq]) as cfile:
_, freq_ind, coeff_ind = np.intersect1d(
Expand Down

0 comments on commit f4d6cc2

Please sign in to comment.