def spheredhm(rp, a_p, n_p, n_m, dim, mpp = 0.135, lamb = .447, alpha = False, precision = False, lut = False): """ Compute holographic microscopy image of a sphere immersed in a transparent medium. Args: rp : [x, y, z] 3 dimensional position of sphere relative to center of image. a_p : radius of sphere [micrometers] n_p : (complex) refractive index of sphere n_m : (complex) refractive index of medium dim : [nx, ny] dimensions of image [pixels] NOTE: The imaginary parts of the complex refractive indexes should be positive for absorbing materials. This follows the convention used in SPHERE_COEFFICIENTS. Keywords: precision: alpha: fraction of incident light scattered by particle. Default: 1. lamb: vacuum wavelength of light [micrometers] mpp: micrometers per pixel precision: relative precision with which fields are calculated. Returns: dhm: [nx, ny] holographic image """ nx, ny = dim x = np.tile(np.arange(nx, dtype = float), ny) y = np.repeat(np.arange(ny, dtype = float), nx) x -= float(nx)/2. + float(rp[0]) y -= float(ny)/2. + float(rp[1]) if lut: rho = np.sqrt(x**2 + y**2) x = np.arange(np.fix(rho).max()+1) y = 0. * x zp = float(rp[2]) field = spherefield(x, y, zp, a_p, n_p, n_m = n_m, cartesian = True, mpp = mpp, lamb = lamb, precision = precision) if alpha: field *= alpha k = 2.0*np.pi/(lamb/np.real(n_m)/mpp) # Compute the sum of the incident and scattered fields, then square. field *= np.exp(np.complex(0.,-k*zp)) field[0,:] += 1.0 image = np.sum(np.real(field*np.conj(field)), axis = 0) if lut: image = np.interpolate(image, rho, cubic=-0.5) return image.reshape(int(ny), int(nx))
def irradiance(self, wavelength): """ Returns spectral irradiance for the given wavelength Units: W/(m–2⋅nm–1) """ if wavelength < self.lambda_min or wavelength > self.lambda_max: return 0.0 if wavelength in self._wavelength: ix = self._wavelength.index(wavelength) return self._irradiance[ix] return interpolate(wavelength, self._wavelength, self._irradiance)
def acc_photon_flux(self, wavelength): """ Returns the cumulative photon flux for the given wavelength Units: cm-2 * s-1 """ if wavelength < self.lambda_min or wavelength > self.lambda_max: return 0.0 if wavelength in self._wavelength: ix = self._wavelength.index(wavelength) return self._acc_photon_flux[ix] return interpolate(wavelength, self._wavelength, self._acc_photon_flux)
def run(self, metricVals, Hvals): # Check if desired H value is within range of H values. if (self.Hmark < Hvals.min()) or (self.Hmark > Hvals.max()): warnings.warn('Desired H value of metric outside range of provided H values.') return None value = np.interpolate([self.Hmark], Hvals, np.mean(metricVals.swapaxes(0, 1))) # Combine Hmark and Value into a structured array to match resultsDB expectations. summaryVal = np.empty(1, dtype=[('name', '|S20'), ('value', float)]) summaryVal['name'] = self.name summaryVal['value'] = value return summaryVal
def run(self, metricVals, Hvals): # Check if desired H value is within range of H values. if (self.Hmark < Hvals.min()) or (self.Hmark > Hvals.max()): warnings.warn('Desired H value of metric outside range of provided H values.') return None nHvals = len(Hvals) nHMetricVals = metricVals.shape[1] if nHvals == nHMetricVals: # Hvals matched the points where the metric values were calculated (clone H distribution). eps = 1.0e-6 # Hvals is an array used for each metric value, # we have to pick out the particular metricValues to use. diffs = np.abs(self.Hmark - Hvals) Hidx = np.where(diffs == diffs.min())[0] result = metricVals.swapaxes(0,1)[Hidx] Hmark = Hvals[Hidx] self.name = 'Value At H=%.1f' %(Hmark) else: # We have a range of metric values, one per Hval. result = np.interpolate([self.Hmark], Hvals, metricVals.swapaxes(0, 1)) return result
def interpolate_times(keyvals, len_data_times, data_times=None, times=None): return np.interpolate(np.arange(len_data_times), data_times, times, method='nearest')
def spheredhm(rp, a_p, n_p, n_m, dim, mpp=0.135, lamb=.447, alpha=False, precision=False, lut=False): """ Compute holographic microscopy image of a sphere immersed in a transparent medium. Args: rp : [x, y, z] 3 dimensional position of sphere relative to center of image. a_p : radius of sphere [micrometers] n_p : (complex) refractive index of sphere n_m : (complex) refractive index of medium dim : [nx, ny] dimensions of image [pixels] NOTE: The imaginary parts of the complex refractive indexes should be positive for absorbing materials. This follows the convention used in SPHERE_COEFFICIENTS. Keywords: precision: alpha: fraction of incident light scattered by particle. Default: 1. lamb: vacuum wavelength of light [micrometers] mpp: micrometers per pixel precision: relative precision with which fields are calculated. Returns: dhm: [nx, ny] holographic image """ nx, ny = dim x = np.tile(np.arange(nx, dtype=float), ny) y = np.repeat(np.arange(ny, dtype=float), nx) x -= float(nx) / 2. + float(rp[0]) y -= float(ny) / 2. + float(rp[1]) if lut: rho = np.sqrt(x**2 + y**2) x = np.arange(np.fix(rho).max() + 1) y = 0. * x zp = float(rp[2]) field = spherefield(x, y, zp, a_p, n_p, n_m=n_m, cartesian=True, mpp=mpp, lamb=lamb, precision=precision) if alpha: field *= alpha k = 2.0 * np.pi / (lamb / np.real(n_m) / mpp) # Compute the sum of the incident and scattered fields, then square. field *= np.exp(np.complex(0., -k * zp)) field[0, :] += 1.0 image = np.sum(np.real(field * np.conj(field)), axis=0) if lut: image = np.interpolate(image, rho, cubic=-0.5) return image.reshape(int(ny), int(nx))
def absorption(self, wavelength): if wavelength in self._lambda: ix = self._lambda.index(wavelength) return self._alpha[ix] return interpolate(wavelength, self._lambda, self._alpha)
def extinction(self, wavelength): if wavelength in self._lambda: ix = self._lambda.index(wavelength) return self._k[ix] return interpolate(wavelength, self._lambda, self._k)
def refraction(self, wavelength): if wavelength in self._lambda: ix = self._lambda.index(wavelength) return self._n[ix] return interpolate(wavelength, self._lambda, self._n)
def tag_cloud(self, count=100): m = site.tags.most_common(count) counts = [count for tag, count in m] return sorted( [(tag, interpolate(count, (min(counts), max(counts)), (50, 150))) for (tag, count) in m], key=lambda l: l[0] )
def tag_cloud(self, count=100): m = site.tags.most_common(count) counts = [count for tag,count in m] return sorted([(tag,interpolate(count, (min(counts), max(counts)), (50, 150))) for (tag,count) in m], key=lambda l:l[0])