Ejemplo n.º 1
0
Archivo: fits.py Proyecto: kcsaff/CA
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
Ejemplo n.º 2
0
Archivo: png.py Proyecto: kcsaff/CA
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