Repository: obspy/obspy

Issue:
When reading a stationxml response stage into a generic ResponseStage object, decimation info is dropped
### Avoid duplicates

- [X] I searched existing issues

### Bug Summary

The IRIS validation rule 423 tests stationxml response_stages to check for any
stage that *has* decimation + gain info specified, but has stage type that is *not* one of:
{'PolesZerosResponseStage', 'CoefficientsTypeResponseStage', 'FIRResponseStage', 'ResponseListResponseStage'}

IRIS checks this test against the stationxml file F1_423.xml which is meant to fail this test.

However, using obspy read_inventory() to read file F1_423.xml breaks the test since
read_inventory() reads this stage into a generic ResponseStage, but it *drops* the
stage decimation info (e.g., stage.decimation_input_sample_rate is set to None even though it
is specified for this stage).

Is this behavior correct ?  The allowed stage types are all descended from ResponseStage so I
don't see any reason why ResponseStage wouldn't allow decimation info, but perhaps obspy
is intentionally disallowing generic ResponseStage with decimation info (?)

Thanks!
-Mike

### Code to Reproduce

```python
from obspy import read_inventory

# First copy/paste the stationxml in the Traceback below to ./F1_423_small.xml
inv = read_inventory('F1_423_small.xml')

resp = inv.networks[0].stations[0].channels[0].response

# Note that decimation info is lost for stages 1 and 2:
for stage in resp.response_stages:
    print(stage.stage_sequence_number, type(stage), stage.decimation_input_sample_rate,  stage.decimation_factor, stage.stage_gain)
```


### Error Traceback

```Python traceback
<?xml version="1.0" encoding="ISO-8859-1"?>

<FDSNStationXML xmlns="http://www.fdsn.org/xml/station/1" schemaVersion="1.0" xsi:schemaLocation="http://www.fdsn.org/xml/station/1 http://www.fdsn.org/xml/station/fdsn-station-1.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:iris="http://www.fdsn.org/xml/station/1/iris">
 <Source>IRIS-DMC</Source>
 <Sender>IRIS-DMC</Sender>
 <Module>IRIS WEB SERVICE: fdsnws-station | version: 1.1.33</Module>
 <ModuleURI>http://service.iris.edu/fdsnws/station/1/query?net=QI&amp;sta=VPASS&amp;cha=BDF&amp;starttime=2018-08-06T00:00:01&amp;level=response&amp;format=xml&amp;includecomments=true&amp;nodata=404</ModuleURI>
 <Created>2018-08-06T20:17:16</Created>
 <Network code="QI" startDate="2018-08-06T00:00:00" endDate="2500-12-31T23:59:59" restrictedStatus="open">
  <Description>[IRIS DMC] Station XML Validator Passing Test File</Description>
  <TotalNumberStations>1</TotalNumberStations>
  <SelectedNumberStations>1</SelectedNumberStations>
  <Station code="TPASS" startDate="2018-08-06T00:00:00" endDate="2500-12-31T23:59:59" restrictedStatus="open" iris:alternateNetworkCodes="_FDSN,.UNRESTRICTED">
   <Latitude>47.66157</Latitude>
   <Longitude>-122.31332</Longitude>
   <Elevation>225.879999</Elevation>
   <Site>
    <Name>Synthetic Test File, IRIS DMC, USA, 218 2018, Tim Ronan</Name>
   </Site>
   <CreationDate>2018-08-06T00:00:00</CreationDate>
   <TotalNumberChannels>1</TotalNumberChannels>
   <SelectedNumberChannels>1</SelectedNumberChannels>
   <Channel code="BDF" endDate="2500-12-31T23:59:59" locationCode="00" restrictedStatus="open" startDate="2018-08-06T00:00:00">
    <Latitude>47.66157</Latitude>
    <Longitude>-122.31332</Longitude>
    <Elevation>225.879999</Elevation>
    <Depth>0</Depth>
    <Azimuth>359</Azimuth>
    <Dip>0</Dip>
    <Type>CONTINUOUS</Type>
    <Type>GEOPHYSICAL</Type>
    <SampleRate>2E01</SampleRate>
    <ClockDrift>0E00</ClockDrift>
    <CalibrationUnits>
     <Name>V</Name>
     <Description>Volts</Description>
    </CalibrationUnits>
    <Sensor>
     <Description>GEM (Infrasound), 0.2-50 Hz, 0.4 V/Pa-null</Description>
    </Sensor>
    <Response>
     <InstrumentSensitivity>
      <Value>2.44648E5</Value>
      <Frequency>1E0</Frequency>
      <InputUnits>
       <Name>PA</Name>
       <Description>No Abbreviation Referenced</Description>
      </InputUnits>
      <OutputUnits>
       <Name>COUNTS</Name>
       <Description>Digital Counts</Description>
      </OutputUnits>
     </InstrumentSensitivity>
     <Stage number="1">
      <Decimation>
       <InputSampleRate>512000.0</InputSampleRate>
       <Factor>1</Factor>
       <Offset>0</Offset>
       <Delay>0.0</Delay>
       <Correction>0.0</Correction>
      </Decimation>
      <StageGain>
       <Value>0.4</Value>
       <Frequency>1.0</Frequency>
      </StageGain>
     </Stage>
     <Stage number="2">
      <StageGain>
       <Value>1.0</Value>
       <Frequency>1.0</Frequency>
      </StageGain>
     </Stage>
     <Stage number="3">
      <Coefficients>
       <InputUnits>
        <Name>V</Name>
        <Description>Volts</Description>
       </InputUnits>
       <OutputUnits>
        <Name>COUNTS</Name>
        <Description>Digital Counts</Description>
       </OutputUnits>
       <CfTransferFunctionType>DIGITAL</CfTransferFunctionType>
       <Numerator minusError="0.00000" plusError="0.00000">1.00000</Numerator>
      </Coefficients>
      <Decimation>
       <InputSampleRate>512000.0</InputSampleRate>
       <Factor>1</Factor>
       <Offset>0</Offset>
       <Delay>0.0</Delay>
       <Correction>0.0</Correction>
      </Decimation>
      <StageGain>
       <Value>611621.0</Value>
       <Frequency>1.0</Frequency>
      </StageGain>
     </Stage>

    </Response>
   </Channel>
  </Station>
 </Network>
</FDSNStationXML>
```


