Beispiel #1
0
    def encode(self, use_pickle=False, use_gzip=False, to_json=False):

        _data = []
        _meata_d = []
        _kw_d = []
        _d = None
        _dt = None
        _binarys = None
        if self.data is not None:
            _dt = numpy_encode(numpy.array(self.data))['dtype']

            if use_pickle is True:

                if use_gzip == True:
                    print('gizziping')
                    out_file = StringIO()
                    gzip_file = gzip.GzipFile(fileobj=out_file, mode='wb')

                    gzip_file.write(pickle.dumps(numpy.array(self.data)))
                    _binarys = base64.b64encode(out_file.getvalue())
                    gzip_file.close()
                else:
                    _binarys = base64.b64encode(
                        pickle.dumps(numpy.array(self.data), 2))

            else:
                _d = json.dumps(self.data, cls=JsonCustomEncoder)

        _o_dict = {
            'data': _d,
            'dt': _dt,
            'name': self.name,
            'header': self.header,
            'binarys': _binarys,
            'meta_data': self.meta_data,
            'hdu_type': self.hdu_type
        }

        if to_json == True:
            _o_dict = json.dump(_o_dict)

        return _o_dict
Beispiel #2
0
    def encode(self,):
        _table=numpy_encode(self.table.as_array())
        _meta=dumps(self.table.meta)

        return dumps(_table,_meta)