def model_evaluation(dataframe, classes, datapath='./', filename='results'): pred_chisq = [] alternative_chisq = [] for i in range(len(dataframe)): row = dataframe.iloc[i] filepath = datapath + row[0] + '.csv' data = load_data(filepath) probab = [ item for item in row[3].split('[')[1].split(']')[0].split(' ') if item != '' ] probab = list(map(np.float64, probab)) max_label = [probab.index(x) for x in sorted(probab, reverse=True)[:2]] label = classes[max_label[0]] chi_squared = scat_model(data, label) pred_chisq.append((label, chi_squared)) if probab[max_label[0]] >= 0.7: alternative_chisq.append('-') else: label = classes[max_label[1]] chi_squared = scat_model(data, label) alternative_chisq.append((label, chi_squared)) dataframe['predicted_chi_square'] = pred_chisq dataframe['alternative_chi_square'] = alternative_chisq dataframe.to_csv(filename, index=False) return dataframe
from bumps.names import * from sasmodels.data import load_data from sasmodels.core import load_model from sasmodels.bumps_model import Model, Experiment # Spherical particle data, not ellipsoids sans, usans = load_data('../../sasview/sasview/test/1d_data/latex_smeared.xml') usans.qmin, usans.qmax = np.min(usans.x), np.max(usans.x) usans.mask = (usans.x < 0.0) usans.oriented = True #print sans.dxl, usans.dxl #import pprint; pprint.pprint(sans.__dict__) kernel = load_model("ellipsoid") model = Model( kernel, scale=0.08, background=0, sld=.291, sld_solvent=7.105, r_polar=1800, r_polar_pd=0.222296, r_polar_pd_n=0, r_equatorial=2600, r_equatorial_pd=0.28, r_equatorial_pd_n=0, theta=60, theta_pd=0, theta_pd_n=0, phi=60, phi_pd=0, phi_pd_n=0, ) # SET THE FITTING PARAMETERS model.r_polar.range(1000, 10000) model.r_equatorial.range(1000, 10000) model.theta.range(0, 360) model.phi.range(0, 360)
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys from bumps.names import * from sasmodels.core import load_model from sasmodels.bumps_model import Model, Experiment from sasmodels.data import load_data, set_beam_stop, set_top """ IMPORT THE DATA USED """ radial_data = load_data('DEC07267.DAT') set_beam_stop(radial_data, 0.00669, outer=0.025) set_top(radial_data, -.0185) tan_data = load_data('DEC07266.DAT') set_beam_stop(tan_data, 0.00669, outer=0.025) set_top(tan_data, -.0185) #sas.set_half(tan_data, 'right') name = "ellipsoid" if len(sys.argv) < 2 else sys.argv[1] section = "radial" if len(sys.argv) < 3 else sys.argv[2] if section not in ("radial", "tangential", "both"): raise ValueError("section %r should be 'radial', 'tangential' or 'both'" % section) data = radial_data if section != "tangential" else tan_data theta = 89.9 if section != "tangential" else 0 phi = 90 kernel = load_model(name, dtype="single") cutoff = 1e-3 if name == "ellipsoid": model = Model(
from bumps.names import * from sasmodels.core import load_model from sasmodels.bumps_model import Model, Experiment from sasmodels.data import load_data, plot_data # latex data, same sample usans and sans # particles radius ~2300, uniform dispersity datasets = load_data('latex_smeared.xml', index='all') #[print(data) for data in datasets] # A single sphere model to share between the datasets. We will use # FreeVariables below to set the parameters that are independent between # the datasets. kernel = load_model('sphere') pars = dict( scale=0.01, background=0.0, sld=5.0, sld_solvent=0.0, radius=1500., #radius_pd=0.1, radius_pd_n=35, ) model = Model(kernel, **pars) # radius and polydispersity (if any) are shared model.radius.range(0, inf) #model.radius_pd.range(0, 1) # Contrast and dilution are the same for both measurements, but are not # separable with a single measurement (i.e., I(q) ~ F(q) contrast^2 Vf), # so fit one of scale, sld or solvent sld. With absolute scaling from
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys from bumps.names import * from sasmodels.core import load_model from sasmodels.bumps_model import Model, Experiment from sasmodels.data import load_data, set_beam_stop, set_top """ IMPORT THE DATA USED """ radial_data = load_data('DEC07267.DAT') set_beam_stop(radial_data, 0.00669, outer=0.025) set_top(radial_data, -.0185) kernel = load_model("ellipsoid") model = Model(kernel, scale=0.08, r_polar=15, r_equatorial=800, sld=.291, sld_solvent=7.105, background=0, theta=90, phi=0, theta_pd=15, theta_pd_n=40, theta_pd_nsigma=3, r_polar_pd=0.222296, r_polar_pd_n=1, r_polar_pd_nsigma=0, r_equatorial_pd=.000128, r_equatorial_pd_n=1, r_equatorial_pd_nsigma=0, phi_pd=0, phi_pd_n=20, phi_pd_nsigma=3, ) # SET THE FITTING PARAMETERS model.r_polar.range(15, 1000) model.r_equatorial.range(15, 1000)
sasview.exe bumps.cli multiscatfit.py --store=t1 """ import sys from bumps.names import * from sasmodels.core import load_model from sasmodels.bumps_model import Model, Experiment from sasmodels.data import load_data, set_beam_stop, set_top from sasmodels.multiscat import MultipleScattering ## Load the data #data = load_data('DEC07267.DAT') #set_beam_stop(data, 0.003, outer=0.025) data = load_data('latex_smeared.xml', index=0) ## Define the model kernel = load_model("ellipsoid") model = Model( kernel, scale=0.005, background=0.05, radius_polar=2200, radius_equatorial=2200, sld=.291, sld_solvent=7.105, #theta=90, theta_pd=0, theta_pd_n=0, theta_pd_nsigma=3, #phi=90, phi_pd=0, phi_pd_n=20, phi_pd_nsigma=3, radius_polar_pd=0.222296,
from bumps.names import * from sasmodels.data import load_data from sasmodels.core import load_model from sasmodels.bumps_model import Model, Experiment # Spherical particle data, not ellipsoids sans, usans = load_data('../../sasview/sasview/test/1d_data/latex_smeared.xml') usans.qmin, usans.qmax = np.min(usans.x), np.max(usans.x) usans.mask = (usans.x < 0.0) usans.oriented = True #print sans.dxl, usans.dxl #import pprint; pprint.pprint(sans.__dict__) kernel = load_model("ellipsoid") model = Model( kernel, scale=0.08, background=0, sld=.291, sld_solvent=7.105, r_polar=1800, r_polar_pd=0.222296, r_polar_pd_n=0, r_equatorial=2600, r_equatorial_pd=0.28, r_equatorial_pd_n=0, theta=60, theta_pd=0, theta_pd_n=0,
import sys #sys.path.append('path_to_sasmodels') import numpy as np from bumps.names import * from sasmodels.core import load_model from sasmodels.bumps_model import Model, Experiment from sasmodels.data import load_data, plot_data # IMPORT THE DATA USED data = load_data(sys.argv[1]) #setattr(data, 'qmin', 0.0) #setattr(data, 'qmax', 10.0) # DEFINE THE MODEL kernel = load_model('ellipsoid') pars = dict(scale=0.08, background=35, radius_polar=15, radius_equatorial=800, sld=.291, sld_solvent=7.105, theta=89.9, phi=90, theta_pd=0, theta_pd_n=0, theta_pd_nsigma=3, phi_pd=0,
'P3DDT': 0.316, 'PQT-12': 0.676, #'Polystyrene-D8':6.407, 'Polystyrene-D8': 6.464, # density of 1.13 g/mL 'Polystyrene-H8': 1.426 } # loading data for fitting data_dir = '../../data/sans/Smeared_Data_20200629/' files = os.listdir(data_dir) sans_data = {} usans_data = {} for file in files: if 'USANS' in file: key = int(file.split('_')[0][3:]) usans_data[key] = load_data(data_dir + file) elif 'SANS' in file: key = int(file.split('_')[0][3:]) sans_data[key] = load_data(data_dir + file) # filtering which samples to fit with ellipsoid model true_keys = [] true_reads = pd.read_csv('../../data/sans/Fit_Truths.csv') true_reads = true_reads.to_numpy() mask = true_reads[:, 2].astype(bool) ellipsoid_keys = true_reads[mask, 0] run_keys = list(ellipsoid_keys)
#!/usr/bin/env python # -*- coding: utf-8 -*- # To Sasview/documents/scripts from bumps.names import * from sasmodels.core import load_model from sasmodels.bumps_model import Model, Experiment from sasmodels.data import load_data, plot_data """ IMPORT THE DATA USED """ datafiles = ['latex_smeared_out_0.txt', 'latex_smeared_out_1.txt'] datasets = [load_data(el) for el in datafiles] for data in datasets: data.qmin = 0.0 data.qmax = 10.0 #sphere model kernel = load_model('sphere', dtype="single") pars = dict(scale=0.01, background=0.0, sld=1.0, sld_solvent=6.0, radius=1500.) model = Model(kernel, **pars) model.radius.range(0, inf) #model.background.range(-inf, inf) #model.scale.range(0, inf) model.sld.range(-inf, inf) model.sld_solvent.range(-inf, inf) free = FreeVariables( names=[data.filename for data in datasets], background=model.background, scale=model.scale,
from bumps.names import * from sasmodels.data import load_data from sasmodels.core import load_model from sasmodels.bumps_model import Model, Experiment # Spherical particle data, not ellipsoids sans, usans = load_data('latex_smeared.xml', index='all') usans.qmin, usans.qmax = np.min(usans.x), np.max(usans.x) usans.mask = (usans.x < 0.0) usans.oriented = True #print sans.dxl, usans.dxl #import pprint; pprint.pprint(sans.__dict__) kernel = load_model("ellipsoid") model = Model( kernel, scale=0.08, background=0, sld=.291, sld_solvent=7.105, radius_polar=1800, radius_polar_pd=0.222296, radius_polar_pd_n=0, radius_equatorial=2600, radius_equatorial_pd=0.28, radius_equatorial_pd_n=0, theta=60, theta_pd=0, theta_pd_n=0,