### ObsPy Version?

1.3.0

### Operating System?

OS/X 

### Python Version?

3.10.5

### Installation Method?

conda


Discussion:
Hmm.. not sure about this one, and I'd have to dig deeper, not sure when I get to that. Anybody else wanna look at this one?
I guess we could try to not drop that info and see if it breaks anything in our tests :rofl: 

Resolving patch:
diff --git a/obspy/io/stationxml/core.py b/obspy/io/stationxml/core.py
--- a/obspy/io/stationxml/core.py
+++ b/obspy/io/stationxml/core.py
@@ -526,7 +526,12 @@ def _read_response_stage(stage_elem, _ns):
                 stage_sequence_number=stage_sequence_number,
                 stage_gain=stage_gain,
                 stage_gain_frequency=stage_gain_frequency,
-                resource_id=resource_id, input_units=None, output_units=None)
+                resource_id=resource_id, input_units=None, output_units=None,
+                decimation_input_sample_rate=decimation_input_sample_rate,
+                decimation_factor=decimation_factor,
+                decimation_offset=decimation_offset,
+                decimation_delay=decimation_delay,
+                decimation_correction=decimation_correction)
         # Raise if none of the previous ones has been found.
         msg = "Could not find a valid Response Stage Type."
         raise ValueError(msg)


