Back to SDS/2 Parametric Scripts

 

imagelist = ['image1.fits', 'image2.fits', 'image3.fits', 'image4.fits', 'image5.fits', 'image6.fits', 'image7.fits']

 

datalist = [['pg2203+051', 'Z', '275'],

            ['MarkA', 'A', '150'],

            ['pg2203+051', 'Z', '275'],

            ['pg2203+051', 'A', '275'],

            ['sa95', 'T', '500'],

            ['MarkA', 'B', '150'],

            ['MarkA', 'C', '150']

            ]

 

dd = {}

for i, item in enumerate(imagelist):

    dd[item] = dict(zip(['star', 'type', 'dist'], datalist[i]))

 

for key in dd:

    print '%s = %s' % (key, dd[key])

 

'''

>>> image2.fits = {'type': 'A', 'star': 'MarkA', 'dist': '150'}

image6.fits = {'type': 'B', 'star': 'MarkA', 'dist': '150'}

image1.fits = {'type': 'Z', 'star': 'pg2203+051', 'dist': '275'}

image7.fits = {'type': 'C', 'star': 'MarkA', 'dist': '150'}

image5.fits = {'type': 'T', 'star': 'sa95', 'dist': '500'}

image3.fits = {'type': 'Z', 'star': 'pg2203+051', 'dist': '275'}

image4.fits = {'type': 'A', 'star': 'pg2203+051', 'dist': '275'}

'''

 

# Python 2.3

starList = [x['star'] for x in dd.values() if x['star'] not in locals()['_[1]'].__self__]

 

# Python 2.4

# starList = list(set([x['star'] for x in dd.values()]))

 

print starList

 

'''

>>> ['MarkA', 'pg2203+051', 'sa95']

'''

 

# Star, image files

starImageDict = {}

 

for key in dd:

    try:

        starImageDict[dd[key]['star']].append(key)

    except:

        starImageDict[dd[key]['star']] = [key, ]

 

print starImageDict

 

'''

>>> {'sa95': ['image5.fits'], 'MarkA': ['image2.fits', 'image6.fits', 'image7.fits'], 'pg2203+051': ['image1.fits', 'image3.fits', 'image4.fits']}

>>>

'''

 

 

distDict = {}

 

for key in dd:

    distDict[dd[key]['dist']] = dd[key]['star']

 

print distDict       

 

distList = [(int(key), distDict[key]) for key in distDict]

distList.sort()

print distList

for item in distList:

    print 'The distance to star %s is %d light-years.' % (item[1], item[0])

 

'''

>>> {'150': 'MarkA', '275': 'pg2203+051', '500': 'sa95'}

>>> [(150, 'MarkA'), (275, 'pg2203+051'), (500, 'sa95')]

>>> The distance to star MarkA is 150 light-years

The distance to star pg2203+051 is 275 light-years

The distance to star sa95 is 500 light-years

>>>

'''