Skip to content

Commit

Permalink
fringing bug fixing; several.
Browse files Browse the repository at this point in the history
setfringe seemed to work by the end.
  • Loading branch information
Tom Marsh committed May 21, 2021
1 parent c86436a commit 1323022
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 33 deletions.
4 changes: 2 additions & 2 deletions hipercam/fringe.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def dist(self, x, y):
def __repr__(self):
return \
f"FringePair(x1={self.x1:.2f}, y1={self.y1:.2f}," \
f" x2={self.x2:.2f}, y2={self.y2:.2f)"
f" x2={self.x2:.2f}, y2={self.y2:.2f})"

class CcdFringePair(Group):
"""Class representing all the :class:`FringePair`s for a single CCD.
Expand All @@ -80,7 +80,7 @@ def __init__(self, fpairs=Group(FringePair)):
fpairs : Group
Group of :class:`FringePair` objects
"""
super().__init__(FringePair, defs)
super().__init__(FringePair, fpairs)

def __repr__(self):
return "{:s}(fpairs={:s})".format(self.__class__.__name__, super().__repr__())
Expand Down
54 changes: 54 additions & 0 deletions hipercam/mpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,3 +550,57 @@ def pCcdDefect(axes, ccdDefect, animated=False, previous=None):
pobjs[key] = pDefect(axes, dfct)

return pobjs

def pFringePair(axes, fpair):
"""Plots a :class:`FringePair` object, returning
a list of artists created.
Arguments::
axes : :class:`matplotlib.axes.Axes`
the Axes to plot to.
fpair : FringePair
the :class:`FringePair` to plot
"""

a1, = axes.plot(
[fpair.x1,fpair.x2], [fpair.y1,fpair.y2], 'g'
)
a2, = axes.plot(fpair.x1, fpair.y1, '.r')
a3, = axes.plot(fpair.x2, fpair.y2, '.b')

return [a1,a2,a3]


def pCcdFringePair(axes, ccdFringePair, animated=False, previous=None):
"""Plots a :class:`CcdFringePair` object, returning references to the plot
objects.
Arguments::
axes : :class:`matplotlib.axes.Axes`
the Axes to plot to.
ccdFringePair : CcdFringePair
the :class:`CcdFringePair` to plot
animated : bool
whether to mark the plot objects as "animated" or not.
previous : None | Group
If not None, should be a saved version of the Group of
tuples returned from a previous call to this routine with
animated=True
Returns a Group keyed on the same keys as ccdFringePair but
containing tuples of the plot objects used to plot each
Defect. This can be used to delete them if need be.
"""
pobjs = {}
for key, fpair in ccdFringePair.items():
pobjs[key] = pFringePair(axes, fpair)

return pobjs
64 changes: 33 additions & 31 deletions hipercam/scripts/setfringe.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import matplotlib.pyplot as plt

import hipercam as hcam
from hipercam import cline, utils, defect
from hipercam import cline, utils, fringe
from hipercam.cline import Cline

