def parse_datastream(filename):
splits = filename.split('.')
datastream = '.'.join(splits[:2])
partial_ds = splits[0]
site = partial_ds[:3]
for index, character in enumerate(partial_ds):
if character.isupper():
break
instrument = partial_ds[3:index]
facility = partial_ds[index:]
level = splits[1]
date = splits[-3]
time = splits[-2]
extension = splits[-1].strip()
return_dict = {
'datastream':datastream,
'site':site,
'instrument':instrument,
'facility':facility,
'level':level,
'date':date,
'time':time,
'extension':extension
}
return return_dict