MCPcopy Create free account
hub / github.com/danieljfarrell/pvtrace / component

Method component

pvtrace/material/material.py:49–63  ·  view source on GitHub ↗

Monte-Carlo sampling to find which component captures the ray.

(self, wavelength: float)

Source from the content-addressed store, hash-verified

47 return depth
48
49 def component(self, wavelength: float) -> Component:
50 """ Monte-Carlo sampling to find which component captures the ray.
51 """
52 coefs = np.array([x.coefficient(wavelength) for x in self.components])
53 if np.any(coefs < 0.0):
54 raise ValueError("Must be positive.")
55 count = len(self.components)
56 bins = list(range(0, count + 1))
57 cdf = np.cumsum(coefs)
58 pdf = cdf / max(cdf)
59 pdf = np.hstack([0, pdf[:]])
60 pdfinv_lookup = np.interp(np.random.uniform(), pdf, bins)
61 index = int(np.floor(pdfinv_lookup))
62 component = self.components[index]
63 return component

Callers 1

followFunction · 0.80

Calls 1

coefficientMethod · 0.80

Tested by

no test coverage detected