Comments by "Dr Gamma D" (@DrDeuteron) on "Indently"
channel.
-
37
-
35
-
29
-
27
-
23
-
21
-
21
-
16
-
14
-
10
-
9
-
9
-
slice is fantastic. I have a complicated space instrument with around 500 channels, and it comes in so fast the electronics can't keep up, so there are 4 separate amplifier chains...which are all identical. but of course they aren't, so each needs to be calibrated separately, The guys were doing it in Matlab with handwritten if chain=='north': idx = [1, 5, ...] else./...repeated everywhere.
So I enlightened them (oh, and it had a time stamp in position 0), so I just made a dictionary of slice object vs amplifier chain (named after the cardinal directions):
AMP = dict(time=slice(0,1), north=slice(1, None, 4), east=slice(2, None, 4), south=(3, None, 4), west=(4, None, 4))
so a
calibration = {amp: sensor.data[AMP[amp]].mean() for amp in ('north', 'east', 'south', 'west')}
gave me a dictionary of time stamped calibration sample averages (when the system was in calibration mode). Then you save that and scale environmental data until the next cal measurment 2 seconds later.
`No ifs, no loops. cyclomatic complexity minimized. Nothing is WETT (write everything twice), it's all DRY (don't repeat yourself).
9
-
9
-
8
-
8
-
8
-
7
-
7
-
7
-
6
-
6
-
6
-
6
-
6
-
6
-
6
-
6
-
5
-
5
-
when I write code that is a tool, let's say something about LEO assets... when python goes wrong, I throw a builtin exception, (and if it;s I/O, I import errors and figure out which I/O thing went wrong), but if it's a domain specific user mistake, I send a custom exception. for example, they set orbit altitude to 2000 km, I'll throw a:
>>>class LEOAltitude(ValueError):
telling them LEO is 200 - 1600 km.
If it's more general, I may go nuts and have an mro that looks like:
LEOAltitudeError [or MEO, GEO]
AltitudeError. [or Inclination, RightAscension, Eccentricity, MeanAnomaly, ...]
OrbitParameterError [or Epoch or Classification... any thing in aTwo Line Element]
ValueError. [now it's python's mro from here on out]
StandardError
Exception
BaseException
object
5
-
5
-
5
-
4
-
4
-
4
-
4
-
4
-
3
-
3
-
3
-
3
-
3
-
3
-
3
-
3
-
3
-
3
-
3
-
3