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