obspy / obspy

ObsPy: A Python Toolbox for seismology/seismological observatories.

Home Page:https://www.obspy.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

missing network_identifier_code attribute when reading RESP file

paitor opened this issue · comments

Avoid duplicates

  • I searched existing issues

Bug Summary

ObsPy version:
1.4.0

input file (not supported by github, sorry):
ds.iris.edu/NRL/sensors/kinemetrics/RESP.XX.NS214..BNZ.Episensor.DC_200.5VDF.4G

reading the file above using obspy.io.xseed.Parser works fine but trying to print the resulting parser object fails

Note: Error traceback given below were produced using obspy 1.1.1 so line numbers may not be the same as in 1.4

Code to Reproduce

from obspy.io.xseed import Parser
p = Parser("XX.NS214..BNZ.Episensor.DC_200.5VDF.4G.RESP")
print(p)

Error Traceback

File "/usr/lib/python3/dist-packages/obspy/io/xseed/parser.py", line 134, in __str__
    inv = self.get_inventory()
  File "/usr/lib/python3/dist-packages/obspy/io/xseed/parser.py", line 1902, in get_inventory
    network_id = blkt.network_identifier_code
AttributeError: 'Blockette050' object has no attribute 'network_identifier_code'

ObsPy Version?

1.4.0

Operating System?

CentOS 7

Python Version?

3.11

Installation Method?

conda

I don't get an error on 1.4.0

Strange, tested this on my colleagues computer who claimed to have installed obspy 2 months ago. WIll try again tomorrow when at office and my colleague have time, and also try to update his obspy install to the latest version available via conda to see if that fixes the issue

Re-tested and still get the error after updating to latest version via conda (could it be an issue with an older conda version?):

traceback, conda env etc.
(obspy311) python
Python 3.11.4 | packaged by conda-forge | (main, Jun 10 2023, 18:08:17) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from obspy.io.xseed import Parser
>>> p = Parser("XX.NS214..BNZ.Episensor.DC_200.5VDF.4G.RESP")
>>> print(p)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/mro/miniconda3/envs/obspy311/lib/python3.11/site-packages/obspy/io/xseed/parser.py", line 129, in __str__
    inv = self.get_inventory()
          ^^^^^^^^^^^^^^^^^^^^
  File "/home/mro/miniconda3/envs/obspy311/lib/python3.11/site-packages/obspy/io/xseed/parser.py", line 1898, in get_inventory
    network_id = blkt.network_identifier_code
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Blockette050' object has no attribute 'network_identifier_code'
>>> print(obspy.__version__)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'obspy' is not defined
>>> import obspy
>>> print(obspy.__version__)
1.4.0
>>>

(obspy311) conda update obspy
Collecting package metadata (current_repodata.json): done
Solving environment: done


==> WARNING: A newer version of conda exists. <==
  current version: 22.9.0
  latest version: 23.7.4

Please update conda by running

    $ conda update -n base -c conda-forge conda



