Skip to content

Commit

Permalink
Added in new image class to hold image and associated metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisfish committed May 7, 2020
1 parent 684ebde commit 6189931
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pawlikMorphLSST/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

__all__ = ["gaussfitter", "pixmap", "apertures", "asymmetry",
"imageutils", "objectMasker", "sersic", "result", "main",
"casgm", "helpers", "skyBackground"]
"casgm", "helpers", "skyBackground", "image"]
21 changes: 16 additions & 5 deletions pawlikMorphLSST/image.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from abc import ABC, abstractmethod
import warnings

from astropy.coordinates import SkyCoord
from astropy.io import fits
from astropy.nddata import Cutout2D
from astropy.wcs import WCS
from astropy import units
from astropy.utils.exceptions import AstropyWarning

try:
import lsst.daf.persistence as dafPersist
Expand All @@ -14,6 +16,9 @@
lsst = None


__all__ = ["sdssImage", "lsstImage"]


class Image(ABC):
"""Abstract base class for images"""
def __init__(self):
Expand All @@ -39,10 +44,17 @@ def __init__(self, filename):
self.filename = filename
self.image = None

def setView(self, ra, dec, npix):
img, self.header = fits.getdata(self.filename, header=True)
def setView(self, ra=None, dec=None, npix=128):
with warnings.catch_warnings():
# ignore invalid card warnings
warnings.simplefilter('ignore', category=AstropyWarning)
img, self.header = fits.getdata(self.filename, header=True)

self.largeImage = img.byteswap().newbyteorder()
self.cutout = self._make_cutout(ra, dec, npix)
if self.largeImage.shape[0] >= npix and ra and dec:
self.cutout = self._make_cutout(ra, dec, npix)
else:
self.cutout = self.largeImage

def getImage(self):
self.image = self.cutout
Expand All @@ -69,8 +81,7 @@ def __init__(self, filename):
self.butler = dafPersist.Butler(filename)
self.image = None
if lsst is none:
raise ImportError:
print("LSST stack not installed!")
raise ImportError("LSST stack not installed!")

def setView(self, ra, dec, run, camCol, field, filter, npix=128):
self.largeImage = self.butler.get("fpC", run=run, camcol=camCol, field=field, filter=filter)
Expand Down
9 changes: 8 additions & 1 deletion pawlikMorphLSST/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from .asymmetry import calcA
from .asymmetry import minapix
from .helpers import checkFile
from .image import sdssImage, lsstImage
from .imageutils import maskstarsPSF
from .imageutils import maskstarsSEG
from .casgm import gini, m20, concentration, calcR20_R80, smoothness
Expand Down Expand Up @@ -275,7 +276,13 @@ def _analyseImage(file, outfolder, filterSize, asymmetry,
newResult = Result(file.name, outfolder, occludedSaveFile)

try:
img, header, imgsize = checkFile(file)
sdssimg = sdssImage(file)

sdssimg.setView()
img = sdssimg.getImage()
header = sdssimg.getHeader()
imgsize = img.shape[0]
# img, header, imgsize = checkFile(file)
except IOError:
print(f"File {file}, does not exist!")
return newResult
Expand Down

0 comments on commit 6189931

Please sign in to comment.