[824e488] | 1 | # TODO: the line slicer should listen to all 2DREFRESH events, get the data and slice it |
---|
| 2 | # before pushing a new 1D data update. |
---|
[ef0c170] | 3 | # |
---|
[824e488] | 4 | # TODO: NEED MAJOR REFACTOR |
---|
[ef0c170] | 5 | # |
---|
[0d9dae8] | 6 | import math |
---|
| 7 | import wx |
---|
[ef0c170] | 8 | from BaseInteractor import _BaseInteractor |
---|
[d85c194] | 9 | from sas.sasgui.guiframe.events import NewPlotEvent |
---|
| 10 | from sas.sasgui.guiframe.events import EVT_SLICER_PARS |
---|
[ef0c170] | 11 | |
---|
| 12 | class SectorInteractor(_BaseInteractor): |
---|
| 13 | """ |
---|
[83f4445] | 14 | Select an annulus through a 2D plot |
---|
[ef0c170] | 15 | """ |
---|
[32c0841] | 16 | def __init__(self, base, axes, color='black', zorder=3): |
---|
[83f4445] | 17 | """ |
---|
| 18 | """ |
---|
[ef0c170] | 19 | _BaseInteractor.__init__(self, base, axes, color=color) |
---|
| 20 | self.markers = [] |
---|
| 21 | self.axes = axes |
---|
[54cc36a] | 22 | self.qmax = self.base.data2D.xmax |
---|
[ef0c170] | 23 | self.connect = self.base.connect |
---|
[824e488] | 24 | |
---|
| 25 | # # Number of points on the plot |
---|
[ef0c170] | 26 | self.nbins = 20 |
---|
[824e488] | 27 | theta1 = 2 * math.pi / 3 |
---|
| 28 | theta2 = -2 * math.pi / 3 |
---|
| 29 | |
---|
[ef0c170] | 30 | # Inner circle |
---|
| 31 | from Arc import ArcInteractor |
---|
[32c0841] | 32 | self.inner_circle = ArcInteractor(self, self.base.subplot, |
---|
[824e488] | 33 | zorder=zorder, |
---|
| 34 | r=self.qmax / 2.0, |
---|
| 35 | theta1=theta1, |
---|
| 36 | theta2=theta2) |
---|
[54cc36a] | 37 | self.inner_circle.qmax = self.qmax |
---|
[32c0841] | 38 | self.outer_circle = ArcInteractor(self, self.base.subplot, |
---|
[824e488] | 39 | zorder=zorder + 1, |
---|
| 40 | r=self.qmax / 1.8, |
---|
[32c0841] | 41 | theta1=theta1, |
---|
[824e488] | 42 | theta2=theta2) |
---|
[32c0841] | 43 | self.outer_circle.qmax = self.qmax * 1.2 |
---|
[824e488] | 44 | # self.outer_circle.set_cursor(self.base.qmax/1.8, 0) |
---|
[ef0c170] | 45 | from Edge import RadiusInteractor |
---|
[824e488] | 46 | self.right_edge = RadiusInteractor(self, self.base.subplot, |
---|
| 47 | zorder=zorder + 1, |
---|
| 48 | arc1=self.inner_circle, |
---|
| 49 | arc2=self.outer_circle, |
---|
| 50 | theta=theta1) |
---|
| 51 | self.left_edge = RadiusInteractor(self, self.base.subplot, |
---|
| 52 | zorder=zorder + 1, |
---|
| 53 | arc1=self.inner_circle, |
---|
| 54 | arc2=self.outer_circle, |
---|
| 55 | theta=theta2) |
---|
[ef0c170] | 56 | self.update() |
---|
| 57 | self._post_data() |
---|
| 58 | # Bind to slice parameter events |
---|
[0d9dae8] | 59 | self.base.parent.Bind(EVT_SLICER_PARS, self._onEVT_SLICER_PARS) |
---|
[ef0c170] | 60 | |
---|
| 61 | def _onEVT_SLICER_PARS(self, event): |
---|
[83f4445] | 62 | """ |
---|
| 63 | """ |
---|
[824e488] | 64 | # printEVT("AnnulusSlicer._onEVT_SLICER_PARS") |
---|
[ef0c170] | 65 | event.Skip() |
---|
| 66 | if event.type == self.__class__.__name__: |
---|
| 67 | self.set_params(event.params) |
---|
| 68 | self.base.update() |
---|
| 69 | |
---|
| 70 | def set_layer(self, n): |
---|
[83f4445] | 71 | """ |
---|
| 72 | """ |
---|
[ef0c170] | 73 | self.layernum = n |
---|
| 74 | self.update() |
---|
[824e488] | 75 | |
---|
[ef0c170] | 76 | def clear(self): |
---|
[83f4445] | 77 | """ |
---|
| 78 | """ |
---|
[ef0c170] | 79 | self.clear_markers() |
---|
| 80 | self.outer_circle.clear() |
---|
| 81 | self.inner_circle.clear() |
---|
| 82 | self.right_edge.clear() |
---|
| 83 | self.left_edge.clear() |
---|
[824e488] | 84 | # self.base.connect.disconnect() |
---|
[0d9dae8] | 85 | self.base.parent.Unbind(EVT_SLICER_PARS) |
---|
[824e488] | 86 | |
---|
[ef0c170] | 87 | def update(self): |
---|
| 88 | """ |
---|
| 89 | Respond to changes in the model by recalculating the profiles and |
---|
| 90 | resetting the widgets. |
---|
| 91 | """ |
---|
[824e488] | 92 | # Update locations |
---|
| 93 | if self.inner_circle.has_move: |
---|
| 94 | # print "inner circle has moved" |
---|
[ef0c170] | 95 | self.inner_circle.update() |
---|
[32c0841] | 96 | r1 = self.inner_circle.get_radius() |
---|
| 97 | r2 = self.outer_circle.get_radius() |
---|
| 98 | self.right_edge.update(r1, r2) |
---|
| 99 | self.left_edge.update(r1, r2) |
---|
[824e488] | 100 | if self.outer_circle.has_move: |
---|
| 101 | # print "outer circle has moved" |
---|
[ef0c170] | 102 | self.outer_circle.update() |
---|
[32c0841] | 103 | r1 = self.inner_circle.get_radius() |
---|
| 104 | r2 = self.outer_circle.get_radius() |
---|
| 105 | self.left_edge.update(r1, r2) |
---|
| 106 | self.right_edge.update(r1, r2) |
---|
[ef0c170] | 107 | if self.right_edge.has_move: |
---|
[824e488] | 108 | # print "right edge has moved" |
---|
[ef0c170] | 109 | self.right_edge.update() |
---|
[32c0841] | 110 | self.inner_circle.update(theta1=self.right_edge.get_angle(), |
---|
| 111 | theta2=None) |
---|
| 112 | self.outer_circle.update(theta1=self.right_edge.get_angle(), |
---|
| 113 | theta2=None) |
---|
[ef0c170] | 114 | if self.left_edge.has_move: |
---|
[824e488] | 115 | # print "left Edge has moved" |
---|
[ef0c170] | 116 | self.left_edge.update() |
---|
[32c0841] | 117 | self.inner_circle.update(theta1=None, |
---|
| 118 | theta2=self.left_edge.get_angle()) |
---|
| 119 | self.outer_circle.update(theta1=None, |
---|
| 120 | theta2=self.left_edge.get_angle()) |
---|
[824e488] | 121 | |
---|
[ef0c170] | 122 | def save(self, ev): |
---|
| 123 | """ |
---|
| 124 | Remember the roughness for this layer and the next so that we |
---|
| 125 | can restore on Esc. |
---|
| 126 | """ |
---|
| 127 | self.base.freeze_axes() |
---|
| 128 | self.inner_circle.save(ev) |
---|
| 129 | self.outer_circle.save(ev) |
---|
| 130 | self.right_edge.save(ev) |
---|
| 131 | self.left_edge.save(ev) |
---|
[824e488] | 132 | |
---|
[ef0c170] | 133 | def _post_data(self): |
---|
| 134 | pass |
---|
[824e488] | 135 | |
---|
| 136 | def post_data(self, new_sector): |
---|
[ef0c170] | 137 | """ post data averaging in Q""" |
---|
| 138 | if self.inner_circle.get_radius() < self.outer_circle.get_radius(): |
---|
[32c0841] | 139 | rmin = self.inner_circle.get_radius() |
---|
| 140 | rmax = self.outer_circle.get_radius() |
---|
[ef0c170] | 141 | else: |
---|
[32c0841] | 142 | rmin = self.outer_circle.get_radius() |
---|
| 143 | rmax = self.inner_circle.get_radius() |
---|
[ef0c170] | 144 | if self.right_edge.get_angle() < self.left_edge.get_angle(): |
---|
[32c0841] | 145 | phimin = self.right_edge.get_angle() |
---|
| 146 | phimax = self.left_edge.get_angle() |
---|
[ef0c170] | 147 | else: |
---|
[32c0841] | 148 | phimin = self.left_edge.get_angle() |
---|
[824e488] | 149 | phimax = self.right_edge.get_angle() |
---|
| 150 | # print "phimin, phimax, rmin ,rmax",math.degrees(phimin), |
---|
[32c0841] | 151 | # math.degrees(phimax), rmin ,rmax |
---|
[b699768] | 152 | # from sas.sascalc.dataloader.manipulations import SectorQ |
---|
[824e488] | 153 | |
---|
[32c0841] | 154 | sect = new_sector(r_min=rmin, r_max=rmax, |
---|
| 155 | phi_min=phimin, phi_max=phimax) |
---|
[ef0c170] | 156 | sector = sect(self.base.data2D) |
---|
[824e488] | 157 | |
---|
[d85c194] | 158 | from sas.sasgui.guiframe.dataFitting import Data1D |
---|
[32c0841] | 159 | if hasattr(sector, "dxl"): |
---|
| 160 | dxl = sector.dxl |
---|
[ef0c170] | 161 | else: |
---|
[32c0841] | 162 | dxl = None |
---|
| 163 | if hasattr(sector, "dxw"): |
---|
| 164 | dxw = sector.dxw |
---|
[ef0c170] | 165 | else: |
---|
[32c0841] | 166 | dxw = None |
---|
| 167 | new_plot = Data1D(x=sector.x, y=sector.y, dy=sector.dy, |
---|
| 168 | dxl=dxl, dxw=dxw) |
---|
| 169 | new_plot.name = str(new_sector.__name__) + \ |
---|
[824e488] | 170 | "(" + self.base.data2D.name + ")" |
---|
[32c0841] | 171 | new_plot.source = self.base.data2D.source |
---|
[ef0c170] | 172 | new_plot.interactive = True |
---|
[824e488] | 173 | # print "loader output.detector",output.source |
---|
[32c0841] | 174 | new_plot.detector = self.base.data2D.detector |
---|
[ef0c170] | 175 | # If the data file does not tell us what the axes are, just assume... |
---|
| 176 | new_plot.xaxis("\\rm{Q}", 'rad') |
---|
[32c0841] | 177 | new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}") |
---|
| 178 | new_plot.group_id = str(new_sector.__name__) + self.base.data2D.name |
---|
[13382fc7] | 179 | self.base.parent.update_theory(data_id=self.base.data2D.id, \ |
---|
| 180 | theory=new_plot) |
---|
[32c0841] | 181 | wx.PostEvent(self.base.parent, |
---|
[824e488] | 182 | NewPlotEvent(plot=new_plot, title=str(new_sector.__name__))) |
---|
| 183 | |
---|
[ef0c170] | 184 | def moveend(self, ev): |
---|
[824e488] | 185 | #TODO: why is this empty? |
---|
[78cae5a] | 186 | pass |
---|
[824e488] | 187 | |
---|
[ef0c170] | 188 | def restore(self): |
---|
| 189 | """ |
---|
| 190 | Restore the roughness for this layer. |
---|
| 191 | """ |
---|
| 192 | self.inner_circle.restore() |
---|
| 193 | self.outer_circle.restore() |
---|
| 194 | self.right_edge.restore() |
---|
| 195 | self.left_edge.restore() |
---|
| 196 | |
---|
| 197 | def move(self, x, y, ev): |
---|
| 198 | """ |
---|
| 199 | Process move to a new position, making sure that the move is allowed. |
---|
| 200 | """ |
---|
| 201 | pass |
---|
[824e488] | 202 | |
---|
[ef0c170] | 203 | def set_cursor(self, x, y): |
---|
[83f4445] | 204 | """ |
---|
| 205 | """ |
---|
[ef0c170] | 206 | pass |
---|
[824e488] | 207 | |
---|
[ef0c170] | 208 | def get_params(self): |
---|
[83f4445] | 209 | """ |
---|
| 210 | """ |
---|
[ef0c170] | 211 | params = {} |
---|
| 212 | params["r_min"] = self.inner_circle.get_radius() |
---|
| 213 | params["r_max"] = self.outer_circle.get_radius() |
---|
| 214 | params["phi_min"] = self.right_edge.get_angle() |
---|
| 215 | params["phi_max"] = self.left_edge.get_angle() |
---|
| 216 | params["nbins"] = self.nbins |
---|
| 217 | return params |
---|
[824e488] | 218 | |
---|
[ef0c170] | 219 | def set_params(self, params): |
---|
[83f4445] | 220 | """ |
---|
| 221 | """ |
---|
[824e488] | 222 | # print "setparams on main slicer ",params |
---|
| 223 | inner = params["r_min"] |
---|
| 224 | outer = params["r_max"] |
---|
| 225 | phi_min = params["phi_min"] |
---|
| 226 | phi_max = params["phi_max"] |
---|
[ef0c170] | 227 | self.nbins = int(params["nbins"]) |
---|
[824e488] | 228 | |
---|
| 229 | self.inner_circle.set_cursor(inner, phi_min, phi_max, self.nbins) |
---|
| 230 | self.outer_circle.set_cursor(outer, phi_min, phi_max, self.nbins) |
---|
[ef0c170] | 231 | self.right_edge.set_cursor(inner, outer, phi_min) |
---|
| 232 | self.left_edge.set_cursor(inner, outer, phi_max) |
---|
| 233 | self._post_data() |
---|
[824e488] | 234 | |
---|
[ef0c170] | 235 | def freeze_axes(self): |
---|
[83f4445] | 236 | """ |
---|
| 237 | """ |
---|
[ef0c170] | 238 | self.base.freeze_axes() |
---|
[824e488] | 239 | |
---|
[ef0c170] | 240 | def thaw_axes(self): |
---|
[83f4445] | 241 | """ |
---|
| 242 | """ |
---|
[ef0c170] | 243 | self.base.thaw_axes() |
---|
| 244 | |
---|
| 245 | def draw(self): |
---|
[83f4445] | 246 | """ |
---|
| 247 | """ |
---|
[ef0c170] | 248 | self.base.draw() |
---|
| 249 | |
---|
| 250 | class SectorInteractorQ(SectorInteractor): |
---|
[83f4445] | 251 | """ |
---|
| 252 | """ |
---|
[32c0841] | 253 | def __init__(self, base, axes, color='black', zorder=3): |
---|
[83f4445] | 254 | """ |
---|
| 255 | """ |
---|
[ef0c170] | 256 | SectorInteractor.__init__(self, base, axes, color=color) |
---|
[824e488] | 257 | self.base = base |
---|
[ef0c170] | 258 | self._post_data() |
---|
[824e488] | 259 | |
---|
[ef0c170] | 260 | def _post_data(self): |
---|
[83f4445] | 261 | """ |
---|
| 262 | """ |
---|
[b699768] | 263 | from sas.sascalc.dataloader.manipulations import SectorQ |
---|
[824e488] | 264 | self.post_data(SectorQ) |
---|
| 265 | |
---|
[ef0c170] | 266 | |
---|
| 267 | class SectorInteractorPhi(SectorInteractor): |
---|
[83f4445] | 268 | """ |
---|
| 269 | """ |
---|
[32c0841] | 270 | def __init__(self, base, axes, color='black', zorder=3): |
---|
[83f4445] | 271 | """ |
---|
| 272 | """ |
---|
[ef0c170] | 273 | SectorInteractor.__init__(self, base, axes, color=color) |
---|
[824e488] | 274 | self.base = base |
---|
[ef0c170] | 275 | self._post_data() |
---|
[824e488] | 276 | |
---|
[ef0c170] | 277 | def _post_data(self): |
---|
[83f4445] | 278 | """ |
---|
| 279 | """ |
---|
[b699768] | 280 | from sas.sascalc.dataloader.manipulations import SectorPhi |
---|
[824e488] | 281 | self.post_data(SectorPhi) |
---|
| 282 | |
---|