for debugging: download demodulated signal as CSV file
974028
function downloadDemodulatedData(){
      var blob = new Blob([csvContent], {type: 'text/csv;charset=utf-8;'});
      var url = URL.createObjectURL(blob)
      var link = document.createElement('a');
      link.setAttribute('href', url);
      link.setAttribute('download', 'data.csv');
      link.click();
    }
205176
def _get_example_csv(self):
        
        station_key = self.json["station"][0]["key"]
        period = "corrected-archive"
        url = self.url\
                  .replace(".json", "/station/{}/period/{}/data.csv"\
                  .format(station_key, period))

        r = requests.get(url)
        if r.status_code == 200:
            return DataCsv().from_string(r.content)
        else:
            raise Exception("Error connecting to api")
11978
def save_signal(self,filename=None):
        
        if filename is None:
            filename = os.path.join(self.folder,'trsig.pkl')
        self.trsig.save(filename)
1097120
def _read_audio_data(self, file_path):
        
        try:
            self.log(u"Reading audio data...")
            # if we know the TTS outputs to PCM16 mono WAVE
            # with the correct sample rate,
            # we can read samples directly from it,
            # without an intermediate conversion through ffmpeg
            audio_file = AudioFile(
                file_path=file_path,
                file_format=self.OUTPUT_AUDIO_FORMAT,
                rconf=self.rconf,
                logger=self.logger
            )
            audio_file.read_samples_from_file()
            self.log([u"Duration of '%s': %f", file_path, audio_file.audio_length])
            self.log(u"Reading audio data... done")
            return (True, (
                audio_file.audio_length,
                audio_file.audio_sample_rate,
                audio_file.audio_format,
                audio_file.audio_samples
            ))
        except (AudioFileUnsupportedFormatError, OSError) as exc:
            self.log_exc(u"An unexpected error occurred while reading audio data", exc, True, None)
            return (False, None)
88094
def data_received(self, data):
        """"""
        self.buffer += data.decode()
        self.log.debug('Received %d bytes from AVR: %s', len(self.buffer), self.buffer)
        self._assemble_buffer()
471026
def get_transcoder():
	""""""

	transcoders = ['ffmpeg', 'avconv']
	transcoder_details = {}

	for transcoder in transcoders:
		command_path = shutil.which(transcoder)
		if command_path is None:
			transcoder_details[transcoder] = 'Not installed.'
			continue

		stdout = subprocess.run([command_path, '-codecs'], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, universal_newlines=True).stdout
		mp3_encoding_support = ('libmp3lame' in stdout and 'disable-libmp3lame' not in stdout)
		if mp3_encoding_support:
			transcoder_details[transcoder] = "MP3 encoding support."
			break
		else:
			transcoder_details[transcoder] = "No MP3 encoding support."
	else:
		raise ValueError(
			f"ffmpeg or avconv must be in the path and support mp3 encoding."
			"\nDetails: {transcoder_details}"
		)

	return command_path
887916
def main(source_samplerate, target_samplerate, params, converter_type):
    """"""
    from time import sleep

    ratio = target_samplerate / source_samplerate

    with sr.CallbackResampler(get_input_callback(source_samplerate, params),
                              ratio, converter_type) as resampler, \
            sd.OutputStream(channels=1, samplerate=target_samplerate,
                            callback=get_playback_callback(
                                resampler, target_samplerate, params)):
        print("Playing back...  Ctrl+C to stop.")
        try:
            while True:
                sleep(1)
        except KeyboardInterrupt:
            print("Aborting.")
14396
def read_data(self, timeout=10.0):
        """"""
        # Read from stdout in a separate thread and consume data from
        # the queue.
        start_time = time.time()
        while True:
            # Wait for data to be available or a timeout.
            data = None
            try:
                data = self.stdout_reader.queue.get(timeout=timeout)
                if data:
                    yield data
                else:
                    # End of file.
                    break
            except queue.Empty:
                # Queue read timed out.
                end_time = time.time()
                if not data:
                    if end_time - start_time >= timeout:
                        # Nothing interesting has happened for a while --
                        # FFmpeg is probably hanging.
                        raise ReadTimeoutError('ffmpeg output: {}'.format(
                            ''.join(self.stderr_reader.queue.queue)
                        ))
                    else:
                        start_time = end_time
                        # Keep waiting.
                        continue
1260820
def recv_raw(self, x=MTU):
        """"""  # noqa: E501
        pkt, sa_ll = self.ins.recvfrom(x)
        if self.outs and sa_ll[2] == socket.PACKET_OUTGOING:
            return None, None, None
        ts = get_last_packet_timestamp(self.ins)
        return self.LL, pkt, ts
