Make laser parameters configurable; utility function for tunable laser - #970
Make laser parameters configurable; utility function for tunable laser#970oczoske wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #970 +/- ##
==========================================
+ Coverage 75.89% 75.92% +0.03%
==========================================
Files 70 70
Lines 9030 9054 +24
==========================================
+ Hits 6853 6874 +21
- Misses 2177 2180 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
teutoburg
left a comment
There was a problem hiding this comment.
See individual comments, but overall fine.
| if not hasattr(wavelength, "__len__"): | ||
| wavelength = [wavelength] |
There was a problem hiding this comment.
I think what you want instead of these hasattr checks is either isinstance(wavelength, Iterable) (from collections.abc import Iterable), or, to do it entirely in one line, wavelength = always_iterable(wavelength) (from more_itertools import always_iterable). Both variants are fine for me.
| def _validate_tunable(self, wave): | ||
| """Validate wave against a wavelength range | ||
|
|
||
| This is currently not used as there is no reliable | ||
| information on the tuning range of the QCL. | ||
| """ | ||
| reject = [] | ||
| accept = [] | ||
| lam_min = 1. | ||
| lam_max = 30. | ||
| for lam in wave: | ||
| if lam < lam_min or lam > lam_max: | ||
| reject.append(lam) | ||
| else: | ||
| accept.append(lam) | ||
| if len(reject) > 0: | ||
| logger.warning("Removed %d wavelengths outside allowed range (%f, %f) um", len(reject), lam_min, lam_max) | ||
| return accept |
There was a problem hiding this comment.
I think this function could be done more elegantly with numpy, instead of that loop. Something like
mask = (lam_min < wave) & (wave < lam_max)
n_rejected = len(wave) - mask.sum()
# warning ...
return wave[mask]Also, I think this needs to either put the lam_min and lam_max into the arguments, or take the values from self.. The currently used defaults could then be stored either in self or as default values for the arguments. If you go with arguments, you can even decorate this with a @staticmethod, because self isn't used anywhere.
| print("Computing laser intensity") | ||
| logger.info("Computing laser intensity") | ||
| lam = self.wavelength | ||
| dlam = lam[1] - lam[0] |
There was a problem hiding this comment.
Does it make sense to check if lam is evenly spaced? Your current dlam silently assumes that I think.
| if not hasattr(self.meta['laser_t_wave'], "__len__"): | ||
| self.meta['laser_t_wave'] = [self.meta['laser_t_wave']] |
| intens_2 = np.sum(bbsource.intens_lamp) | ||
|
|
||
| assert intens_2 / intens_1 == ft_2 / ft_1 | ||
| assert np.allclose(intens_2 / intens_1, ft_2 / ft_1) |
There was a problem hiding this comment.
| assert np.allclose(intens_2 / intens_1, ft_2 / ft_1) | |
| npt.assert_allclose(intens_2 / intens_1, ft_2 / ft_1) |
The laser parameters (wavelength, power) are now taken from
wcu.meta, i.e. from a config file or from kwargs.All parameters can be changed by doing, e.g.
set_lampis necessary to recompute the lamp emission.The wavelengths of the tunable laser should be more easily accessible to the user, therefore a utility method is offered (this recomputes the emission automatically):
A validation method for the wavelengths has been implemented but is not yet used as we do not have reliable information on the actually available wavelength range.