open, evaluate, and save a set of worksheets in a single notebook

I have a notebook with 25+ worksheets which calculate parameters for shaped NMR pulses. I use an attached .sage file which does most of the calculation. I have updated the .sage file and would like to update the calculations for each worksheet. I would like to automate the following:

Open a worksheet

Delete all output

Evaluate all cells

Save the worksheet

Close the worksheet

From looking through the documentation it is not how to do this or if it is possible. Any advice on how to do this would greatly appreciated.

Comments

It sounds like you might do better by just updating the worksheet source files.

All of the worksheet data is in ~/.sage/sage_notebook.sagenb/home/admin (unless you chose a different user name for your sage notebook, in which case the last directory will be that user name). In there the directories are numbered -- I think in the order than the worksheets were created. Inside each there is a file named worksheet_conf.pickle and another one named worksheet.html. There are also directories named cells, data, snapshots.

Although it has a promising name, the data directory is empty for all of my worksheets (which are certainly not empty).

The pickle file stores a dictionary with some basic information about the worksheet. In particular, the worksheet name is there. But the data of what's in each cell does not seem to be there. The html file does have the input data for each cell. I tried editing this file, and the change appeared when I opened the worksheet in sage. I don't know if this is a good way to do it, but I didn't see data stored elsewhere. (Except, possibly, in the snapshots directory, which I'm assuming is for backup.) I guess your task doesn't require changing the worksheet input anyway though. But you could write a script to collect all of those input cells, for use later.

The cells directory seems to hold the output of all cells. In your case, you might delete the contents of all those directories to clear the output. Did I mention you should make a backup of your sage_notebook.sagenb directory first? Definitely do :)

To re-evaluate all cells, you could write a sage script to take the input (collected from worksheet.html) for each cell, evaluate it, and store the result in the corresponding directory.

By the way, do you have some other strong reason to be tied to the notebook? Once you're writing a sage script to evaluate a series of commands and store the results, you could store them anywhere you like, in any format you like.

Comments

The data directory is for uploaded files attached to a worksheet. The `worksheet.html` file is where the cells are actually stored (input and output), and the cells/ directory is where cell output files go (like images generated, etc.). One problem with your method, though, is that Sage can change how it presents output when being run under a notebook vs. under a normal session (e.g., plots can be saved to different places, even if it is the same plot, etc.)

Thank you for the information, from what I can understand the answer is no unless I completely want to rewrite what I have done to date.

The reason I used a notebook is because it is very convenient and the path most users would have used when starting with Sage. That is where I started. I have shifted some work to .sage files for speed and use in multiple worksheets. But for visualization of results the notebook is the most convenient from what I have been able to find. I understand that many things can be done in sage, but sometimes it can be frustrating because a lot of the documentation is pointed at programers not users who are scientists trying to solve a problem without a lot of programming heavy lifting. That is why I started with sage in the first place. I hope this does not come across as a complaint I really like Sage even with the difficulties I encounter.

Comments

Thanks! Yes, we're working on making things more friendly (and this site is one of those things...). I think you're basically right---the easiest way to do this right now is to manually open and run each worksheet.