## Package Plan ##

  environment location: /home/mro/miniconda3/envs/obspy311

  added / updated specs:
    - obspy


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    anyio-4.0.0                |     pyhd8ed1ab_0          97 KB conda-forge
    brotli-1.1.0               |       hd590300_0          19 KB conda-forge
    brotli-bin-1.1.0           |       hd590300_0          19 KB conda-forge
    brotli-python-1.1.0        |  py311hb755f60_0         343 KB conda-forge
    cffi-1.15.1                |  py311hb3a22ac_5         289 KB conda-forge
    contourpy-1.1.1            |  py311h9547e67_1         229 KB conda-forge
    cryptography-41.0.4        |  py311h63ff55d_0         2.0 MB conda-forge
    dnspython-2.4.2            |     pyhd8ed1ab_0         161 KB conda-forge
    exceptiongroup-1.1.3       |     pyhd8ed1ab_0          19 KB conda-forge
    fonttools-4.42.1           |  py311h459d7ec_0         2.6 MB conda-forge
    freetype-2.12.1            |       h267a509_2         620 KB conda-forge
    httpcore-0.18.0            |     pyhd8ed1ab_0          44 KB conda-forge
    icu-73.2                   |       h59595ed_0        11.5 MB conda-forge
    kiwisolver-1.4.5           |  py311h9547e67_1          72 KB conda-forge
    lcms2-2.15                 |       h7f713cb_2         235 KB conda-forge
    libblas-3.9.0              |18_linux64_openblas          14 KB  conda-forge
    libbrotlicommon-1.1.0      |       hd590300_0          68 KB conda-forge
    libbrotlidec-1.1.0         |       hd590300_0          32 KB conda-forge
    libbrotlienc-1.1.0         |       hd590300_0         276 KB conda-forge
    libcblas-3.9.0             |18_linux64_openblas          14 KB  conda-forge
    libdeflate-1.19            |       hd590300_0          66 KB conda-forge
    libgcc-ng-13.2.0           |       h807b86a_2         753 KB conda-forge
    libgfortran-ng-13.2.0      |       h69a702a_2          23 KB conda-forge
    libgfortran5-13.2.0        |       ha4646dd_2         1.4 MB conda-forge
    libgomp-13.2.0             |       h807b86a_2         411 KB conda-forge
    libjpeg-turbo-2.1.5.1      |       hd590300_1         485 KB conda-forge
    liblapack-3.9.0            |18_linux64_openblas          14 KB  conda-forge
    libnsl-2.0.0               |       hd590300_1          32 KB conda-forge
    libopenblas-0.3.24         |pthreads_h413a1c8_0         5.2 MB  conda-forge
    libsqlite-3.43.0           |       h2797004_0         821 KB conda-forge
    libstdcxx-ng-13.2.0        |       h7e041cc_2         3.7 MB conda-forge
    libtiff-4.6.0              |       h29866fb_1         271 KB conda-forge
    libwebp-base-1.3.2         |       hd590300_0         392 KB conda-forge
    libxml2-2.11.5             |       h232c23b_1         689 KB conda-forge
    lxml-4.9.3                 |  py311h1a07684_1         1.4 MB conda-forge
    matplotlib-base-3.8.0      |  py311h54ef318_1         7.5 MB conda-forge
    mysql-common-8.0.33        |       hf1915f5_4         749 KB conda-forge
    mysql-libs-8.0.33          |       hca2cd23_4         1.5 MB conda-forge
    numpy-1.26.0               |  py311h64a7726_0         7.7 MB conda-forge
    openjpeg-2.5.0             |       h488ebb8_3         348 KB conda-forge
    openssl-3.1.3              |       hd590300_0         2.5 MB conda-forge
    pillow-10.0.1              |  py311h8aef010_1        44.7 MB conda-forge
    python_abi-3.11            |          4_cp311           6 KB conda-forge
    scipy-1.11.3               |  py311h64a7726_0        15.7 MB conda-forge
    setuptools-68.2.2          |     pyhd8ed1ab_0         454 KB conda-forge
    tk-8.6.13                  |       h2797004_0         3.1 MB conda-forge
    typing_extensions-4.8.0    |     pyha770c72_0          34 KB conda-forge
    urllib3-2.0.5              |     pyhd8ed1ab_0          96 KB conda-forge
    wheel-0.41.2               |     pyhd8ed1ab_0          56 KB conda-forge
    zstd-1.5.5                 |       hfc55251_0         532 KB conda-forge
    ------------------------------------------------------------
                                           Total:       119.1 MB

The following packages will be REMOVED:

  platformdirs-3.10.0-pyhd8ed1ab_0
  pooch-1.7.0-pyha770c72_3
  typing-extensions-4.7.1-hd8ed1ab_0

