Changeset 2773c66 in sasmodels for sasmodels/sasview_model.py


Ignore:
Timestamp:
Sep 8, 2018 8:29:05 AM (6 years ago)
Author:
Torin Cooper-Bennun <torin.cooper-bennun@…>
Branches:
master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
ba51e00
Parents:
b763f9d (diff), c88f983 (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.
Message:

Merge branch 'beta_approx' into beta_approx_new_R_eff

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/sasview_model.py

    raa44a6a r2773c66  
    543543            # pylint: disable=unpacking-non-sequence 
    544544            q, phi = x 
    545             return self.calculate_Iq([q*math.cos(phi)], [q*math.sin(phi)])[0] 
    546         else: 
    547             return self.calculate_Iq([x])[0] 
     545            result, _ = self.calculate_Iq([q*math.cos(phi)], [q*math.sin(phi)]) 
     546            return result[0] 
     547        else: 
     548            result, _ = self.calculate_Iq([x]) 
     549            return result[0] 
    548550 
    549551 
     
    560562        """ 
    561563        if isinstance(x, (list, tuple)): 
    562             return self.calculate_Iq([x[0]], [x[1]])[0] 
    563         else: 
    564             return self.calculate_Iq([x])[0] 
     564            result, _ = self.calculate_Iq([x[0]], [x[1]]) 
     565            return result[0] 
     566        else: 
     567            result, _ = self.calculate_Iq([x]) 
     568            return result[0] 
    565569 
    566570    def evalDistribution(self, qdist): 
     
    596600            # Check whether we have a list of ndarrays [qx,qy] 
    597601            qx, qy = qdist 
    598             return self.calculate_Iq(qx, qy) 
     602            result, _ = self.calculate_Iq(qx, qy) 
     603            return result 
    599604 
    600605        elif isinstance(qdist, np.ndarray): 
    601606            # We have a simple 1D distribution of q-values 
    602             return self.calculate_Iq(qdist) 
     607            result, _ = self.calculate_Iq(qdist) 
     608            return result 
    603609 
    604610        else: 
     
    640646        if composition and composition[0] == 'product': # only P*S for now 
    641647            with calculation_lock: 
    642                 self._calculate_Iq(qx) 
    643                 # for compatibility with sasview 4.3 
    644                 results = self._intermediate_results() 
    645                 return results["P(Q)"], results["S(Q)"] 
     648                _, lazy_results = self._calculate_Iq(qx) 
     649                # for compatibility with sasview 4.x 
     650                results = lazy_results() 
     651                pq_data = results.get("P(Q)") 
     652                sq_data = results.get("S(Q)") 
     653                return pq_data, sq_data 
    646654        else: 
    647655            return None 
    648656 
    649     def calculate_Iq(self, qx, qy=None): 
    650         # type: (Sequence[float], Optional[Sequence[float]]) -> np.ndarray 
     657    def calculate_Iq(self, 
     658                     qx,     # type: Sequence[float] 
     659                     qy=None # type: Optional[Sequence[float]] 
     660                     ): 
     661        # type: (...) -> Tuple[np.ndarray, Callable[[], collections.OrderedDict[str, np.ndarray]]] 
    651662        """ 
    652663        Calculate Iq for one set of q with the current parameters. 
     
    656667        This should NOT be used for fitting since it copies the *q* vectors 
    657668        to the card for each evaluation. 
     669 
     670        The returned tuple contains the scattering intensity followed by a 
     671        callable which returns a dictionary of intermediate data from 
     672        ProductKernel. 
    658673        """ 
    659674        ## uncomment the following when trying to debug the uncoordinated calls 
     
    688703        result = calculator(call_details, values, cutoff=self.cutoff, 
    689704                            magnetic=is_magnetic) 
     705        lazy_results = getattr(calculator, 'results', 
     706                               lambda: collections.OrderedDict()) 
    690707        #print("result", result) 
    691         self._intermediate_results = getattr(calculator, 'results', None) 
     708 
    692709        calculator.release() 
    693710        #self._model.release() 
    694         return result 
     711 
     712        return result, lazy_results 
    695713 
    696714    def calculate_ER(self): 
     
    881899    q = np.linspace(-0.35, 0.35, 500) 
    882900    qx, qy = np.meshgrid(q, q) 
    883     result = model.calculate_Iq(qx.flatten(), qy.flatten()) 
     901    result, _ = model.calculate_Iq(qx.flatten(), qy.flatten()) 
    884902    result = result.reshape(qx.shape) 
    885903 
Note: See TracChangeset for help on using the changeset viewer.