Ask Your Question
1

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

asked 2012-09-12 21:52:12 +0200

mhfrey gravatar image

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:

  1. Open a worksheet
  2. Delete all output
  3. Evaluate all cells
  4. Save the worksheet
  5. 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.

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
0

answered 2012-09-13 09:35:36 +0200

niles gravatar image

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.

edit flag offensive delete link more

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.)

Jason Grout gravatar imageJason Grout ( 2012-09-15 01:30:59 +0200 )edit
0

answered 2012-09-14 08:01:38 +0200

mhfrey gravatar image

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.

edit flag offensive delete link more

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.

Jason Grout gravatar imageJason Grout ( 2012-09-15 01:32:11 +0200 )edit
1

answered 2012-09-15 01:36:16 +0200

Jason Grout gravatar image

For 25 worksheets, I'd block out 20 minutes and do the following:

  1. middle-click on each worksheet to open it in a new tab
  2. rapidly go through each worksheet tab in the browser and select "delete all output" and "evaluate all"
  3. then go through each worksheet again and click "save and quit" when the computations have finished.
edit flag offensive delete link more

Comments

yeah, this sounds easier that what I described...

niles gravatar imageniles ( 2012-09-15 15:08:24 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-09-12 21:52:12 +0200

Seen: 924 times

Last updated: Sep 15 '12