The following packages will be UPDATED:

  anyio                                  3.7.1-pyhd8ed1ab_0 --> 4.0.0-pyhd8ed1ab_0 None
  brotli                                   1.0.9-h166bdaf_9 --> 1.1.0-hd590300_0 None
  brotli-bin                               1.0.9-h166bdaf_9 --> 1.1.0-hd590300_0 None
  brotli-python                       1.0.9-py311ha362b79_9 --> 1.1.0-py311hb755f60_0 None
  cffi                               1.15.1-py311h409f033_3 --> 1.15.1-py311hb3a22ac_5 None
  contourpy                           1.1.0-py311h9547e67_0 --> 1.1.1-py311h9547e67_1 None
  cryptography                       41.0.2-py311h63ff55d_0 --> 41.0.4-py311h63ff55d_0 None
  dnspython                              2.4.1-pyhd8ed1ab_0 --> 2.4.2-pyhd8ed1ab_0 None
  exceptiongroup                         1.1.2-pyhd8ed1ab_0 --> 1.1.3-pyhd8ed1ab_0 None
  fonttools                          4.42.0-py311h459d7ec_0 --> 4.42.1-py311h459d7ec_0 None
  freetype                                2.12.1-hca18f0e_1 --> 2.12.1-h267a509_2 None
  httpcore                              0.17.3-pyhd8ed1ab_0 --> 0.18.0-pyhd8ed1ab_0 None
  icu                                       72.1-hcb278e6_0 --> 73.2-h59595ed_0 None
  kiwisolver                          1.4.4-py311h4dd048b_1 --> 1.4.5-py311h9547e67_1 None
  lcms2                                     2.15-haa2dc70_1 --> 2.15-h7f713cb_2 None
  libblas                         3.9.0-17_linux64_openblas --> 3.9.0-18_linux64_openblas None
  libbrotlicommon                          1.0.9-h166bdaf_9 --> 1.1.0-hd590300_0 None
  libbrotlidec                             1.0.9-h166bdaf_9 --> 1.1.0-hd590300_0 None
  libbrotlienc                             1.0.9-h166bdaf_9 --> 1.1.0-hd590300_0 None
  libcblas                        3.9.0-17_linux64_openblas --> 3.9.0-18_linux64_openblas None
  libdeflate                                1.18-h0b41bf4_0 --> 1.19-hd590300_0 None
  libgcc-ng                               13.1.0-he5830b7_0 --> 13.2.0-h807b86a_2 None
  libgfortran-ng                          13.1.0-h69a702a_0 --> 13.2.0-h69a702a_2 None
  libgfortran5                            13.1.0-h15d22d2_0 --> 13.2.0-ha4646dd_2 None
  libgomp                                 13.1.0-he5830b7_0 --> 13.2.0-h807b86a_2 None
  libjpeg-turbo                          2.1.5.1-h0b41bf4_0 --> 2.1.5.1-hd590300_1 None
  liblapack                       3.9.0-17_linux64_openblas --> 3.9.0-18_linux64_openblas None
  libnsl                                   2.0.0-h7f98852_0 --> 2.0.0-hd590300_1 None
  libopenblas                    0.3.23-pthreads_h80387f5_0 --> 0.3.24-pthreads_h413a1c8_0 None
  libsqlite                               3.42.0-h2797004_0 --> 3.43.0-h2797004_0 None
  libstdcxx-ng                            13.1.0-hfd8a6a1_0 --> 13.2.0-h7e041cc_2 None
  libtiff                                  4.5.1-h8b53f26_0 --> 4.6.0-h29866fb_1 None
  libwebp-base                             1.3.1-hd590300_0 --> 1.3.2-hd590300_0 None
  libxml2                                 2.11.4-h0d562d8_0 --> 2.11.5-h232c23b_1 None
  lxml                                4.9.3-py311h1a07684_0 --> 4.9.3-py311h1a07684_1 None
  matplotlib-base                     3.7.1-py311h8597a09_0 --> 3.8.0-py311h54ef318_1 None
  mysql-common                            8.0.33-hf1915f5_2 --> 8.0.33-hf1915f5_4 None
  mysql-libs                              8.0.33-hca2cd23_2 --> 8.0.33-hca2cd23_4 None
  numpy                              1.25.2-py311h64a7726_0 --> 1.26.0-py311h64a7726_0 None
  openjpeg                                 2.5.0-hfec8fc6_2 --> 2.5.0-h488ebb8_3 None
  openssl                                  3.1.2-hd590300_0 --> 3.1.3-hd590300_0 None
  pillow                             10.0.0-py311h0b84326_0 --> 10.0.1-py311h8aef010_1 None
  python_abi                                   3.11-3_cp311 --> 3.11-4_cp311 None
  scipy                              1.11.1-py311h64a7726_0 --> 1.11.3-py311h64a7726_0 None
  setuptools                            68.0.0-pyhd8ed1ab_0 --> 68.2.2-pyhd8ed1ab_0 None
  tk                                      8.6.12-h27826a3_0 --> 8.6.13-h2797004_0 None
  typing_extensions                      4.7.1-pyha770c72_0 --> 4.8.0-pyha770c72_0 None
  urllib3                                2.0.4-pyhd8ed1ab_0 --> 2.0.5-pyhd8ed1ab_0 None
  wheel                                 0.41.1-pyhd8ed1ab_0 --> 0.41.2-pyhd8ed1ab_0 None
  zstd                                     1.5.2-hfc55251_7 --> 1.5.5-hfc55251_0 None


