Installing NIMS

From VISTA LAB WIKI

Jump to: navigation, search

DO NOT run nims in development mode (i.e. using development.ini) if NIMS will be accessible outside of the development team!

Contents

[edit] Fedora

 sudo yum install python-setuptools python-paste python-paste-script python-pylons python-pip numpy python-devel swig git

Then follow the instructions here (link appears broken - please fix): http://blue.stanford.edu/intro.html

svn co https://white.stanford.edu/srepos/nims/trunk

sudo pip install -r requirements.txt
sudo python setup.py develop

Pynifti can be installed from a repo. For FC12:

wget http://download.opensuse.org/repositories/home://hankem://rh5/Fedora_12/home:hankem:rh5.repo
mv home:hankem:rh5.repo /etc/yum.repos.d/pynifti.repo
yum update
yum install python-nifti

Or, install from source:

git clone git://git.debian.org/git/pkg-exppsy/pynifti.git
cd pynifti
ln -s 3rd/nifticlibs

Edit setup.py and change numpy.distutils.core to distutils.core and add './nifticlibs' and '/usr/lib64/python2.6/site-packages/numpy/core/include/' to include_dirs. Also, try:

ln -s /usr/lib64/python2.6/site-packages/numpy/core/include/numpy 3rd/nifticlibs/
cd 3rd/nifticlibs
make
python setup.py install

Although it compiles, it still doesn't seem to work. Maybe try the pure pythin nifti reader from nipy? (https://launchpad.net/nipy)

[edit] Ubuntu

NIMS is intended to be deployed as a dedicated server application. If you want to run NIMS on a development machine and do not want to load all the NIMS Python libraries and packages into your system's Python directory you can use a virtual environment for your deployment. Refer to the Python documentation for virtualenv for more details.

To install NIMS you must have easy_install and pip installed in your Python distribution. The former is available in the setuptools package which can be downloaded from http://pypi.python.org/pypi/setuptools, or installed with apt-get

apt-get install python-setuptools

