Skip to content

Commit 2f5b525

Browse files
authored
Merge pull request #27 from lightwave-lab/development
Signing off version 1.1
2 parents 3889fc6 + e83109d commit 2f5b525

33 files changed

+1088
-153
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
dev-requirements-temp.txt
44
test*.json
55
labstate*.json
6+
.vscode
67

78
# compiled data
89
data/*

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ default: help ;
1717

1818
venv: venv/bin/activate
1919
venv/bin/activate:
20-
test -e venv/bin/activate || virtualenv -p python3 --prompt "(lightlab-venv) " --distribute venv
20+
test -e venv/bin/activate || virtualenv -p python3 --prompt "(lightlab-venv) " venv
2121
touch venv/bin/activate
2222

2323
devbuild: venvinfo/devreqs~

docs/_static/misc/mergeWithNotebooks.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ Interactive tutorials are in notebooks. A full "experiment" in the lab is contai
88
Jupyter notebooks have two sections: inputs (code, markdown) and outputs (stdout, plots, images). Interactive python notebook files embed compiled outputs. This is good if you want to restart a kernel but still see the output, or if you close the file, etc.
99

1010
### Solution 1 and Problem 2: The nbstripout filter
11-
This is a cool thing that is integrated within the git commands. It basically ignores all of the outputs and metadata of `.ipynb` files. When you commit and push, it only pushes the inputs. It is installed via the requirements.txt, but there is also some interesting [discussion](https://stackoverflow.com/questions/18734739/using-ipython-notebooks-under-version-control/20844506) and [documentation](https://github.com/toobaz/ipynb_output_filter)
11+
`nbstripout` is a Git filter and "hides" the output and some metadata in `.ipynb` files from Git such that it does not get committed. This allows only tracking the actual input code cells in Git. It is installed via the `requirements.txt`, but there is also some interesting [discussion](https://stackoverflow.com/questions/18734739/using-ipython-notebooks-under-version-control/20844506) and [documentation](https://github.com/kynan/nbstripout)
1212

1313
#### There are three downsides:
1414
1. What if you liked keeping those outputs without rerunning every commit?
1515
2. It has to strip evvverything, including all those high-quality graphics, every single time you `git status`.
1616
3. It crashes your essential commands. Very easy to get into a chicken-and-egg hole where you can't `diff` anything because __some__thing isn't JSON -- causing a crash -- but you can't figure out what isn't JSON because you can't see which files just changed.
17-
4. It corrupts your files. That's why we made cleannbline.
17+
4. It can corrupt files. That's why we made `cleannbline`.
1818

1919
### Solution 2. Deactivate the nbstripout filter
2020

@@ -75,13 +75,13 @@ Run
7575

7676
git status
7777

78-
It takes some time. What is that error? It means that some of the notebooks are not sufficiently JSON for the nbstripout filter.
78+
It takes some time. What is that error? It means that some of the notebooks are not valid JSON and cannot be parsed by the `nbstripout` filter.
7979

8080
In the crash log, it should point to a certain file, let's say `notebooks/Test.ipynb` First, clean it with
8181

8282
./cleannbline notebooks/Test.ipynb
8383

84-
Then, open that file in Sublime and search for `<<<<`. Sometimes conflicts in your stash can get hidden in a way that does not show up in Jupyter. nbstripout will crash. You can find it in Sublime.
84+
Then, open that file in Sublime and search for `<<<<`. Sometimes conflicts in your stash can get hidden in a way that does not show up in Jupyter. `nbstripout` will crash. You can find it in Sublime.
8585

8686
Return to running `git status` until it completes without error. It should show a ton of modifications: those are the effects of stripping. Add those and commit
8787

@@ -95,13 +95,13 @@ Your filter is currently active, so when you try
9595

9696
it will automatically crash. As above though, it will point to a file. Keep going until `git status` completes. Add those and commit.
9797

98-
Side note: even though `git status` shows a ton of modifications, you should get a clean `git diff` (Although sometimes it will just crash, NBD). Both commands are applying the ipynb filter... in some way.
98+
Side note: even though `git status` shows a ton of modifications, you should get a clean `git diff` (Although sometimes it will just crash, NBD). Both commands are applying the `.ipynb` filter... in some way.
9999

100100
#### Do the merge
101101
git checkout test_merge_cool-feature-into-development
102102
git merge cool-feature
103103

104-
You will get conflicts in two categories: notebooks and other. Since there are `<<<<` things everywhere, your `git diff` will crash while you're in the merge. It also doesn't point you to an offending file. Here is where you'll really appreciate Sublime.
104+
You will get conflicts in two categories: notebooks and other. Since there are `<<<<` conflict markers everywhere, your `git diff` will crash while you're in the merge. It also doesn't point you to an offending file. Here is where you'll really appreciate Sublime.
105105

106106
Make sure Sublime opens the entire `notebooks` _directory_. That way Find All will search all the files.
107107

@@ -116,7 +116,7 @@ Repeat for all the notebooks. Then do the same for all the regular code files. W
116116

117117
git commit
118118

119-
If for some reason, you want to escape the merge while keeping the test_merge branch stripped, you can run `git reset --hard`
119+
If for some reason, you want to abandon the merge while keeping the test_merge branch stripped, you can run `git reset --hard`
120120

121121
#### Finalize
122122
Double check that everything went well (i.e. open some notebooks in Jupyter). If something screwed up in your merging _or_ stripping, you can just delete the test_merge branch and start over.

lightlab/equipment/abstract_drivers/TekScopeAbstract.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def _triggerAcquire(self, timeout=None):
153153
if timeout is None:
154154
timeout = self.timeout / 1e3
155155
if timeout > 60:
156-
logger.warning(f'Long timeout {timeout} specified, testing')
156+
logger.warning('Long timeout %s specified, testing', timeout)
157157
old_avgCnt = self.timebaseConfig()['avgCnt']
158158
self.timebaseConfig(avgCnt=2)
159159
self._triggerAcquire(timeout=10)

lightlab/equipment/abstract_drivers/configurable.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from lightlab import visalogger as logger
22
from pyvisa import VisaIOError
33
from contextlib import contextmanager
4-
import dpath
4+
import dpath.util
55
import json
66
from numpy import floor
77
from pathlib import Path
@@ -149,6 +149,7 @@ def transfer(self, source, subgroup=''):
149149
raise Exception('Invalid source for transfer. Got ' + str(type(source)))
150150
commands = sCon.getList(subgroup=subgroup)
151151
self.setList(commands)
152+
return self
152153

153154
@classmethod
154155
def fromFile(cls, fname, subgroup=''):

lightlab/equipment/abstract_drivers/electrical_sources.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ def _checkMode(cls, mode):
4343
'''
4444
if mode not in cls.supportedModes:
4545
raise TypeError('Invalid mode: ' + str(mode) + '. Valid: ' + str(cls.supportedModes))
46-
else:
47-
return mode.lower()
46+
47+
return mode.lower()
4848

4949
@classmethod
5050
def val2baseUnit(cls, value, mode):

lightlab/equipment/lab_instruments/Agilent_N5222A_NA.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def spectrum(self):
198198

199199
self.setConfigParam('FORM', 'ASC')
200200
self.open()
201-
dbm = self.mbSession.query_ascii_values('CALC{}:DATA? FDATA'.format(self.chanNum))
201+
dbm = self.query_ascii_values('CALC{}:DATA? FDATA'.format(self.chanNum))
202202
self.close()
203203

204204
fStart = float(self.getConfigParam('SENS:FREQ:STAR'))

lightlab/equipment/lab_instruments/Anritsu_MP1763B_PPG.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from . import VISAInstrumentDriver
22
from lightlab.equipment.abstract_drivers import Configurable
33
from lightlab.laboratory.instruments import PulsePatternGenerator
4+
from lightlab.util.data.one_dim import prbs_pattern
45
import warnings
56
import numpy as np
67
import matplotlib.pyplot as plt
@@ -10,7 +11,7 @@ class Anritsu_MP1763B_PPG(VISAInstrumentDriver, Configurable):
1011
''' ANRITSU MP1761A PulsePatternGenerator
1112
The PPG MP1763B at Alex's bench, which also support MP1761A (by Hsuan-Tung 07/27/2017)
1213
13-
Manual?
14+
Manual (MP1763C): http://www.otntech.com/modules/catalogue/download.php?id=52&mode=download&file_name=MP1763C.pdf
1415
1516
Usage: :any:`/ipynbs/Hardware/PulsePatternGenerator.ipynb`
1617
@@ -182,7 +183,8 @@ def bitseq(self, chpulses, clockfreq, ext=0, addplot=False, mult=1, res=5):
182183
# delay channel (D=0) outputs the (P=N) set of pulses, the second min. delay channel (D=1)
183184
# outputs the (P=N-1) set of pulses, etc.
184185
# As a result, each pulse receives an inverse channel delay: K - current_delay + pulsePosition, for some K.
185-
# We set K to max(delay) since that sets the last channel [max(delay)] at the beginning of the pattern.
186+
# We set K to max(delay) since that sets the last channel [max(delay)] at
187+
# the beginning of the pattern.
186188

187189
pIndex = int(np.round((max(chpulses.keys()) - delay + pulsePos) * clockfreq))
188190
# add pulse to pattern at correct delay
@@ -206,3 +208,37 @@ def circ_time(T, pattern):
206208
plt.legend()
207209

208210
return pattern
211+
212+
@classmethod
213+
def PRBS_pattern(cls, order, mark_ratio=0.5):
214+
# Documentation present in page 5-1 of the manual.
215+
if mark_ratio != 0.5:
216+
raise NotImplementedError("Only mark ratio of 1/2 is implemented so far.")
217+
218+
# The seed corresponds to the first digits in the bit sequence
219+
# presented on the PPG (inverted order)
220+
if order == 7:
221+
polynomial = 0b10000011 # 1 + X^6 + X^7
222+
seed = 0b1000000
223+
elif order == 9:
224+
polynomial = 0b1000010001 # 1 + X^5 + X^9
225+
seed = 0b111100000
226+
elif order == 11:
227+
polynomial = 0b100000000101 # 1+X9+X11
228+
seed = 0b11000000000
229+
elif order == 15:
230+
polynomial = 0b1000000000000011 # 1+X14+X15
231+
seed = 0b000000000000001
232+
elif order == 20:
233+
polynomial = (1 << 20) + (1 << 20 - 3) + (1 << 20 - 20) # 1+X3+X20
234+
seed = 0b00111000111000111000
235+
elif order == 23:
236+
polynomial = (1 << 23) + (1 << 23 - 18) + (1 << 23 - 23) # 1+X18+X23
237+
seed = 0b1111100 << 16
238+
elif order == 31:
239+
polynomial = (1 << 31) + (1 << 31 - 28) + (1 << 31 - 31) # 1+X28+X31
240+
seed = 0b1110000 << 24
241+
else:
242+
raise NotImplementedError("PRBS{} not implemented.".format(order))
243+
244+
return prbs_pattern(polynomial, seed)

lightlab/equipment/lab_instruments/Apex_AP2440A_OSA.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,14 @@ def transferData(self):
190190

191191
dataLen = int(powerData[0])
192192
powerData = np.array(powerData[1:])
193-
wavelengthData = np.linspace(self.wlRange[1], self.wlRange[0], dataLen)
193+
retStr = self._query('SPDATAWL0')
194+
wavelengthData = pyvisa.util.from_ascii_block(retStr,
195+
converter='f',
196+
separator=' ',
197+
container=list)
198+
assert dataLen == wavelengthData[0]
199+
wavelengthData = np.array(wavelengthData[1:])
200+
# wavelengthData = np.linspace(self.wlRange[1], self.wlRange[0], dataLen)
194201

195202
return wavelengthData[::-1], powerData[::-1]
196203

@@ -205,7 +212,7 @@ def spectrum(self, average_count=1):
205212
self.triggerAcquire()
206213
nm, dbm = self.transferData()
207214

208-
if i is 0:
215+
if i == 0:
209216
dbmAvg = dbm / average_count
210217
else:
211218
dbmAvg = dbmAvg + dbm / average_count

lightlab/equipment/lab_instruments/Keithley_2400_SM.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,6 @@ def enable(self, newState=None):
164164
else:
165165
self.setVoltage(0)
166166
if newState is not None:
167-
self.setConfigParam('OUTP:STATE', 1 if newState else 0)
167+
self.setConfigParam('OUTP:STATE', 1 if newState else 0, forceHardware=True)
168168
retVal = self.getConfigParam('OUTP:STATE', forceHardware=True)
169169
return retVal in ['ON', 1, '1']

0 commit comments

Comments
 (0)