Package client :: Package Dock :: Module StellarDynamics
[hide private]
[frames] | no frames]

Source Code for Module client.Dock.StellarDynamics

  1  import PyQt4.QtCore 
  2  import PyQt4.QtGui 
  3   
  4  import Constants 
  5  import DataGuesser 
  6  import Widget 
  7  import Holders 
  8   
9 -class AbstractStellarDynamics (Widget.DockWidget):
10 - def __init__ (self, parent, bridge):
11 self._type = "Stellar Dynamics" 12 Widget.DockWidget.__init__ (self, parent, bridge)
13
14 - def _addCommands (self):
15 box = PyQt4.QtGui.QGroupBox ("Commands") 16 layout = PyQt4.QtGui.QHBoxLayout () 17 box.setLayout (layout) 18 19 executeButton = Constants.BQPushButton ("Perform", layout) 20 PyQt4.QtCore.QObject.connect (executeButton, PyQt4.QtCore.SIGNAL ("clicked ()"), self.perform) 21 22 clearButton = Constants.BQPushButton ("Clear", layout) 23 PyQt4.QtCore.QObject.connect (clearButton, PyQt4.QtCore.SIGNAL ("clicked ()"), self.clear) 24 25 return box
26
27 - def _addDataSelection (self):
28 outline = PyQt4.QtGui.QGroupBox ("Data Selection") 29 self.list = Holders.FreeHolderGroup (self._bridge, self._inList, self._outList) 30 outline.setLayout (self.list.layout) 31 32 return outline
33
34 - def clear (self):
35 self.list.clear () 36 for holder in self.list._inList: 37 holder.clear () 38 for holder in self.list._outList: 39 holder.clear ()
40
41 - def DoubleClicked (self, attr = None):
42 if attr == None: 43 return 44 45 if attr.Type () == "ALIAS": 46 attr = attr._item 47 48 if attr.Type () == "ATTRIBUTE" \ 49 or (attr.Type () == "VALUE" and attr._type == "_basin.Attribute"): 50 for holder in self.list._inList: 51 if holder.SetItem (attr, clobber = False) == True: 52 return True 53 return False
54
55 - def setOutput (self, state):
56 self.clear () 57 if state == 0: 58 self.list.setEnabled (False) 59 elif state == 2: 60 self.list.setEnabled (True)
61
62 - def perform (self):
63 if not ( self._bridge._connected == True and self._bridge._parallel == True): 64 return False 65 66 inAttributes = "" 67 result = self.list.getInAccesses () 68 if result == False: 69 return 70 for attr in result: 71 inAttributes += ", " + str (attr) 72 outAttribute = "" 73 result = self.list.getOutNames () 74 if result == False: 75 return 76 for attr in result: 77 outAttribute = str (attr) 78 79 commands = [] 80 for out in self.list.getOutNames (): 81 commands.append (str (out) + " = Attribute ()") 82 83 commands.append (str (outAttribute) + " = " + \ 84 self._funcName + " (" + str (inAttributes[2:]) + ")") 85 86 self._bridge._ipyShell.BatchCommands (commands, True) 87 88 for holder in self.list._inList: 89 holder.clear () 90 for holder in self.list._outList: 91 holder.clear () 92 self.list.clear ()
93 94
95 -class CenterOfMass (AbstractStellarDynamics):
96 - def __init__ (self, parent, bridge):
97 self._displayName = "Center of Mass" 98 self._displayIcon = PyQt4.QtGui.QIcon (Constants.ICON_DIR + "/stellar_dynamics/centerofmass.png") 99 self._description = "" 100 self._inList = ["x", "y", "z"] 101 self._outList = ["cm_out"] 102 AbstractStellarDynamics.__init__ (self, parent, bridge) 103 self.m = Holders.ChildAttributeHolder (bridge, self.list) 104 self.list.layout.addWidget (PyQt4.QtGui.QLabel ("mass:"), 4, 0) 105 self.list.layout.addWidget (self.m, 4, 1)
106
107 - def guessDefaults (self):
108 guessList = [] 109 for item in self._inList: 110 guessList.append (DataGuesser.GenerateRegExpFromName (item)) 111 guessList.append (DataGuesser.GenerateRegExpFromWord ("MASS")) 112 DataGuesser.GuessAttributes (self, guessList)
113
114 - def clear (self):
115 AbstractStellarDynamics.clear (self) 116 self.m.clear ()
117
118 - def DoubleClicked (self, attr = None):
119 if not AbstractStellarDynamics.DoubleClicked (self, attr): 120 if self.m.SetItem (attr, clobber = False) == True: 121 return True 122 return False
123
124 - def perform (self):
125 if not ( self._bridge._connected == True and self._bridge._parallel == True): 126 return False 127 128 inAttributes = "" 129 inResult = self.list.getInAccesses (False) 130 if inResult == False: 131 return 132 for attr in inResult: 133 inAttributes += ", " + str (attr) 134 outAttributes = "" 135 outResult = self.list.getOutNames (False) 136 if outResult == False: 137 return 138 for attr in outResult: 139 outAttributes = str (attr) 140 141 commands = [] 142 if len (inResult) == 2 and len (outResult) == 1: 143 commands.append (str (outAttributes) + \ 144 " = center_of_mass_2d (" + str (inAttributes[2:]) + ", " + \ 145 str (self.m._item._shellAccess) + ")") 146 elif len (inResult) == 3 and len (outResult) == 1: 147 commands.append (str (outAttributes) + \ 148 " = center_of_mass (" + str (inAttributes[2:]) + ", " + \ 149 str (self.m._item._shellAccess) + ")") 150 self._bridge._ipyShell.BatchCommands (commands, True)
151 152
153 -class LocalDensity (AbstractStellarDynamics):
154 - def __init__ (self, parent, bridge):
155 self._displayName = "Local Density" 156 self._displayIcon = PyQt4.QtGui.QIcon (Constants.ICON_DEFAULT) 157 self._description = "" 158 self._inList = ["x", "y", "z", "m"] 159 self._outList = ["ld_out"] 160 AbstractStellarDynamics.__init__ (self, parent, bridge) 161 self.m = Holders.ChildAttributeHolder (bridge, self.list) 162 self.list.layout.addWidget (PyQt4.QtGui.QLabel ("m:"), 4, 0) 163 self.list.layout.addWidget (self.m, 4, 1)
164 165
166 -class DensityList (AbstractStellarDynamics):
167 - def __init__ (self, parent, bridge):
168 self._displayName = "Density List" 169 self._displayIcon = PyQt4.QtGui.QIcon (Constants.ICON_DEFAULT) 170 self._description = "" 171 self._inList = ["x", "y", "z", "mass"] 172 self._outList = ["dl_out"] 173 AbstractStellarDynamics.__init__ (self, parent, bridge) 174 175 self._neighbors = PyQt4.QtGui.QSpinBox () 176 self._neighbors.setRange (0, 100) 177 self._neighbors.setSingleStep (1) 178 self.list.layout.addWidget (PyQt4.QtGui.QLabel ("Neighbors:"), 4, 0, 1, 2, PyQt4.QtCore.Qt.AlignRight) 179 self.list.layout.addWidget (self._neighbors, 4, 2, 1, 2, PyQt4.QtCore.Qt.AlignLeft)
180
181 - def clear (self):
182 AbstractStellarDynamics.clear (self) 183 self._neighbors.setValue (0)
184
185 - def perform (self):
186 if not ( self._bridge._connected == True and self._bridge._parallel == True): 187 return False 188 189 inAttributes = "" 190 inResult = self.list.getInAccesses (False) 191 if inResult == False: 192 return 193 for attr in inResult: 194 inAttributes += ", " + str (attr) 195 outAttributes = "" 196 outResult = self.list.getOutNames (False) 197 if outResult == False: 198 return 199 for attr in outResult: 200 outAttributes = str (attr) 201 202 if len (inResult) == 4 and len (outResult) == 1: 203 commands = [] 204 commands.append (str (outAttributes) + 205 " = density_list (" + str (inAttributes[2:]) + ", " + \ 206 str (self._neighbors.value ()) + ")") 207 self._bridge._ipyShell.BatchCommands (commands, True) 208 self.clear ()
209 210
211 -class DensityCenter (AbstractStellarDynamics):
212 - def __init__ (self, parent, bridge):
213 self._funcName = "density_center" 214 self._displayName = "Density Center" 215 self._displayIcon = PyQt4.QtGui.QIcon (Constants.ICON_DEFAULT) 216 self._description = "" 217 self._inList = ["x", "y", "z", "dens_list"] 218 self._outList = ["dens_center"] 219 AbstractStellarDynamics.__init__ (self, parent, bridge)
220 221
222 -class RadialProfile (AbstractStellarDynamics):
223 - def __init__ (self, parent, bridge):
224 self._displayName = "Radial Profile" 225 self._displayIcon = PyQt4.QtGui.QIcon (Constants.ICON_DEFAULT) 226 self._description = "" 227 self._inList = ["x", "y", "z", "a"] 228 self._outList = ["out"] 229 AbstractStellarDynamics.__init__ (self, parent, bridge) 230 self.mass = Holders.ChildAttributeHolder (bridge, self.list) 231 PyQt4.QtCore.QObject.connect (self.mass, PyQt4.QtCore.SIGNAL ("textChanged (const QString&)"), self.checkMass) 232 self.list.layout.addWidget (PyQt4.QtGui.QLabel ("mass (opt):"), 4, 0, PyQt4.QtCore.Qt.AlignRight) 233 self.list.layout.addWidget (self.mass, 4, 1) 234 self.massRange = Holders.ChildListHolder (bridge, self.list) 235 self.massRange.setEnabled (False) 236 self.list.layout.addWidget (PyQt4.QtGui.QLabel ("mass range:"), 5, 0, PyQt4.QtCore.Qt.AlignRight) 237 self.list.layout.addWidget (self.massRange, 5, 1, PyQt4.QtCore.Qt.AlignLeft) 238 239 self.bins = PyQt4.QtGui.QSpinBox () 240 self.bins.setRange (1, 999999999) 241 self.list.layout.addWidget (PyQt4.QtGui.QLabel ("bins:"), 2, 2, PyQt4.QtCore.Qt.AlignRight) 242 self.list.layout.addWidget (self.bins, 2, 3, PyQt4.QtCore.Qt.AlignLeft) 243 self.rmin = PyQt4.QtGui.QDoubleSpinBox () 244 self.rmin.setRange (0.0, 999999999.0) 245 self.rmin.setDecimals (Constants.DOUBLE_PRECISION) 246 self.list.layout.addWidget (PyQt4.QtGui.QLabel ("rmin:"), 3, 2, PyQt4.QtCore.Qt.AlignRight) 247 self.list.layout.addWidget (self.rmin, 3, 3, PyQt4.QtCore.Qt.AlignLeft) 248 self.rmax = PyQt4.QtGui.QDoubleSpinBox () 249 self.rmax.setRange (0.0, 999999999.0) 250 self.rmax.setDecimals (Constants.DOUBLE_PRECISION) 251 self.list.layout.addWidget (PyQt4.QtGui.QLabel ("rmax:"), 4, 2, PyQt4.QtCore.Qt.AlignRight) 252 self.list.layout.addWidget (self.rmax, 4, 3, PyQt4.QtCore.Qt.AlignLeft) 253 self.scale = PyQt4.QtGui.QCheckBox ("log scale?") 254 self.list.layout.addWidget (self.scale, 5, 2, 1, 2)
255
256 - def checkMass (self, text):
257 if str (text) == "None": 258 self.massRange.setEnabled (False) 259 else: 260 self.massRange.setEnabled (True)
261
262 - def clear (self):
263 AbstractStellarDynamics.clear (self) 264 self.mass.clear () 265 self.massRange.clear () 266 self.bins.setValue (1) 267 self.rmin.setValue (0.0) 268 self.rmax.setValue (0.0)
269
270 - def perform (self):
271 if not ( self._bridge._connected == True and self._bridge._parallel == True): 272 return False 273 274 inResult = self.list.getInAccesses (False) 275 outResult = self.list.getOutNames (False) 276 if len (inResult) != 4: 277 return 278 if len (outResult) != 1: 279 return 280 281 scale = "" 282 if self.scale.checkState () == PyQt4.QtCore.Qt.Checked: 283 scale = "log" 284 285 commands = [] 286 if self.massRange.isEnabled (): 287 if self.mass._item != None and self.massRange._item != None: 288 commands.append (str (outResult[0]) + 289 " = radial_profile (" + str (inResult[0]) + ", " + \ 290 str (inResult[1]) + ", " + str (inResult[2]) + ", " + \ 291 str (self.mass._item._shellAccess) + ", " + \ 292 str (inResult[3]) + ", " + str (self.bins.value ()) + ", " + \ 293 str (self.rmin.value ()) + ", " + str (self.rmax.value ()) + \ 294 ", " + self.massRange._item._shellAccess + ", \"" + scale + "\")") 295 else: 296 commands.append (str (outResult[0]) + \ 297 " = radial_profile (" + str (inResult[0]) + ", " + \ 298 str (inResult[1]) + ", " + str (inResult[2]) + ", " + \ 299 str (inResult[3]) + ", " + str (self.bins.value ()) + ", " + \ 300 str (self.rmin.value ()) + ", " + str (self.rmax.value ()) + \ 301 ", \"" + scale + "\")") 302 self._bridge._ipyShell.BatchCommands (commands, True) 303 304 self.clear ()
305 306
307 -class DensityProfile (AbstractStellarDynamics):
308 - def __init__ (self, parent, bridge):
309 self._displayName = "Density Profile" 310 self._displayIcon = PyQt4.QtGui.QIcon (Constants.ICON_DEFAULT) 311 self._description = "" 312 self._inList = ["x", "y", "z", "mass"] 313 self._outList = ["out"] 314 AbstractStellarDynamics.__init__ (self, parent, bridge) 315 self.massRange = Holders.ChildListHolder (bridge, self.list) 316 self.list.layout.addWidget (PyQt4.QtGui.QLabel ("m range:"), 4, 0, PyQt4.QtCore.Qt.AlignRight) 317 self.list.layout.addWidget (self.massRange, 4, 1, PyQt4.QtCore.Qt.AlignLeft) 318 319 comboList = PyQt4.QtCore.QStringList ("mn") 320 comboList.append ("mass") 321 comboList.append ("number") 322 self.compute = PyQt4.QtGui.QComboBox () 323 self.compute.addItems (comboList) 324 self.list.layout.addWidget (self.compute, 1, 2, 1, 2, PyQt4.QtCore.Qt.AlignHCenter) 325 326 self.bins = PyQt4.QtGui.QSpinBox () 327 self.bins.setRange (1, 999999999) 328 self.list.layout.addWidget (PyQt4.QtGui.QLabel ("bins:"), 2, 2, PyQt4.QtCore.Qt.AlignRight) 329 self.list.layout.addWidget (self.bins, 2, 3, PyQt4.QtCore.Qt.AlignLeft) 330 self.rmin = PyQt4.QtGui.QDoubleSpinBox () 331 self.rmin.setRange (0.0, 999999999.0) 332 self.rmin.setDecimals (Constants.DOUBLE_PRECISION) 333 self.list.layout.addWidget (PyQt4.QtGui.QLabel ("rmin:"), 3, 2, PyQt4.QtCore.Qt.AlignRight) 334 self.list.layout.addWidget (self.rmin, 3, 3, PyQt4.QtCore.Qt.AlignLeft) 335 self.rmax = PyQt4.QtGui.QDoubleSpinBox () 336 self.rmax.setRange (0.0, 999999999.0) 337 self.rmax.setDecimals (Constants.DOUBLE_PRECISION) 338 self.list.layout.addWidget (PyQt4.QtGui.QLabel ("rmax:"), 4, 2, PyQt4.QtCore.Qt.AlignRight) 339 self.list.layout.addWidget (self.rmax, 4, 3, PyQt4.QtCore.Qt.AlignLeft) 340 self.scale = PyQt4.QtGui.QCheckBox ("log scale?") 341 self.list.layout.addWidget (self.scale, 5, 2, 1, 2)
342
343 - def clear (self):
344 AbstractStellarDynamics.clear (self) 345 self.massRange.clear () 346 self.bins.setValue (1) 347 self.rmin.setValue (0.0) 348 self.rmax.setValue (0.0)
349
350 - def perform (self):
351 if not ( self._bridge._connected == True and self._bridge._parallel == True): 352 return False 353 354 inResult = self.list.getInAccesses (False) 355 outResult = self.list.getOutNames (False) 356 if len (inResult) != 4: 357 return 358 if len (outResult) != 1: 359 return 360 361 scale = "" 362 if self.scale.checkState () == PyQt4.QtCore.Qt.Checked: 363 scale = "log" 364 compute = str (self.compute.itemText (self.compute.currentIndex ())) 365 366 commands = [] 367 if self.massRange._item == None: 368 commands.append (str (outResult[0]) + \ 369 " = density_profile (" + str (inResult[0]) + ", " + \ 370 str (inResult[1]) + ", " + str (inResult[2]) + ", " + \ 371 str (inResult[3]) + ", " + str (self.bins.value ()) + ", " + \ 372 str (self.rmin.value ()) + ", " + str (self.rmax.value ()) + \ 373 ", \"" + compute + "\", \"" + scale + "\")") 374 else: 375 commands.append (str (outResult[0]) + \ 376 " = density_profile (" + str (inResult[0]) + ", " + \ 377 str (inResult[1]) + ", " + str (inResult[2]) + ", " + \ 378 str (inResult[3]) + ", " + str (self.bins.value ()) + ", " + \ 379 str (self.rmin.value ()) + ", " + str (self.rmax.value ()) + \ 380 ", " + self.massRange._item._shellAccess + ", \"" + \ 381 compute + "\", \"" + scale + "\")") 382 self._bridge._ipyShell.BatchCommands (commands, True) 383 384 self.clear ()
385 386
387 -class DispProfile (AbstractStellarDynamics):
388 - def __init__ (self, parent, bridge):
389 self._displayName = "Disp Profile" 390 self._displayIcon = PyQt4.QtGui.QIcon (Constants.ICON_DEFAULT) 391 self._description = \ 392 "" 393 self._inList = ["x", "y", "z", "A"] 394 self._outList = ["out"] 395 AbstractStellarDynamics.__init__ (self, parent, bridge) 396 self.massRange = Holders.ChildListHolder (bridge, self.list) 397 self.list.layout.addWidget (PyQt4.QtGui.QLabel ("scale:"), 4, 0, PyQt4.QtCore.Qt.AlignRight) 398 self.list.layout.addWidget (self.massRange, 4, 1, PyQt4.QtCore.Qt.AlignLeft) 399 400 comboList = PyQt4.QtCore.QStringList ("log") 401 comboList.append ("normal") 402 self.compute = PyQt4.QtGui.QComboBox () 403 self.compute.addItems (comboList) 404 self.list.layout.addWidget (self.compute, 1, 2, 1, 2, PyQt4.QtCore.Qt.AlignHCenter) 405 406 self.bins = PyQt4.QtGui.QSpinBox () 407 self.bins.setRange (1, 999999999) 408 self.list.layout.addWidget (PyQt4.QtGui.QLabel ("bins:"), 2, 2, PyQt4.QtCore.Qt.AlignRight) 409 self.list.layout.addWidget (self.bins, 2, 3, PyQt4.QtCore.Qt.AlignLeft) 410 self.rmin = PyQt4.QtGui.QDoubleSpinBox () 411 self.rmin.setRange (0.0, 999999999.9) 412 self.rmin.setDecimals (Constants.DOUBLE_PRECISION) 413 self.list.layout.addWidget (PyQt4.QtGui.QLabel ("rmin:"), 3, 2, PyQt4.QtCore.Qt.AlignRight) 414 self.list.layout.addWidget (self.rmin, 3, 3, PyQt4.QtCore.Qt.AlignLeft) 415 self.rmax = PyQt4.QtGui.QDoubleSpinBox () 416 self.rmax.setRange (0.0, 999999999.9) 417 self.rmax.setDecimals (Constants.DOUBLE_PRECISION) 418 self.list.layout.addWidget (PyQt4.QtGui.QLabel ("rmax:"), 4, 2, PyQt4.QtCore.Qt.AlignRight) 419 self.list.layout.addWidget (self.rmax, 4, 3, PyQt4.QtCore.Qt.AlignLeft) 420 self.scale = PyQt4.QtGui.QCheckBox ("log scale?") 421 self.list.layout.addWidget (self.scale, 5, 2, 1, 2)
422
423 - def clear (self):
424 AbstractStellarDynamics.clear (self) 425 self.massRange.clear () 426 self.bins.setValue (1) 427 self.rmin.setValue (0.0) 428 self.rmax.setValue (0.0)
429
430 - def perform (self):
431 if not ( self._bridge._connected == True and self._bridge._parallel == True): 432 return False 433 434 inResult = self.list.getInAccesses (False) 435 outResult = self.list.getOutNames (False) 436 if len (inResult) != 4: 437 return 438 if len (outResult) != 1: 439 return 440 441 scale = "" 442 if self.scale.checkState () == PyQt4.QtCore.Qt.Checked: 443 scale = "log" 444 compute = str (self.compute.itemText (self.compute.currentIndex ())) 445 446 commands = [] 447 if self.massRange._item == None: 448 commands.append (str (outResult[0]) + \ 449 " = density_profile (" + str (inResult[0]) + ", " + \ 450 str (inResult[1]) + ", " + str (inResult[2]) + ", " + \ 451 str (inResult[3]) + ", " + str (self.bins.value ()) + ", " + \ 452 str (self.rmin.value ()) + ", " + str (self.rmax.value ()) + \ 453 ", \"" + compute + "\", \"" + scale + "\")") 454 else: 455 commands.append (str (outResult[0]) + \ 456 " = density_profile (" + str (inResult[0]) + ", " + \ 457 str (inResult[1]) + ", " + str (inResult[2]) + ", " + \ 458 str (inResult[3]) + ", " + str (self.bins.value ()) + ", " + \ 459 str (self.rmin.value ()) + ", " + str (self.rmax.value ()) + \ 460 ", " + self.massRange._item._shellAccess + ", \"" + \ 461 compute + "\", \"" + scale + "\")") 462 self._bridge._ipyShell.BatchCommands (commands, True) 463 464 self.clear ()
465