Test patch:
diff --git a/obspy/io/stationxml/tests/data/F1_423_small.xml b/obspy/io/stationxml/tests/data/F1_423_small.xml
new file mode 100644
--- /dev/null
+++ b/obspy/io/stationxml/tests/data/F1_423_small.xml
@@ -0,0 +1,103 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<FDSNStationXML xmlns="http://www.fdsn.org/xml/station/1" schemaVersion="1.0" xsi:schemaLocation="http://www.fdsn.org/xml/station/1 http://www.fdsn.org/xml/station/fdsn-station-1.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:iris="http://www.fdsn.org/xml/station/1/iris">
+ <Source>IRIS-DMC</Source>
+ <Sender>IRIS-DMC</Sender>
+ <Module>IRIS WEB SERVICE: fdsnws-station | version: 1.1.33</Module>
+ <ModuleURI>http://service.iris.edu/fdsnws/station/1/query?net=QI&amp;sta=VPASS&amp;cha=BDF&amp;starttime=2018-08-06T00:00:01&amp;level=response&amp;format=xml&amp;includecomments=true&amp;nodata=404</ModuleURI>
+ <Created>2018-08-06T20:17:16</Created>
+ <Network code="QI" startDate="2018-08-06T00:00:00" endDate="2500-12-31T23:59:59" restrictedStatus="open">
+  <Description>[IRIS DMC] Station XML Validator Passing Test File</Description>
+  <TotalNumberStations>1</TotalNumberStations>
+  <SelectedNumberStations>1</SelectedNumberStations>
+  <Station code="TPASS" startDate="2018-08-06T00:00:00" endDate="2500-12-31T23:59:59" restrictedStatus="open" iris:alternateNetworkCodes="_FDSN,.UNRESTRICTED">
+   <Latitude>47.66157</Latitude>
+   <Longitude>-122.31332</Longitude>
+   <Elevation>225.879999</Elevation>
+   <Site>
+    <Name>Synthetic Test File, IRIS DMC, USA, 218 2018, Tim Ronan</Name>
+   </Site>
+   <CreationDate>2018-08-06T00:00:00</CreationDate>
+   <TotalNumberChannels>1</TotalNumberChannels>
+   <SelectedNumberChannels>1</SelectedNumberChannels>
+   <Channel code="BDF" endDate="2500-12-31T23:59:59" locationCode="00" restrictedStatus="open" startDate="2018-08-06T00:00:00">
+    <Latitude>47.66157</Latitude>
+    <Longitude>-122.31332</Longitude>
+    <Elevation>225.879999</Elevation>
+    <Depth>0</Depth>
+    <Azimuth>359</Azimuth>
+    <Dip>0</Dip>
+    <Type>CONTINUOUS</Type>
+    <Type>GEOPHYSICAL</Type>
+    <SampleRate>2E01</SampleRate>
+    <ClockDrift>0E00</ClockDrift>
+    <CalibrationUnits>
+     <Name>V</Name>
+     <Description>Volts</Description>
+    </CalibrationUnits>
+    <Sensor>
+     <Description>GEM (Infrasound), 0.2-50 Hz, 0.4 V/Pa-null</Description>
+    </Sensor>
+    <Response>
+     <InstrumentSensitivity>
+      <Value>2.44648E5</Value>
+      <Frequency>1E0</Frequency>
+      <InputUnits>
+       <Name>PA</Name>
+       <Description>No Abbreviation Referenced</Description>
+      </InputUnits>
+      <OutputUnits>
+       <Name>COUNTS</Name>
+       <Description>Digital Counts</Description>
+      </OutputUnits>
+     </InstrumentSensitivity>
+     <Stage number="1">
+      <Decimation>
+       <InputSampleRate>1024000.0</InputSampleRate>
+       <Factor>2</Factor>
+       <Offset>1</Offset>
+       <Delay>0.5</Delay>
+       <Correction>0.4</Correction>
+      </Decimation>
+      <StageGain>
+       <Value>0.4</Value>
+       <Frequency>1.0</Frequency>
+      </StageGain>
+     </Stage>
+     <Stage number="2">
+      <StageGain>
+       <Value>1.0</Value>
+       <Frequency>1.0</Frequency>
+      </StageGain>
+     </Stage>
+     <Stage number="3">
+      <Coefficients>
+       <InputUnits>
+        <Name>V</Name>
+        <Description>Volts</Description>
+       </InputUnits>
+       <OutputUnits>
+        <Name>COUNTS</Name>
+        <Description>Digital Counts</Description>
+       </OutputUnits>
+       <CfTransferFunctionType>DIGITAL</CfTransferFunctionType>
+       <Numerator minusError="0.00000" plusError="0.00000">1.00000</Numerator>
+      </Coefficients>
+      <Decimation>
+       <InputSampleRate>512000.0</InputSampleRate>
+       <Factor>1</Factor>
+       <Offset>0</Offset>
+       <Delay>0.0</Delay>
+       <Correction>0.0</Correction>
+      </Decimation>
+      <StageGain>
+       <Value>611621.0</Value>
+       <Frequency>1.0</Frequency>
+      </StageGain>
+     </Stage>
+
+    </Response>
+   </Channel>
+  </Station>
+ </Network>
+</FDSNStationXML>
diff --git a/obspy/io/stationxml/tests/test_stationxml.py b/obspy/io/stationxml/tests/test_stationxml.py
--- a/obspy/io/stationxml/tests/test_stationxml.py
+++ b/obspy/io/stationxml/tests/test_stationxml.py
@@ -1321,6 +1321,20 @@ def test_read_with_level(self):
         self.assertEqual(len(inv_stationxml_network), 1)
         self.assertEqual(len(inv_stationxml_network[0]), 0)
 
+    def test_read_basic_responsestage_with_decimation(self):
+        """
+        Make sure basic ResponseStage elements that have decimation information
+        do not lose that information.
+        """
+        path = os.path.join(self.data_dir, 'F1_423_small.xml')
+        inv = _read_stationxml(path)
+        stage = inv[0][0][0].response.response_stages[0]
+        assert stage.decimation_correction == 0.4
+        assert stage.decimation_delay == 0.5
+        assert stage.decimation_factor == 2
+        assert stage.decimation_input_sample_rate == 1024000.0
+        assert stage.decimation_offset == 1
+
 
 def suite():
     return unittest.makeSuite(StationXMLTestCase, "test")