Difference: JeanDuffyPythonCode (2 vs. 3)

Revision 331 Oct 2013 - JeanDuffy

Line: 1 to 1
 
META TOPICPARENT name="JeanDuffyBScProject"
-- JeanDuffy - 25 Oct 2013

Extraction of useful information from a fit file

Changed:
<
<
#Change directory
>
>
import os
import pyfits
import matplotlib.pyplot as plt
import numpy as np
import math
 
Changed:
<
<
import os
>
>
# Plot a fits file
 
Changed:
<
<
os.chdir("C:/Users/Jean/Desktop/Python/Bsc/Fits")
>
>
os.chdir("C:/Users/Jean/Desktop/Python/Bsc/Fits") # Changes the directory
 
Changed:
<
<
# Import fits from astropy.io
>
>
f=pyfits.open("Atlas_pleione_1sec.fit") # Open the fit file "Atlas_pleione_1sec.fit" which opens it as an HDU (Header Data Unit) list and set to f.
 
Changed:
<
<
from astropy.io import fits
>
>
i=f[0] # Set i to be an HDU object.
d=i.data # Set d to be an array of data.
 
Changed:
<
<
# Open the fit file "Atlas_pleione_1sec.fit" which
>
>
plt.figure('Atlas & Pleione'),plt.imshow(d), plt.title('Atlas & Pleione') # Plots the array and creates a specific figure for the plot
print pyfits.getheader("Atlas_pleione_1sec.fit") # Gets and shows all the Header information from the fit file
print
 
Changed:
<
<
# opens it as an HDU (Header Data Unit) list and set to f.
>
>
print 'Mean of d =',d.mean() # Prints the mean of d
print
print 'Standard Deviation of d =',d.std() # Prints the standard deviation of d
print
print 'Total Flux =',d.sum() # Prints the sum of d, whihc is the total flux
print
print 'Sum of the ADU in the x-axis',d.sum(0) # Prints the sum of values of the pixels in direction 0
print 'Sum of the ADU in the y-axis',d.sum(1) # Prints the sum of values of the pixels in direction 1
print
 
Changed:
<
<
f=fits.open("Atlas_pleione_1sec.fit")
>
>
d2=d[720:760,870:915] # Create a sub area, which is the subarea around Atlas (Brighter sar)
d3=d[220:265,835:885] # Create a sub area around Pleione
 
Changed:
<
<
# Set i to be an HDU object.
>
>
# Plot the sub area of Atlas and Pleione on a new figure
 
Changed:
<
<
i=f[0]
>
>
plt.figure('Sub Areas'),
plt.subplot(211), plt.imshow(d3), plt.title('Pleione'), plt.text(155,20,d3.sum()), plt.text(110,20,r'Total Flux='),
plt.subplot(212), plt.imshow(d2), plt.title('Atlas'), plt.text(155,20,d2.sum()), plt.text(110,20,r'Total Flux='),
 
Changed:
<
<
# Set d to be an array of data.
>
>
y1=d.sum(1) # Sum the values of all the pixels in direction 1
y1_2=y1[0:300] # Subset of y1 covering the smaller peak
x1=np.arange(0,len(y1),1) # Create an array of length y1, starting from 0 in increments of 1
 
Changed:
<
<
d=i.data
>
>
xmean=(x1[600:]*y1[600:]).sum()/y1[600:].sum() # The mean of the values in a specified region
print 'Weighted mean =',xmean
print
 
Changed:
<
<
# Imports matplotlib.pyplot module
>
>
# Plot x1 against y1 and calculate the maximums and their y position on the plot for Figure 3
 
Changed:
<
<
import matplotlib.pyplot as plt
>
>
plt.figure(3),plt.plot(x1,y1), plt.title("ADU against y1"),
plt.xlabel('y1'), plt.ylabel('ADU')
 
Changed:
<
<
# Plots the array
>
>
max_y1=max(y1) # Maximum y value
max_y1_2=max(y1_2) # Maximum y value in subset y1_2
max_x1=x1[y1.argmax()] # x value corresponding to max y value
max_x1_2=x1[y1_2.argmax()] # x value corresponding to max y value in subset y1_2
 
Changed:
<
<
plt.figure(0),plt.imshow(d)
>
>
print 'max_x1 =',max_x1 # Print the maximum y value
print 'max_x1_2 =',max_x1_2 # Print the maximum y value in subset y1_2
print 'max_y1 =',max_y1 # Print the x value corresponding to max y value
print 'max_y1_2 =',max_y1_2 # Print the x value corresponding to max y value in subset y1_2
 
Changed:
<
<
# Creates a figure and shows the plot
>
>
# Plot x0 against y0 and calculate the maximums and their y position on the plot for Figure 4
 
Changed:
<
<
# Not needed in the kernel (for some reason)
>
>
y0=d.sum(0) # Sum the values of all the pixels in direction 0
y0_2=y0[0:880] # Subset of y0 covering the smaller peak
x0=np.arange(0,len(y0),1) # Array of legnth y0 strarting at 0 in increments of 1
 
Changed:
<
<
# Gets all the Header information from the fit file
>
>
plt.figure(4),plt.plot(x0,y0), plt.title("Other one"),
print
 
Changed:
<
<
print fits.getheader("Atlas_pleione_1sec.fit")
>
>
max_y0=max(y0) # Maximum y value
max_y0_2=max(y0_2) # Maximum y value in subset y0_2
max_x0=x0[y0.argmax()] # x value corresponding to max y value
max_x0_2=x0[y0_2.argmax()] # x value corresponding to max y value in subset y0_2
 
Changed:
<
<
# These can be run in the kernel
>
>
print 'max_x0 =',max_x0 # Print the maximum y value
print 'max_x0_2 =',max_x0_2 # Print the maximum y value in subset y0_2
print 'max_y0 =',max_y0 # Print the x value corresponding to max y value
print 'max_y0_2 =',max_y0_2 # Print the x value corresponding to max y value in subset y0_2
print
 
Changed:
<
<
print d.mean()
>
>
# Calculating the angular seperation
 
Changed:
<
<
print d.std()
>
>
d0=max_x0-max_x0_2 # Distance in pixels of the stars in direction 0
d1=max_x1-max_x1_2 # Distance in pixels of the stars in direction 1
d=math.sqrt((d0**2)+(d1**2)) # Total distance between the stars
 
Changed:
<
<
print d.sum()
>
>
print 'Distance between the peaks on the CCD in pixels =',d
print
 
Changed:
<
<
print d.sum(0)
>
>
P=0.61 # Plate scale in arcseconds per pixel
theta=P*d # Theta - Angular seperation, P - Plate Scale, d - Seperation on CCD in pixels
 
Changed:
<
<
print d.sum(1)
>
>
print 'Angular seperation in arcseconds =',theta
 
Changed:
<
<
# Create a sub area
>
>
plt.show()
 
Changed:
<
<
d2=d[700:800,850:950]
>
>
# Calculate the absolute magnitude where m is the apparent magnitude and dis is the distance to the star in light years
 
Changed:
<
<
# Plot the subarea on a new figure
>
>
m=3.62
dis=435
 
Deleted:
<
<
plt.figure(1), plt.imshow(d2)

y=d.sum(1)

import numpy as np

x=np.arange(0,len(y),1)

xmean=(x[600:]*y[600:]).sum()/y[600:].sum()

print xmean

plt.figure(2),plt.plot(x,y)

plt.show()

 \ No newline at end of file
Added:
>
>
print 'Absolute magnitude =',m-5*(math.log10(dis/32.6))
 \ No newline at end of file
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding RHUL Physics Department TWiki? Send feedback