[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 | |
---|
[161713c] | 184 | |
---|
| 185 | def validate(self, param_name, param_value): |
---|
| 186 | """ |
---|
| 187 | Test the proposed new value "value" for row "row" of parameters |
---|
| 188 | """ |
---|
| 189 | # Here, always return true |
---|
| 190 | return True |
---|
| 191 | |
---|
[ef0c170] | 192 | def moveend(self, ev): |
---|
[824e488] | 193 | #TODO: why is this empty? |
---|
[78cae5a] | 194 | pass |
---|
[824e488] | 195 | |
---|
[ef0c170] | 196 | def restore(self): |
---|
| 197 | """ |
---|
| 198 | Restore the roughness for this layer. |
---|
| 199 | """ |
---|
| 200 | self.inner_circle.restore() |
---|
| 201 | self.outer_circle.restore() |
---|
| 202 | self.right_edge.restore() |
---|
| 203 | self.left_edge.restore() |
---|
| 204 | |
---|
| 205 | def move(self, x, y, ev): |
---|
| 206 | """ |
---|
| 207 | Process move to a new position, making sure that the move is allowed. |
---|
| 208 | """ |
---|
| 209 | pass |
---|
[824e488] | 210 | |
---|
[ef0c170] | 211 | def set_cursor(self, x, y): |
---|
[83f4445] | 212 | """ |
---|
| 213 | """ |
---|
[ef0c170] | 214 | pass |
---|
[824e488] | 215 | |
---|
[ef0c170] | 216 | def get_params(self): |
---|
[83f4445] | 217 | """ |
---|
| 218 | """ |
---|
[ef0c170] | 219 | params = {} |
---|
| 220 | params["r_min"] = self.inner_circle.get_radius() |
---|
| 221 | params["r_max"] = self.outer_circle.get_radius() |
---|
| 222 | params["phi_min"] = self.right_edge.get_angle() |
---|
| 223 | params["phi_max"] = self.left_edge.get_angle() |
---|
| 224 | params["nbins"] = self.nbins |
---|
| 225 | return params |
---|
[824e488] | 226 | |
---|
[ef0c170] | 227 | def set_params(self, params): |
---|
[83f4445] | 228 | """ |
---|
| 229 | """ |
---|
[824e488] | 230 | # print "setparams on main slicer ",params |
---|
| 231 | inner = params["r_min"] |
---|
| 232 | outer = params["r_max"] |
---|
| 233 | phi_min = params["phi_min"] |
---|
| 234 | phi_max = params["phi_max"] |
---|
[ef0c170] | 235 | self.nbins = int(params["nbins"]) |
---|
[824e488] | 236 | |
---|
| 237 | self.inner_circle.set_cursor(inner, phi_min, phi_max, self.nbins) |
---|
| 238 | self.outer_circle.set_cursor(outer, phi_min, phi_max, self.nbins) |
---|
[ef0c170] | 239 | self.right_edge.set_cursor(inner, outer, phi_min) |
---|
| 240 | self.left_edge.set_cursor(inner, outer, phi_max) |
---|
| 241 | self._post_data() |
---|
[824e488] | 242 | |
---|
[ef0c170] | 243 | def freeze_axes(self): |
---|
[83f4445] | 244 | """ |
---|
| 245 | """ |
---|
[ef0c170] | 246 | self.base.freeze_axes() |
---|
[824e488] | 247 | |
---|
[ef0c170] | 248 | def thaw_axes(self): |
---|
[83f4445] | 249 | """ |
---|
| 250 | """ |
---|
[ef0c170] | 251 | self.base.thaw_axes() |
---|
| 252 | |
---|
| 253 | def draw(self): |
---|
[83f4445] | 254 | """ |
---|
| 255 | """ |
---|
[ef0c170] | 256 | self.base.draw() |
---|
| 257 | |
---|
| 258 | class SectorInteractorQ(SectorInteractor): |
---|
[83f4445] | 259 | """ |
---|
| 260 | """ |
---|
[32c0841] | 261 | def __init__(self, base, axes, color='black', zorder=3): |
---|
[83f4445] | 262 | """ |
---|
| 263 | """ |
---|
[ef0c170] | 264 | SectorInteractor.__init__(self, base, axes, color=color) |
---|
[824e488] | 265 | self.base = base |
---|
[ef0c170] | 266 | self._post_data() |
---|
[824e488] | 267 | |
---|
[ef0c170] | 268 | def _post_data(self): |
---|
[83f4445] | 269 | """ |
---|
| 270 | """ |
---|
[b699768] | 271 | from sas.sascalc.dataloader.manipulations import SectorQ |
---|
[824e488] | 272 | self.post_data(SectorQ) |
---|
| 273 | |
---|
[ef0c170] | 274 | |
---|
| 275 | class SectorInteractorPhi(SectorInteractor): |
---|
[83f4445] | 276 | """ |
---|
| 277 | """ |
---|
[32c0841] | 278 | def __init__(self, base, axes, color='black', zorder=3): |
---|
[83f4445] | 279 | """ |
---|
| 280 | """ |
---|
[ef0c170] | 281 | SectorInteractor.__init__(self, base, axes, color=color) |
---|
[824e488] | 282 | self.base = base |
---|
[ef0c170] | 283 | self._post_data() |
---|
[824e488] | 284 | |
---|
[ef0c170] | 285 | def _post_data(self): |
---|
[83f4445] | 286 | """ |
---|
| 287 | """ |
---|
[b699768] | 288 | from sas.sascalc.dataloader.manipulations import SectorPhi |
---|
[824e488] | 289 | self.post_data(SectorPhi) |
---|
| 290 | |
---|