knine / py2-biff

BIFF - BInary Fitting Facility - Python 2
GNU General Public License v3.0
0 stars 0 forks source link

Code to turn PSF fits files into numpy arrays using astropy #1

Open lmbeus opened 4 years ago

lmbeus commented 4 years ago

Here is the base code/lines needed to write the PSF file data to a numpy array, I've also thrown together a quick function that can be used to handle both the PSF model files and the actual HST data, feel free to modify them however you want.

import numpy as np
from astropy.io import fits

#infile = input("Enter PSF File Name \n")
infile = "n8yj37qvq_rnl.fits" #Testing one of the HST PSF files

psf_data = fits.open(infile)
psf_array = psf_data['SCI'].data #The name of the Science Frame (the data we want) is 'SCI'

print(type(psf_array)) #Test to make sure it works (should return as numpy)
print(psf_array.shape) #Should return 256 x 256

#ALTERNATE METHOD to handle both the real data that has multiple frames (Science, Calibration, etc.) and the PSF model which is just one frame
#Define a function so you can call it for either situation
def psf_to_array(psf_file):
    psf_data = fits.open(psf_file)
    if len(psf_data) != 1: #For the HST data since it has multiple frames
        frame = 'SCI'
    else:                  #For the PSf model since it only has one frame
        frame = 0

    psf_array = psf_data[frame].data
    return psf_array

psf_array = psf_to_array(infile)
print(type(psf_array)) 
print(psf_array.shape)
knine commented 4 years ago

Cool, thanks!

denstephz commented 4 years ago

Nice work

Get Outlook for Androidhttps://aka.ms/ghei36


From: Jake Albretsen notifications@github.com Sent: Thursday, August 27, 2020 10:49:48 AM To: knine/py2-biff py2-biff@noreply.github.com Cc: Subscribed subscribed@noreply.github.com Subject: Re: [knine/py2-biff] Code to turn PSF fits files into numpy arrays using astropy (#1)

Cool, thanks!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/knine/py2-biff/issues/1#issuecomment-682066834, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALCA5WV7CRLUQXXDBPPNGHLSC2FCZANCNFSM4QMJKKAA.