459510
def _support_diag_dump(self):
        '''
        
        '''
        # check insights config
        cfg_block = []

        pconn = InsightsConnection(self.config)
        logger.info('Insights version: %s', get_nvr())

        reg_check = registration_check(pconn)
        cfg_block.append('Registration check:')
        for key in reg_check:
            cfg_block.append(key + ': ' + str(reg_check[key]))

        lastupload = 'never'
        if os.path.isfile(constants.lastupload_file):
            with open(constants.lastupload_file) as upl_file:
                lastupload = upl_file.readline().strip()
        cfg_block.append('\nLast successful upload was ' + lastupload)

        cfg_block.append('auto_config: ' + str(self.config.auto_config))
        if self.config.proxy:
            obfuscated_proxy = re.sub(r'(.*)(:)(.*)(@.*)',
                                      r'\1\2********\4',
                                      self.config.proxy)
        else:
            obfuscated_proxy = 'None'
        cfg_block.append('proxy: ' + obfuscated_proxy)

        logger.info('\n'.join(cfg_block))
        logger.info('python-requests: %s', requests.__version__)

        succ = pconn.test_connection()
        if succ == 0:
            logger.info('Connection test: PASS\n')
        else:
            logger.info('Connection test: FAIL\n')

        # run commands
        commands = ['uname -a',
                    'cat /etc/redhat-release',
                    'env',
                    'sestatus',
                    'subscription-manager identity',
                    'systemctl cat insights-client.timer',
                    'systemctl cat insights-client.service',
                    'systemctl status insights-client.timer',
                    'systemctl status insights-client.service']
        for cmd in commands:
            logger.info("Running command: %s", cmd)
            try:
                proc = Popen(
                    shlex.split(cmd), shell=False, stdout=PIPE, stderr=STDOUT,
                    close_fds=True)
                stdout, stderr = proc.communicate()
            except OSError as o:
                if 'systemctl' not in cmd:
                    # suppress output for systemctl cmd failures
                    logger.info('Error running command "%s": %s', cmd, o)
            except Exception as e:
                # unknown error
                logger.info("Process failed: %s", e)
            logger.info("Process output: \n%s", stdout)
        # check available disk space for /var/tmp
        tmp_dir = '/var/tmp'
        dest_dir_stat = os.statvfs(tmp_dir)
        dest_dir_size = (dest_dir_stat.f_bavail * dest_dir_stat.f_frsize)
        logger.info('Available space in %s:\t%s bytes\t%.1f 1K-blocks\t%.1f MB',
                    tmp_dir, dest_dir_size,
                    dest_dir_size / 1024.0,
                    (dest_dir_size / 1024.0) / 1024.0)
255525
def _generate_signal_samples_body(notebook_object):
    

    # =========================== Code Cell for Importing Packages =================================
    notebook_object["cells"].append(nb.v4.new_code_cell(signal_samples_code.IMPORT_CODE,
                                                        **{"metadata":
                                                            {"tags": ["hide_both"]}}))

    # ========= Generation of a table that synthesises the information about each signal ===========
    signal_samples_dir_jupyter = "../../signal_samples"
    signal_samples_dir_project = "biosignalsnotebooks_environment/signal_samples"
    list_of_files = os.listdir(signal_samples_dir_project)
    for file in list_of_files:
        if ".json" not in file:
            file_name = file.split(".")[0]
            with open(signal_samples_dir_project + "/" + file_name + '_info.json') as json_data:
                signal_info = json.load(json_data)

            info_table = "<table width='100%'>\n" \
                         "\t<tr>\n" \
                         "\t\t<td colspan='2' class='signal_samples_header'>" + file_name + \
                         "</td>\n" + "</tr>\n"
            info_keys = list(signal_info.keys())
            for key in info_keys:
                info_table += "\t<tr>\n" \
                              "\t\t<td class='signal_samples_info_keys'>" + key + "</td>\n" + \
                              "\t\t<td class='signal_samples_info_values'>" + signal_info[key] + \
                              "</td>\n" + \
                              "\t</tr>\n"

            info_table += "</table>"

            # ============== Insertion of the HTML table inside a markdown cell ===================
            notebook_object["cells"].append(nb.v4.new_markdown_cell(info_table))

            # ========================= Graphical Representation of Signals =======================
            path_str = '"' + (signal_samples_dir_jupyter + "\\").replace("\\", "/") + '"'
            plot_signal_samples_temp = re.sub(re.compile(r'\bsignal_samples_dir\b'),
                                              path_str, signal_samples_code.PLOTS_SIGNAL_SAMPLES)
            plot_signal_samples_temp = re.sub(re.compile(r'\bfile\b'),
                                              '"' + str(file) + '"',
                                              plot_signal_samples_temp)
            notebook_object["cells"].append(nb.v4.new_code_cell(plot_signal_samples_temp,
                                                                **{"metadata":
                                                                    {"tags": ["hide_in"]}}))
