-
Notifications
You must be signed in to change notification settings - Fork 558
Description
Avoid duplicates
- I searched existing issues
Bug Summary
From the perspective of general XML syntax, the tag <FieldName/> is perfectly valid. This syntax is a self-closing tag, which is equivalent to an empty element written as:
<FieldName></FieldName>
Both forms are allowed in XML, and <FieldName/> is a standard and widely used way to represent an empty element.
Link: KAGSR FDSNWS
returns:
<FDSNStationXML xmlns="http://www.fdsn.org/xml/station/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:iris="http://www.fdsn.org/xml/station/1/iris" xsi:schemaLocation="http://www.fdsn.org/xml/station/1 http://www.fdsn.org/xml/station/fdsn-station-1.1.xsd" schemaVersion="1.1">
<Source>SDIS KB GS RAS</Source>
<Created>2025-12-16T23:21:02.696380</Created>
<Network code="II">
<TotalNumberStations>18</TotalNumberStations>
<Station code="PET" alternateCode="Петропавловск" startDate="1905-05-14T00:00:00">
<Latitude>53.023300</Latitude>
<Longitude>158.649900</Longitude>
<Elevation>100.0000</Elevation>
<Site>
<Name>PET</Name>
</Site>
<CreationDate>1905-05-14T00:00:00</CreationDate>
<Channel code="BHZ" locationCode="00" startDate="2018-05-23T21:46:58.640200" restrictedStatus="open">
<Latitude>53.023300</Latitude>
<Longitude>158.649900</Longitude>
<Elevation>100.0000</Elevation>
<Depth>0</Depth>
<Azimuth>0</Azimuth>
<Dip>0</Dip>
<SampleRate/>
</Channel>
</Station>
</Network>
</FDSNStationXML>
Note that the response contains the tag <SampleRate/>.
Running the following code:
client = Client('http://sdis.emsd.ru')
starttime = UTCDateTime('2021-01-01')
channel = client.get_stations(level='channel', starttime = starttime, endtime = (starttime + 1),
station = 'PET', channel = 'BHZ', network = 'II' )
produces the warning message during execution:
...obspy\io\stationxml\core.py:317: UserWarning: 'b''' could not be converted to a float. Will be skipped. Please contact to report this issue.
warnings.warn(
This warning occurs specifically when processing the <SampleRate/> tag.
I see two possible solutions:
- Improve XML parsing logic to correctly handle the semantic equivalence between and (i.e., treat both as empty/missing values rather than attempting float conversion).
- Modify the file ...\obspy\io\stationxml\core.py by adding a check for
if elem.text is Nonein the_read_floattype()function.
Current code:
def _read_floattype(parent, tag, cls, unit=False, datum=False,
additional_mapping={}):
elem = parent.find(tag)
if elem is None:
return None
# Catch non-convertible numbers.
try:
convert = float(elem.text)
except Exception:
...
Proposed change:
def _read_floattype(parent, tag, cls, unit=False, datum=False,
additional_mapping={}):
elem = parent.find(tag)
if elem is None:
return None
# Catch non-convertible numbers.
try:
if elem.text is None:
return None
convert = float(elem.text)
except Exception:
...
Code to Reproduce
Error Traceback
ObsPy Version?
1.4.0
Operating System?
Windows
Python Version?
3.11
Installation Method?
pip