How to create string template for mseed_storage variable in the MassDownloader?

Hi!

I am trying to use the obspy MassDownloader to download waveforms for a catalogue of events. I don’t know yet which stations might have data, so I specified a circular domain around each event, set start and end time (and some other parameters) in the Restrictions, included a list of networks, but no restriction to certain stations.

The data is supposed to be stored in a SeisComP database, i.e. the folder structure is year/julian day/network/station/channel. The year and julian day I get from the event time, but I don’t know how to define network and station, since I don’t know yet what the MassDownloader will find. There is an option to give a string template for the mseed_storage variable of the MassDownloader, which seems to be exactly what I want, but I don’t manage to define it correctly. (My expertise in both python and obspy is still limited, I am afraid.) I always end up with an error like “NameError: name ‘network’ is not defined”.

I’ve looked through the MassDownloader-related topics, but unfortunately, everybody seems to use a simple “waveforms” directory for downloading without sub-directory structure. Therefore, it would be very nice if someone could help me out.

This part of the code looks as follows:
domain = CircularDomain(latitude=lat, longitude=lon,
minradius=0, maxradius=25)

restrictions = Restrictions(
starttime=evt - dt,
endtime=evt + dt,
reject_channels_with_gaps=False,
minimum_length=0.01,
minimum_interstation_distance_in_m=0,
channel_priorities=[“HH[ZNE]”, “BH[ZNE]”],
location_priorities=[“”, “00”, “10”],
network=“GE,GR,DK,NL,GB,NO,NS,BE”)

mdl = MassDownloader()
mdl.download(domain, restrictions, download_chunk_size_in_mb=50,
threads_per_client=3, mseed_storage=(maindir/{network}/{station}),
stationxml_storage=xml_dir, print_report = True)

Thank you very much for your help!

Kind regards,
Daniela

According to docs, you would use something like (you’re missing the quotes to make it a string)…

..., mseed_storage='sds_root/{network}/{station}', ...

If maindir is something like a Path object (hard to tell from your code), you’d want something like

..., mseed_storage=str(maindir / '{network}' / '{station}'), ...

You could get the folder structure to be fully SDS compliant with something like `‘sds_root/{network}/{station}/{channel}.D’ but it might be tricky to get it compliant with the filenaming as well (one file for each day).

Also according to docs it looks like if there are any placeholders in the provided string, you need to make it so it goes all the way to full filename as well…

`‘sds_root/{network}/{station}/{channel}.D/{network}.{station}.{location}.{channel}.D.{starttime}.mseed’ or similar