Changeset ecc58e72 in sasview for sansmodels/src/sans
- Timestamp:
- Aug 7, 2009 11:17:18 PM (15 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- d9dc518
- Parents:
- 26e4a24
- Location:
- sansmodels/src/sans/models
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansmodels/src/sans/models/BaseComponent.py
r26e4a24 recc58e72 60 60 """ 61 61 Evaluate a distribution of q-values. 62 A list of either scale q-values or [qx,qy] doublets 63 are assumed. The allowed data types for the doublets are 64 the same as for run() and runXY(). 65 66 Since the difference between scale and vector q-values 67 are dealt with in runXY(), we pass along the values 68 as-is. 69 70 @param qdist: list of scalar q-values or list of [qx,qy] doublets 71 """ 72 q_array = numpy.asarray(qdist) 73 iq_array = numpy.zeros(len(q_array)) 74 for i in xrange(len(q_array)): 75 iq_array[i] = self.runXY(q_array[i]) 76 77 return iq_array 62 63 * For 1D, a numpy array is expected as input: 64 65 evalDistribution(q) 66 67 where q is a numpy array. 68 69 70 * For 2D, a list of numpy arrays are expected: [qx_prime,qy_prime]. 71 72 For the following matrix of q_values [qx,qy], we will have: 73 +--------+--------+--------+ 74 qy[2] | | | | 75 +--------+--------+--------+ 76 qy[1] | | | | 77 +--------+--------+--------+ 78 qy[0] | | | | 79 +--------+--------+--------+ 80 qx[0] qx[1] qx[2] 81 82 83 The q-values must be stored in numpy arrays. 84 The qxprime and qyprime are 2D arrays. From the two lists of q-values 85 above, numpy arrays must be created the following way: 86 87 qx_prime = numpy.reshape(qx, [3,1]) 88 qy_prime = numpy.reshape(qy, [1,3]) 89 90 The method is then called the following way: 91 92 evalDistribution([qx_prime, qy_prime]) 93 94 @param qdist: ndarray of scalar q-values or list [qx,qy] where qx,qy are 2D ndarrays 95 """ 96 if qdist.__class__.__name__ == 'list': 97 # Check whether we have a list of ndarrays [qx,qy] 98 if len(qdist)!=2 or \ 99 qdist[0].__class__.__name__ != 'ndarray' or \ 100 qdist[1].__class__.__name__ != 'ndarray': 101 raise RuntimeError, "evalDistribution expects a list of 2 ndarrays" 102 103 # Extract qx and qy for code clarity 104 qx = qdist[0] 105 qy = qdist[1] 106 107 # Create output array 108 iq_array = numpy.zeros([qx.shape[0], qy.shape[1]]) 109 110 for i in range(qx.shape[0]): 111 for j in range(qy.shape[1]): 112 iq_array[i][j] = self.runXY([qx[i][0],qy[0][j]]) 113 return iq_array 114 115 elif qdist.__class__.__name__ == 'ndarray': 116 # We have a simple 1D distribution of q-values 117 iq_array = numpy.zeros(len(qdist)) 118 for i in range(len(qdist)): 119 iq_array[i] = self.runXY(qdist[i]) 120 return iq_array 121 122 else: 123 mesg = "evalDistribution is expecting an ndarray of scalar q-values" 124 mesg += " or a list [qx,qy] where qx,qy are 2D ndarrays." 125 raise RuntimeError, mesg 78 126 79 127 def clone(self):
Note: See TracChangeset
for help on using the changeset viewer.