obspy.io.csv.core._write_csv
- _write_csv(events, fname, fields='basic', depth_in_km=True, delimiter=',', header=None)[source]
Write ObsPy catalog to CSV file
- Parameters:
events – catalog or list of events
fname – filename or file-like object to write to
fields – set format and header names of CSV file, see
obspy.io.csv.FIELDS
, you can use your own format string here, just make sure to use the pre-defined header namesdepth_in_km – write depth in units of kilometer (default: True) or meter
delimiter – defaults to ‘,’, if the delimiter is changed, ObsPy’s read_events function will not automatically identify the file as CSV file
header – Use a non-default header row
Warning
If the parameters delimiter or header are changed, ObsPy’s read_events function will not automatically identify the file as CSV file
Example
>>> from obspy import read_events >>> events = read_events() # get example catalog >>> events.write('local_catalog.csv', 'CSV') # declare 'CSV' as format >>> with open('local_catalog.csv') as f: print(f.read()) id,time,lat,lon,dep,magtype,mag 20120404_0000041,2012-04-04T14:21:42.30000,41.818000,79.689000,1.000,mb,4.40 20120404_0000038,2012-04-04T14:18:37.00000,39.342000,41.044000,14.400,ML,4.30 20120404_0000039,2012-04-04T14:08:46.00000,38.017000,37.736000,7.000,ML,3.00