How to delete a particular line in xml file based on the condition

I combiled all channels xml files under one xml file by using obspy…
only the end of the final XML file should look like:

but it remains at each end of channel parametrs.


Would you please, recommend what should I add to the following scipt to remove unnecessary lines?
from obspy import read_inventory
from obspy import read_inventory as read
inv = read(‘AB.MV01.00.HHE.xml’, format=‘STATIONXML’)
inv += read(‘AB.MV01.00.HHN.xml’, format=‘STATIONXML’)
inv += read(‘AB.MV01.00.HHZ.xml’, format=‘STATIONXML’)
inv += read(‘AB.MV01.00.LHE.xml’, format=‘STATIONXML’)
inv += read(‘AB.MV01.00.LHN.xml’, format=‘STATIONXML’)
inv += read(‘AB.MV01.00.LHZ.xml’, format=‘STATIONXML’)
inv.write(‘MV01.xml’, format= ‘STATIONXML’)

in addition: is it possible to correct Startdate; sensor type; azimuth;dip parameters using obspy and how???

Every read command creates new Inventory/Network objects. You could do something like…

inv[0][0].channels = [cha for net in inv for sta in net for cha in sta]
inv.networks = [inv[0]]

…obviously this only makes sense if you are 100% sure this is correct, or you can end up with malformed metadata.

How to change things in the inventory object structure, you can look up [this page for a general idea]/obspy.core - Core classes of ObsPy — ObsPy 1.3.1.post0+255.gc851e5af93.obspy.master documentation) and then go through our Tutorial pages and jupyter notebooks for details.