obspy.io.csv.core._read_csv

_read_csv(fname, skipheader=0, default=None, names=None, format_check=False, **kwargs)[source]

Read a CSV file and return ObsPy catalog

Parameters:
  • fname – filename or file-like object to read from

  • skipheader – skip first rows of file

  • default – dictionary with default values, at the moment only magtype is supported, i.e. to set magtypes use default={'magtype': 'Ml'}

  • names – determined automatically from header line of file, otherwise can be specified as string, sequence or dict

  • format_check – Check if the first event can be read

  • **kargs

    all other kwargs are passed to csv.DictReader, important additional arguments are fieldnames, dialect, delimiter, etc

Example

>>> from obspy import read_events
>>> events = read_events('/path/to/catalog.csv')
>>> print(events)  
3 Event(s) in Catalog:
2012-04-04T14:21:42.300000Z | +41.818,  +79.689 | 4.4  mb
2012-04-04T14:18:37.000000Z | +39.342,  +41.044 | 4.3  ML
2012-04-04T14:08:46.000000Z | +38.017,  +37.736 | 3.0  ML

You can read CSV files created by this module or external CSV files. Example reading an external CSV file:

>>> from obspy import read_events
>>> names = 'year mon day hour minu sec _ lat lon dep mag id'
>>> events = read_events(
...     '/path/to/external.csv', 'CSV', skipheader=1, names=names)
>>> print(events)  
1 Event(s) in Catalog:
2023-05-06T19:55:01.300000Z | +10.194, +124.830 | 0.2