Skip to content

Commit

Permalink
Made a better interface to different image types. Still to be improve…
Browse files Browse the repository at this point in the history
…d...
  • Loading branch information
lewisfish committed May 7, 2020
1 parent 6189931 commit 38de93b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
20 changes: 15 additions & 5 deletions pawlikMorphLSST/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
lsst = None


__all__ = ["sdssImage", "lsstImage"]
__all__ = ["Image"]


class Image(ABC):
Expand All @@ -36,12 +36,20 @@ def getHeader(self):
def _make_cutout(self, ra, dec, npix):
pass

def __new__(cls, _IMAGE_TYPE, **kwargs):
subclass_map = {subclass._IMAGE_TYPE: subclass for subclass in cls.__subclasses__()}
subclass = subclass_map[_IMAGE_TYPE]
instance = super(Image, subclass).__new__(subclass)
return instance


class sdssImage(Image):
"""Class for SDSS images, as ingested by standard 'method'"""
def __init__(self, filename):
_IMAGE_TYPE = "sdss"

def __init__(self, *args, **kwargs):
super(sdssImage, self).__init__()
self.filename = filename
self.filename = kwargs["filename"]
self.image = None

def setView(self, ra=None, dec=None, npix=128):
Expand Down Expand Up @@ -76,9 +84,11 @@ class lsstImage(Image):
some metadata not available
this includes wcs, and pixel value conversion information (bscal, bzero etc)
"""
def __init__(self, filename):
_IMAGE_TYPE = "lsst"

def __init__(self, *args, **kwargs):
super(lsstImage, self).__init__()
self.butler = dafPersist.Butler(filename)
self.butler = dafPersist.Butler(kwargs["filename"])
self.image = None
if lsst is none:
raise ImportError("LSST stack not installed!")
Expand Down
19 changes: 11 additions & 8 deletions pawlikMorphLSST/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@
from multiprocessing import Pool

import numpy as np
import parsl
from astropy.io import fits
from astropy.utils.exceptions import AstropyWarning
from parsl.app.app import python_app
from parsl.configs.local_threads import config
try:
import parsl
from parsl.app.app import python_app
from parsl.configs.local_threads import config
except ModuleNotFoundError:
parsl = None

from .apertures import aperpixmap
from .asymmetry import calcA
from .asymmetry import minapix
from .helpers import checkFile
from .image import sdssImage, lsstImage
from .image import Image
from .imageutils import maskstarsPSF
from .imageutils import maskstarsSEG
from .casgm import gini, m20, concentration, calcR20_R80, smoothness
Expand Down Expand Up @@ -276,11 +279,11 @@ def _analyseImage(file, outfolder, filterSize, asymmetry,
newResult = Result(file.name, outfolder, occludedSaveFile)

try:
sdssimg = sdssImage(file)
imgObj = Image("sdss", filename=file)

sdssimg.setView()
img = sdssimg.getImage()
header = sdssimg.getHeader()
imgObj.setView()
img = imgObj.getImage()
header = imgObj.getHeader()
imgsize = img.shape[0]
# img, header, imgsize = checkFile(file)
except IOError:
Expand Down

0 comments on commit 38de93b

Please sign in to comment.