In the Notebook
Now you've opened up a tier notebook by clicking the open icon:
The default tier templates will have created a first cell that e.g. for <Sample "WP1.1a">
will look something like:
from cas_project import project # (1)!
smpl = project.env('WP1.1a') # (2)!
smpl.gui.header() # (3)!
- import the
project
object you defined in yourcas_project.py
file (rememberproject.launch()
added it to yourPYTHONPATH
so it can be imported anywhere?). - Tells the
project
, I want this notebook (and it's interpretter) to be associated with theSample
calledWP1.1a
. It can grabWP1.1a
by name because it understands your project's naming convention - neat! - Display a nice UI that you can use to edit the description/ conclusion for this tier as well as a list of the tier's children:
Getting Children and Paths
All tier's have a folder associated with them:
>>> smpl.folder
Path('.../WorkPackages/WP1/WP1.1')
And they can act like pathlib.Path
to get relative paths:
>>> smpl / 'diagram.png'
Path('.../WorkPackages/WP1/WP1.1/diagram.png')
We can use the __getitem__
(tier[id]
) syntax to get children of a tier by it's identifier:
>>> smpl
<Sample "WP1.1a">
>>> smpl['XRD']
<DataSet "WP1.1a-XRD">
This is particularly useful for loading data:
>>> import pandas as pd
>>> df = pd.read_csv(smpl['Raman'] / 'raw_data.csv')
Anywhere we can import project
we can access any tier
by using the __getitem__
(project[name]
) syntax:
>>> from cas_project import project
>>> other_data = project['WP2.1c-Raman'] / 'more_raman_data.csv'
>>> other_data
Path('.../WorkPackages/WP2/WP2.1/Raman/c/more_raman_data.csv')
This becomes incredibly useful when trying to consolidate work, as you can load data without having to move it around.
Tip
For convenience, iterating over a DataSets
is equivalent to using os.scandir
:
>>> raman_dataset = smpl['Raman']
>>> for entry in raman_dataset:
... print(data)
DirEntry('.../WP2.1/Raman/c/data1.txt')
DirEntry('.../WP2.1/Raman/c/data2.txt')
Creating Highlights
Now you can load your data into the notebook, you can perform some analysis.
Generally this might result in some key graphs or images.
You can use the %%hlt
cell magic to mark the output of a cell as a highlight.
You should provide a title for the highlight, and you can also finish the cell with a string that will be used as a caption. e.g.
%%hlt U Gotta See This # (1)!
x = np.linspace(-5, 5)
plt.plot(x, x * x)
"""
This curve reminds me of U.
""" # (2)!
- The text after
%%hlt
forms the title of the highlight. - A
str
at the bottom of the cell acts as a caption.
Cassini will then capture the output of this cell and will allow it to be viewed in the Cassini Browser Preview panel without having to run or open the notebook.
Note
Behind the scenes, the %%hlt
magic only knows which tier to associate the highlight with, because you called project.env
at the top of your notebook.
You've now added something to the Browser Preview Panel... but what is that? Next learn about this feature.