Changeset 6824af5 in sasmodels for example/sesansfit.py
- Timestamp:
- Mar 17, 2016 10:48:04 AM (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:
- 8898d0f, bdb653c
- Parents:
- 84db7a5 (diff), 54954e1 (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
-
example/sesansfit.py
ra98958b r84db7a5 1 #TODO: Convert units properly (nm -> A)2 #TODO: Implement constraints3 4 1 from bumps.names import * 5 from sasmodels import core, bumps_model 2 from sasmodels import core, bumps_model, sesans 6 3 7 4 HAS_CONVERTER = True … … 11 8 HAS_CONVERTER = False 12 9 13 def sesans_fit(file, model_name, initial_vals={}, custom_params={}, param_range=[]): 10 def get_bumps_model(model_name): 11 kernel = core.load_model(model_name) 12 model = bumps_model.Model(kernel) 13 return model 14 15 def sesans_fit(file, model, initial_vals={}, custom_params={}, param_range=[]): 14 16 """ 15 16 17 @param file: SESANS file location 17 @param model _name: model name string- can be model, model_1 * model_2, and/or model_1 + model_218 @param model: Bumps model object or model name - can be model, model_1 * model_2, and/or model_1 + model_2 18 19 @param initial_vals: dictionary of {param_name : initial_value} 19 20 @param custom_params: dictionary of {custom_parameter_name : Parameter() object} 20 21 @param param_range: dictionary of {parameter_name : [minimum, maximum]} 22 @param constraints: dictionary of {parameter_name : constraint} 21 23 @return: FitProblem for Bumps usage 22 24 """ … … 29 31 default_unit = "A" 30 32 data_conv_q = Converter(data._xunit) 33 for x in data.x: 34 print x 31 35 data.x = data_conv_q(data.x, units=default_unit) 36 for x in data.x: 37 print x 32 38 data._xunit = default_unit 33 39 … … 51 57 data = SESANSData1D() 52 58 53 radius = 1000 59 if "radius" in initial_vals: 60 radius = initial_vals.get("radius") 61 else: 62 radius = 1000 54 63 data.Rmax = 3*radius # [A] 55 64 56 kernel = core.load_model(model_name)57 model = bumps_model.Model(kernel)65 if isinstance(model, basestring): 66 model = get_bumps_model(model) 58 67 59 # Load custom parameters, initial values and parameter constraints68 # Load custom parameters, initial values and parameter ranges 60 69 for k, v in custom_params.items(): 61 70 setattr(model, k, v) … … 69 78 setattr(param.bounds, "limits", v) 70 79 71 if False: # have sans data80 if False: # for future implementation 72 81 M_sesans = bumps_model.Experiment(data=data, model=model) 73 82 M_sans = bumps_model.Experiment(data=sans_data, model=model)
Note: See TracChangeset
for help on using the changeset viewer.