def write(filename, data, file=None, chart=(0,0)): atlases = formats.get_atlases(data) for i, atlas in enumerate(list(atlases)): for j, chart in enumerate(list(atlas)): atlases[i][j] = chart.transpose() meta_to_store = dict(data) del meta_to_store['center'] #put in CRPIX in header. extra = meta.encode(meta_to_store) special_records = [] while extra: special_records.append(SPECIAL_RECORD_HEADER + extra[:SPECIAL_RECORD_SIZE]) extra = extra[SPECIAL_RECORD_SIZE:] images = [] if 'center' in data: center = data['center'] crpix = [center[0] + 1, center[1] + 1, 1, 1] if 'palette' in data: import numpy palette = numpy.array(data['palette'], dtype=numpy.int32) images.append((palette, {'ctype': ['COLOR']} )) fits.write(file or open(filename, 'wb'), atlases, special_records=special_records, ctype=('X', 'Y', 'CHART', 'HISTORY'), crpix=crpix, images=images )
def _write_charts(z, data): if data['chart(0,0)'].dtype == numpy.dtype(numpy.uint8): ext = 'png' elif data['chart(0,0)'].dtype == numpy.dtype(numpy.float64): _write_charts_fits(z, data) return else: ext = 'png' import formats for atlasno, atlas in enumerate(formats.get_atlases(data)): for chartno, _ in enumerate(atlas): s = StringIO() filename = 'chart.%d-%d.%s' % (atlasno, chartno, ext) formats.write(filename, data, s, (atlasno, chartno)) z.writestr('chart.%d-%d.%s' % (atlasno, chartno, ext), s.getvalue())