{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "name": "usingcasa.ipynb", "provenance": [], "toc_visible": true } }, "cells": [ { "cell_type": "markdown", "metadata": { "id": "WH_shvqvRL_D" }, "source": [ "# Using CASA \n", "\n", "See the [CASA API](../api/configuration.rst) for information on configuration options prior to startup.\n", "\n" ] }, { "cell_type": "markdown", "metadata": { "id": "a3hTMmuiRL_M" }, "source": [ "## Starting CASA\n", "\n", "CASA packages installed through pip may be imported in to the standard Python environment on the host machine. For example:\n", "\n", "```\n", "(casa6) $ python\n", "\n", "Python 3.6.9 (default, Nov 7 2019, 10:44:02) \n", "[[GCC 8.3.0] on linux]\n", "Type \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n", ">>> import casatasks\n", ">>> help(casatasks)\n", "```\n", "\n", "The \\~/.casa/**config.py** file will be read and processed when the casatasks package is imported.\n", "\n", "The full installation of CASA includes an IPython environment which is executed like an application. Any desired command line arguments may be included. For example:\n", "\n", "```\n", "$ ./casa6/bin/casa --logfile MyTestRun.txt --nogui\n", "```\n", "\n", "The \\~/.casa/**config.py** file will be read and processed as the casa application executes, with the supplied command line arguments (logfile and nogui) added on top.\n", "\n", "This environment is based upon IPython. CASA uses IPython because it provides nice command completion, comandline editing and function invocation without parenthesis. The fact that the CASA application environment is IPython based means that users can also use the IPython magic commands like `%run`. Users are encouraged to explore the options available with IPython, but this is outside the scope of this document. CASA only supports configuration using **config.py**. Some of these configuration variable in **config.py** are used to configure IPython at startup time. CASA configures IPython to supply parentheses when they are omitted. For example, when `sin 3` is executed IPython supplies the missing parens and invokes `sin(3)`. CASA also turns off any output that the paren expansion would normally generate.\n", "\n", "Users may wish to set shortcuts, links, aliases or add bin/casa to their envrionment PATH. See the documentation for your operating system. \n", "\n", "\n", "\n", "***\n", "\n", "\n", "\n" ] }, { "cell_type": "markdown", "metadata": { "id": "4HIenczRRL_M" }, "source": [ "## Running User Scripts \n", "\n", "**CASA 6: modular version**\n", "\n", "The modular version of CASA behaves like a standard Python package and user scripts should include the relevant modules as they would any other python module (i.e. numpy). Executing external user scripts with modular CASA is just like any other python application. Note we recommend running in a Python venv, see the [installation instructions](introduction.ipynb#id1) for more information.\n", "\n", "```\n", "$ (casa6) python myscript.py param1 param2\n", "```\n", "\n", "**CASA 6: all-inclusive version** \n", "\n", "Since the full CASA installation from a tar file includes its own python environment that is (typically) not called directly, alternative methods of feeding in user scripts are necessary. There are three main standard Python ways of executing external user scripts in the full installation of CASA:\n", "\n", "1. -c startup parameter (see configuration instructions)\n", "2. exec(open(\\\"./filename\\\").read()) within the CASA Python environment\n", "3. add your script to startup.py in the \\~/.casa directory\n", "\n", "In addition, an *\\\"execfile\\\"* python shortcut has been added to the full installation of CASA 6 for backwards compatibility with ALMA scriptForPI.py restore scripts. This allows running scripts with the following command:\n", "\n", "4. execfile \\'filename.py\\' within the CASA Python environment\n", "\n", "The *execfile* command in CASA 6 has been tested and found to work in the same way as in (Python 2 based) CASA 5 with the exception that (1) the treatment of global variables has changed in Python 3, (2) only direct arguments should be used (i.e., *listobs(vis='name.ms'*)), and (3) the command *default('taskname')* no longer works with *execfile* (but note that direct arguments always invoke the defaults anyway). While casashell tasks (tasks run in the [CASA shell environment](../api/casashell.rst)) could be treated as scriptable in the Python 2.7/CASA 5 version of *execfile*, in Python 3/CASA 6 this behavior is not supported. Python replacements for *execfile* exist [i.e., \"%run -i\" or \"exec(open(read...\"] which provide some scripting capabilities for casashell commands, though these Python alternatives are not tested in any internal CASA regression tests.\n", "\n", "Regarding the treatment of global variables: for *execfile* calls within a script which itself is run via *execfile*, it is necessary to add *globals()* as the second argument to those *execfile* calls in order for the nested script to know about the global variables of the calling script. For example, within a script *\\'mainscript.py\\'*, calls to another script *\\'myscript.py\\'* should be written as follows: *execfile(\\'myscript.py\\', globals())* . \n", "\n", "*** \n", "\n", "\n" ] }, { "cell_type": "markdown", "metadata": { "id": "djxGQD3qRL_N" }, "source": [ "## Logging \n", "\n", "Detailed description of the CASA logger\n", "\n" ] }, { "cell_type": "markdown", "metadata": { "id": "lnOmzBpJRL_O" }, "source": [ "### Logging your session\n", "\n", "\n", "The output from CASA commands is sent to the file casa-YYYYMMDD-HHMMSS.log in your local directory, where YYYYMMDD-HHMMSS are the UT date and time when CASA was started up. New starts of CASA create new log files.\n", "\n", "{width=\"900\" height=\"353\"}\n", "\n", ">The CASA Logger GUI window under Linux. Note that under MacOSX a stripped down logger will instead appear as a Console.\n", " \n", "\n", "The output contained in casa-YYYYMMDD-HHMMSS.log *i*s also displayed in a separate window using the **casalogger**. Generally, the logger window will be brought up when CASA is started. If you do not want the logger GUI to appear, then start casa using the *\\--nologger* option,\n", "\n", "```\n", " casa --nologger\n", "```\n", "\n", "which will run CASA in the terminal window. See [Starting CASA](usingcasa.ipynb#starting-casa) for more startup options.\n", "\n", "