Skip to content

Commit

Permalink
setfringe -- now reports values of differences.
Browse files Browse the repository at this point in the history
  • Loading branch information
trmrsh committed May 24, 2021
1 parent b0bb94c commit 9d9ea62
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
14 changes: 10 additions & 4 deletions hipercam/fringe.py
@@ -1,7 +1,10 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
"""
Defines classes to specify pairs of points for fringe
measurements. See 'setfringe' for usage.
measurements. See 'setfringe' for usage. Basic idea is
to measure peak-trough difference in two frames to measure
the ratio of fringes between them. Median values are used
to eliminate discrepant points caused by objects.
"""

import numpy as np
Expand Down Expand Up @@ -92,16 +95,19 @@ def inside(self, ccd, nhalf):
return self.wnam

def diff(self, ccd, nhalf):
"""Returns difference in intensity. Only run after having run
"inside" with the same value of nhalf because it assumes the
window name has been set
"""Returns difference in intensity.
nhalf : int
will measure difference in the medians over regions
+/-nhalf binned pixels around nearest pixel of either
end of FringePair
"""

if self.wnam is None:
self.wnam = self.inside(ccd,nhalf)
if self.wnam is None:
return None

wind = ccd[self.wnam]

# pixel centres
Expand Down
38 changes: 23 additions & 15 deletions hipercam/scripts/setfringe.py
@@ -1,5 +1,6 @@
import sys
import os
import warnings

import numpy as np
import matplotlib as mpl
Expand Down Expand Up @@ -46,7 +47,7 @@


def setfringe(args=None):
"""``setfringe fmap fringe ccd [width height] nx [cmap] iset (ilo ihi
"""``setfringe fmap fringe ccd [width height] nx [cmap nhalf] iset (ilo ihi
| plo phi)``
Interactive definition of CCD fringe pairs. The idea is to place a large
Expand Down Expand Up @@ -92,10 +93,11 @@ def setfringe(args=None):
There are many others; typing an incorrect one will give a list. "none"
for matplotlib default.
hsbox : int
nhalf : int [hidden]
half-width in binned pixels of stats box as offset from central pixel
hsbox = 1 gives a 3x3 box; hsbox = 2 gives 5x5 etc. This is used by
the "show" option when setting FringePair
nhalf = 1 gives a 3x3 box; hsbox = 2 gives 5x5 etc. This is used by
the "show" option when setting FringePair and when reporting FringePair
differences.
iset : str [single character]
determines how the intensities are determined. There are three
Expand Down Expand Up @@ -131,7 +133,7 @@ def setfringe(args=None):
cl.register("height", Cline.LOCAL, Cline.HIDE)
cl.register("nx", Cline.LOCAL, Cline.PROMPT)
cl.register("cmap", Cline.LOCAL, Cline.HIDE)
cl.register("hsbox", Cline.GLOBAL, Cline.HIDE)
cl.register("nhalf", Cline.GLOBAL, Cline.HIDE)
cl.register("iset", Cline.GLOBAL, Cline.PROMPT)
cl.register("ilo", Cline.GLOBAL, Cline.PROMPT)
cl.register("ihi", Cline.GLOBAL, Cline.PROMPT)
Expand Down Expand Up @@ -185,7 +187,7 @@ def setfringe(args=None):
cmap = cl.get_value("cmap", "colour map to use ['none' for mpl default]", "Greys")
cmap = None if cmap == "none" else cmap

hsbox = cl.get_value("hsbox", "half-width of stats box (binned pixels)", 2, 1)
nhalf = cl.get_value("nhalf", "half-width of stats box (binned pixels)", 2, 0)
iset = cl.get_value(
"iset",
"set intensity a(utomatically)," " d(irectly) or with p(ercentiles)?",
Expand Down Expand Up @@ -217,6 +219,11 @@ def setfringe(args=None):

# Inputs obtained.

# hopefully temporary to avoid warning produced by the
# keymap.all_axes line associated with the use of 'a' to
# add pairs
warnings.filterwarnings('ignore')

# re-configure keyboard shortcuts to avoid otherwise confusing behaviour
# quit_all does not seem to be universal, hence the try/except
try:
Expand All @@ -233,6 +240,7 @@ def setfringe(args=None):
mpl.rcParams["keymap.xscale"] = ""
mpl.rcParams["keymap.yscale"] = ""
mpl.rcParams["keymap.zoom"] = ""
mpl.rcParams["keymap.all_axes"] = ""
except KeyError:
pass

Expand Down Expand Up @@ -293,7 +301,7 @@ def setfringe(args=None):

# create the FringePair picker (see below for class def)
picker = PickFringePair(
mccd, cnams, anams, toolbar, fig, mccd_fpair, fpair, hsbox, pobjs
mccd, cnams, anams, toolbar, fig, mccd_fpair, fpair, nhalf, pobjs
)

picker.action_prompt(False)
Expand All @@ -316,7 +324,7 @@ class PickFringePair:
"""

def __init__(
self, mccd, cnams, anams, toolbar, fig, mccd_fpair, fringenam, hsbox, pobjs
self, mccd, cnams, anams, toolbar, fig, mccd_fpair, fringenam, nhalf, pobjs
):

# save the inputs, tack on event handlers.
Expand All @@ -328,7 +336,7 @@ def __init__(
self.toolbar = toolbar
self.mccd_fpair = mccd_fpair
self.fringenam = fringenam
self.hsbox = hsbox
self.nhalf = nhalf
self.pobjs = pobjs

# then mutually exclusive flags to indicate the action we are in
Expand Down Expand Up @@ -506,15 +514,12 @@ def _pair(self):
self._mid_pair = False
if wnam is None:
print(" cannot set pairs outside windows")
self.action_prompt(True)

elif wnam != self._first_wnam:
print(" cannot set pairs across different windows")
self.action_prompt(True)

elif self._cnam != self._first_cnam:
print(" cannot set pairs across different CCDs")
self.action_prompt(True)

else:
# add new pair
Expand All @@ -534,14 +539,17 @@ def _pair(self):
plt.draw()

# let user know what has happened
diff = frng.diff(self.mccd[self._cnam],self.nhalf)
print(
(
f"added fringe pair to CCD {self._cnam} "
f"from x1,y1 = {self._first_x:.2f},{self._first_y:.2f} "
f"to x2,y2 = {self._x:.2f},{self._y:.2f}"
f"to x2,y2 = {self._x:.2f},{self._y:.2f}. "
f"Median difference = {diff:.2f}"
)
)
self.action_prompt(True)

self.action_prompt(True)

def _show(self):
"""
Expand All @@ -551,7 +559,7 @@ def _show(self):
# search for enclosing window, print stats
wnam, wind = utils.print_stats(
self.mccd[self._cnam], self._cnam,
self._x, self._y, self.hsbox, False
self._x, self._y, self.nhalf, False
)
if wnam is None:
print(' must hit "s" inside a window')
Expand Down

0 comments on commit 9d9ea62

Please sign in to comment.