FROM morgan1971/lofar-base:0.1.0
LABEL Description="This image is used to execute the LOFAR DDF 2.0"
LABEL maintainer="Giuliano Taffoni <giuliano.taffoni@inaf.it>"
ENV CONTAINER_NAME='Lofar  Software'
# Set non-interactive
USER root
ENV DEBIAN_FRONTEND noninteractive
RUN sudo apt-get -y update

#####################################################################################
# Astropy python3
#####################################################################################
RUN sudo apt-get -y install  python3-astropy python3-gwcs libcfitsio-dev  wcslib-dev wcslib-tools
LABEL it.inaf.lofar.software.astropy=2.1-1
LABEL it.inaf.lofar.software.cfitsio=2.35

#####################################################################################
# CASA: casacore, casalite, casarest,  python3-casacore
#####################################################################################
RUN sudo apt-get -y install casacore-dev casacore-doc casacore-doc casacore-tools \
libcasa-casa4 libcasa-casa5 libcasa-coordinates4 libcasa-coordinates5 libcasa-derivedmscal4 \
libcasa-derivedmscal5 libcasa-fits4 libcasa-fits5 libcasa-images4 libcasa-images5 \
libcasa-lattices4 libcasa-lattices5 libcasa-meas4 libcasa-meas5 libcasa-measures4 \
libcasa-measures5 libcasa-mirlib4 libcasa-mirlib5 libcasa-ms4 libcasa-ms5 \
libcasa-msfits4 libcasa-msfits5 libcasa-python3-4 libcasa-python3-5 libcasa-python4 \
libcasa-python5 libcasa-scimath-f4 libcasa-scimath-f5 libcasa-scimath4 libcasa-scimath5 \
libcasa-tables4 libcasa-tables5 casacore-data casalite casarest python3-casacore
LABEL it.inaf.lofar.software.casacore=3.3.0-1
LABEL it.inaf.lofar.software.casacore-data=20210112-160001-2
LABEL it.inaf.lofar.software.casalite=5.6.0-1
LABEL it.inaf.lofar.software.casarest=1.7.0-1
LABEL it.inaf.lofar.software.python-casacore=4.3.1-1

#####################################################################################
# Install LOFAR BEAM
#####################################################################################
RUN sudo apt-get -y install python3-lofarbeam lofarbeam-dev
LABEL it.inaf.lofar.software.lofarbeam=4.1.1

#####################################################################################
# install other packages
#####################################################################################
RUN sudo apt-get -y install  python3-astro-kittens python3-purr python3-astro-tigger-lsm python3-astro-tigger \
         libwsclean2 wsclean wsclean-dev aoflagger aoflagger-dev libaoflagger0 \
         libblitz0 libblitz0-dev  libxml2-dev \
         python3-rmextract python3-lsmtool python3-psycopg2
#dysco dysco-dev libdyscostman2 

LABEL it.inaf.lofar.software.wsclean=2.9-2 \
      it.inaf.lofar.software.tigger-lsm=1.6.0 \
      it.inaf.lofar.software.kittens=1.4.3-1 \
      it.inaf.lofar.software.purr=1.5.0 it.inaf.lofar.software.aoflagger=2.15.0-1 \
      it.inaf.lofar.software.blitz=1.0.2-1 \
      it.inaf.lofar.software.dysco=1.2-1 \
      it.inaf.lofar.software.RMexctract=0.4 \
      it.inaf.lofar.software.lsmtool=1.4.2

#####################################################################################
#  IDG
#####################################################################################
ENV IDG_VERSION_TAG=0.8
RUN mkdir /idg && cd /idg \
    && git clone https://git.astron.nl/RD/idg.git src \
    && ( cd src/ && git checkout ${IDG_VERSION_TAG} ) \
    && mkdir build && cd build \
    && cmake -G Ninja -DPYTHON_EXECUTABLE=/usr/bin/python3 -DCMAKE_INSTALL_PREFIX=/usr ../src \
    && ninja install \
    && cd / && rm -rf idg
LABEL it.inaf.lofar.software.idg=0.8

#####################################################################################
# DP3 version 4.2
#####################################################################################
ENV DPPP_VERSION_TAG=4.2
#
# Solve a a boost dep problem (it is DPPP related not OS related)
RUN cd  /usr/lib/x86_64-linux-gnu/ && ln -s libboost_numpy3-py36.so libboost_numpy36.so && \
    ln -s libboost_python3-py36.so libboost_python36.so
