Changeset dbc01f2 in sasview
- Timestamp:
- Jan 10, 2013 5:16:51 PM (12 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- b1174ec
- Parents:
- 2d9c7266
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
calculatorview/src/sans/perspectives/calculator/gen_scatter_panel.py
r3cfa760 rdbc01f2 353 353 x_in = n_qbins * n_pixs / 100000 354 354 # magic equation: not very accurate 355 etime = 0.00001 + 0.085973* x_in355 etime = 1.0 + 0.14 * x_in 356 356 return int(etime) 357 357 … … 526 526 else: 527 527 raise 528 for name, _, unit in self.parameters:529 if name.GetLabelText() == 'background':530 if is_pdbdata:531 unit.SetLabel('[A^(2)]')532 else:533 unit.SetLabel('[1/cm]')534 break535 528 self._set_sld_data_helper(True) 536 529 except: … … 575 568 Draw 3D sld profile 576 569 """ 570 color_dic = {'H':'blue', 'D':'purple', 'N': 'orange', 571 'O':'red', 'C':'green', 'Other':'k'} 577 572 graph_title = self.file_name 578 573 graph_title += " 3D SLD Profile " 574 579 575 flag = self.parent.check_omfpanel_inputs() 580 576 if not flag: … … 595 591 add_icon(self.parent, frame) 596 592 panel = frame.plotpanel 593 597 594 try: 598 595 # mpl >= 1.0.0 … … 606 603 logging.error("PlotPanel could not import Axes3D") 607 604 raise 605 608 606 marker = ',' 609 607 m_size = 2 … … 622 620 is_nonzero = sld_tot > 0.0 623 621 is_zero = sld_tot == 0.0 622 623 # Plot null points 624 624 if is_zero.any(): 625 625 ax.plot(pos_x[is_zero], pos_z[is_zero], pos_y[is_zero], marker, … … 632 632 sld_my = sld_my[is_nonzero] 633 633 sld_mz = sld_mz[is_nonzero] 634 635 ax.plot(pos_x, pos_z, pos_y, 636 marker, c="k", 637 alpha=0.5, markeredgecolor="k", markersize=m_size) 634 635 # Plot selective points in color 636 for key in color_dic.keys(): 637 chosen_color = output.pix_symbol == key 638 other_color = numpy.ones(len(output.pix_symbol), dtype='bool') 639 if chosen_color.any(): 640 other_color = other_color & (chosen_color != True) 641 color = color_dic[key] 642 ax.plot(pos_x[chosen_color], pos_z[chosen_color], 643 pos_y[chosen_color], marker, c=color, alpha=0.5, 644 markeredgecolor=color, markersize=m_size, label=key) 645 # Plot All others 646 if other_color.any(): 647 ax.plot(pos_x[other_color], pos_z[other_color], pos_y[other_color], 648 marker, c="k", alpha=0.5, markeredgecolor="k", 649 markersize=m_size, label="Other") 638 650 639 651 if has_arrow and len(pos_x) > 0: … … 643 655 draw w/arrow 644 656 """ 645 #frame.SetSize(wx.Size(650, 570))646 #event.Skip()647 657 max_mx = max(numpy.fabs(sld_mx)) 648 658 max_my = max(numpy.fabs(sld_my)) … … 679 689 mutation_scale=10, lw=1, 680 690 arrowstyle="->", alpha = 0.5) 681 ax.add_artist(arrows) 682 691 ax.add_artist(arrows) 683 692 except: 684 693 pass … … 701 710 ax.set_ylabel('z ($\A%s$)'% output.pos_unit) 702 711 ax.set_zlabel('y ($\A%s$)'% output.pos_unit) 712 if output.pix_type == 'atom': 713 ax.legend(loc='upper left', prop={'size':10}) 703 714 num_graph = str(self.graph_num) 704 715 frame.SetTitle('Graph %s: %s'% (num_graph, graph_title)) … … 743 754 return 744 755 try: 745 vol = self.parent.get_pix_volume()746 self.model.set_pixel_volume(vol)756 #vol = self.parent.get_pix_volumes() 757 #self.model.set_pixel_volumes(vol) 747 758 self.model.set_sld_data(self.sld_data) 748 759 self.set_input_params() … … 754 765 755 766 cal_out = CalcGen(input=[self.data.qx_data, 756 self.data.qy_data, i_out],767 self.data.qy_data, i_out], 757 768 completefn=self.complete, 758 769 updatefn=self._update) … … 1043 1054 return self.sld_data 1044 1055 1045 def get_pix_volume (self):1056 def get_pix_volumes(self): 1046 1057 """ 1047 1058 Get the pixel volume 1048 1059 """ 1049 val = 1 1050 if self.sld_data.pix_type == 'pixel': 1051 for lst in self.stepsize: 1052 val *= float(lst[1].GetValue()) 1053 1054 return numpy.fabs(val) 1060 vol = self.sld_data.vol_pix 1061 1062 return vol 1055 1063 1056 1064 def _get_other_val(self): … … 1270 1278 ctl = InputTextCtrl(self, -1, size=(_BOX_WIDTH, 20), 1271 1279 style=wx.TE_PROCESS_ENTER) 1280 ctl.Bind(wx.EVT_TEXT, self._onstepsize ) 1272 1281 ctl.SetValue(format_number(value, True)) 1273 1282 ctl.Enable(not is_data) … … 1387 1396 ctr_list[1].SetValue(format_number(mean_val, True)) 1388 1397 ctr_list[1].Enable(enable) 1389 ctr_list[2].SetLabel("[" + sld_data.sld_unit + "]")1398 #ctr_list[2].SetLabel("[" + sld_data.sld_unit + "]") 1390 1399 break 1391 1400 … … 1483 1492 return flag 1484 1493 1494 def _onstepsize(self, event): 1495 """ 1496 On stepsize event 1497 """ 1498 flag = True 1499 if event != None: 1500 event.Skip() 1501 ctl = event.GetEventObject() 1502 ctl.SetBackgroundColour("white") 1503 1504 if flag and not self.sld_data.is_data:#ctl.IsEnabled(): 1505 s_size = 1.0 1506 try: 1507 for item in self.stepsize: 1508 s_val = float(item[1].GetValue()) 1509 if s_val <= 0: 1510 item[1].SetBackgroundColour("pink") 1511 ctl.Refresh() 1512 return 1513 if numpy.isfinite(s_val): 1514 s_size *= s_val 1515 self.sld_data.set_pixel_volumes(s_size) 1516 except: 1517 pass 1518 ctl.Refresh() 1519 1520 1485 1521 def set_npts_from_slddata(self): 1486 1522 """ … … 1759 1795 return n_pix 1760 1796 1761 def get_pix_volume (self):1797 def get_pix_volumes(self): 1762 1798 """ 1763 1799 Get a pixel volume 1764 1800 """ 1765 vol = self.omfpanel.get_pix_volume ()1801 vol = self.omfpanel.get_pix_volumes() 1766 1802 return vol 1767 1803 -
calculatorview/src/sans/perspectives/calculator/load_thread.py
rdbc5dc9b rdbc01f2 3 3 """ 4 4 import time 5 import wx6 5 from data_util.calcthread import CalcThread 7 6 from sans.dataloader.loader import Loader -
calculatorview/src/sans/perspectives/calculator/media/gen_sans_help.html
r54d6c3e rdbc01f2 115 115 For example, both values are 0.5 for unpolarized neutrons. 116 116 <br> 117 *Note II: The unit of intensity calculated from .sld, .omf, or .txt files is 1/cm, otherwise 118 it is Å<sup>2</sup>. (In the first equation above, the V is set to 1.) 119 <br> 120 *Note III: This computation is totally based on the pixel (or atomic) data fixed 117 *Note II: This computation is totally based on the pixel (or atomic) data fixed 121 118 in the xyz coordinates. Thus no angular orientational averaging is considered. 122 119 <br> 123 *Note IV: For the nuclear scattering length density, only the real component is taken account. 120 *Note III: For the nuclear scattering length density, only the real component is taken account. 121 <br> 124 122 </body> -
sanscalculator/src/sans/calculator/sans_gen.py
rd7b6913 rdbc01f2 5 5 import sans.models.sans_extension.sld2i as mod 6 6 from periodictable import formula 7 from periodictable import nsf 7 8 import numpy 8 9 import os … … 11 12 MFactor_mT = 2.3164E-9 12 13 METER2ANG = 1.0E+10 14 #Avogadro constant [1/mol] 15 NA = 6.02214129e+23 13 16 14 17 def mag2sld(mag, v_unit=None): … … 48 51 self.data_my = None 49 52 self.data_mz = None 50 self. volume = 1000#[A^3]53 self.data_vol = None #[A^3] 51 54 ## Name of the model 52 55 self.name = "GenSAS" … … 69 72 self.fixed=[] 70 73 71 def set_pixel_volume (self, volume):74 def set_pixel_volumes(self, volume): 72 75 """ 73 76 Set the volume of a pixel in (A^3) unit 74 """ 75 self.volume = volume 77 :Param volume: pixel volume [float] 78 """ 79 if self.data_vol == None: 80 raise 81 self.data_vol = volume 76 82 77 83 def _gen(self, x, y, i): … … 87 93 model = mod.new_GenI(len_x, self.data_x, self.data_y, self.data_z, 88 94 self.data_sldn, self.data_mx, self.data_my, 89 self.data_mz, self.params['Up_frac_in'], 95 self.data_mz, self.data_vol, 96 self.params['Up_frac_in'], 90 97 self.params['Up_frac_out'], 91 98 self.params['Up_theta']) 99 92 100 mod.genicom(model, len_q, x, y, i) 93 return self.params['scale'] * i * self.volume \ 94 + self.params['background'] 101 return self.params['scale'] * i + self.params['background'] 95 102 96 103 def set_sld_data(self, sld_data=None): … … 107 114 self.data_my = sld_data.sld_my 108 115 self.data_mz = sld_data.sld_mz 116 self.data_vol = sld_data.vol_pix 109 117 110 118 def getProfile(self): … … 126 134 y_in = numpy.zero_like(x[0]) 127 135 # 1D I is found at y =0 in the 2D pattern 128 return self._gen(x[0], y_in, i_out )136 return self._gen(x[0], y_in, i_out ) 129 137 else: 130 138 msg = "Q must be given as list of qx's and qy's" … … 183 191 self.mz = None 184 192 self.sld_n = None 193 self.vol_pix = None 185 194 self.output = None 186 195 self.omfdata = None … … 443 452 type = ["pdb files (*.PDB, *.pdb)|*.pdb"] 444 453 ## List of allowed extensions 445 ext = ['.pdb', '.PDB'] 454 ext = ['.pdb', '.PDB'] 446 455 447 456 def read(self, path): … … 462 471 sld_my = numpy.zeros(0) 463 472 sld_mz = numpy.zeros(0) 473 vol_pix = numpy.zeros(0) 464 474 pix_symbol = numpy.zeros(0) 465 475 try: … … 498 508 pos_z = numpy.append(pos_z, _pos_z) 499 509 try: 500 #from periodictable import nsf501 #val = nsf.neutron_sld(atom_name)502 val = formula(atom_name).atoms.keys()[0].neutron.b_c503 510 # sld in Ang unit (from fm) 504 val = float(val) 505 val *= 1.0e-5 511 #val = formula(atom_name).atoms.keys()[0].neutron.b_c 512 #val *= 1.0e-5 513 val = nsf.neutron_sld(atom_name)[0] 514 # sld in Ang^-2 unit 515 val *= 1.0e-6 506 516 sld_n = numpy.append(sld_n, val) 517 atom = formula(atom_name) 518 # cm to A units 519 vol = 1.0e+24 * atom.mass / atom.density / NA 520 vol_pix = numpy.append(vol_pix, vol) 507 521 except: 508 522 print "Error: set the sld of %s to zero"% atom_name … … 525 539 output.set_pixel_symbols(pix_symbol) 526 540 output.set_nodes() 527 output.sld_unit = 'A' 541 output.set_pixel_volumes(vol_pix) 542 output.sld_unit = '1/A^(2)' 528 543 return output 529 544 except: … … 561 576 :raise ValueError: when the length of the data vectors are inconsistent 562 577 """ 563 pos_x = numpy.zeros(0) 564 pos_y = numpy.zeros(0) 565 pos_z = numpy.zeros(0) 566 sld_n = numpy.zeros(0) 567 sld_mx = numpy.zeros(0) 568 sld_my = numpy.zeros(0) 569 sld_mz = numpy.zeros(0) 578 579 570 580 try: 571 input_f = open(path, 'rb') 572 buff = input_f.read() 573 lines = buff.split('\n') 574 input_f.close() 575 for line in lines: 576 toks = line.split() 577 try: 578 _pos_x = float(toks[0]) 579 _pos_y = float(toks[1]) 580 _pos_z = float(toks[2]) 581 _sld_n = float(toks[3]) 582 _sld_mx = float(toks[4]) 583 _sld_my = float(toks[5]) 584 _sld_mz = float(toks[6]) 585 586 pos_x = numpy.append(pos_x, _pos_x) 587 pos_y = numpy.append(pos_y, _pos_y) 588 pos_z = numpy.append(pos_z, _pos_z) 589 sld_n = numpy.append(sld_n, _sld_n) 590 sld_mx = numpy.append(sld_mx, _sld_mx) 591 sld_my = numpy.append(sld_my, _sld_my) 592 sld_mz = numpy.append(sld_mz, _sld_mz) 593 except: 594 # Skip non-data lines 595 pass 581 input_f = numpy.loadtxt(path, dtype='float', skiprows=1, 582 ndmin=1, unpack=True) 583 pos_x = numpy.array(input_f[0]) 584 pos_y = numpy.array(input_f[1]) 585 pos_z = numpy.array(input_f[2]) 586 sld_n = numpy.array(input_f[3]) 587 sld_mx = numpy.array(input_f[4]) 588 sld_my = numpy.array(input_f[5]) 589 sld_mz = numpy.array(input_f[6]) 590 ncols = len(input_f) 591 if ncols == 8: 592 vol_pix = numpy.array(input_f[7]) 593 elif ncols == 7: 594 vol_pix = None 595 else: 596 raise 596 597 pos_x -= (min(pos_x) + max(pos_x)) / 2.0 597 598 pos_y -= (min(pos_y) + max(pos_y)) / 2.0 598 599 pos_z -= (min(pos_z) + max(pos_z)) / 2.0 599 600 600 output = MagSLD(pos_x, pos_y, pos_z, sld_n, sld_mx, sld_my, sld_mz) 601 output = MagSLD(pos_x, pos_y, pos_z, sld_n, 602 sld_mx, sld_my, sld_mz) 603 601 604 output.filename = os.path.basename(path) 602 605 output.set_pix_type('pixel') 603 606 output.set_pixel_symbols('pixel') 607 if vol_pix != None: 608 output.set_pixel_volumes(vol_pix) 604 609 return output 605 610 except: … … 621 626 y_val = data.pos_y 622 627 z_val = data.pos_z 628 vol_pix = data.vol_pix 623 629 624 630 length = len(x_val) … … 639 645 out = open(path, 'w') 640 646 # First Line: Column names 641 out.write("X Y Z SLDN SLDMx SLDMy SLDMz")647 out.write("X Y Z SLDN SLDMx SLDMy SLDMz VOLUMEpix") 642 648 for ind in range(length): 643 out.write("\n%g %g %g %g %g %g %g " % (x_val[ind], y_val[ind],649 out.write("\n%g %g %g %g %g %g %g %g" % (x_val[ind], y_val[ind], 644 650 z_val[ind], sld_n[ind], 645 651 sld_mx[ind], sld_my[ind], 646 sld_mz[ind] ))652 sld_mz[ind], vol_pix[ind])) 647 653 out.close() 648 654 … … 749 755 750 756 def __init__(self, pos_x, pos_y, pos_z, sld_n=None, 751 sld_mx=None, sld_my=None, sld_mz=None ):757 sld_mx=None, sld_my=None, sld_mz=None, vol_pix=None): 752 758 """ 753 759 Init for mag SLD … … 773 779 self.sld_my = sld_my 774 780 self.sld_mz = sld_mz 781 self.vol_pix = vol_pix 775 782 self.sld_m = None 776 783 self.sld_phi = None … … 851 858 else: 852 859 self.pix_symbol = symbol 860 861 def set_pixel_volumes(self, vol): 862 """ 863 Set pixel volumes 864 :Params pixel: str; pixel or atomic symbol, or array of strings 865 """ 866 if self.sld_n == None: 867 return 868 if vol.__class__.__name__ == 'ndarray': 869 self.vol_pix = vol 870 elif vol.__class__.__name__.count('float') > 0: 871 self.vol_pix = numpy.repeat(vol, len(self.sld_n)) 872 else: 873 self.vol_pix = None 853 874 854 875 def get_sldn(self): … … 913 934 self.zstepsize = numpy.fabs(z_pos - zpos_pre) 914 935 break 936 #default pix volume 937 self.vol_pix = numpy.ones(len(self.pos_x)) 938 vol = self.xstepsize * self.ystepsize * self.zstepsize 939 self.set_pixel_volumes(vol) 915 940 self.has_stepsize = True 916 941 except: … … 918 943 self.ystepsize = None 919 944 self.zstepsize = None 945 self.vol_pix = None 920 946 self.has_stepsize = False 921 947 else: … … 1006 1032 1007 1033 if __name__ == "__main__": 1008 #test()1034 test() 1009 1035 test_load()
Note: See TracChangeset
for help on using the changeset viewer.