Skip to content

Commit

Permalink
Merge pull request #5 from z-gora/dev - v1.02
Browse files Browse the repository at this point in the history
- **Lineouts!** The major new feature of v1.02, lineouts allow you to inspect your data along a particular line. You can set the width of the scan to eliminate numerical noise, colour-code your lineouts, export the lineout data, and redraw the lineout for a different data set. You can also pin the layout window to the main Magic2 window for easy access. All new, shiny, and hopefully intuitive - more details in the manual!
- **Proper implementation of dimensions for the plasma density graph.** The millimetre ticks are no longer unwieldy floats, they also point to zero if you set a centre point.
- **Setting centre refurbished.** You get a crosshair, as well as the ability to cancel the process with the 'escape' key. The setting is now saved in .m2 files too (note that this doesn't break backwards and forwards compatibility, so you can still use your old files).
- **The manual** has been updated with a few new sections (mostly concerning layouts) ans restyled a bit.
- **Recomputing by right-click on a display mode** should now work regardless of the mode you are currently in.
  • Loading branch information
jdranczewski authored Sep 5, 2018
2 parents 5891c39 + 6689cda commit e3e90df
Show file tree
Hide file tree
Showing 5 changed files with 557 additions and 32 deletions.
98 changes: 88 additions & 10 deletions help.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<title>Magic2 manual</title>
<style>
html, body {
background-color: #90CAF9;
background-color: #5709a4;
background: linear-gradient(140deg, #5709a4, #c84579 35%, #f3cd22);
}
#main {
max-width: 700px;
Expand All @@ -27,7 +28,7 @@
</head>
<body>
<div id="main">
<h1>Magic 2 - the manual</h1>
<h1><img src="logo_s.png" style="width: 8em;vertical-align: bottom;"/> - the manual</h1>
<div id="contents">
<h2>Table of contents</h2>
<ul>
Expand All @@ -37,6 +38,7 @@ <h2>Table of contents</h2>
<li><a href="#h2_interpolation">Interpolation</a></li>
<li><a href="#h2_subtract_plasma">Subtraction and plasma density calculation</a></li>
<li><a href="#h2_export">Exporting</a></li>
<li><a href="#h2_lineouts">Taking lineouts</a></li>
<li><a href="#h2_other_operations">Other operations</a></li>
<li><a href="#h2_saving">.m2 - Magic2's very own file format</a></li>
</ul>
Expand Down Expand Up @@ -104,8 +106,8 @@ <h3 id="h3_project_name">Project name</h3>
name in the File <a href="#h3_menu">menu</a>.
</p>
<p>
The project name is used as a name template when <a>exporting the data</a> or <a
href="#h2_saving">saving .m2 files</a>.
The project name is used as a name template when <a href="#h3_data_export">
exporting the data</a> or <a href="#h2_saving">saving .m2 files</a>.
</p>
<h3 id="h3_labelling">Labelling fringes</h3>
<p>
Expand Down Expand Up @@ -189,15 +191,23 @@ <h3 id="h3_plasma_density">Calculating the plasma density</h3>
shift). You can always set those options by going to <b>Process -> Set shot
details</b>.
</p>
<h3 id="h3_set_centre">Set the centre of the map</h3>
<p>
By using the <b>Process -> Set centre of the density map</b> option in <a
href="h3_menu">the menu</a> it is possible to set an arbitrary [0, 0] point for
the plasma density map. In the dialog window that pops up, pressing 'Yes' will
allow you to click anywhere on the map (press the escape key to cancel the
operation) and pressing 'No' will reset the centre to the original position.


<h2 id="h2_export">Exporting</a>
<h3 id="h2_data_export">Exporting data</h3>
<p>
You can export the data you are currently viewing in the <a
href="#h3_graphing_area">graphing area</a> at any point by using the "Export the
current view's data" option in the File <a href="#h3_menu">menu</a>. This will
give you an option to choose the desired file location and name. The default
format is .csv. The areas that are masked out (or not interpolated) are
href="#h3_graphing_area">graphing area</a> at any point by using the <b>"Export
the current view's data"</b> option in the File <a href="#h3_menu">menu</a>.
This will give you an option to choose the desired file location and name. The
default format is .csv. The areas that are masked out (or not interpolated) are
indicated with the string 'nan'.
</p>
<h3 id="h3_saving_figures">Saving figures</h3>
Expand All @@ -208,6 +218,73 @@ <h3 id="h3_saving_figures">Saving figures</h3>
You can then choose a location for your file.
</p>

<h2 id="h2_lineouts">Taking lineouts</h2>
<h3 id="h3_drawing_lineout">Drawing a lineout</h3>
<p>
To initialise drawing a lineout you can either use the <b>'Take lineout'</b>
button on the bottom of <a href="#h3_sidebar">the sidebar</a>, or use the
<b>Process -> Take lineout</b> option in <a href="#h3_menu">the menu</a>. This
should work in any display mode. Your cursor will turn into a crosshair. You can
draw the line by clicking the starting and ending points. A new window will
appear, containing the lineout graph and several other options.
</p>
<h3 id="h3_lineout_export">Exporting a lineout</h3>
<p>
This works very similarly to <a href="#h2_data_export">exporting the data
displayed in the graphing area</a> and can be done by pressing a button in the
layout window. The .csv file that is created will contain a
header with the starting and ending points and the display mode specified. The
header also specifies the units that have to be used when analysing the data.
</p>
<h3 id="h3_lineout_width">Width of the lineout</h3>
<p>
By using the input box at the bottom of the layout window, the width of the line
sampled to create the layout can be set. This will be represented by a
semi-transparent rectangle displayed in <a href="#h3_graphing_area">the graphing
area</a>. The rectangle can be turned off with a switch in the layout window.
<h3 id="h3_lineout_colour">The lineout's colour</h3>
<p>
You can set the colour of the lineout at the bottom of the lineout window. This
will change the colour of the lineout line, as well as the lineout graph, making
them easier to colour-code and associate with each other.
</p>
<p>
The colours available are the standard matplotlib colours (the ones it cycles
through when plotting multiple things).
</p>
<h3 id="h3_lineout_lifecycle">The lifecycle of a layout</h3>
<p>
When a layout is created in a particular display mode, it is attached to that
mode. This is indicated by the title of the lineout window (eg. 'plasma map
lineout'). It will show as a solid line only in that mode, turning into a
dashed, semi-transparent line in other modes.
</p>
<p>
The lineout will exist until you close its respective window. It should survive
pretty much any operation you perform on your data.
</p>
<h3 id="#h3_redraw_lineout">Redraw lineout in current mode</h3>
<p>
The <b>'Redraw in current mode'</b> button at the bottom of the lineout window creates
a new lineout of the same width, colour and position as the old one, but changes
the source of data (and the display mode that the lineout is attached to) to the
data currently being displayed.
</p>
<p>
For example, if you create a lineout in the 'Background map' display mode, you
can inspect the plasma map data along the same line by going to switching to the
'Plasma map' mode and clicking the 'Redraw in current mode' button. This will
delete the original layout.
</p>
<h3 id="h3_lineout_pin">Pinning the lineout window</h3>
<p>
The <b>(Un)pin this window</b> button in a layout window allows you to choose
whether you want the window to be attached (<i>modal</i>) to Magic2's main
window or not. When modal, the window doesn't show in your system's taskbar, and
is always displayed on top of the main Magic2 window, minimising itself when you
minimise Magic2 etc.
</p>

<h2 id="h2_other_operations">Other operations</h2>
<h3 id="h3_invert">Invert</h3>
<p>
Expand Down Expand Up @@ -237,8 +314,9 @@ <h3 id="h3_whats_in_m2">What's in an .m2 file?</h3>
interferograms (one for the fringes and one for the user-defined mask), together
with the fringes' phases. It also
contains the <a href="#h3_project_name">project's name</a>,
<a href="#h3_plasma_density">shot details</a>, and the <a
href="#h3_zero_shift">zero point setting</a>.
<a href="#h3_plasma_density">shot details</a>, <a
href="#h3_zero_shift">zero point setting</a>, and the <a
href="#h3_set_centre">centre of the plasma density map</a>.
</p>
<h3 id="h3_openin_m2">Opening an .m2 file</h3>
<p>
Expand Down
4 changes: 2 additions & 2 deletions magic2/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def __init__(self, filename, fi=None, m=None, imshow=None):
image = plt.imread(filename.name)
# Fringes are black, extract them from the image
self.fringes_image = image == 0
# This is the user defined mask, it was grey (so neither black nor
# white, which is the condition we're using here)
# This is the user defined mask, it was grey (so neither black
# nor white, which is the condition we're using here)
self.mask = sp.logical_or(image == 1, self.fringes_image)
else:
# This uses a provide mask and image (for example from an .m2 file)
Expand Down
96 changes: 76 additions & 20 deletions magic2gui/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import matplotlib.ticker as ticker

import magic2gui.dialog as m2dialog
import magic2gui.lineouts as m2lineouts
import magic2.graphics as m2graphics
import magic2.fringes as m2fringes
import magic2.labelling as m2labelling
Expand Down Expand Up @@ -105,6 +106,7 @@ def m_save(options):
dump.append(options.depth)
dump.append(options.wavelength)
dump.append(options.double)
dump.append(options.centre)
# We use gzip to make the file smaller. Normal pickling produced files
# that were around 30MB, while the compressed version of the same data
# is 188KB
Expand Down Expand Up @@ -156,6 +158,13 @@ def m_open(options, interpolate = None):
options.depth = dump[9]
options.wavelength = dump[10]
options.double = dump[11]
# For saved variables introduced in v1.02
try:
options.centre = dump[12]
except IndexError:
# The centre option is set to a default of [0, 0] when creating
# the Options object.
pass
options.status.set("Done", 100)
# If data is available for either background or plasma fringes,
# display them
Expand Down Expand Up @@ -347,8 +356,8 @@ def show_radio(options):
set_mode(options)
# If the user wants the interpolated map, check if it exists...
elif key[1] == 'map':
options.mode = "_".join(key)
if options.objects[key[0]]['canvas'].interpolation_done:
options.mode = "_".join(key)
set_mode(options)
# ...if not, give the user the option to generate one
else:
Expand Down Expand Up @@ -380,6 +389,7 @@ def show_radio(options):
# the radio buttons on the right
def recompute(event, options):
key = event.widget['value'].split("_")
print(key)
if key[1] == 'fringes':
phases = [fringe.phase for fringe in options.objects[key[0]]['fringes'].list]
options.objects[key[0]]['fringes'].min = sp.amin([phase for phase in phases if phase != -2048.0])
Expand All @@ -402,10 +412,15 @@ def recompute(event, options):
# Also used for refreshing
def set_mode(options):
key = options.mode.split("_")
# This allows one to stop the conserve_limits variable from switching
# back to True after the function executes
stop_reverting = False
if options.conserve_limits:
# Get the current display limits
ylim = options.ax.get_ylim()
xlim = options.ax.get_xlim()
if options.lineout_meta is not None:
m2lineouts.stop_lineout(options)
# Clear the axes and all labellers/event handlers attached to them
# (if they exist)
options.ax.clear()
Expand Down Expand Up @@ -453,12 +468,13 @@ def set_mode(options):
# stops it from touching the colorbar's ticks' labels
options.cbar.ax.set_ylabel('Fringe shift', rotation=270, labelpad=20)
elif key[0] == 'density':
options.imshow = options.ax.imshow(options.density, cmap=options.cmap)
# Adjust the tick labels to be in milimeters
ticks = ticker.FuncFormatter(lambda x, pos: '{:0.2f}'.format((x - options.centre[1])/options.resolution))
options.ax.xaxis.set_major_formatter(ticks)
ticks = ticker.FuncFormatter(lambda y, pos: '{:0.2f}'.format((y - options.centre[0])/options.resolution))
options.ax.yaxis.set_major_formatter(ticks)
y_size, x_size = options.density.shape
extent = sp.array([0-options.centre[1],x_size-options.centre[1],y_size-options.centre[0],0-options.centre[0]])/options.resolution
# Don't conserve limits (we're changing the range here)
options.conserve_limits = False
# This means that next time we switch mode, the limits will be reset:
stop_reverting = True
options.imshow = options.ax.imshow(options.density, cmap=options.cmap, extent=extent)
# Add x and y axis labels
options.ax.set_xlabel("Distance / $mm$")
options.ax.set_ylabel("Distance / $mm$")
Expand All @@ -469,9 +485,12 @@ def set_mode(options):
# revert the graph to the old display limits
options.ax.set_xlim(xlim)
options.ax.set_ylim(ylim)
else:
elif not stop_reverting:
# Revert to the original setting
options.conserve_limits = True
# Update all the active lineouts
for lineout in options.lineouts:
lineout.update()
# Refresh the graph's canvas
options.fig.canvas.draw()
# Set the radio buttons to the correct position
Expand Down Expand Up @@ -806,20 +825,38 @@ def plasma_density(options):


# Event handler for setting the centre of the density map
def onclick(event, options, bind):
options.centre = [event.ydata, event.xdata]
print(options.centre)
options.fig.canvas.mpl_disconnect(bind)
def set_centre_onclick(event, options, binds):
options.centre = [event.ydata*options.resolution, event.xdata*options.resolution]
# Unbind all the event handlers
for bind in binds:
options.fig.canvas.mpl_disconnect(bind)
# Allow the graph to resize after the centre is set
options.conserve_limits = False
set_mode(options)
options.mframe.config(cursor="")


# Event handler for cancelling the process of setting the centre
# of the density map
def set_centre_onpress(event, options, binds):
if event.key == "escape":
for bind in binds:
options.fig.canvas.mpl_disconnect(bind)
options.mframe.config(cursor="")


# Set centre of the plasma density map
def set_centre(options):
if options.mode == "density_graph":
ans = mb.askyesnocancel("Set centre?", "Press 'Yes' and then click anywhere on the graph to set the centre of the density map.\n\n"
ans = mb.askyesnocancel("Set centre?", "Press 'Yes' and then click anywhere on the graph to set the centre of the density map. Use the escape key to cancel.\n\n"
"Press 'No' to reset the centre to [0, 0].")
if ans:
bind = options.fig.canvas.mpl_connect('button_press_event',
lambda event: onclick(event, options, bind))
options.mframe.config(cursor="crosshair")
binds = [None, None]
binds[0] = options.fig.canvas.mpl_connect('button_press_event',
lambda event: set_centre_onclick(event, options, binds))
binds[1] = options.fig.canvas.mpl_connect('key_press_event',
lambda event: set_centre_onpress(event, options, binds))
elif ans is not None:
options.centre = [0, 0]
set_mode(options)
Expand All @@ -835,23 +872,42 @@ def cosine(options):
multiplier = 1
else:
multiplier = 2
options.imshow = options.ax.imshow(sp.cos(options.imshow.get_array()*multiplier*sp.pi), cmap="Greys")
# This mode is a spetial little snowflake, in that it doesn't have
# a radio button or a set_mode if clause. We handle it ourselves here
# a radio button or a set_mode if clause. We handle its rendering
# ourselves here:
# Clear the canvas
options.ax.clear()
# Draw the cosine
options.imshow = options.ax.imshow(sp.cos(options.imshow.get_array()*multiplier*sp.pi), cmap="Greys")
# Set the mode variable
mode = options.mode.split("_")[0]+"_cosine_graph"
options.show_var.set(mode)
options.mode = mode
# Take care of the lineouts
if options.lineout_meta is not None:
m2lineouts.stop_lineout(options)
for lineout in options.lineouts:
lineout.update()
# Draw the canvas
options.fig.canvas.draw()
options.show_var.set("cosine_graph")
options.mode = "cosine_graph"
else:
mb.showinfo("Open a map", "Taking the cosine is possible only for interpolated phase maps.")


def lineout(options):
if options.mode is not None:
m2lineouts.create_lineout(options)
else:
mb.showinfo("No mode chosen", "Please choose one of the display modes from the menu on the right!")


class AboutDialog(m2dialog.Dialog):
def body(self, master):
photo = Tk.PhotoImage(file="logo_s.png")
logo = Tk.Label(master, image=photo)
logo.photo = photo
logo.pack()
label = Tk.Label(master, text="This software was created by Jakub Dranczewski during a UROP in 2018.\nIt is based on concepts from Magic, which was created by George Swadling.\n\nYou can contact me on jbd17@ic.ac.uk or (as I inevitably loose either the whole email or the 17) jakub.dranczewski@gmail.com\n\nv1.1")
label = Tk.Label(master, text="This software was created by Jakub Dranczewski during a UROP in 2018.\nIt is based on concepts from Magic, which was created by George Swadling.\n\nYou can contact me on jbd17@ic.ac.uk or (as I inevitably loose either the whole email or the 17) jakub.dranczewski@gmail.com\n\nv1.02")
label.pack()

def buttonbox(self):
Expand Down
Loading

0 comments on commit e3e90df

Please sign in to comment.