Once you have easy_install available, connect to the nims top-level distribution directory (i.e. the application's code root). You will know that you are in the right directory if you see development.ini, test.ini and requirements.txt in it. Next, download pip and proceed to setup NIMS using the requirements.txt file, which specifies the base packages required for NIMS to run:

cd nims
sudo easy_install pip
sudo easy_install -m pyro=3.10
sudo pip install -r requirements.txt
sudo python setup.py develop

Important The instructions above force a load of Pyro version 3.10 which is needed for NIMS r84. The -m flag ensures the possibility for a multiversion Pyro. If you do not specify a version number, Ubuntu as of r67 will load automatically Pyro 4.00 or later which is incompatible with NIMS r84. If this happens NIMS will not work. Note that when NIMS Phase 3 starts, these instructions will change to use Pyro4.

Currently (NIMS r67) the requirements.txt file specifies loading the following packages at setup time:

pydicom
numpy
SQLAlchemy
Jinja2
FormAlchemy
Sphinx
nose
Babel
Pylons
Pyro (r3.10)

It is very important that you follow this initial step, as these packages are essential for NIMS operation. A few required packages have to be installed separately. The next step is for you to install these system-wide packages as follows:

sudo apt-get install postgresql python-all-dev python-nifti python-psycopg2

These packages include the Postgres database and its Python driver psycopg2, a set of Python development tools, and the Python dinifti DICOM to Nifti converter. You may be interested in also loading psyco, a Python compiled code optimizer, which comes in very handy if you are concerned about Python compiled code performance.

You also need dinifti to conver dicoms to nifti files. On Ubuntu, try:

sudo apt-get install dicomnifti

[edit] Setup Postgres

Now, configure postgres (see the Ubuntu help site for details):

sudo -u postgres psql postgres
sudo -u postgres createuser --no-superuser --no-createdb --no-createrole nims
# Run psql to set the passwords:
sudo -u postgres psql
# the root postgres password for the system:
\password postgres
# The NIMS user password. This MUST match the password specified in the .ini file that you use to configure NIMS (development.ini by default).
\password nims
[CTRL-D to quite psql]
sudo -u postgres createdb -O nims nimsdb
# Now edit postgres config to allow password logins:
sudo vi /etc/postgresql/8.4/main/pg_hba.conf
# change "local  all  all  ident" to "local  all  all  md5"
# save and quit, then restart postgres:
sudo /etc/init.d/postgresql-8.4 restart

Note that on freeBSD, you would use:

su pgsql 
createuser --no-superuser --no-createdb --no-createrole nims
psql postgres
# Set the root DB password:
\password pgsql
# Set the nims password:
\password nims
[CTRL-D to quite psql]
createdb -O nims nimsdb
# exit back to the root user.
exit
# Now edit postgres config to require encrypted passwords:
vi /usr/local/pqsql/data/pg_hba.conf
# change "local  all  all  trust" to "local  all  all  md5"
# save and quit, then restart postgres:
/usr/local/etc/rc.d/postgresql restart

Set up the NIMS environment.

# now setup the wsgi application
paster setup-app development.ini

At this point if desired, you can run the NIMS regression test tools to make sure that everything is ok with the application. As of NIMS r56 some of these tests are out of sync with the latest functionality and need to be updated.

nosetests

NIMS is almost ready. You will now initialize the database to an initial bootstrap configuration that allows you to login and start using the system. Once this step is complete, you will start the NRP -- the NIMS computational request processor, a backend distributed multiprocessing facility for asynchronous execution of space and time intensive computations on NIMS objects. Finally, you start the web server.

To set up an initial database use paster as follows (we assume you are at the nims root directory):

# Create initial database from nims initial content template
cd src/
paster reloaddb ../development.ini

Notice that whenever you run the NIMS reloaddb command and there is already content in the database, all tables are dropped and the database reinitialized. This is useful in development, especially if your code inadvertently damages the database.

In a separate process, e.g. a terminal or a daemon, start the request processor as follows:

# starts the asynchronous request processor
cd src/nims/nrp
python serve.py -v -i ../../../development.ini

Notice the three .. in the Pylons configuration descriptor filename. At this point nrp should echo the number of processes created and the URI it is running under.

Now, you can run nims in development mode using paster as follows

# start nims, make sure you are at nims/src
cd src/
paster serve ../development.ini

If all goes well, NIMS should be running on port 5000 (or whichever port is specified in development.ini). Use a browser to go to the NIMS login page at

https://localhost:5000

You can now login as root and setup your users, user groups and grant/experiment structure.

Note that if you are not running, you might need to tunnel into the NIMS machine:

ssh -L 5000:tlraider.stanford.edu:5000 tlraider.stanford.edu


[edit] NRP4

The deployment of NIMS to its actual home server and the cleanup of all dependencies to make it simpler to install, has required changing the backend request processor infrastructure to Pyro 4 from Pyro 3.x. This not only entails changes in the actual NIMS code, but changes in the process for setting up NRP. This section covers the issues with setting up

For NIMS r86, there are two NRP directories nims.src.nims.nrp and nims.src.nims.nrp4. We will keep the 3.x NRP around just in case we need to revert (not likely). The Pyro 4 changes have percolated to nims.src.lib.client, because Pyro 4 request processor discovery needs a name server running, unlike the Pyro 3.x version. The old version of the client only exists after NIMS r71 up to NIMS r84. Should you need to revert to Pyro 3.x processing you must revert back the client module.

At this point (r86) the process to run NRP4 is as follows:

  • Start up the Pyro4 name server
  • Cleanup the NFS and Data spaces and reload the database if necessary.
  • Run the nrp4 directory version of the request processor server.
  • Start up the NIMS web server application

Your life will be simpler if you add a few aliases to your shell. Here are the bash aliases:

 alias nrp-nson   'python -m Pyro4.naming'           # starts up the name server
 alias nrp-nscmd  'python -m Pyro4.nsc'              # issues a cmd to the name server, e.g. nrp-nscmd list

Then, once you have cleaned the NFS spaces and database if needed, then at a shell prompt do

 nrp-nson

and the name server will start up, showing what URI it is dispatching from.

Notice that in Pyro 4 there are no namespaces for request servers. A request processor has to register its name with the Pyro name server. One can obtain the effect of namespaces by using '.' notation for the name. For example, in NIMS r86 we use

 nrp4.request

as the request processor name in the name server for nifti volume conversion. As a suggestion, as new computational filters are implemented, use this notation for the request processors for those filters. For example, if there is only one filter of class AdaptiveMinSquare you could define the name for this filter as

 nrp4.AdaptiveMinSquare

If you have a class of filters SnazzyFilters, and two filters in this class, say BobFilter and JorgeFilter, you could name the corresponding request processors

 nrp4.SnazzyFilters.BobFilter
 nrp4.SnazzyFilters.JorgeFilter

In this last case, in the NIMS side, dispatching to the request processor would determine which SnazzyFilter is best, and then call the corresponding request processor entry point.

Notice that request processors can reside in different machines, or in the same machine, as is most appropriate for deployment purposes and the computational characteristics of each.

At this point you are ready to start nrp as before. First, make sure you are standing at the correct directory. Assuming you are standing at nims.src in the nims package hierarchy, do this

 cd nims/nrp4            # notice the nrp4 directory. You can run old nrp from nims/nrp
                         # as long as you revert nims.lib.client to the old version
 python serve.py -v -i ../../../development.ini          # nothing has changed in our external API!

and now the NRP4 server will print out some information letting you know it is active, and the exact URI it is dispatching from. Now, you can just proceed to run the web application as usual.

 paster serve ../development.ini

NOTE: You must make sure that Pyro4 is loaded as Pyro4 into the Python library space. This will happen if you load the latest version of Pyro4 from its website. If Pyro4 does not get loaded with the Pyro4 name NIMS will not work. BEWARE

Personal tools