def read(filename, file=None): result = qdict.qdict() data = fits.read(file or open(filename, 'rb')) extra = ''.join([record[len(SPECIAL_RECORD_HEADER):] for record in data.special_records if record.startswith(SPECIAL_RECORD_HEADER)]) result.update(meta.decode(extra)) result.reduce_quality(0.2) #We want these overridden by external data if necessary. result['palette', 0.1, filename] = views.palette.grays naxis = data.hdu[0]['NAXIS*'] ctype = data.hdu[0]['CTYPE*'] crpix = data.hdu[0]['CRPIX*'] if crpix: result['center', 1.0, filename] = (crpix[0] - 1, crpix[1] - 1) if ctype and ctype[-1] == 'HISTORY' and ctype[-2] == 'CHART': atlases = [] for atlasno in range(naxis[-1]): atlas = [] atlases.append(atlas) for chartno in range(naxis[-2]): chart = data.hdu[0].data[atlasno, chartno, ...] atlas.append(chart.transpose()) formats.set_atlases(result, atlases) else: chart = data.hdu[0].data.transpose() result['chart(%d,%d)' % formats.get_subscripts(filename), 1.0, filename] = chart return result
def read(filename, file=None): import formats result = qdict.qdict() z = zipfile.ZipFile(file or filename, 'r') resources = z.namelist() for resource in resources: result.update(formats.read(resource, z.open(resource) )) return result
def _interpret_raw(data, filename = None): if 'MCell' not in data: raise ValueError, 'Not recognized as an MCell file.' rule = _create_rule(data['GAME'], data['RULE'], data['CCOLORS'], data['COLORING'], ) _, _, states = registry.get.compile_rule(rule) chart = _create_field(data['BOARD'], data['L']) #Fix states. #The state numbers used to define the grid may be different # from those we use internally, so we have to map them over. #TODO: this shouldn't be here. for x in range(chart.shape[0]): for y in range(chart.shape[1]): chart[x,y] = states[chart[x,y]] topology = _create_topology(data['WRAP']) palette = _create_palette(data['PALETTE']) delay = data['SPEED'] / 1000.0 #seconds to delay between frames description = data['D'] #ignored for now? toys = _create_objects(data['DIV']) result = qdict.qdict() if rule: result['rule', 1.0, filename] = rule if chart is not None: result['chart(0,0)', 1.0, filename] = chart if topology: result['topology', 1.0, filename] = topology if toys: result['toys', 1.0, filename] = toys if palette: result['palette', 1.0, filename] = palette else: result['palette', 0.5, '(MCell default)'] = views.palette.mcell(states) if delay: result['speed', 0.5, filename] = 2.0 / delay if description: result['description', 1.0, filename] = description return result
def read(filename, file=None): result = qdict.qdict() p = png.Reader(file=file or open(filename, 'rb')) width, height, pixels, pmeta = p.read() if 'text' in pmeta: for text_item in pmeta['text']: print text_item if text_item['key'] == META_TAG: result.update(meta.decode(text_item['value'])) result['palette', 0.7, filename] = views.palette.from_rgb(p.palette()) chart = numpy.zeros(shape=(width, height), dtype=numpy.uint8) chart[:,:] = numpy.transpose(list(pixels)) result['chart(%d,%d)' % formats.get_subscripts(filename), 1.0, filename] = chart print result return result
def _interpret(data): result = qdict.qdict() if 'SPEED' in data: result['speed'] = 2000.0 / data['SPEED'] if 'ZOOM' in data: result['zoom'] = data['ZOOM'] if 'CENTER' in data: result['center'] = tuple([int(x) for x in data['CENTER']]) if 'GENERATION' in data: result['generation'] = data['GENERATION'] if 'RULE' in data: from rules._rule import rule result['rule'] = eval('rule(%s)' % data['RULE']) if 'WRAP' in data: from topologies._topology import topology result['topology'] = eval('topology(%s)' % data['WRAP']) return result
def __init__(self): self.resources = qdict.qdict()