In [9]:
# Typical imports here
import numpy as np
import matplotlib.pyplot as plt
import astropy.units as u
import astropy.constants as c
In [10]:
from astropy.io import fits
from astropy.table import Table,join,vstack
In [11]:
import pickle
from pathlib import Path
homedir = str(Path.home())
In [12]:
fl = homedir+'/Dropbox/GBT-AMIGA/Data-Reduced/AMIGA-GBT.fits'
In [13]:
a=fits.open(fl)
np.shape(a)
Out[13]:
There are 50 extensions, each potentially holding multiple sight lines.
In [14]:
a[0:5].info()
In [15]:
x1 = a[1]
x2 = a[2]
x3 = a[48]
x1.columns
Out[15]:
In [16]:
all_obj = []
for j in np.arange(1,np.size(a)):
print("{0}: {1}".format(j,a[j].data['object']))
all_obj.append(a[j].data['object'].tolist())
In [17]:
Table(x2.data)
Out[17]:
In [18]:
b=x2.data[0]
nu0=b['RESTFREQ']
nu = ((np.arange(np.size(b['DATA']))+1)-b['CRPIX1'])*b['CDELT1'] + b['CRVAL1']
In [19]:
vel = (nu0-nu)/nu0 * c.c.to('km/s')
Ta = b['DATA']
In [20]:
plt.figure(figsize=(10,5))
plt.plot(vel,Ta)
plt.xlim(-800,500)
plt.ylim(-0.05,0.1)
plt.axhline(0.,linestyle='--',color='k',linewidth=1)
plt.title(b['OBJECT']);
In [13]:
fnd_obj = 'RBS2055'
for j in np.arange(1,np.size(a)):
xxx = a[j].data
gd=(xxx['OBJECT'] == fnd_obj)
if gd.sum() > 0:
out = xxx[gd]
In [14]:
b=out.copy()
In [15]:
b.columns
Out[15]:
In [16]:
# Counter variable
i=0
# Outputs
indx=[]
object_names = []
array_indeces = []
for j in np.arange(1,np.size(a)):
xxx = a[j].data
for k in np.arange(np.size(xxx)):
indx.append(i)
object_names.append(xxx['OBJECT'][k])
array_indeces.append((j,k))
print("{0}: {1:20s} \t{2}".format(i,
object_names[i],array_indeces[i]))
# Advance the counter
i+=1
In [17]:
tbl = Table([indx,object_names,array_indeces],
names=['INDX','OBJECT','ARRAY_INDECES'])
In [18]:
tbl[0:5]
Out[18]:
In [19]:
tbl['ARRAY_INDECES'][5]
Out[19]:
In [22]:
tbl[tbl.colnames[0]][0:5]
Out[22]:
In [20]:
def example():
max_time = 7
# Calls for an infinite loop that keeps executing
# until an exception occurs
valid = False
while valid == False:
try:
test4num = int(input("From 1 to 7, how many hours do you play in your mobile?" ))
# If something else that is not the string
# version of a number is introduced, the
# ValueError exception will be called.
except:
# The cycle will go on until validation
print("Error! This is not a number. Try again.")
# When successfully converted to an integer,
# the loop will end.
if test4num <= max_time:
valid = True
print("Impressive! You spent", test4num*60,
"minutes or", test4num*60*60, "seconds in your mobile!")
break
else:
print("Your answer is outside the allowed range.")
In [21]:
example()
In [ ]: