Changeset 32e3c9b in sasmodels for sasmodels/modelinfo.py
- Timestamp:
- Jul 21, 2016 4:08:04 PM (9 years ago)
- Branches:
- master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- b966a96
- Parents:
- 42356c8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/modelinfo.py
rce176ca r32e3c9b 414 414 self.kernel_parameters = parameters 415 415 self._set_vector_lengths() 416 417 self.npars = sum(p.length for p in self.kernel_parameters) 418 self.num_magnetic = sum(p.length for p in self.kernel_parameters 419 if p.type=='sld') 420 416 421 self.call_parameters = self._get_call_parameters() 417 422 self.defaults = self._get_defaults() … … 441 446 num_pd = sum(p.length for p in self.kernel_parameters if p.polydisperse) 442 447 # Don't use more polydisperse parameters than are available in the model 443 # Note: we can do polydispersity on arbitrary parameters, so it is not444 # clear that this is a good idea; it does however make the poly_details445 # code easier to write, so we will leave it in for now.446 448 self.max_pd = min(num_pd, MAX_PD) 447 448 self.npars = sum(p.length for p in self.kernel_parameters)449 449 450 450 # true if has 2D parameters 451 451 self.has_2d = any(p.type in ('orientation', 'magnetic') 452 452 for p in self.kernel_parameters) 453 self.magnetism_index = [k for k,p in enumerate(self.call_parameters) 454 if p.id.startswith('M0:')] 453 455 454 456 self.pd_1d = set(p.name for p in self.call_parameters 455 457 if p.polydisperse and p.type not in ('orientation', 'magnetic')) 456 self.pd_2d = set(p.name for p in self.call_parameters 457 if p.polydisperse and p.type != 'magnetic') 458 self.pd_2d = set(p.name for p in self.call_parameters if p.polydisperse) 458 459 459 460 def _set_vector_lengths(self): … … 519 520 pk.relative_pd = p.relative_pd 520 521 full_list.append(pk) 522 523 # Add the magnetic parameters to the end of the call parameter list. 524 if self.num_magnetic > 0: 525 full_list.extend([ 526 Parameter('up:frac_i', '', 0., [0., 1.], 527 'magnetic', 'fraction of spin up incident'), 528 Parameter('up:frac_f', '', 0., [0., 1.], 529 'magnetic', 'fraction of spin up final'), 530 Parameter('up:angle', 'degress', 0., [0., 360.], 531 'magnetic', 'spin up angle'), 532 ]) 533 slds = [p for p in full_list if p.type == 'sld'] 534 for p in slds: 535 full_list.extend([ 536 Parameter('M0:'+p.id, '1e-6/Ang^2', 0., [-np.inf, np.inf], 537 'magnetic', 'magnetic amplitude for '+p.description), 538 Parameter('mtheta:'+p.id, 'degrees', 0., [-90., 90.], 539 'magnetic', 'magnetic latitude for '+p.description), 540 Parameter('mphi:'+p.id, 'degrees', 0., [-180., 180.], 541 'magnetic', 'magnetic longitude for '+p.description), 542 ]) 543 #print("call parameters", full_list) 521 544 return full_list 522 545 … … 553 576 parameter is always returned first since the GUI will want to set it 554 577 early, and rerender the table when it is changed. 578 579 Parameters marked as sld will automatically have a set of associated 580 magnetic parameters (m0:p, mtheta:p, mphi:p), as well as polarization 581 information (up:theta, up:frac_i, up:frac_f). 555 582 """ 556 583 # control parameters go first … … 565 592 566 593 # Gather entries such as name[4] into groups of the same length 567 fixed = {} # type: Dict[int, List[Parameter]]594 fixed_length = {} # type: Dict[int, List[Parameter]] 568 595 for p in self.kernel_parameters: 569 596 if p.length > 1 and p.length_control is None: 570 fixed .setdefault(p.length, []).append(p)597 fixed_length.setdefault(p.length, []).append(p) 571 598 572 599 # Using the call_parameters table, we already have expanded forms 573 600 # for each of the vector parameters; put them in a lookup table 574 601 expanded_pars = dict((p.name, p) for p in self.call_parameters) 602 603 def append_group(name): 604 """add the named parameter, and related magnetic parameters if any""" 605 result.append(expanded_pars[name]) 606 if is2d: 607 for tag in 'M0:', 'mtheta:', 'mphi:': 608 if tag+name in expanded_pars: 609 result.append(expanded_pars[tag+name]) 575 610 576 611 # Gather the user parameters in order … … 589 624 for k in range(1, table_length+1): 590 625 for entry in table: 591 result.append(expanded_pars[entry.id+str(k)])626 append_group(entry.id+str(k)) 592 627 else: 593 628 pass # already processed all entries 594 629 elif p.length > 1: 595 table = fixed .get(p.length, [])630 table = fixed_length.get(p.length, []) 596 631 if table: 597 632 table_length = p.length 598 del fixed [p.length]633 del fixed_length[p.length] 599 634 for k in range(1, table_length+1): 600 635 for entry in table: 601 result.append(expanded_pars[entry.id+str(k)])636 append_group(entry.id+str(k)) 602 637 else: 603 638 pass # already processed all entries 604 639 else: 605 result.append(p) 640 append_group(p.id) 641 642 if is2d and 'up:angle' in expanded_pars: 643 result.extend([ 644 expanded_pars['up:frac_i'], 645 expanded_pars['up:frac_f'], 646 expanded_pars['up:angle'], 647 ]) 606 648 607 649 return result … … 634 676 if (model_info.Iq is None 635 677 and model_info.Iqxy is None 678 and model_info.Imagnetic is None 636 679 and model_info.form_volume is None): 637 680 return … … 643 686 return 644 687 for k, v in enumerate(source.split('\n')): 645 if v.startswith('Iqxy'): 688 if v.startswith('Imagnetic'): 689 model_info._Imagnetic_line = k+1 690 elif v.startswith('Iqxy'): 646 691 model_info._Iqxy_line = k+1 647 692 elif v.startswith('Iq'): … … 692 737 info.Iq = getattr(kernel_module, 'Iq', None) # type: ignore 693 738 info.Iqxy = getattr(kernel_module, 'Iqxy', None) # type: ignore 739 info.Imagnetic = getattr(kernel_module, 'Imagnetic', None) # type: ignore 694 740 info.profile = getattr(kernel_module, 'profile', None) # type: ignore 695 741 info.sesans = getattr(kernel_module, 'sesans', None) # type: ignore … … 843 889 #: Returns *I(qx, qy, a, b, ...)*. The interface follows :attr:`Iq`. 844 890 Iqxy = None # type: Union[None, str, Callable[[np.ndarray], np.ndarray]] 891 #: Returns *I(qx, qy, a, b, ...)*. The interface follows :attr:`Iq`. 892 Imagnetic = None # type: Union[None, str, Callable[[np.ndarray], np.ndarray]] 845 893 #: Returns a model profile curve *x, y*. If *profile* is defined, this 846 894 #: curve will appear in response to the *Show* button in SasView. Use … … 857 905 # line numbers within the python file for bits of C source, if defined 858 906 # NB: some compilers fail with a "#line 0" directive, so default to 1. 907 _Imagnetic_line = 1 859 908 _Iqxy_line = 1 860 909 _Iq_line = 1
Note: See TracChangeset
for help on using the changeset viewer.