Advertisement
canorve

Panstarrs remove nans pixels

Jun 6th, 2024 (edited)
435
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | Source Code | 0 0
  1. #! /usr/bin/env python3
  2.  
  3. import numpy as np
  4. import argparse
  5. import os
  6.  
  7.  
  8. from astropy.io import fits
  9.  
  10. # Load your FITS file
  11. #hdul = fits.open('A407-pan-g-cut.fits')
  12.  
  13. parser = argparse.ArgumentParser(description="removes nan pixels")
  14. parser.add_argument("ImageFile", help="Fits image file")
  15.  
  16. args = parser.parse_args()
  17. image_file = args.ImageFile
  18.  
  19.  
  20. if not os.path.exists(image_file):
  21.     print ('{} image filename does not exist!'.format(image_file))
  22.     sys.exit()
  23.  
  24.  
  25. hdul = fits.open(image_file)
  26.  
  27. # Access the CompImageHDU (assuming it's the first extension)
  28.  
  29. # Extract the data
  30. data = hdul[0].data
  31. masknan = np.isnan(data)
  32. data[masknan] = 30000
  33.  
  34.  
  35. hdul[0].data= data
  36.  
  37.  
  38. hdul.writeto(image_file.replace("fits", "new.fits"), overwrite=True)
  39.  
  40.  
  41. hdul.close()
  42.  
  43.  
  44.  
Tags: panstarrs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement