suncasa is a Python wrapper around CASA for importing, calibrating, synthesis imaging and visualizing solar spectral imaging data. CASA is one of the leading software tools for "supporting the data post-processing needs of the next generation of radio astronomical telescopes such as ALMA and VLA", an international effort led by the National Radio Astronomy Observatory (NRAO). The current version of CASA uses Python 3.6 to 3.8 on most of the platform. More information about the compatibility of CASA can be found on CASA Compatibility.
NOTE: CASA is available ONLY on unix-based platforms, and therefore, so as for suncasa.
In principle, suncasa an casa can be installed easily using pip, assuming the right python version is in use. However, YMMV if your do not have prerequisite environment configured.The followinig tutorial demonstrates the installation of suncasa in python 3.8 environment on MacOS 12 and Ubuntu 18.04.6 LTS.
Full installation instructions of the standalone CASA package (as a Linux (.tar) or Mac (.dmg) files) including the build-in Python environment are available from NRAO Downloads page (http://casa.nrao.edu/casa_obtaining.shtml)
The CASA 6.x series is also available as modular packages, giving users the flexibility to build CASA tools and tasks in their own Python environment. This includes the casatools, casatasks, and casampi modules, allowing for core data processing capabilities in parallel.
If you want to use full funtionalities provided by the standalone CASA, please go through all steps.
If you just want to install SUNCASA with the modular CASA option in the usual "Pythonic" manner, after Step 1 (Python installation), you can skip Step 2 and go directly to Step 3.
(Adapted from this tutorial)
CASA requires certain libraries be installed in the users operating system. Some may already be present by default. In case they are not, the following list should be checked before using CASA or if errors are encountered at runtime. Commands and package names are for Red Hat Linux, but equivalents can be found for other Linux distributions.
On Linux:
A system administrator may be required to install OS libraries. One can use yum ( RHEL) or apt-get (Ubuntu) to install the missing libraries. For example, for RHEL8 the following OS libraries should be installed:
sudo yum install libgfortran3
sudo yum install ImageMagick*
sudo yum install xorg-x11-server-Xvfb
sudo yum install compat-libgfortran-48
sudo yum install libnsl
sudo yum install libcanberra-gtk2
For modular CASA, one must supply their own Python environment. There are many, including ipython and Jupyter, here is a basic example for RHEL8 (yum) and Ubuntu (apt-get), respectively.
sudo yum install python38-devel
sudo apt install python3.8 python3.8-venv python3-venv
On Macintosh:
Same as for Linux, one must supply their own Python environment for modular CASA. Here is an example for MacOS to install python 3.8 using PyEnv.
Clone pyenv to a local directory (e.g., $HOME/.pyenv
):
git clone https://github.com/pyenv/pyenv.git $HOME/.pyenv
Set up your shell environment for Pyenv. Assuming you are using bash, add the configuration commands to ~/.bashrc
by running the following in your terminal:
bash
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
Install the Python 3.8.
pyenv install 3.8.16
Troubleshooting: If you encounter an error that "C compiler cannot create executables" then the simplest way to solve this is to reinstall Apple's Xcode. Xcode is a tool created by Apple that includes all the C libraries and other tools that Python uses when it runs on MacOS. Xcode is a whopping 11 gigabytes, but you'll want to be up-to-date. You may want to run this while you're sleeping. Once it is done, just re-run the above
pyenv install 3.8.16
and it should now work.
Now you can set this version of Python to be the current version of Python MacOS uses. This setting is temporary.
pyenv global 3.8.16
If you want to set this version of Python to the the default version of Python, add the configuration command to ~/.bashrc
.
echo 'pyenv global 3.8.16' >> ~/.bashrc
Download the standalone CASA package (as a Linux (.tar) or Mac (.dmg) files) including the build-in Python environment following http://casa.nrao.edu/casa_obtaining.shtml.
On Linux:
-
Download the .tar file and place it in a work directory (e.g.
$HOME/casa
). -
From a Linux terminal window:
tar -xvf casa-xyz.tar.xz $HOME/casa/casa-xyz/bin/casa
-
Add casa to environment
PATH
. Assuming you are using bash, add the configuration commands to~/.bashrc
by running the following in your terminal:echo 'export CASAROOT="$HOME/casa/casa-xyz/"' >> ~/.bashrc echo 'export PATH="$PATH:$CASAROOT/bin"' >> ~/.bashrc
- Restart your shell for the
PATH
changes to take effect.
exec "$SHELL"
You can now start casa.
casa
The one caveat is that CASA on Linux currently will not run if the Security-Enhanced Linux option of the linux operating
system is set to enforcing. For the non-root install to work, SElinux must be set to disabled or permissive (in _
/etc/selinux/config_) or you must run (as root): $: setsebool -P allow_execheap=1
. Otherwise, you will encounter
errors like:
error while loading shared libraries: /opt/casa/casa-20.0.5653-001/lib/liblapack.so.3.1.1: cannot restore segment prot after reloc: Permission denied_
WARNING: By default, python 3.6 (and earlier versions of python 3) include the current working directory in the python path at startup. Any script in that directory with the same name as a standard python module or a CASA module will be detected and used by python instead of the code that is delivered with CASA. Protections have been included for files called “new.py” and “pickle.py”, but other scripts may cause problems with the CASA startup. For example, do not include a file named runpy.py in the working directory.
On Macintosh:
-
Download the .dmg disk image file
-
Double click on the disk image file (if your browser does not automatically open it).
-
Drag the CASA application to the Applications folder of your hard disk.
-
Eject the CASA disk image.
-
Double click the CASA application to run it for the first time. If the OS does not allow you to install apps from non-Apple sources, please Change the settings in “System Preferences-> Security & Privacy -> General” and “Allow applications downloaded from: Mac App store and identified developers”.
-
Optional: Create symbolic links to the CASA version and its executables (Administrator privileges are required), which will allow you to run
casa
,casaviewer
,casaplotms
, etc. from any terminal command line. To do so, run
!create-symlinks
Pip wheels for casatools, casatasks, as well as suncasa are available as Python 3 modules. This allows simple installation and import into standard Python environments. Make sure you have set up your machine with the necessary prerequisite libraries first. Then a separate installation of desired modules (from a unix terminal window) as follows. First create a Python virtual environment
named suncasaenv
under the $HOME
directory:
cd $HOME
python3.8 -m venv suncasaenv
NOTE: We strongly recommend using a Python virtual environment to prevent breaking any packages within a pre-existing Python environment.
Then use pip to install suncasa within the newly-created virtual environment:
source suncasaenv/bin/activate
pip install --upgrade pip
pip install suncasa
NOTE: If this does not work, it could be due to unsuccessful installation of some dependencies. Running these commands should address this.
pip install casatasks
pip install casatools
pip install casadata
pip install PyQt5
pip install sunpy[all]
pip install suncasa
To exit the python venv, type deactivate
from the terminal. However, the rest of this tutorial assumes the venv is
active (to reactivate, type source $HOME/suncasaenv/bin/activate
)
You can update suncasa to its latest version by running:
pip install --upgrade suncasa
Sanity check
With the pip installation, suncasa as well as CASA may be used in a standard Pythonic manner. For example, suncasa modules and CASA tasks can be invoked using “import”, while CASA tools first need to be instantiated:
(suncasaenv) $ ipython
In [1]: import suncasa
In [2]: help(suncasa)
In [3]: import casatasks
In [4]: help(casatasks)
The use of python3 venv is a simple built-in method of containerizing the pip install such that multiple versions of suncasa can be kept on a single machine in different environments. In addition, suncasa is built and tested using standard python 3.8 libraries (backward compatible) which can be replicated with a fresh venv, keeping the libraries needed for suncasa isolated from other libraries which may already be installed on your machine.
Add EOVSA to CASA observatories list
The following command creates a configuration file to define the EOVSA instrument so that CASA is aware of it. We plan to add EOVSA officially to the CASA distribution in the future, after which this step is unnecessary.
printf "import sys \nimport os \nimport sysconfig \nimport casatools \nimport casadata \nimport time \nlogfile='casalog-{}.log'.format(time.strftime('%%Y%%m%%d-%%H',time.localtime())) \ntelemetry_enabled = False \ncrashreporter_enabled = True \ntb=casatools.table() \nospathsep = os.path.sep \nlibpath = sysconfig.get_paths()['purelib'] \nobsdict = {'MJD': 57447.0, 'Name': 'EOVSA', 'Type': 'WGS84', 'Long': -118.287, \n 'Lat': 37.2332, 'Height': 1207.13, 'X': 0.0, 'Y': 0.0, 'Z': 0.0, \n 'Source': 'Dale Gary'} \nobstable = os.path.join(casadata.datapath,'geodetic','Observatories') \ntb.open(obstable, nomodify=True) \nif 'EOVSA' not in tb.getcol('Name'): \n print('Adding EOVSA to the Observatories') \n tb.close() \n tb.open(obstable, nomodify=False) \n nrows = tb.nrows() \n tb.addrows(1) \n for k in obsdict.keys(): \n tb.putcell(k, nrows, obsdict[k]) \ntb.close() \n" > $HOME/.casa/config.py
Last but not least, add the site-packages
path where the suncasa and its dependent packages installedd to the Monolithic CASA
echo "sitepackagepath = '$HOME/suncasaenv/lib/python3.8/site-packages'" >> $HOME/.casa/config.py
echo "if sitepackagepath not in sys.path:" >> $HOME/.casa/config.py
echo " sys.path.append(sitepackagepath)" >> $HOME/.casa/config.py
note: The
sitepackagepath
may varies for python versions on different platforms.
Note for Mac M1 users: For macOS 12 on an ARM-based M1 chip, users will need to install the wheels of CASA version 11 for x86 architecture. For that, we recommend to use the following command to pip install the CASA wheels:
arch -x86\_64 python3.8 -m pip install ...