Skip to content

Instantly share code, notes, and snippets.

@varun-magesh
Created August 30, 2019 21:50
Show Gist options
  • Save varun-magesh/cdc4bbc005eae94043ee143002ecc952 to your computer and use it in GitHub Desktop.
Save varun-magesh/cdc4bbc005eae94043ee143002ecc952 to your computer and use it in GitHub Desktop.
Fuzzy Comparison for Fitsfiles
from astropy.io import fits
import numpy.linalg as la
import numpy as np
from sys import argv
import glob
dir_ = ""
if len(argv) <= 1:
dir_ = raw_input("Enter FITSfile directory to compare > ")
else:
dir_ = sys.argv[1]
fitsfiles = []
for fit in glob.glob(dir_ + "/*.fits"):
fitsfiles.append(fits.open(fit)[0].data)
mean = np.mean(fitsfiles, axis=0)
# frobenius norm is default
max_norm = la.norm(fitsfiles[0] - mean)
norms = []
for f in fitsfiles:
norm = la.norm(fitsfiles[0] - mean)
norms.append(norm)
max_norm = norm if norm > max_norm else max_norm
print(norms)
print("Maximum norm is {}".format(max_norm))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment