Skip to content

Commit b3d65c8

Browse files
authored
Merge pull request #127 from dihm/destar_imports
Remove star imports from documentation
2 parents af528f1 + c59c095 commit b3d65c8

6 files changed

Lines changed: 85 additions & 42 deletions

File tree

docs/listing_1.py

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,46 @@
1-
from lyse import *
1+
from lyse import Run, data, path
2+
import matplotlib.pyplot as plt
3+
4+
# Let's obtain our data for this shot -- globals, image attributes and
5+
# the results of any previously run single-shot routines:
6+
ser = data(path)
7+
8+
# Get a global called x:
9+
x = ser['x']
10+
11+
# Get a result saved by another single-shot analysis routine which has
12+
# already run. The result is called 'y', and the routine was called
13+
# 'some_routine':
14+
y = ser['some_routine','y']
15+
16+
# Image attributes are also stored in this series:
17+
w_x2 = ser['side','absorption','OD','Gaussian_XW']
18+
19+
# If we want actual measurement data, we'll have to instantiate a Run object:
20+
run = Run(path)
21+
22+
# Obtaining a trace:
23+
t, mot_fluorecence = run.get_trace('mot fluorecence')
24+
25+
# Now we might do some analysis on this data. Say we've written a
26+
# linear fit function (or we're calling some other libaries linear
27+
# fit function):
28+
m, c = linear_fit(t, mot_fluorecence)
29+
30+
# We might wish to plot the fit on the trace to show whether the fit is any good:
31+
32+
plt.plot(t,mot_fluorecence,label='data')
33+
plt.plot(t,m*t + x,label='linear fit')
34+
plt.xlabel('time')
35+
plt.ylabel('MOT flourescence')
36+
plt.legend()
37+
38+
# Don't call show() ! lyse will introspect what figures have been made
39+
# and display them once this script has finished running. If you call
40+
# show() it won't find anything. lyse keeps track of figures so that new
41+
# figures replace old ones, rather than you getting new window popping
42+
# up every time your script runs.
43+
44+
# We might wish to save this result so that we can compare it across
45+
# shots in a multishot analysis:
46+
run.save_result('mot loadrate', c)

docs/listing_2.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from lyse import *
2-
from pylab import *
1+
from lyse import data, Run, path
2+
import matplotlib.pyplot as plt
33

44
# Let's obtain our data for this shot -- globals, image attributes and
55
# the results of any previously run single-shot routines:
@@ -29,11 +29,11 @@
2929

3030
# We might wish to plot the fit on the trace to show whether the fit is any good:
3131

32-
plot(t,mot_fluorecence,label='data')
33-
plot(t,m*t + x,label='linear fit')
34-
xlabel('time')
35-
ylabel('MOT flourescence')
36-
legend()
32+
plt.plot(t,mot_fluorecence,label='data')
33+
plt.plot(t,m*t + x,label='linear fit')
34+
plt.xlabel('time')
35+
plt.ylabel('MOT flourescence')
36+
plt.legend()
3737

3838
# Don't call show() ! lyse will introspect what figures have been made
3939
# and display them once this script has finished running. If you call

docs/listing_3.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from lyse import *
2-
from pylab import *
1+
import lyse
2+
import matplotlib.pyplot as plt
33

44
# Let's obtain the dataframe for all of lyse's currently loaded shots:
5-
df = data()
5+
df = lyse.data()
66

77
# Now let's see how the MOT load rate varies with, say a global called
88
# 'detuning', which might be the detuning of the MOT beams:
@@ -15,17 +15,16 @@
1515

1616
# Let's plot them against each other:
1717

18-
plot(detunings, load_rates,'bo',label='data')
18+
plt.plot(detunings, load_rates,'bo',label='data')
1919

2020
# Maybe we expect a linear relationship over the range we've got:
2121
m, c = linear_fit(detunings, load_rates)
22-
# (note, not a function provided by lyse, though I'm sure we'll have
23-
# lots of stock functions like this available for import!)
22+
# (note, not a function provided by lyse)
2423

25-
plot(detunings, m*detunings + c, 'ro', label='linear fit')
26-
legend()
24+
plt.plot(detunings, m*detunings + c, 'ro', label='linear fit')
25+
plt.legend()
2726

2827
#To save this result to the output hdf5 file, we have to instantiate a
2928
#Sequence object:
30-
seq = Sequence(path, df)
29+
seq = lyse.Sequence(lyse.path, df)
3130
seq.save_result('detuning_loadrate_slope',c)

docs/source/examples.rst

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ An analysis on a single shot
66

77
.. code-block:: python
88
9-
from lyse import *
10-
from pylab import *
9+
from lyse import Run, data, path
10+
import matplotlib.pyplot as plt
1111
1212
# Let's obtain our data for this shot -- globals, image attributes and
1313
# the results of any previously run single-shot routines:
@@ -37,11 +37,11 @@ An analysis on a single shot
3737
3838
# We might wish to plot the fit on the trace to show whether the fit is any good:
3939
40-
plot(t,mot_fluorecence,label='data')
41-
plot(t,m*t + x,label='linear fit')
42-
xlabel('time')
43-
ylabel('MOT flourescence')
44-
legend()
40+
plt.plot(t,mot_fluorecence,label='data')
41+
plt.plot(t,m*t + x,label='linear fit')
42+
plt.xlabel('time')
43+
plt.ylabel('MOT flourescence')
44+
plt.legend()
4545
4646
# Don't call show() ! lyse will introspect what figures have been made
4747
# and display them once this script has finished running. If you call
@@ -58,7 +58,7 @@ Single shot analysis with global file opening
5858

5959
.. code-block:: python
6060
61-
from lyse import *
61+
from lyse import Run, path
6262
6363
# Instantiate Run object and open
6464
# Globally opening the shot keeps the h5 file open
@@ -91,11 +91,11 @@ An analysis on multiple shots
9191

9292
.. code-block:: python
9393
94-
from lyse import *
95-
from pylab import *
94+
import lyse
95+
import matplotlib.pyplot as plt
9696
9797
# Let's obtain the dataframe for all of lyse's currently loaded shots:
98-
df = data()
98+
df = lyse.data()
9999
100100
# Now let's see how the MOT load rate varies with, say a global called
101101
# 'detuning', which might be the detuning of the MOT beams:
@@ -108,19 +108,18 @@ An analysis on multiple shots
108108
109109
# Let's plot them against each other:
110110
111-
plot(detunings, load_rates,'bo',label='data')
111+
plt.plot(detunings, load_rates,'bo',label='data')
112112
113113
# Maybe we expect a linear relationship over the range we've got:
114114
m, c = linear_fit(detunings, load_rates)
115-
# (note, not a function provided by lyse, though I'm sure we'll have
116-
# lots of stock functions like this available for import!)
115+
# (note, not a function provided by lyse)
117116
118-
plot(detunings, m*detunings + c, 'ro', label='linear fit')
119-
legend()
117+
plt.plot(detunings, m*detunings + c, 'ro', label='linear fit')
118+
plt.legend()
120119
121120
#To save this result to the output hdf5 file, we have to instantiate a
122121
#Sequence object:
123-
seq = Sequence(path, df)
122+
seq = lyse.Sequence(lyse.path, df)
124123
seq.save_result('detuning_loadrate_slope',c)
125124
126125
.. sectionauthor:: Chris Billington

docs/source/introduction.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
Introduction
22
==============
33

4-
**Lyse** is a data analysis system which gets *your code* running on experimental data as it is acquired. It is fundamenally based around the ideas of experimental *shots* and analysis *routines*. A shot is one trial of an experiment, and a routine is a ``Python`` script, written by you, that does something with the measurement data from one or more shots.
4+
**Lyse** is a data analysis system which gets *your code* running on experimental data as it is acquired. It is fundamentally based around the ideas of experimental *shots* and analysis *routines*. A shot is one trial of an experiment, and a routine is a ``Python`` script, written by you, that does something with the measurement data from one or more shots.
55