__all__ = [
Expand Down Expand Up @@ -95,7 +95,7 @@ def setfringe(args=None):
hsbox : int
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 defects.
the "show" option when setting FringePair
iset : str [single character]
determines how the intensities are determined. There are three
Expand Down Expand Up @@ -150,11 +150,11 @@ def setfringe(args=None):

if os.path.exists(fpair):
# read in old fringe pairs
mccd_fpair = defect.MccdFringePair.read(fpair)
mccd_fpair = fringe.MccdFringePair.read(fpair)
print(f"Loaded existing file = {fpair}")
else:
# create empty container
mccd_fpair = defect.MccdFringePair()
mccd_fpair = fringe.MccdFringePair()
print(
"No file called {:s} exists; " "will create from scratch".format(fpair)
)
Expand Down Expand Up @@ -286,14 +286,14 @@ def setfringe(args=None):

else:
# add in an empty CcdFringePair for any CCD not already present
mccd_fpair[cnam] = defect.CcdFringePair()
mccd_fpair[cnam] = fringe.CcdFringePair()

# and an empty container for any new plot objects
pobjs[cnam] = {}

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

picker.action_prompt(False)
Expand All @@ -312,7 +312,7 @@ def setfringe(args=None):


class PickFringePair:
"""Class to pick defects
"""Class to pick fringe pairs
"""

def __init__(
Expand Down Expand Up @@ -352,11 +352,11 @@ def action_prompt(self, cr):
)

def _keyPressEvent(self, event):
"""
This is where we do the hard work. Every key press event is diverted
to this method. It either takes an action based on the input, such as
removing a defect, or sometimes it causes a state change to get other
input.
"""This is where we do the hard work. Every key press event is
diverted to this method. It either takes an action based on
the input, such as removing a fringe pair, or sometimes it
causes a state change to get other input.
"""

if self._mid_pair:
Expand Down Expand Up @@ -424,9 +424,9 @@ def _standard(self, key, x, y, axes):
# Try to calculate the largest number, label the new
# FringePair with one more
high = 0
for fringe in self.mccd_fpair[self._cnam]:
for frng in self.mccd_fpair[self._cnam]:
try:
high = max(high, int(fringe))
high = max(high, int(frng))
except ValueError:
pass

Expand All @@ -436,7 +436,7 @@ def _standard(self, key, x, y, axes):
self._pair()

elif key == "d":
# delete an defect
# delete an fringe pair
print(key)
self._delete()

Expand Down Expand Up @@ -495,7 +495,7 @@ def _pair(self):
self._pair_y1 = self._y

# prompt stage 2
print(" second point: s(elect) or q(uit)")
print(" second point: a(dd) or q(uit)")

elif self._pair_stage == 2:

Expand All @@ -508,24 +508,25 @@ def _pair(self):
else:

# now the second x,y position
if self._cnam != self._line_cnam:
if self._cnam != self._pair_cnam:
print(" cannot set pairs across different CCDs")
self.action_prompt(True)

self._pair_x2 = self._x
self._pair_y2 = self._y
self._mid_pair = False

fringe = fringe.FringePair(
frng = fringe.FringePair(
self._pair_x1,
self._pair_y1,
self._pair_x2,
self._pair_y2
)
self.mccd_fpair[self._cnam][self._buffer] = fringe
self.mccd_fpair[self._cnam][self._buffer] = frng

# add defect to the plot, store plot objects
self.pobjs[self._cnam][self._buffer] = hcam.mpl.pFringePair(self._axes, fringe)
# add fringe pair to the plot, store plot objects
self.pobjs[self._cnam][self._buffer] = \
hcam.mpl.pFringePair(self._axes, frng)

# make sure it appears
plt.draw()
Expand Down Expand Up @@ -561,20 +562,21 @@ def _delete(self):
"""

# first see if there is a FringePair near enough the selected position
fringe, dfnam, dmin = self._find_fringe()
frng, frngnam, dmin = self._find_fringe()

if dmin is not None and dmin < 10:

# near enough for deletion
self.pobjs[self._cnam][dfnam].remove()
# delete plot objects
for pobj in self.pobjs[self._cnam][frngnam]:
pobj.remove()

# delete FringePair from containers
del self.pobjs[self._cnam][dfnam]
del self.mccd_fpair[self._cnam][dfnam]
# and containers
del self.pobjs[self._cnam][frngnam]
del self.mccd_fpair[self._cnam][frngnam]

# update plot
plt.draw()
print(f' deleted fringe pair "{dfnam}"')
print(f' deleted fringe pair "{frngnam}"')

else:
print(" no fringe pair near enough the cursor position for deletion")
Expand All @@ -594,11 +596,11 @@ def _find_fringe(self):
dmin = None
fringemin = None
dnmin = None
for fringenam, fringe in self.mccd_fpair[self._cnam].items():
dist = fringe.dist(self._x, self._y)
for fringenam, frng in self.mccd_fpair[self._cnam].items():
dist = frng.dist(self._x, self._y)
if dmin is None or dist < dmin:
dmin = dist
fringemin = fringe
fringemin = frng
dnmin = fringenam

return (fringemin, dnmin, dmin)

0 comments on commit 1323022

Please sign in to comment.