Skip to content

Commit ef5ec58

Browse files
committed
Fix linting and stuff
1 parent 935e86d commit ef5ec58

File tree

4 files changed

+35
-16
lines changed

4 files changed

+35
-16
lines changed

adc_eval/adcs/sar.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class SAR(ADC):
3636
Sets or returns the capacitor weighting of the array. Default is binary weighting.
3737
mismatch : float
3838
Sets or returns the stdev of the mismatch of the converter. Default is no mismatch.
39+
comp_noise : float
40+
Sets or returns the stdev of the comparator noise. Default is no noise.
3941
offset : tuple of float
4042
Sets the (mean, stdev) of the offset of the converter. Default is no offset.
4143
gain_error : tuple of float
@@ -57,25 +59,28 @@ def __init__(self, nbits=8, fs=1, vref=1, seed=1, **kwargs):
5759
super().__init__(nbits, fs, vref, seed)
5860

5961
self._mismatch = None
62+
self._comp_noise = 0
6063

6164
# Get keyword arguments
6265
self._weights = kwargs.get("weights", None)
63-
66+
6467
@property
6568
def weights(self):
6669
"""Returns capacitor unit weights."""
6770
if self._weights is None:
68-
self._weights = np.flip(2**np.linspace(0, self.nbits-1, self.nbits))
71+
self._weights = np.flip(2 ** np.linspace(0, self.nbits - 1, self.nbits))
6972
return np.array(self._weights)
7073

7174
@weights.setter
7275
def weights(self, values):
7376
"""Sets the capacitor unit weights."""
7477
self._weights = np.array(values)
7578
if self._weights.size < self.nbits:
76-
print(f"WARNING: Capacitor weight array size is {self._weights.size} for {self.nbits}-bit ADC.")
79+
print(
80+
f"WARNING: Capacitor weight array size is {self._weights.size} for {self.nbits}-bit ADC."
81+
)
7782
self.mismatch = self.err["mismatch"]
78-
83+
7984
@property
8085
def mismatch(self):
8186
"""Return noise stdev."""
@@ -90,24 +95,34 @@ def mismatch(self, stdev):
9095
self._mismatch = np.random.normal(0, stdev, self.weights.size)
9196
self._mismatch /= np.sqrt(self.weights)
9297

98+
@property
99+
def comp_noise(self):
100+
"""Returns the noise of the comparator."""
101+
return self._comp_noise
102+
103+
@comp_noise.setter
104+
def comp_noise(self, value):
105+
"""Sets the noise of the comparator."""
106+
self._comp_noise = value
107+
93108
def run_step(self):
94109
"""Run a single ADC step."""
95110
vinx = self.vin
96-
111+
97112
cweights = self.weights * (1 + self.mismatch)
98113
cdenom = sum(cweights) + 1
99-
100-
comp_noise = np.random.normal(0, self.err["noise"], cweights.size)
101-
114+
115+
comp_noise = np.random.normal(0, self.comp_noise, cweights.size)
116+
102117
# Bit cycling
103118
vdac = vinx
104-
for n in range(len(cweights)):
105-
vcomp = vdac - self.vref / 2
119+
for n, _ in enumerate(cweights):
120+
vcomp = vdac - self.vref / 2 + comp_noise[n]
106121
compout = vcomp * 1e6
107122
compout = -1 if compout <= 0 else 1
108123
self.dbits[n] = max(0, compout)
109124
vdac -= compout * self.vref / 2 * cweights[n] / cdenom
110-
125+
111126
# Re-scale the data
112127
scalar = 2**self.nbits / cdenom
113-
self.dval = min(2**self.nbits-1, scalar * sum(self.weights * self.dbits))
128+
self.dval = min(2**self.nbits - 1, scalar * sum(self.weights * self.dbits))

adc_eval/signals.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,17 @@ def tones(nlen, bins, amps, offset=0, fs=1, nfft=None, phases=None):
119119
Time-series and associated tone array.
120120
"""
121121
t = time(nlen, fs=fs)
122-
122+
123123
signal = np.zeros(nlen)
124124
if phases is None:
125125
phases = np.zeros(nlen)
126126
if nfft is None:
127127
nfft = nlen
128-
128+
129129
fbin = fs / nfft
130130
for index, nbin in enumerate(bins):
131-
signal += sin(t, amp=amps[index], offset=offset, freq=nbin*fbin, ph0=phases[index])
131+
signal += sin(
132+
t, amp=amps[index], offset=offset, freq=nbin * fbin, ph0=phases[index]
133+
)
132134

133-
return (t, signal)
135+
return (t, signal)

pylintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ disable=
99
duplicate-code,
1010
implicit-str-concat,
1111
too-many-arguments,
12+
too-many-positional-arguments,
1213
too-many-branches,
1314
too-many-instance-attributes,
1415
too-many-locals,

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ ignore = [
7373
"PLR0912", # Too many branches ({branches} > {max_branches})
7474
"PLR0913", # Too many arguments to function call ({c_args} > {max_args})
7575
"PLR0915", # Too many statements ({statements} > {max_statements})
76+
"PLR0917", # Too many positional arguments
7677
"PLR2004", # Magic value used in comparison, consider replacing {value} with a constant variable
7778
"PLW2901", # Outer {outer_kind} variable {name} overwritten by inner {inner_kind} target
7879
"T201", # Allow print statements

0 commit comments

Comments
 (0)