RUN mkdir -p /src/build && cd /src/ && \
    wget https://github.com/lofar-astron/DP3/archive/refs/tags/v${DPPP_VERSION_TAG}.tar.gz && \
    tar zxvf v${DPPP_VERSION_TAG}.tar.gz && cd /src/build && \
    cmake ../DP3-4.2 -DPYTHON_EXECUTABLE=/usr/bin/python3 \
    -DBoost_PYTHON36_LIBRARY=/usr/lib/x86_64-linux-gnu/libboost_python-py36.so \
    -DBoost_NUMPY36_LIBRARY=/usr/lib/x86_64-linux-gnu/libboost_numpy3-py36.so  && \
     make -j 40 && make install && rm -fr /src
LABEL it.inaf.lofar.software.dppp=4.2

#####################################################################
# LoSoTo 2.2.1 (git checkout adccc74)
#####################################################################

RUN mkdir -p /src &&  cd /src && \
    git clone https://github.com/revoltek/losoto.git losoto && \
    cd /src/losoto && git checkout adccc74 && \
    python3 setup.py build && \
    python3 setup.py install && \
    rm -fr /src
LABEL it.inaf.lofar.software.losoto=2.2.1

#####################################################################
# Install EveryBeam library 0.2.0
#####################################################################
ENV EVERYBEAM_VERSION=74fe444e
RUN mkdir -p /src/EveryBeam/build && cd /src/EveryBeam && \
    git clone https://git.astron.nl/RD/EveryBeam.git src && \
    cd src && git checkout $EVERYBEAM_VERSION && \
    cd /src/EveryBeam/build && \
    cmake ../src && make -j 40 && make install
LABEL it.inaf.lofar.software.everybeam=0.2.0

#####################################################################
# Install Cattery 1.7.0
#####################################################################
ENV CATTERY_VERSION=1.7.0
RUN cd /tmp/ && wget https://github.com/ska-sa/meqtrees-cattery/archive/v${CATTERY_VERSION}.tar.gz && \
    tar -xvf v${CATTERY_VERSION}.tar.gz && cd /tmp/meqtrees-cattery-${CATTERY_VERSION} && \
    python3 -m pip  install .
RUN rm -fr /tmp/v${CATTERY_VERSION}.tar.gz /tmp/meqtrees-cattery-${CATTERY_VERSION}

#####################################################################
# Install meqtrees-timba 1.8.0
#####################################################################
ENV TIMBA_VERSION=1.8.0
RUN apt-get install -y libqdbm-dev
RUN cd /tmp/ && wget https://github.com/ska-sa/meqtrees-timba/archive/v${TIMBA_VERSION}.tar.gz && \
    tar -xvf v${TIMBA_VERSION}.tar.gz && mkdir /tmp/meqtrees-timba-${TIMBA_VERSION}/build && \
    cd /tmp/meqtrees-timba-${TIMBA_VERSION}/build  && cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_PYTHON_3=ON .. && \
    make -j40 && make install && ldconfig && rm -fr /tmp/meqtrees-timba-${TIMBA_VERSION}/ /tmp/v${TIMBA_VERSION}.tar.gz

#####################################################################
# Install pyxis 1.7.0
#####################################################################
ENV PYXIS_VERSION=1.7.0
RUN cd /tmp && wget https://github.com/ska-sa/pyxis/archive/v${PYXIS_VERSION}.tar.gz && \
    tar -xvf v${PYXIS_VERSION}.tar.gz && cd /tmp/pyxis-${PYXIS_VERSION} && \
    python3 -m pip install .
RUN cp -r /tmp/pyxis-${PYXIS_VERSION}/Pyxis/recipies /usr/local/lib/python3.6/dist-packages/Pyxis/
RUN rm -fr /tmp/v${PYXIS_VERSION}.tar.gz /tmp/pyxis-${PYXIS_VERSION}

#####################################################################
## Install DYSCO 1.2
######################################################################
ENV DYSCO_VERSION=v1.2
RUN mkdir  -p /tmp/dysco/build && cd /tmp/dysco/ && git clone https://github.com/aroffringa/dysco.git src && \
    cd /tmp/dysco/src &&  git checkout ${DYSCO_VERSION} && cd /tmp/dysco/build &&  \
    cmake -DCMAKE_INSTALL_PREFIX=/opt/dysco  -DPORTABLE=True ../src && make -j 40 && make install && \
    rm -fr /tmp/dysco


ENV PATH /usr/local/bin:$PATH
ENV LD_LIBRARY_PATH /usr/local/lib:$LD_LIBRARY_PATH
RUN apt-get -y clean
USER lofar
LABEL Vendor="INAF"
LABEL Version="0.1.0"