6-
Analysis routines can be either *single-shot* or *multi-shot*. This determines what data and functions are available to your code when it runs. A single-shot routine has access to the data from only one shot, and functions available for saving results only to the hdf5 file for that shot. A a multi-shot routine has access to the entire dataset from all the runs that are currently loaded into **lyse**, and has functions available for saving results to an hdf5 file which does not belong to any of the shots---it's a file that exists only to save the "meta results".
6+
Analysis routines can be either *single-shot* or *multi-shot*. This determines what data and functions are available to your code when it runs. A single-shot routine has access to the data from only one shot, and functions available for saving results only to the hdf5 file for that shot. A multi-shot routine has access to the entire dataset from all the runs that are currently loaded into **lyse**, and has functions available for saving results to an hdf5 file which does not belong to any of the shots---it's a file that exists only to save the "meta results".
77

8-
Actually things are far less magical than that. The only enforced difference between a single shot routine and a multi-shot routine is a single variable provided to your code when **lyse** runs it. Your code runs in a perfectly clean ``Python`` environment with this one exception: a variable in the global namespace called ``path``, which is a path to an hdf5 file. If you have told **lyse** that your routine is a singleshot one, then this path will point to the hdf5 file for the current shot being analysed. On the other hand, if you've told **lyse** that your routine is a multishot one, then it will be the path to an h5 file that has been selected in **lyse** for saving results to.
8+
Actually things are far less magical than that. The only enforced difference between a single shot routine and a multi-shot routine is a single variable provided to your code when **lyse** runs it. Your code runs in a perfectly clean ``Python`` environment with this one exception: a variable in the lyse namespace called ``path``, which is a path to an hdf5 file. If you have told **lyse** that your routine is a singleshot one, then this path will point to the hdf5 file for the current shot being analysed. On the other hand, if you've told **lyse** that your routine is a multishot one, then it will be the path to an h5 file that has been selected in **lyse** for saving results to.
99

1010
The other differences listed above are conventions only (though **lyse**'s design is based around the assumption that you'll follow these conventions most of the time), and pertain to how you use the API that **lyse** provides, which will be different depending on what sort of analysis you're doing.
1111

1212
The **lyse** API
1313
~~~~~~~~~~~~~~~~~
1414

15-
So grea, you've got a single filepath. What data analysis could you possibly do with that? It might seem like you have to still do the same amount of work that you would without an analysis system! Whilst that's not quite true, it's intentionally been designed that way so that you can run your code outside **lyse** with very little modification. Another motivating factor is to minimise the amount of magic black box behaviour, such that an analysis routine is actually just an ordinary ``Python`` script which makes use of an API designed for our purposes. **lyse** is both a program which executes your code, and an API that your code can call on.
15+
So great, you've got a single filepath. What data analysis could you possibly do with that? It might seem like you have to still do the same amount of work that you would without an analysis system! Whilst that's not quite true, it's intentionally been designed that way so that you can run your code outside **lyse** with very little modification. Another motivating factor is to minimise the amount of magic black box behaviour, such that an analysis routine is actually just an ordinary ``Python`` script which makes use of an API designed for our purposes. **lyse** is both a program which executes your code, and an API that your code can call on.
1616

17-
To use the API in an analysis routine, begine your code with:
17+
To use the API in an analysis routine, begin your code with:
1818

1919
.. code-block:: python
2020
21-
from lyse import *
21+
import lyse
2222
2323
The details of the API are found in the :doc:`API reference<api/_autosummary/lyse>`.
2424

lyse/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ def open(self, mode):
334334
For better performance, it would be better to combine
335335
these two openings into one.
336336
337-
>>> from lyse import *
337+
>>> from lyse import Run, path
338338
>>> shot = Run(path)
339339
>>> with shot.open('r'):
340340
>>> # shot processing that requires reads/writes
@@ -351,7 +351,7 @@ def open(self, mode):
351351
Open and create the shot handle for the whole analysis
352352
in a single line.
353353
354-
>>> from lyse import *
354+
>>> from lyse import Run, path
355355
>>> with Run(path).open('r+') as shot:
356356
>>> # shot processing that requires reads/writes
357357
>>> t, vals = shot.get_trace('my_trace')

0 commit comments

Comments
 (0)