332308
def _download_from_client(client, client_type, catalog, data_pad, process_len,
                          available_stations=[], all_channels=False, debug=0):
    
    st = Stream()
    catalog = Catalog(sorted(catalog, key=lambda e: e.origins[0].time))
    all_waveform_info = []
    for event in catalog:
        for pick in event.picks:
            if not pick.waveform_id:
                debug_print(
                    "Pick not associated with waveforms, will not use:"
                    " {0}".format(pick), 1, debug)
                continue
            if all_channels:
                channel_code = pick.waveform_id.channel_code[0:2] + "?"
            else:
                channel_code = pick.waveform_id.channel_code
            all_waveform_info.append((
                pick.waveform_id.network_code, pick.waveform_id.station_code,
                channel_code, pick.waveform_id.location_code))
    starttime = UTCDateTime(
        catalog[0].origins[0].time - data_pad)
    endtime = starttime + process_len
    # Check that endtime is after the last event
    if not endtime > catalog[-1].origins[0].time + data_pad:
        raise TemplateGenError(
            'Events do not fit in processing window')
    all_waveform_info = sorted(list(set(all_waveform_info)))
    dropped_pick_stations = 0
    for waveform_info in all_waveform_info:
        net, sta, chan, loc = waveform_info
        if client_type == 'seishub' and sta not in available_stations:
            debug_print("Station not found in SeisHub DB", 0, debug)
            dropped_pick_stations += 1
            continue
        debug_print('Downloading for \n\tstart-time: %s\n\tend-time: %s' %
                    (str(starttime), str(endtime)), 0, debug)
        debug_print('.'.join([net, sta, loc, chan]), 0, debug)
        try:
            st += client.get_waveforms(net, sta, loc, chan,
                                       starttime, endtime)
        except Exception:
            debug_print('Found no data for this station', 2, debug)
            dropped_pick_stations += 1
    if not st and dropped_pick_stations == len(event.picks):
        raise Exception('No data available, is the server down?')
    st.merge()
    # clients download chunks, we need to check that the data are
    # the desired length
    final_channels = []
    for tr in st:
        tr.trim(starttime, endtime)
        if len(tr.data) == (process_len * tr.stats.sampling_rate) + 1:
            tr.data = tr.data[1:len(tr.data)]
        if tr.stats.endtime - tr.stats.starttime < 0.8 * process_len:
            debug_print(
                "Data for {0}.{1} is {2} hours long, which is less than 80 "
                "percent of the desired length, will not pad".format(
                    tr.stats.station, tr.stats.channel,
                    (tr.stats.endtime - tr.stats.starttime) / 3600), 4, debug)
        elif not pre_processing._check_daylong(tr):
            print("Data are mostly zeros, removing trace: {0}".format(tr.id))
        else:
            final_channels.append(tr)
    st.traces = final_channels
    return st
984668
def download_metadata_cli(master_token, output_csv, verbose=False,
                          debug=False):
    
    return download_metadata(master_token, output_csv, verbose, debug)
1089563
def handle_log_data(self, m):
        ''''''
        if self.download_file is None:
            return
        # lose some data
        # import random
        # if random.uniform(0,1) < 0.05:
        #    print('dropping ', str(m))
        #    return
        if m.ofs != self.download_ofs:
            self.download_file.seek(m.ofs)
            self.download_ofs = m.ofs
        if m.count != 0:
            data = m.data[:m.count]
            s = ''.join(str(chr(x)) for x in data)
            self.download_file.write(s)
            self.download_set.add(m.ofs // 90)
            self.download_ofs += m.count
        self.download_last_timestamp = time.time()
        if m.count == 0 or (m.count < 90 and len(self.download_set) == 1 + (m.ofs // 90)):
            dt = time.time() - self.download_start
            self.download_file.close()
            size = os.path.getsize(self.download_filename)
            speed = size / (1000.0 * dt)
            print("Finished downloading %s (%u bytes %u seconds, %.1f kbyte/sec %u retries)" % (
                self.download_filename,
                size,
                dt, speed,
                self.retries))
            self.download_file = None
            self.download_filename = None
            self.download_set = set()
290275
def extract_ar (archive, compression, cmd, verbosity, interactive, outdir):
    """"""
    opts = 'x'
    if verbosity > 1:
        opts += 'v'
    cmdlist = [cmd, opts, os.path.abspath(archive)]
    return (cmdlist, {'cwd': outdir})
484503
def extract_stream(source, dest, stream_id):
    '''
    
    '''
    if not os.path.isfile(source):
        raise IOError('No such file: ' + source)

    subprocess.check_output([
        'ffmpeg',
        '-i', source,
        '-y',  # overwrite - potentially dangerous
        '-nostats',
        '-loglevel', '0',
        '-codec', 'copy',
        '-map', '0:' + str(stream_id),
        '-f', 'rawvideo',
        dest,
    ])
141579
def download_message(self):
    """"""

    print('Failed to find any ImageNet %s files'% self.subset)
    print('')
    print('If you have already downloaded and processed the data, then make '
          'sure to set --data_dir to point to the directory containing the '
          'location of the sharded TFRecords.\n')
    print('If you have not downloaded and prepared the ImageNet data in the '
          'TFRecord format, you will need to do this at least once. This '
          'process could take several hours depending on the speed of your '
          'computer and network connection\n')
    print('Please see README.md for instructions on how to build '
          'the ImageNet dataset using download_and_preprocess_imagenet.\n')
    print('Note that the raw data size is 300 GB and the processed data size '
          'is 150 GB. Please ensure you have at least 500GB disk space.')