Installation
==========================

Simple Installation
~~~~~~~~~~~~~~~~~~~~
:code:`tshirt` can be installed with pip like so:

.. code-block:: python

   pip install tshirt




Setting up a :code:`TSHIRT_DATA` directory
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
It is recommended that users choose a directory to store all of the output from :code:`tshirt`. To define the directory, edit your :code:`~/.bash_profile` file so it contains the following line:

.. code-block:: bash

   export TSHIRT_DATA="/path/to/tshirt_data"

where :code:`"path/to/tshirt_data"` is the path to where you want the tshirt output to go. Without this line, :code:`tshirt` creates a directory structure to store the output in the directory you run it in.
Another option is to specify the :code:`TSHIRT_DATA` path in your python session or Jupyter notebook like so:

.. code-block:: python

   import os
   os.environ['TSHIRT_DATA']="/path/to/tshirt_data"
   
NOTE: 
If you run a notebook/python session without setting up a :code:`TSHIRT_DATA` directory, all plots specified to be saved, will be automatically stored in a folder generated by :code:`tshirt` located at :code:`$HOME/tshirt_data`.




Upgrading :code:`tshirt` to the latest development version
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


- Activate the environment where you use tshirt
   :code:`conda activate tshirt`
- If you do not yet have the source code
   :code:`git clone https://github.com/eas342/tshirt.git`
- Navigate to the :code:`tshirt` directory:
   :code:`cd tshirt`
- Pull the latest code from github
   :code:`git pull`
- Reinstall
   :code:`pip install .`
- Make sure the new code is used
   Either restart your iPython session, restart your Jupyter notebook kernel or run the commands below to update a specific module
   
   .. code-block:: python   
   
      from tshirt.pipeline import spec_pipeline
      from importlib import reload
      reload(spec_pipeline)
      spec = spec_pipeline.spec('path_to_paramfile.yaml')
      
It is important to **re-create** the spec object after the reload, as in the above example.

Dependencies
~~~~~~~~~~~~~~~~~~~~
If you do not wish to use the :code:`anaconda` environment, another option is to manually install dependencies (beta).

- ``astropy``, ``numpy``
- ``photutils`` - needed for photometric extraction on images
- ``ccdphot`` - only needed for flat fielding, dark subtraction etc. for
- ``emcee`` - only needed for time series analysis and model fitting
- ``miescatter`` - only needed for fitting Mie extinction to spectra. Note: I had trouble with ``pip install miescatter`` where it was looking for an old gcc5 it couldn't find and had to download the source from pyPI and run ``python setup.py install``

Upgrading from older versions of :code:`tshirt`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you are upgrading from older versions of :code:`tshirt`, **back up your parameters directory** in case it gets removed with the git pull process. Also, installation may give you an error:

.. code-block:: text

   ERROR: Cannot uninstall 'tshirt'. It is a distutils installed
   project and thus we cannot accurately determine which files belong
   to it which would lead to only a partial uninstall.
   
In this case, you should remove the old files with the following procedure in your Unix shell:

.. code-block:: bash

   rm -r ~/anaconda/envs/this-environment/lib/python3.6/site-packages/tshirt
   rm ~/anaconda/envs/this-environment/lib/python3.6/site-packages/tshirt-0.1dev-py2.7.egg-info

where :code:`this-environment` is the environment where you installed :code:`tshirt`.