Proceed ([y]/n)? y


Downloading and Extracting Packages
numpy-1.26.0         | 7.7 MB    | ######################################################################################################### | 100%
libjpeg-turbo-2.1.5. | 485 KB    | ######################################################################################################### | 100%
brotli-1.1.0         | 19 KB     | ######################################################################################################### | 100%
libbrotlidec-1.1.0   | 32 KB     | ######################################################################################################### | 100%
libsqlite-3.43.0     | 821 KB    | ######################################################################################################### | 100%
fonttools-4.42.1     | 2.6 MB    | ######################################################################################################### | 100%
libgfortran-ng-13.2. | 23 KB     | ######################################################################################################### | 100%
libblas-3.9.0        | 14 KB     | ######################################################################################################### | 100%
liblapack-3.9.0      | 14 KB     | ######################################################################################################### | 100%
wheel-0.41.2         | 56 KB     | ######################################################################################################### | 100%
brotli-bin-1.1.0     | 19 KB     | ######################################################################################################### | 100%
zstd-1.5.5           | 532 KB    | ######################################################################################################### | 100%
mysql-libs-8.0.33    | 1.5 MB    | ######################################################################################################### | 100%
matplotlib-base-3.8. | 7.5 MB    | ######################################################################################################### | 100%
lcms2-2.15           | 235 KB    | ######################################################################################################### | 100%
libgfortran5-13.2.0  | 1.4 MB    | ######################################################################################################### | 100%
setuptools-68.2.2    | 454 KB    | ######################################################################################################### | 100%
libxml2-2.11.5       | 689 KB    | ######################################################################################################### | 100%
icu-73.2             | 11.5 MB   | ######################################################################################################### | 100%
cffi-1.15.1          | 289 KB    | ######################################################################################################### | 100%
libwebp-base-1.3.2   | 392 KB    | ######################################################################################################### | 100%
libstdcxx-ng-13.2.0  | 3.7 MB    | ######################################################################################################### | 100%
contourpy-1.1.1      | 229 KB    | ######################################################################################################### | 100%
lxml-4.9.3           | 1.4 MB    | ######################################################################################################### | 100%
libtiff-4.6.0        | 271 KB    | ######################################################################################################### | 100%
cryptography-41.0.4  | 2.0 MB    | ######################################################################################################### | 100%
python_abi-3.11      | 6 KB      | ######################################################################################################### | 100%
kiwisolver-1.4.5     | 72 KB     | ######################################################################################################### | 100%
tk-8.6.13            | 3.1 MB    | ######################################################################################################### | 100%
scipy-1.11.3         | 15.7 MB   | ######################################################################################################### | 100%
brotli-python-1.1.0  | 343 KB    | ######################################################################################################### | 100%
openssl-3.1.3        | 2.5 MB    | ######################################################################################################### | 100%
libbrotlicommon-1.1. | 68 KB     | ######################################################################################################### | 100%
libbrotlienc-1.1.0   | 276 KB    | ######################################################################################################### | 100%
mysql-common-8.0.33  | 749 KB    | ######################################################################################################### | 100%
exceptiongroup-1.1.3 | 19 KB     | ######################################################################################################### | 100%
dnspython-2.4.2      | 161 KB    | ######################################################################################################### | 100%
pillow-10.0.1        | 44.7 MB   | ######################################################################################################### | 100%
libgomp-13.2.0       | 411 KB    | ############################################################################################################################################## | 100%
libdeflate-1.19      | 66 KB     | ############################################################################################################################################## | 100%
libnsl-2.0.0         | 32 KB     | ############################################################################################################################################## | 100%
freetype-2.12.1      | 620 KB    | ############################################################################################################################################## | 100%
typing_extensions-4. | 34 KB     | ############################################################################################################################################## | 100%
anyio-4.0.0          | 97 KB     | ############################################################################################################################################## | 100%
libcblas-3.9.0       | 14 KB     | ############################################################################################################################################## | 100%
urllib3-2.0.5        | 96 KB     | ############################################################################################################################################## | 100%
httpcore-0.18.0      | 44 KB     | ############################################################################################################################################## | 100%
openjpeg-2.5.0       | 348 KB    | ############################################################################################################################################## | 100%
libgcc-ng-13.2.0     | 753 KB    | ############################################################################################################################################## | 100%
libopenblas-0.3.24   | 5.2 MB    | ############################################################################################################################################## | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
Retrieving notices: ...working... done
(obspy311) python
Python 3.11.4 | packaged by conda-forge | (main, Jun 10 2023, 18:08:17) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import obspy
>>> print(obspy.__version__)
1.4.0
>>> from obspy.io.xseed import Parser
>>> p = Parser("XX.NS214..BNZ.Episensor.DC_200.5VDF.4G.RESP")
>>> print(p)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/mro/miniconda3/envs/obspy311/lib/python3.11/site-packages/obspy/io/xseed/parser.py", line 129, in __str__
    inv = self.get_inventory()
          ^^^^^^^^^^^^^^^^^^^^
  File "/home/mro/miniconda3/envs/obspy311/lib/python3.11/site-packages/obspy/io/xseed/parser.py", line 1898, in get_inventory
    network_id = blkt.network_identifier_code
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Blockette050' object has no attribute 'network_identifier_code'
>>> 

My bad, I can reproduce it, maybe I didn't do the print(p) earlier..

So.. I'm not using RESP much, but that file specifies 2 out of 16 fields that a SEED blockette 50 would usually have. Without looking into details, I'm guessing our old SEED parser just expects to get a full blockette and not a stripped down partial info like might be OK for RESP format.
Any reason to use the Parser and not simply read with read_inventory() which seems to be fine and more forgiving in case of missing fields)?

No idea why IRIS is supplying a striped down version. I'm neither not using RESP very often so can't tell if this is considered valid or not, but if it is I guess it would be nice if ObsPy could handle it.

Why the use of Parser, well... to be honest I had missed that read_inventory() could also read the RESP format. For my current need Parser does the trick for me (the print() were merely used while developing the script).

Why the use of Parser, well... to be honest I had missed that read_inventory() could also read the RESP format.

Ok, fair enough then. Just go with read_inventory() and you should be fine then. =)
I'll close this for now. I think it might not be worth working on this when there's more important things left hanging already. Feel free to reopen if needed.