Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds unequal (i.e. 2x1) binning and option to rotate the CCD by integer multiples of 90 degrees #170

Merged
merged 3 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions scopesim/effects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@
from .obs_strategies import *
from .fits_headers import *

from .rotation import *

# from . import effects_utils
19 changes: 19 additions & 0 deletions scopesim/effects/electronic.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- LinearityCurve - apply detector (non-)linearity and saturation
- ReferencePixelBorder
- BinnedImage
- UnequalBinnedImage
- Bias - adds constant bias level to readout

Functions:
Expand Down Expand Up @@ -557,6 +558,24 @@ def apply_to(self, det, **kwargs):

return det

class UnequalBinnedImage(Effect):
def __init__(self, **kwargs):
super(UnequalBinnedImage, self).__init__(**kwargs)
self.meta["z_order"] = [870]

self.required_keys = ["binx","biny"]
utils.check_keys(self.meta, self.required_keys, action="error")

def apply_to(self, det, **kwargs):
if isinstance(det, DetectorBase):
bx = from_currsys(self.meta["binx"])
by = from_currsys(self.meta["biny"])
image = det._hdu.data
h, w = image.shape
new_image = image.reshape((h//bx, bx, w//by, by))
det._hdu.data = new_image.sum(axis=3).sum(axis=1)

return det

################################################################################

Expand Down
36 changes: 36 additions & 0 deletions scopesim/effects/rotation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""Effects related to rotation of the field/CCD

Classes:
- RotateCCD - Rotates CCD by integer multiples of 90 degrees
"""

import logging
import numpy as np

from . import Effect
from .. import utils
from ..utils import from_currsys
from ..base_classes import DetectorBase


class Rotate90CCD(Effect):
"""
Rotates CCD by integer multiples of 90 degrees
rotations kwarg is number of counter-clockwise rotations

"""
def __init__(self, **kwargs):
super(Rotate90CCD, self).__init__(**kwargs)
params = {"z_order": [809]}
self.meta.update(params)
self.meta.update(kwargs)

required_keys = ["rotations"]
utils.check_keys(self.meta, required_keys, action="error")

def apply_to(self, obj, **kwargs):
if isinstance(obj, DetectorBase):
rotations = from_currsys(self.meta["rotations"])
obj._hdu.data = np.rot90(obj._hdu.data,rotations)

return obj