def _download_from_client(client, client_type, catalog, data_pad, process_len,<EOL>available_stations=[], all_channels=False, debug=<NUM_LIT:0>):
st = Stream()<EOL>catalog = Catalog(sorted(catalog, key=lambda e: e.origins[<NUM_LIT:0>].time))<EOL>all_waveform_info = []<EOL>for event in catalog:<EOL><INDENT>for pick in event.picks:<EOL><INDENT>if not pick.waveform_id:<EOL><INDENT>debug_print(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(pick), <NUM_LIT:1>, debug)<EOL>continue<EOL><DEDENT>if all_channels:<EOL><INDENT>channel_code = pick.waveform_id.channel_code[<NUM_LIT:0>:<NUM_LIT:2>] + "<STR_LIT:?>"<EOL><DEDENT>else:<EOL><INDENT>channel_code = pick.waveform_id.channel_code<EOL><DEDENT>all_waveform_info.append((<EOL>pick.waveform_id.network_code, pick.waveform_id.station_code,<EOL>channel_code, pick.waveform_id.location_code))<EOL><DEDENT><DEDENT>starttime = UTCDateTime(<EOL>catalog[<NUM_LIT:0>].origins[<NUM_LIT:0>].time - data_pad)<EOL>endtime = starttime + process_len<EOL>if not endtime > catalog[-<NUM_LIT:1>].origins[<NUM_LIT:0>].time + data_pad:<EOL><INDENT>raise TemplateGenError(<EOL>'<STR_LIT>')<EOL><DEDENT>all_waveform_info = sorted(list(set(all_waveform_info)))<EOL>dropped_pick_stations = <NUM_LIT:0><EOL>for waveform_info in all_waveform_info:<EOL><INDENT>net, sta, chan, loc = waveform_info<EOL>if client_type == '<STR_LIT>' and sta not in available_stations:<EOL><INDENT>debug_print("<STR_LIT>", <NUM_LIT:0>, debug)<EOL>dropped_pick_stations += <NUM_LIT:1><EOL>continue<EOL><DEDENT>debug_print('<STR_LIT>' %<EOL>(str(starttime), str(endtime)), <NUM_LIT:0>, debug)<EOL>debug_print('<STR_LIT:.>'.join([net, sta, loc, chan]), <NUM_LIT:0>, debug)<EOL>try:<EOL><INDENT>st += client.get_waveforms(net, sta, loc, chan,<EOL>starttime, endtime)<EOL><DEDENT>except Exception:<EOL><INDENT>debug_print('<STR_LIT>', <NUM_LIT:2>, debug)<EOL>dropped_pick_stations += <NUM_LIT:1><EOL><DEDENT><DEDENT>if not st and dropped_pick_stations == len(event.picks):<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>st.merge()<EOL>final_channels = []<EOL>for tr in st:<EOL><INDENT>tr.trim(starttime, endtime)<EOL>if len(tr.data) == (process_len * tr.stats.sampling_rate) + <NUM_LIT:1>:<EOL><INDENT>tr.data = tr.data[<NUM_LIT:1>:len(tr.data)]<EOL><DEDENT>if tr.stats.endtime - tr.stats.starttime < <NUM_LIT> * process_len:<EOL><INDENT>debug_print(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(<EOL>tr.stats.station, tr.stats.channel,<EOL>(tr.stats.endtime - tr.stats.starttime) / <NUM_LIT>), <NUM_LIT:4>, debug)<EOL><DEDENT>elif not pre_processing._check_daylong(tr):<EOL><INDENT>print("<STR_LIT>".format(tr.id))<EOL><DEDENT>else:<EOL><INDENT>final_channels.append(tr)<EOL><DEDENT><DEDENT>st.traces = final_channels<EOL>return st<EOL>
Internal function to handle downloading from either seishub or fdsn client