Changeset da63656 in sasmodels for sasmodels/modelinfo.py
- Timestamp:
- May 4, 2016 11:37:42 PM (8 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:
- 24d5b30
- Parents:
- 13b99fd (diff), 47e498b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/modelinfo.py
r8d62008 rda63656 11 11 from copy import copy 12 12 from os.path import abspath, basename, splitext 13 import inspect 13 14 14 15 import numpy as np # type: ignore … … 609 610 return isinstance(x, str) 610 611 612 613 def _find_source_lines(model_info, kernel_module): 614 """ 615 Identify the location of the C source inside the model definition file. 616 617 This code runs through the source of the kernel module looking for 618 lines that start with 'Iq', 'Iqxy' or 'form_volume'. Clearly there are 619 all sorts of reasons why this might not work (e.g., code commented out 620 in a triple-quoted line block, code built using string concatenation, 621 or code defined in the branch of an 'if' block), but it should work 622 properly in the 95% case, and getting the incorrect line number will 623 be harmless. 624 """ 625 # Check if we need line numbers at all 626 if callable(model_info.Iq): 627 return None 628 629 if (model_info.Iq is None 630 and model_info.Iqxy is None 631 and model_info.form_volume is None): 632 return 633 634 # find the defintion lines for the different code blocks 635 source = inspect.getsource(kernel_module) 636 for k, v in enumerate(source.split('\n')): 637 if v.startswith('Iqxy'): 638 model_info._Iqxy_line = k+1 639 elif v.startswith('Iq'): 640 model_info._Iq_line = k+1 641 elif v.startswith('form_volume'): 642 model_info._form_volume_line = k+1 643 644 611 645 def make_model_info(kernel_module): 612 646 # type: (module) -> ModelInfo … … 654 688 info.control = getattr(kernel_module, 'control', None) 655 689 info.hidden = getattr(kernel_module, 'hidden', None) # type: ignore 690 691 _find_source_lines(info, kernel_module) 656 692 657 693 return info … … 807 843 sesans = None # type: Optional[Callable[[np.ndarray], np.ndarray]] 808 844 845 # line numbers within the python file for bits of C source, if defined 846 _Iqxy_line = 0 847 _Iq_line = 0 848 _form_volume_line = 0 849 850 809 851 def __init__(self): 810 852 # type: () -> None
Note: See TracChangeset
for help on using the changeset viewer.