Synopsis
Create a Python script that will re-create the current ChIPS session.
Syntax
make_script(filename)
Description
The function arguments.
Argument | Description |
---|---|
filename | The file name to write to. |
The make_script function creates a Python script with the specified <filename> that will recreate the state of the current ChIPS session. The session preferences are stored in a related file called "<filename>.prefs". Although the examples below use a suffix of ".txt" for the filename, other suffixes (or even no suffix) can be used.
The make_script command does not record every command that has been issued. Instead it evaluates the current state of ChIPS and builds a set of commands that will replicate it. For instance, if the characteristics of a curve are changed several times, only the final color, symbol, error style etc. are recorded by make_script. It is therefore different to save_state(), which saves a non-human readable file that contains information about the commands that were used (e.g. so you can call undo() after load_state()).
Storing the Data
If the data used in the plot was loaded from a file, make_script records the full path to the original filename. Since the script is stored as plain text, the user can update this path if the data file is moved. If the data was loaded from an array, the array is saved to a FITS file named "<filename>.Data#_<obj>.fits", where "<obj>" is the type of object - curve, contour, image, or histogram - and "#" is the object count.
Using the Script
To run the script, supply it to ChIPS at startup:
unix% chips -n simplecurve.txt chips>
or by using the Python execfile command from within ChIPS
chips> execfile("simplecurve.txt")
After the script is processed, ChIPS returns to a prompt so that the plot(s) can be modified further.
Creating Hardcopies in Batch Mode
The script file may be modified so that it can be run in a non-interactive mode to produce a hardcopy of the plot. The following two lines should be added to the file; the lines in "[]" are written by make_script and are included to show where to add the new commands:
[from pychips.all import *] set_preference("window.display", "false") ... [close_undo_block()] print_window("out.pdf", ["fittopage", True])
The print_window command can be changed to create a JPEG, PS, or any of the other supported formats; see "ahelp print_window". The script can be run by ChIPS in batch mode ("-b"):
unix% chips -b simplecurve.txt
or directly by Python:
unix% python simplecurve.txt
The output file, out.pdf, is written to the working directory.
Examples
Example 1
chips> add_curve("/data/lc.fits[cols dt, count_rate, count_rate_err]") chips> set_curve("line.color=red") chips> set_curve("line.color=red symbol.style=none") chips> set_curve("line.color=blue") chips> set_curve("line.color=green") chips> make_script("simplecurve")
The script output is included below. The full path to the data file "/data/lc.fits" and the column filter that was applied are stored in the variable "MyData_1". This variable is then used to plot the data. Notice that although the line color was changed several times in the session, only the final value (green) is recorded in the add_curve command in the script.
unix% cat simplecurve.txt from pycrates import * # import crates i/o routines from pychips.all import * # import chips hlui and advanced commands ### Data Templates # The template variables below are used to specify the data needed for # objects such as curves. The values may be substituted with other file # names or data arrays as appropriate. It is the user's responsibility to # ensure that data arrays are all the correct length, that provided column # names exist, and that if files are provided, they contain the appropriate # columns in the correct order. Note that the variables are provided in two # flavors- as filenames and as data structures: the former makes use of the # simpler file interface while the latter offers more flexibility. MyData_1="/data/lc.fits[cols dt, count_rate, stat_err]" open_undo_block() # treat script as single command clear() # remove all existing chips objects # This script assumes that the user's default preferences were used # to generate the output and were not changed- so the following # load_preferences() command is unnecessary. To guarantee that this # script uses the correct settings to replicate the saved state, # uncomment out the following line. # load_preferences("/data/simplecurve.prefs") add_plot() add_curve(MyData_1,'line.color=green symbol.style=none id=crv1') current_plot("plot1") shuffle("crv1",chips_curve, chips_front) current_axis("ax1") limits(X_AXIS,AUTO, AUTO) current_axis("ay1") limits(Y_AXIS,AUTO, AUTO) close_undo_block() # end treat script as single command
Example 2
chips> clear() chips> x = np.arange(11) chips> add_curve(x, x*x) chips> add_line([1,5,9], [9,2,7], ["color", "blue", "style", "dot"]) chips> make_script("line.txt")
The curve y=x^2 for the integer values 0 to 10 is plotted. Then a blue dotted line comprised of two segments is overlaid on the curve. Since the curve was created from an array, make_script writes it to a FITS file named "line.txt.Data1_curve.fits" and references that file in the script:
unix% cat line.txt from pycrates import * # import crates i/o routines from pychips.all import * # import chips hlui and advanced commands ### Data Templates # The template variables below are used to specify the data needed for # objects such as curves. The values may be substituted with other file # names or data arrays as appropriate. It is the user's responsibility to # ensure that data arrays are all the correct length, that provided column # names exist, and that if files are provided, they contain the appropriate # columns in the correct order. Note that the variables are provided in two # flavors- as filenames and as data structures: the former makes use of the # simpler file interface while the latter offers more flexibility. class DataObj(): pass MyCrate_1 = TABLECrate("/data/chips/line.txt.Data1_curve.fits") MyData_1 = DataObj() # data- /data/chips/line.txt.Data1_curve.fits MyData_1.xx = MyCrate_1.get_column("xx").values MyData_1.yy = MyCrate_1.get_column("yy").values open_undo_block() # treat script as single command clear() # remove all existing chips objects # This script assumes that the user's default preferences were used # to generate the output and were not changed- so the following # load_preferences() command is unnecessary. To guarantee that this # script uses the correct settings to replicate the saved state, # uncomment out the following line. # load_preferences("/data/chips/line.txt.prefs") add_plot() add_curve(MyData_1.xx, MyData_1.yy,'id=crv1') add_line([1, 5, 9],[9, 2, 7], "color=blue style=dot id=line1") current_plot("plot1") shuffle("ax1",chips_axis, chips_backward) shuffle("ay1",chips_axis, chips_backward) current_axis("ax1") limits(X_AXIS,AUTO, AUTO) current_axis("ay1") limits(Y_AXIS,AUTO, AUTO) close_undo_block() # end treat script as single command
Bugs
See the bugs pages on the ChIPS website for an up-to-date listing of known bugs.
See Also
- saving
- load_state, save_state