Changeset e78edc4 in sasmodels


Ignore:
Timestamp:
Apr 14, 2016 8:41:17 AM (8 years ago)
Author:
Paul Kienzle <pkienzle@…>
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:
7abcc59
Parents:
62cf915
git-author:
Paul Kienzle <pkienzle@…> (04/14/16 08:37:03)
git-committer:
Paul Kienzle <pkienzle@…> (04/14/16 08:41:17)
Message:

add -zero option to test q=0

Location:
sasmodels
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/compare.py

    rf247314 re78edc4  
    5858    -lowq*/-midq/-highq/-exq use q values up to 0.05, 0.2, 1.0, 10.0 
    5959    -nq=128 sets the number of Q points in the data set 
     60    -zero indicates that q=0 should be included 
    6061    -1d*/-2d computes 1d or 2d data 
    6162    -preset*/-random[=seed] preset or random parameters 
     
    476477        index = ~data.mask 
    477478    else: 
    478         if opts['view'] == 'log': 
     479        if opts['view'] == 'log' and not opts['zero']: 
    479480            qmax = math.log10(qmax) 
    480481            q = np.logspace(qmax-3, qmax, nq) 
    481482        else: 
    482483            q = np.linspace(0.001*qmax, qmax, nq) 
     484        if opts['zero']: 
     485            q = np.hstack((0, q)) 
    483486        data = empty_data1D(q, resolution=res) 
    484487        index = slice(None, None) 
     
    498501    else: 
    499502        return eval_opencl(model_info, data, dtype=dtype, cutoff=cutoff) 
     503 
     504def _show_invalid(data, theory): 
     505    if not theory.mask.any(): 
     506        return 
     507 
     508    if hasattr(data, 'x'): 
     509        bad = zip(data.x[theory.mask], theory[theory.mask]) 
     510        print("   *** ", ", ".join("I(%g)=%g"%(x, y) for x,y in bad)) 
     511 
    500512 
    501513def compare(opts, limits=None): 
     
    519531        try: 
    520532            base_value, base_time = time_calculation(base, pars, Nbase) 
     533            base_value = np.ma.masked_invalid(base_value) 
    521534            print("%s t=%.2f ms, intensity=%.0f" 
    522                   % (base.engine, base_time, sum(base_value))) 
     535                  % (base.engine, base_time, base_value.sum())) 
     536            _show_invalid(data, base_value) 
    523537        except ImportError: 
    524538            traceback.print_exc() 
     
    530544        try: 
    531545            comp_value, comp_time = time_calculation(comp, pars, Ncomp) 
     546            comp_value = np.ma.masked_invalid(comp_value) 
    532547            print("%s t=%.2f ms, intensity=%.0f" 
    533                   % (comp.engine, comp_time, sum(comp_value))) 
     548                  % (comp.engine, comp_time, comp_value.sum())) 
     549            _show_invalid(data, comp_value) 
    534550        except ImportError: 
    535551            traceback.print_exc() 
     
    554570        vmin, vmax = np.Inf, -np.Inf 
    555571        if Nbase > 0: 
    556             vmin = min(vmin, min(base_value)) 
    557             vmax = max(vmax, max(base_value)) 
     572            vmin = min(vmin, base_value.min()) 
     573            vmax = max(vmax, base_value.max()) 
    558574        if Ncomp > 0: 
    559             vmin = min(vmin, min(comp_value)) 
    560             vmax = max(vmax, max(comp_value)) 
     575            vmin = min(vmin, comp_value.min()) 
     576            vmax = max(vmax, comp_value.max()) 
    561577        limits = vmin, vmax 
    562578 
     
    581597        if view == 'linear': 
    582598            plt.xscale('linear') 
    583         plt.title("max %s = %.3g"%(errstr, max(abs(err)))) 
     599        plt.title("max %s = %.3g"%(errstr, abs(err).max())) 
    584600        #cbar_title = errstr if errview=="linear" else "log "+errstr 
    585601    #if is2D: 
     
    603619 
    604620def _print_stats(label, err): 
    605     sorted_err = np.sort(abs(err)) 
     621    sorted_err = np.sort(abs(err.compressed())) 
    606622    p50 = int((len(err)-1)*0.50) 
    607623    p98 = int((len(err)-1)*0.98) 
     
    623639    'half', 'fast', 'single', 'double', 
    624640    'single!', 'double!', 'quad!', 'sasview', 
    625     'lowq', 'midq', 'highq', 'exq', 
     641    'lowq', 'midq', 'highq', 'exq', 'zero', 
    626642    '2d', '1d', 
    627643    'preset', 'random', 
     
    700716    try: 
    701717        model_info = core.load_model_info(name) 
    702     except ImportError, exc: 
     718    except ImportError as exc: 
    703719        print(str(exc)) 
    704720        print("Could not find model; use one of:\n    " + models) 
     
    745761        elif arg == '-midq':    opts['qmax'] = 0.2 
    746762        elif arg == '-lowq':    opts['qmax'] = 0.05 
     763        elif arg == '-zero':    opts['zero'] = True 
    747764        elif arg.startswith('-nq='):       opts['nq'] = int(arg[4:]) 
    748765        elif arg.startswith('-res='):      opts['res'] = float(arg[5:]) 
  • sasmodels/data.py

    rd6f5da6 re78edc4  
    380380    use_calc = use_theory and Iq_calc is not None 
    381381    num_plots = (use_data or use_theory) + use_calc + use_resid 
    382  
     382    non_positive_x = (data.x<=0.0).any() 
    383383 
    384384    scale = data.x**4 if view == 'q4' else 1.0 
     
    402402 
    403403        if use_theory: 
     404            # Note: masks merge, so any masked theory points will stay masked, 
     405            # and the data mask will be added to it. 
    404406            mtheory = masked_array(theory, data.mask.copy()) 
    405407            mtheory[~np.isfinite(mtheory)] = masked 
     
    413415            plt.ylim(*limits) 
    414416 
    415         plt.xscale('linear' if not some_present else view) 
     417        plt.xscale('linear' if not some_present or non_positive_x  else view) 
    416418        plt.yscale('linear' 
    417419                   if view == 'q4' or not some_present or not all_positive 
     
    441443        plt.xlabel("$q$/A$^{-1}$") 
    442444        plt.ylabel('residuals') 
    443         plt.xscale('linear' if not some_present else view) 
     445        plt.xscale('linear' if not some_present or non_positive_x else view) 
    444446 
    445447 
  • sasmodels/model_test.py

    r4d76711 re78edc4  
    145145        def _runTest(self): 
    146146            smoke_tests = [ 
     147                # test validity at reasonable values 
    147148                [{}, 0.1, None], 
    148149                [{}, (0.1, 0.1), None], 
     150                # test validity at q = 0 
     151                #[{}, 0.0, None], 
     152                #[{}, (0.0, 0.0), None], 
     153                # test that ER/VR will run if they exist 
    149154                [{}, 'ER', None], 
    150155                [{}, 'VR', None], 
     
    194199                actual = call_kernel(kernel, pars) 
    195200 
    196             self.assertGreater(len(actual), 0) 
     201            self.assertTrue(len(actual) > 0) 
    197202            self.assertEqual(len(y), len(actual)) 
    198203 
Note: See TracChangeset for help on using the changeset viewer.