From 86e257d3f4fba5d5bacd11515f9c8e3ccc7f3552 Mon Sep 17 00:00:00 2001
From: bgeels <bgeels@usgs.gov>
Date: Wed, 27 Mar 2024 14:16:49 -0600
Subject: [PATCH] Exclude invalid entries in get_instrument_calibrations

---
 .../metadata/instrument/InstrumentCalibrations.py     | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/geomagio/metadata/instrument/InstrumentCalibrations.py b/geomagio/metadata/instrument/InstrumentCalibrations.py
index d3f52a9a..330ab8e8 100644
--- a/geomagio/metadata/instrument/InstrumentCalibrations.py
+++ b/geomagio/metadata/instrument/InstrumentCalibrations.py
@@ -2,6 +2,8 @@ from obspy import UTCDateTime
 
 from geomagio.metadata import Metadata, MetadataFactory, MetadataCategory
 
+# REMOVE ANY INSTRUMENT METADATA ELEMENTS W/ "DATA_VALID=FALSE"
+
 
 class InstrumentCalibrations:
     """
@@ -305,7 +307,8 @@ def get_instrument_calibrations(
       observatory: observatory code
       start_time: start time to match, or None to match any.
       end_time: end time to match, or None to match any.
-      calibrations: use custom list, defaults to pulling and converting metadata
+      calibrations: use custom list, defaults to pulling and converting instrument metadata
+      metadata_url: metadata database url
     Returns:
       list of applicable instrument calibrations
     """
@@ -321,6 +324,12 @@ def get_instrument_calibrations(
             station=observatory,
         )
         metadata = factory.get_metadata(query=query)
+
+        # remove invalid metadata entries
+        for i, m in enumerate(metadata):
+            if not m.data_valid:
+                metadata.pop(i)
+
         instrumentCalibrations = InstrumentCalibrations(metadata)
         calibrations = instrumentCalibrations.get_calibrations()
 
-- 
GitLab