Repository: obspy/obspy

Issue:
"id" argument in stream.select function overwritten when only an inventory is passed
### Avoid duplicates

- [X] I searched existing issues

### Bug Summary

In the "select" function of stream.py

If only a non-empty inventory is passed to the select function, the following piece of code will run (lines 1846→1857)

```
  trace_ids = [] 
              start_dates = [] 
              end_dates = [] 
              for net in inventory.networks:
                  for sta in net.stations:
                      for chan in sta.channels:
                          id = '.'.join((net.code, sta.code,
                                         chan.location_code, chan.code))
                          trace_ids.append(id)
                          start_dates.append(chan.start_date)
                          end_dates.append(chan.end_date)
              traces = []
```

and it will modify the variable “id” to some value that is not None. However, the variable “id” is also an argument of the select function (line 1769)

```
select(self, network=None, station=None, location=None, channel=None,
               sampling_rate=None, npts=None, component=None, id=None,
               inventory=None)
```

This unintentional change of the id from None to something else will be “caught” further down in the function and will set the quick_check_possible to True when in fact it should be False (lines 1887→1893).

```
# For st.select(id=) without wildcards, use a quicker comparison mode:
        quick_check = False
        quick_check_possible = (id is not None
                                and sampling_rate is None and npts is None
                                and network is None and station is None
                                and location is None and channel is None
                                and component is None)
```

The problem can be fixed simply by changing the name of the variable id in lines 1852 and 1854 to something else. 

### Code to Reproduce

_No response_

### Error Traceback

_No response_

### ObsPy Version?

1.4.0

### Operating System?

Windows 11 (using WSL2 + Ubuntu 20.04)

### Python Version?

3.11.0

### Installation Method?

None


Discussion:
Do you have a quick self contained example for this problem?
Here is one 
``` from obspy import UTCDateTime, read
from obspy.clients.fdsn import Client
import matplotlib
matplotlib.use('tkagg') # I'm using WSL2 with XLaunch

############
# EVENT INFO
############
c_event = Client("IRIS")
# Event time
event_time = UTCDateTime("2009-09-30T10:16:09")
# Get the event information.
cat = c_event.get_events(starttime=event_time - 10, endtime=event_time + 10,
                         minmagnitude=7.5, maxmagnitude=7.7, minlatitude=-1, 
                         maxlatitude=0, minlongitude=99, maxlongitude=100)


##############
# STATION INFO
##############
c = Client("IRIS")
net = "LB,CN,UW"
sta = "BMN,DRLN,BLOW"
loc = "*"
chn = "BH?"
pre_duration = 0
duration = 30*60
inv = c.get_stations(network=net, station=sta, location=loc, channel=chn,
                        starttime=event_time - pre_duration, endtime=event_time + duration,
                        level="response")
st = c.get_waveforms(network=net, station=sta, location=loc,
                        channel=chn, starttime=cat[0].origins[0].time - pre_duration,
                        endtime=event_time + duration)
print("THE FULL STREAM")
print(st)
print("THE INVENTORY")
print(inv)
# So now we have the "inv" inventory which contains all the networks/stations/channels that
# are present in the "st" stream. If we filter the "st" stream based on the "inv" inventory
# using the .select function, then we expect to get back the same stream, but instead 
# we only get one trace. 
print("THE SELECTED STREAM")
print(st.select(inventory=inv))```
Ah OK, I got it now. Thanks!

Resolving patch:
diff --git a/obspy/core/stream.py b/obspy/core/stream.py
--- a/obspy/core/stream.py
+++ b/obspy/core/stream.py
@@ -1851,9 +1851,9 @@ def select(self, network=None, station=None, location=None, channel=None,
             for net in inventory.networks:
                 for sta in net.stations:
                     for chan in sta.channels:
-                        id = '.'.join((net.code, sta.code,
-                                       chan.location_code, chan.code))
-                        trace_ids.append(id)
+                        _id = '.'.join((net.code, sta.code,
+                                        chan.location_code, chan.code))
+                        trace_ids.append(_id)
                         start_dates.append(chan.start_date)
                         end_dates.append(chan.end_date)
             traces = []


Test patch:
diff --git a/obspy/core/tests/test_stream.py b/obspy/core/tests/test_stream.py
--- a/obspy/core/tests/test_stream.py
+++ b/obspy/core/tests/test_stream.py
@@ -758,7 +758,7 @@ def test_select_from_inventory(self):
                     latitude=0.0, longitude=0.0, elevation=0.0, depth=0.0,
                     start_date=UTCDateTime(1990, 1, 1),
                     end_date=UTCDateTime(1998, 1, 1)),
-            Channel(code='EHZ', location_code='00',
+            Channel(code='EHN', location_code='00',
                     latitude=0.0, longitude=0.0, elevation=0.0, depth=0.0,
                     start_date=UTCDateTime(1999, 1, 1))
         ]