Repository: sunpy/sunpy

Issue:
XRSTimeSeries broken for some netcdf files due to reading quality flags
### Describe the bug

#6260 added parsing of GOES quality flags for netcdf files, unfortunately NOAA is not consistent with these column names and as such now XRSTimeSeries can not load some goes data,  now incompatible files which used to load fine e.g. 1m avg data from post 2009 now give a KeyError.

### To Reproduce

```
import wget
from sunpy.timeseries import TimeSeries
f = wget.download('https://data.ngdc.noaa.gov/platforms/solar-space-observing-satellites/goes/goes16/l2/data/xrsf-l2-avg1m_science/2021/01/sci_xrsf-l2-avg1m_g16_d20210101_v2-1-0.nc')
ts = TimeSeries(f)
```

```
File H:\sunpy\sunpy-git\sunpy\timeseries\sources\goes.py:238, in XRSTimeSeries._parse_netcdf(filepath)
    236 xrsa = np.array(h5nc[flux_name_a])
    237 xrsb = np.array(h5nc[flux_name_b])
--> 238 xrsa_quality = np.array(h5nc[flux_name_a.replace("flux", "flags")])
    239 xrsb_quality = np.array(h5nc[flux_name_b.replace("flux", "flags")])
    240 start_time_str = h5nc["time"].attrs["units"]

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\h5netcdf\core.py:810, in Group.__getitem__(self, key)
    808 def __getitem__(self, key):
    809     if key.startswith("/"):
--> 810         return self._root[key[1:]]
    811     keys = key.split("/")
    812     item = self

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\h5netcdf\core.py:814, in Group.__getitem__(self, key)
    812 item = self
    813 for k in keys:
--> 814     item = item._get_child(k)
    815 return item

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\h5netcdf\core.py:806, in Group._get_child(self, key)
    804     return self.variables[key]
    805 except KeyError:
--> 806     return self.groups[key]

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\h5netcdf\utils.py:14, in Frozen.__getitem__(self, key)
     13 def __getitem__(self, key):
---> 14     return self._mapping[key]

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\h5netcdf\core.py:397, in _LazyObjectLookup.__getitem__(self, key)
    395 if key not in self._objects and "_nc4_non_coord_" + key in self._objects:
    396     key = "_nc4_non_coord_" + key
--> 397 if self._objects[key] is not None:
    398     return self._objects[key]
    399 else:

KeyError: 'xrsa_flags'
```


### Screenshots

_No response_

### System Details

astropy: 5.1
numpy: 1.23.2
packaging: 21.3
parfive: 2.0.1

### Installation method

pip


Discussion:

Resolving patch:
diff --git a/sunpy/timeseries/sources/goes.py b/sunpy/timeseries/sources/goes.py
--- a/sunpy/timeseries/sources/goes.py
+++ b/sunpy/timeseries/sources/goes.py
@@ -235,8 +235,10 @@ def _parse_netcdf(filepath):
             flux_name_b = flux_name_a.replace("a", "b")
             xrsa = np.array(h5nc[flux_name_a])
             xrsb = np.array(h5nc[flux_name_b])
-            xrsa_quality = np.array(h5nc[flux_name_a.replace("flux", "flags")])
-            xrsb_quality = np.array(h5nc[flux_name_b.replace("flux", "flags")])
+            flux_flag_a = h5nc.variables.get("a_flags") or h5nc.variables.get("xrsa_flags") or h5nc.variables.get("xrsa_flag")
+            flux_flag_b = h5nc.variables.get("b_flags") or h5nc.variables.get("xrsb_flags") or h5nc.variables.get("xrsb_flag")
+            xrsa_quality = np.array(h5nc[flux_flag_a.name])
+            xrsb_quality = np.array(h5nc[flux_flag_b.name])
             start_time_str = h5nc["time"].attrs["units"]
             # h5netcdf < 0.14 return bytes instead of a str
             if isinstance(start_time_str, bytes):


Test patch:
diff --git a/sunpy/data/test/goes_truncated_test_1m_avg.nc b/sunpy/data/test/goes_truncated_test_1m_avg.nc
new file mode 100644
Binary files /dev/null and b/sunpy/data/test/goes_truncated_test_1m_avg.nc differ
diff --git a/sunpy/timeseries/sources/tests/test_goes.py b/sunpy/timeseries/sources/tests/test_goes.py
--- a/sunpy/timeseries/sources/tests/test_goes.py
+++ b/sunpy/timeseries/sources/tests/test_goes.py
@@ -8,6 +8,7 @@
 goes_filepath_com = get_test_filepath('go1520120601.fits.gz')
 new_goes15_filepath = get_test_filepath('goes_truncated_test_goes15.nc')
 new_goes17_filepath = get_test_filepath('goes_truncated_test_goes17.nc')
+new_goes1m_avg_filepath = get_test_filepath('goes_truncated_test_1m_avg.nc')
 goes13_leap_second_filepath = get_test_filepath('goes_13_leap_second.nc')
 
 
@@ -31,6 +32,12 @@ def test_implicit_new_goes17():
     assert isinstance(ts_goes, sunpy.timeseries.sources.goes.XRSTimeSeries)
 
 
+def test_implicit_goes_1m_avg():
+    # Test a 1m avg GOES TimeSeries
+    ts_goes = sunpy.timeseries.TimeSeries(new_goes1m_avg_filepath)
+    assert isinstance(ts_goes, sunpy.timeseries.sources.goes.XRSTimeSeries)
+
+
 def test_implicit_goes_satno(goes_test_ts):
     assert goes_test_ts.observatory == 'GOES-15'