Exports to simple csv

        :param str filename:
            Path to file for export
775855
def write_to_csv(self, filename):
        '''
        
        '''
        fid = open(filename, 'wt')
        # Create header list
        header_info = ['Longitude', 'Latitude', 'Depth', 'Observed Count',
                       'Smoothed Rate', 'b-value']
        writer = csv.DictWriter(fid, fieldnames=header_info)
        headers = dict((name0, name0) for name0 in header_info)
        # Write to file
        writer.writerow(headers)
        for row in self.data:
            # institute crude compression by omitting points with no seismicity
            # and taking advantage of the %g format
            if row[4] == 0:
                continue
            row_dict = {'Longitude': '%g' % row[0],
                        'Latitude': '%g' % row[1],
                        'Depth': '%g' % row[2],
                        'Observed Count': '%d' % row[3],
                        'Smoothed Rate': '%.6g' % row[4],
                        'b-value': '%g' % self.bval}
            writer.writerow(row_dict)
        fid.close()
1259336
def to_csv(weekmatrices, filename, digits=5):
    

    with open(filename, 'w') as f:
        w = csv.writer(f, lineterminator='\n')
        w.writerow(['year_week', 'channel', 'weekday', 'section', 'value'])

        def make_repr(item):
            if item is None:
                return None
            elif isinstance(item, float):
                return repr(round(item, digits))
            else:
                return str(item)

        for row in weekmatrices:
            w.writerow([make_repr(item) for item in row])
480759
def export_json_object(dict_obj, filename=None):
    
    try:
        if filename:
            try:
                with open(filename, 'w') as handle:
                    handle.write(json.dumps(dict_obj, indent=4, sort_keys=True))
                    logger.info(
                        '%s: Wrote %s to local filesystem location' %
                        (inspect.stack()[0][3], filename))
                handle.close()
            except TypeError as e:
                logger.warning(
                    '%s: object in dict not serializable: %s' %
                    (inspect.stack()[0][3], str(e)))
        else:
            json_str = json.dumps(dict_obj, indent=4, sort_keys=True)
            print(highlight(json_str, lexers.JsonLexer(), formatters.TerminalFormatter()))
            logger.info('%s: successful export to stdout' % inspect.stack()[0][3])
            return True
    except IOError as e:
        logger.critical(
            '%s: export_file_object: error writing to %s to filesystem. Error: %s' %
            (inspect.stack()[0][3], filename, str(e)))
        return False
    else:
        logger.info('export_file_object: successful export to %s' % filename)
        return True
475471
def to_file(self, file_name=None):
        """"""

        file_name = self._check_file_name(file_name)
        pages = self.pages

        top_level_dict = {
            'info_df': pages,
            'metadata': self._prm_packer()
        }

        jason_string = json.dumps(
            top_level_dict,
            default=lambda info_df: json.loads(
                info_df.to_json()
            )
        )

        self.paginate()

        with open(file_name, 'w') as outfile:
            outfile.write(jason_string)

        self.file_name = file_name
        logging.info("Saved file to {}".format(file_name))
669150
def to_file(self, filename):
        
        d = {"mass_info": self.mass_info,
             "nonbond_coeffs": self.nonbond_coeffs,
             "topo_coeffs": self.topo_coeffs}
        yaml = YAML(typ="safe")
        with open(filename, "w") as f:
            yaml.dump(d, f)
588819
def save_csvf(data: list, fieldnames: Sequence[str], fpath: str, encoding: str, with_header: bool = False,
              crlf: bool = False, tsv: bool = False) -> str:
    
    with codecs.open(fpath, mode='w', encoding=encoding) as f:
        f.write(dump_csv(data, fieldnames, with_header=with_header, crlf=crlf, tsv=tsv))
        return fpath
1142585
def exportProfile(self, filename=''):
        
        if not (filename and isinstance(filename, basestring)):
            filename = QtGui.QFileDialog.getSaveFileName(self,
                                                         'Export Layout as...',
                                                         QtCore.QDir.currentPath(),
                                                         'XView (*.xview)')
            
            if type(filename) == tuple:
                filename = filename[0]
        
        filename = nativestring(filename)
        if not filename:
            return
        
        if not filename.endswith('.xview'):
            filename += '.xview'
        
        profile = self.saveProfile()
        profile.save(filename)
256573
def get_csv(filename):
    
    check_if_this_file_exist(filename)

    #Process this function
    filename = os.path.abspath(filename)
    s = command_line(['exiftool', '-G', '-csv', '-sort', filename])
    if s:
        #convert bytes to string
        s = s.decode('utf-8')
        return s
    else:
        return 0
631691
def export(self, filename, fmt="DER"):
        
        f = open(filename, "wb")
        f.write(self.output(fmt))
        f.close()
267831
def export(self, elec_file):
        
        elec_file = Path(elec_file)
        if elec_file.suffix == '.csv':
            sep = ', '
        elif elec_file.suffix == '.sfp':
            sep = ' '

        with elec_file.open('w') as f:
            for one_chan in self.chan:
                values = ([one_chan.label, ] +
                          ['{:.3f}'.format(x) for x in one_chan.xyz])
                line = sep.join(values) + '\n'
                f.write(line)
31117
def write_to_file(self, filename):
        
        if not exists(dirname(filename)):
            return -1
        with open(filename, 'w') as fd:
            needs_json = json.dumps(self.minimum_needs)
            fd.write(needs_json)
        return 0
402505
def save(self, filename):
        

        if filename is None:
            filename = self.filename('.b26s')
        # if len(filename.split('\\\\?\\')) == 1:
        #     filename = '\\\\?\\' + filename
        with open(filename, 'w') as outfile:
            outfile.write(pickle.dumps(self.__dict__))
107408
def export_to_dot(self, filename: str = 'output') -> None:
        
        with open(filename + '.dot', 'w') as output:
            output.write(self.as_dot())
392275
def filename_to_module(filename):
    
    find = re.compile(r"^[^.|-]*")
    name = re.search(find, filename).group(0)
    return name
897729
def filename_to_str(self, filename):
        '''
        
        '''
        if filename.__class__ != str:
            if not IS_PY3K:
                filename = filename.encode(file_system_encoding)
            else:
                raise AssertionError('Expected to have str on Python 3. Found: %s (%s)' % (filename, filename.__class__))
        return filename
3181
def dump(self, filename):
        
        flags = os.O_WRONLY|os.O_CREAT|os.O_NOFOLLOW|os.O_EXCL
        fd = os.open(filename, flags, 0o0600)
        os.write(fd, bytes(self.__str__(), locale.getpreferredencoding()))
        os.close(fd)
548696
def fastq_to_csv(in_file, fastq_format, work_dir):
    
    out_file = "%s.csv" % (os.path.splitext(os.path.basename(in_file))[0])
    out_file = os.path.join(work_dir, out_file)
    if not (os.path.exists(out_file) and os.path.getsize(out_file) > 0):
        with open(in_file) as in_handle:
            with open(out_file, "w") as out_handle:
                writer = csv.writer(out_handle)
                for rec in SeqIO.parse(in_handle, fastq_format):
                    writer.writerow([rec.id] + rec.letter_annotations["phred_quality"])
    return out_file