diff options
Diffstat (limited to 'Wrappers/Python')
-rw-r--r-- | Wrappers/Python/CMakeLists.txt | 195 | ||||
-rw-r--r-- | Wrappers/Python/ccpi/reconstruction/Reconstructor.py | 4 | ||||
-rw-r--r-- | Wrappers/Python/compile-fista.bat.in | 7 | ||||
-rw-r--r-- | Wrappers/Python/compile-fista.sh.in | 9 | ||||
-rw-r--r-- | Wrappers/Python/compile.bat.in | 7 | ||||
-rw-r--r-- | Wrappers/Python/compile.sh.in | 9 | ||||
-rw-r--r-- | Wrappers/Python/fista-recipe/meta.yaml | 2 | ||||
-rw-r--r-- | Wrappers/Python/setup-fista.py.in | 27 | ||||
-rw-r--r-- | Wrappers/Python/setup.py.in | 69 |
9 files changed, 3 insertions, 326 deletions
diff --git a/Wrappers/Python/CMakeLists.txt b/Wrappers/Python/CMakeLists.txt deleted file mode 100644 index 92baf2c..0000000 --- a/Wrappers/Python/CMakeLists.txt +++ /dev/null @@ -1,195 +0,0 @@ -# Copyright 2017 Edoardo Pasca -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# variables that must be set for conda compilation -cmake_minimum_required (VERSION 3.0) - -project(FISTA) -#https://stackoverflow.com/questions/13298504/using-cmake-with-setup-py - -# The version number. -set (FISTA_VERSION_MAJOR 1) -set (FISTA_VERSION_MINOR 0) - -set (CIL_VERSION_MAJOR 0) -set (CIL_VERSION_MINOR 9) -set (CIL_VERSION_PATCH 1) - -set (CIL_VERSION '${CIL_VERSION_MAJOR}.${CIL_VERSION_MINOR}.${CIL_VERSION_PATCH}' CACHE INTERNAL "Core Imaging Library version" FORCE) - -#PREFIX=C:\Apps\Miniconda2\envs\cil\Library -#LIBRARY_INC=C:\\Apps\\Miniconda2\\envs\\cil\\Library\\include -set (NUMPY_VERSION 1.12) - -## Tries to parse the output of conda env list to determine the current -## active conda environment -message ("Trying to determine your active conda environment...") -execute_process(COMMAND "conda" "env" "list" - OUTPUT_VARIABLE _CONDA_ENVS - RESULT_VARIABLE _CONDA_RESULT - ERROR_VARIABLE _CONDA_ERR) - if(NOT _CONDA_RESULT) - string(REPLACE "\n" ";" ENV_LIST ${_CONDA_ENVS}) - foreach(line ${ENV_LIST}) - string(REGEX MATCHALL "(.+)[*](.+)" match ${line}) - if (NOT ${match} EQUAL "") - #message("MATCHED " ${CMAKE_MATCH_0}) - #message("MATCHED " ${CMAKE_MATCH_1}) - #message("MATCHED " ${CMAKE_MATCH_2}) - string(STRIP ${CMAKE_MATCH_1} CONDA_ENVIRONMENT) - string(STRIP ${CMAKE_MATCH_2} CONDA_ENVIRONMENT_PATH) - endif() - endforeach() - else() - message(FATAL_ERROR "ERROR with conda command " ${_CONDA_ERR}) - endif() - -if (${CONDA_ENVIRONMENT} AND ${CONDA_ENVIRONMENT_PATH}) - message (FATAL_ERROR "CONDA NOT FOUND") -else() - message("**********************************************************") - message("Using current conda environmnet " ${CONDA_ENVIRONMENT}) - message("Using current conda environmnet path " ${CONDA_ENVIRONMENT_PATH}) -endif() - -message("CIL VERSION " ${CIL_VERSION}) - -findPythonForAnacondaEnvironment(${CONDA_ENVIRONMENT_PATH}) - -message("Python found " ${PYTHON_VERSION_STRING}) -message("Python found Major " ${PYTHON_VERSION_MAJOR}) -message("Python found Minor " ${PYTHON_VERSION_MINOR}) - -findPythonPackagesPath() -message("PYTHON_PACKAGES_FOUND " ${PYTHON_PACKAGES_PATH}) - -## CACHE SOME VARIABLES ## -set (CONDA_ENVIRONMENT ${CONDA_ENVIRONMENT} CACHE INTERNAL "active conda environment" FORCE) -set (CONDA_ENVIRONMENT_PATH ${CONDA_ENVIRONMENT_PATH} CACHE INTERNAL "active conda environment" FORCE) - -set (PYTHON_VERSION_STRING ${PYTHON_VERSION_STRING} CACHE INTERNAL "conda environment Python version string" FORCE) -set (PYTHON_VERSION_MAJOR ${PYTHON_VERSION_MAJOR} CACHE INTERNAL "conda environment Python version major" FORCE) -set (PYTHON_VERSION_MINOR ${PYTHON_VERSION_MINOR} CACHE INTERNAL "conda environment Python version minor" FORCE) -set (PYTHON_VERSION_PATCH ${PYTHON_VERSION_PATCH} CACHE INTERNAL "conda environment Python version patch" FORCE) -set (PYTHON_PACKAGES_PATH ${PYTHON_PACKAGES_PATH} CACHE INTERNAL "conda environment Python packages path" FORCE) - -if (WIN32) - #set (CONDA_ENVIRONMENT_PATH "C:\\Apps\\Miniconda2\\envs\\${CONDA_ENVIRONMENT}" CACHE PATH "Main environment directory") - set (CONDA_ENVIRONMENT_PREFIX "${CONDA_ENVIRONMENT_PATH}\\Library" CACHE PATH "env dir") - set (CONDA_ENVIRONMENT_LIBRARY_INC "${CONDA_ENVIRONMENT_PREFIX}\\include" CACHE PATH "env dir") -elseif (UNIX) - #set (CONDA_ENVIRONMENT_PATH "/apps/anaconda/2.4/envs/${CONDA_ENVIRONMENT}" CACHE PATH "Main environment directory") - set (CONDA_ENVIRONMENT_PREFIX "${CONDA_ENVIRONMENT_PATH}/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}" CACHE PATH "env dir") - set (CONDA_ENVIRONMENT_LIBRARY_INC "${CONDA_ENVIRONMENT_PREFIX}/include" CACHE PATH "env dir") -endif() - -######### CONFIGURE REGULARIZER PACKAGE ############# - -# copy the Pyhon files of the package regularizer -file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/ccpi/imaging/) -file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/ccpi/__init__.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/ccpi) -# regularizers -file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/ccpi/imaging/__init__.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/ccpi/imaging) -file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/ccpi/imaging/Regularizer.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/ccpi/imaging) - -# Copy and configure the relative conda build and recipes -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/setup.py) -file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/conda-recipe) -file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/conda-recipe/meta.yaml DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/conda-recipe) - -if (WIN32) - - file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/conda-recipe/bld.bat DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/conda-recipe/) - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/compile.bat.in ${CMAKE_CURRENT_BINARY_DIR}/compile.bat) - -elseif(UNIX) - - message ("We are on UNIX") - file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/conda-recipe/build.sh DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/conda-recipe/) - # assumes we will use bash - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/compile.sh.in ${CMAKE_CURRENT_BINARY_DIR}/compile.sh) - -endif() - -########## CONFIGURE FISTA RECONSTRUCTOR PACKAGE -# fista reconstructor -file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/ccpi/reconstruction/FISTAReconstructor.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/ccpi/reconstruction) -file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/ccpi/reconstruction/__init__.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/ccpi/reconstruction) -file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/ccpi/reconstruction/DeviceModel.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/ccpi/reconstruction) -file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/ccpi/reconstruction/AstraDevice.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/ccpi/reconstruction) - -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/setup-fista.py.in ${CMAKE_CURRENT_BINARY_DIR}/setup-fista.py) -file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/fista-recipe) -file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/fista-recipe/meta.yaml DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/fista-recipe) - -if (WIN32) - - file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/fista-recipe/bld.bat DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/fista-recipe/) - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/compile-fista.bat.in ${CMAKE_CURRENT_BINARY_DIR}/compile-fista.bat) - -elseif(UNIX) - message ("We are on UNIX") - file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/fista-recipe/build.sh DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/fista-recipe/) - # assumes we will use bash - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/compile-fista.sh.in ${CMAKE_CURRENT_BINARY_DIR}/compile-fista.sh) -endif() - -############################# TARGETS - -########################## REGULARIZER PACKAGE ############################### - -# runs cmake on the build tree to update the code from source -add_custom_target(update_code - COMMAND ${CMAKE_COMMAND} - ARGS ${CMAKE_SOURCE_DIR} - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - ) - - -add_custom_target(fista - COMMAND bash - compile-fista.sh - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - DEPENDS ${update_code} - ) - -add_custom_target(regularizers - COMMAND bash - compile.sh - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - DEPENDS update_code - ) - -add_custom_target(install-fista - COMMAND ${CONDA_EXECUTABLE} - install --force --use-local ccpi-fista=${CIL_VERSION} -c ccpi -c conda-forge - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - ) - -add_custom_target(install-regularizers - COMMAND ${CONDA_EXECUTABLE} - install --force --use-local ccpi-regularizers=${CIL_VERSION} -c ccpi -c conda-forge - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - ) -### add tests - -#add_executable(RegularizersTest ) -#find_package(tiff) -#if (TIFF_FOUND) -# message("LibTIFF Found") -# message("TIFF_INCLUDE_DIR " ${TIFF_INCLUDE_DIR}) -# message("TIFF_LIBRARIES" ${TIFF_LIBRARIES}) -#else() -# message("LibTIFF not found") -#endif() diff --git a/Wrappers/Python/ccpi/reconstruction/Reconstructor.py b/Wrappers/Python/ccpi/reconstruction/Reconstructor.py index ba67327..2ad8a44 100644 --- a/Wrappers/Python/ccpi/reconstruction/Reconstructor.py +++ b/Wrappers/Python/ccpi/reconstruction/Reconstructor.py @@ -351,7 +351,7 @@ class FISTA(): #end del proj_geomT del vol_geomT - else + else: #% divergen beam geometry #fprintf('%s \n', 'Calculating Lipshitz constant for divergen beam geometry...'); niter = 8; #% number of iteration for PM @@ -391,7 +391,7 @@ class FISTA(): def setRegularizer(self, regularizer): - if regularizer + #if regularizer self.pars['regularizer'] = regularizer diff --git a/Wrappers/Python/compile-fista.bat.in b/Wrappers/Python/compile-fista.bat.in deleted file mode 100644 index b1db686..0000000 --- a/Wrappers/Python/compile-fista.bat.in +++ /dev/null @@ -1,7 +0,0 @@ -set CIL_VERSION=@CIL_VERSION@ - -set PREFIX=@CONDA_ENVIRONMENT_PREFIX@ -set LIBRARY_INC=@CONDA_ENVIRONMENT_LIBRARY_INC@ - -REM activate @CONDA_ENVIRONMENT@ -conda build fista-recipe --python=@PYTHON_VERSION_MAJOR@.@PYTHON_VERSION_MINOR@ --numpy=@NUMPY_VERSION@ -c ccpi -c conda-forge diff --git a/Wrappers/Python/compile-fista.sh.in b/Wrappers/Python/compile-fista.sh.in deleted file mode 100644 index 267f014..0000000 --- a/Wrappers/Python/compile-fista.sh.in +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh -# compile within the right conda environment -#module load python/anaconda -#source activate @CONDA_ENVIRONMENT@ - -export CIL_VERSION=@CIL_VERSION@ -export LIBRARY_INC=@CONDA_ENVIRONMENT_LIBRARY_INC@ - -conda build fista-recipe --python=@PYTHON_VERSION_MAJOR@.@PYTHON_VERSION_MINOR@ --numpy=@NUMPY_VERSION@ -c ccpi diff --git a/Wrappers/Python/compile.bat.in b/Wrappers/Python/compile.bat.in deleted file mode 100644 index e5342ed..0000000 --- a/Wrappers/Python/compile.bat.in +++ /dev/null @@ -1,7 +0,0 @@ -set CIL_VERSION=@CIL_VERSION@ - -set PREFIX=@CONDA_ENVIRONMENT_PREFIX@ -set LIBRARY_INC=@CONDA_ENVIRONMENT_LIBRARY_INC@ - -REM activate @CONDA_ENVIRONMENT@ -conda build conda-recipe --python=@PYTHON_VERSION_MAJOR@.@PYTHON_VERSION_MINOR@ --numpy=@NUMPY_VERSION@ -c ccpi -c conda-forge
\ No newline at end of file diff --git a/Wrappers/Python/compile.sh.in b/Wrappers/Python/compile.sh.in deleted file mode 100644 index 93fdba2..0000000 --- a/Wrappers/Python/compile.sh.in +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh -# compile within the right conda environment -#module load python/anaconda -#source activate @CONDA_ENVIRONMENT@ - -export CIL_VERSION=@CIL_VERSION@ -export LIBRARY_INC=@CONDA_ENVIRONMENT_LIBRARY_INC@ - -conda build conda-recipe --python=@PYTHON_VERSION_MAJOR@.@PYTHON_VERSION_MINOR@ --numpy=@NUMPY_VERSION@ -c ccpi diff --git a/Wrappers/Python/fista-recipe/meta.yaml b/Wrappers/Python/fista-recipe/meta.yaml index 265541f..4e5cba6 100644 --- a/Wrappers/Python/fista-recipe/meta.yaml +++ b/Wrappers/Python/fista-recipe/meta.yaml @@ -19,7 +19,7 @@ requirements: - python - numpy #- astra-toolbox - - ccpi-regularizers + - ccpi-regularizer diff --git a/Wrappers/Python/setup-fista.py.in b/Wrappers/Python/setup-fista.py.in deleted file mode 100644 index c5c9f4d..0000000 --- a/Wrappers/Python/setup-fista.py.in +++ /dev/null @@ -1,27 +0,0 @@ -from distutils.core import setup -#from setuptools import setup, find_packages -import os - -cil_version=os.environ['CIL_VERSION'] -if cil_version == '': - print("Please set the environmental variable CIL_VERSION") - sys.exit(1) - -setup( - name="ccpi-fista", - version=cil_version, - packages=['ccpi','ccpi.reconstruction'], - install_requires=['numpy'], - - zip_safe = False, - - # metadata for upload to PyPI - author="Edoardo Pasca", - author_email="edo.paskino@gmail.com", - description='CCPi Core Imaging Library - FISTA Reconstructor module', - license="Apache v2.0", - keywords="tomography interative reconstruction", - url="http://www.ccpi.ac.uk", # project home page, if any - - # could also include long_description, download_url, classifiers, etc. -) diff --git a/Wrappers/Python/setup.py.in b/Wrappers/Python/setup.py.in deleted file mode 100644 index 12e8af1..0000000 --- a/Wrappers/Python/setup.py.in +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/env python - -import setuptools -from distutils.core import setup -from distutils.extension import Extension -from Cython.Distutils import build_ext - -import os -import sys -import numpy -import platform - -cil_version=@CIL_VERSION@ - -library_include_path = "" -library_lib_path = "" -try: - library_include_path = os.environ['LIBRARY_INC'] - library_lib_path = os.environ['LIBRARY_LIB'] -except: - library_include_path = os.environ['PREFIX']+'/include' - pass - -extra_include_dirs = [numpy.get_include(), library_include_path] -extra_library_dirs = [os.path.join(library_include_path, "..", "lib")] -extra_compile_args = ['-fopenmp','-O2', '-funsigned-char', '-Wall', '-std=c++0x'] -extra_libraries = [] -extra_include_dirs += [os.path.join("@CMAKE_SOURCE_DIR@" , "main_func" , "regularizers_CPU"), - os.path.join("@CMAKE_SOURCE_DIR@" , "main_func" , "regularizers_GPU") , - "@CMAKE_CURRENT_SOURCE_DIR@"] - -if platform.system() == 'Windows': - extra_compile_args[0:] = ['/DWIN32','/EHsc','/DBOOST_ALL_NO_LIB' , '/openmp' ] - - if sys.version_info.major == 3 : - extra_libraries += ['boost_python3-vc140-mt-1_64', 'boost_numpy3-vc140-mt-1_64'] - else: - extra_libraries += ['boost_python-vc90-mt-1_64', 'boost_numpy-vc90-mt-1_64'] -else: - if sys.version_info.major == 3: - extra_libraries += ['boost_python3', 'boost_numpy3','gomp'] - else: - extra_libraries += ['boost_python', 'boost_numpy','gomp'] - -setup( - name='ccpi', - description='CCPi Core Imaging Library - Image Regularizers', - version=cil_version, - cmdclass = {'build_ext': build_ext}, - ext_modules = [Extension("ccpi.imaging.cpu_regularizers", - sources=[os.path.join("@CMAKE_CURRENT_SOURCE_DIR@" , "fista_module.cpp" ), - os.path.join("@CMAKE_SOURCE_DIR@" , "main_func" , "regularizers_CPU", "FGP_TV_core.c"), - os.path.join("@CMAKE_SOURCE_DIR@" , "main_func" , "regularizers_CPU", "SplitBregman_TV_core.c"), - os.path.join("@CMAKE_SOURCE_DIR@" , "main_func" , "regularizers_CPU", "LLT_model_core.c"), - os.path.join("@CMAKE_SOURCE_DIR@" , "main_func" , "regularizers_CPU", "PatchBased_Regul_core.c"), - os.path.join("@CMAKE_SOURCE_DIR@" , "main_func" , "regularizers_CPU", "TGV_PD_core.c"), - os.path.join("@CMAKE_SOURCE_DIR@" , "main_func" , "regularizers_CPU", "utils.c") - ], - include_dirs=extra_include_dirs, - library_dirs=extra_library_dirs, - extra_compile_args=extra_compile_args, - libraries=extra_libraries ), - - ], - zip_safe = False, - packages = {'ccpi','ccpi.imaging'}, -) - - |