From a509f83eb4508e9e03da0f169dedf6654e3b66d3 Mon Sep 17 00:00:00 2001 From: Leszek Grzanka Date: Mon, 3 Oct 2022 21:35:32 +0200 Subject: [PATCH] fix GSM methods for python wrapper (#198) --- .github/workflows/main.yml | 4 +-- README.md | 8 +---- .../Python/pyamtrack/make_wheel_package.sh | 36 +++++++++++++------ example/demo/CMakeLists.txt | 8 +++++ include/AT_Algorithms_GSM.h | 19 +++++----- src/AT_Algorithms_GSM.c | 6 +++- 6 files changed, 51 insertions(+), 30 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8abdca95..f2de2888 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -26,7 +26,7 @@ jobs: mkdir build cd build cmake -DCMAKE_BUILD_TYPE=Release ../ -DCMAKE_INSTALL_PREFIX=$HOME/usr - cmake --build . --target install -- -j2 + cmake --build . --target install -- -j - name: tests run: | @@ -61,7 +61,7 @@ jobs: tar -xzf gsl-latest.tar.gz -C $HOME/gsl-latest mv $HOME/gsl-latest/** $HOME/gsl-latest/gsl mkdir $HOME/usr - cd $HOME/gsl-latest/gsl/ && emconfigure ./configure --prefix=$HOME/usr --disable-shared && emmake make -j2 && emmake make install + cd $HOME/gsl-latest/gsl/ && emconfigure ./configure --prefix=$HOME/usr --disable-shared && emmake make -j && emmake make install ls -al $HOME/usr/lib/ - name: Compile libamtrack webassembly package diff --git a/README.md b/README.md index 63757e62..eb20ad77 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,3 @@ -[![Build Status](https://travis-ci.org/libamtrack/library.svg?branch=master)](https://travis-ci.org/libamtrack/library) - # 1. WHAT IS LIBAMTRACK? * libamtrack provides computational routines for the prediction of detector response and radiobiological efficiency in heavy charged particle beams. @@ -11,8 +9,6 @@ * libamtrack is free, open-source software under GNU GPL licence. * libamtrack is intended to facilitate the comparison of and the communication on amorphous track models for particle beam research. -libamtrack's main website: http://libamtrack.dkfz.org - # 2. HOW CAN I USE LIBAMTRACK? @@ -43,8 +39,6 @@ This should be the very last alternative - THE FACT THAT YOU ARE LOOKING AT THIS Everybody is welcome to read, use and modify (preferably to improve) the code according to GNU GPL 3. - # 4. WHERE DO I FIND DOCUMENTATION ON LIBAMTRACK? -- The libamtrack manual is found here: /docs/libamtrackManual.pdf -- On the webpage: libamtrack.dkfz.org +- The libamtrack manual is found here: /docs/libamtrackManual.pdf \ No newline at end of file diff --git a/distributions/Python/pyamtrack/make_wheel_package.sh b/distributions/Python/pyamtrack/make_wheel_package.sh index f7e9b4e3..d5982a88 100755 --- a/distributions/Python/pyamtrack/make_wheel_package.sh +++ b/distributions/Python/pyamtrack/make_wheel_package.sh @@ -3,7 +3,13 @@ # get the tool which aids making wheel package # it will automatically generate python wrapper for decorated (doxygen) C code rm -rf cBinder || exit 1 -git clone https://github.com/Tetrite/cBinder.git || exit 1 +if [ -d "$DIR" ]; then + echo "cBinder already exists" + cd cBinder || exit 1 + git pull || exit 1 +else + git clone https://github.com/Tetrite/cBinder.git || exit 1 +fi # copy source files and headers to local folder, so the docker container can access them rm -rf libamtrack || exit 1 @@ -13,20 +19,28 @@ cp -rf ../../../include libamtrack/ || exit 1 cp -rf ../../../src libamtrack/ || exit 1 # get necessary dependency (latest) version of GSL library -rm -f gsl.tar.gz || exit 1 -wget --quiet "http://ftpmirror.gnu.org/gnu/gsl/gsl-latest.tar.gz" --output-document=gsl.tar.gz || exit 1 +if [ -d "gsl-latest" ]; then + echo "gsl-latest already exists" +else + rm -f gsl.tar.gz || exit 1 + wget --quiet "http://ftpmirror.gnu.org/gnu/gsl/gsl-latest.tar.gz" --output-document=gsl.tar.gz || exit 1 -# unpack into gsl-x.y directory -rm -rf gsl-?.* || exit 1 -tar -zxf gsl.tar.gz || exit 1 + # unpack into gsl-x.y directory + rm -rf gsl-?.* || exit 1 + tar -zxf gsl.tar.gz || exit 1 + + # move into gsl-latest directory + rm -rf gsl-latest || exit 1 + mv gsl-?.* gsl-latest || exit 1 +fi -# move into gsl-latest directory -rm -rf gsl-latest || exit 1 -mv gsl-?.* gsl-latest || exit 1 # make directory for GSL installation -rm -rf gsl || exit 1 -mkdir gsl || exit 1 +if [ -d "gsl" ]; then + echo "gsl already exists" +else + mkdir gsl || exit 1 +fi # run the docker process which using manylinux1 machine (SLC6 based) will compile # the C extensions using old enough libraries diff --git a/example/demo/CMakeLists.txt b/example/demo/CMakeLists.txt index 9b7dfde6..c545149b 100644 --- a/example/demo/CMakeLists.txt +++ b/example/demo/CMakeLists.txt @@ -10,4 +10,12 @@ add_executable (${PROJECT_NAME} ${SOURCE_FILES} ) target_link_libraries( ${PROJECT_NAME} LINK_PUBLIC amtrack ${GSL_LIBRARIES}) +# Visual Studio does not need or want you to explicitly request linking the math library. +# You must avoid adding it as a link library when building for Windows. +# see https://stackoverflow.com/questions/54935559/linking-math-library-in-cmake-file-on-windows-and-linux +IF (NOT WIN32) + target_link_libraries (${PROJECT_NAME} m) +ENDIF() + + install(TARGETS ${PROJECT_NAME} DESTINATION bin) diff --git a/include/AT_Algorithms_GSM.h b/include/AT_Algorithms_GSM.h index fc7f2107..03c31f64 100644 --- a/include/AT_Algorithms_GSM.h +++ b/include/AT_Algorithms_GSM.h @@ -234,18 +234,19 @@ void AT_run_GSM_method( const long number_of_field_components, * @param[in] material_no index number for detector material * @see AT_DataMaterial.h for definition * @param[in] rdd_model index number for chosen radial dose distribution - * @param[in] rdd_parameter parameters for chosen radial dose distribution (array of size depending on chosen model) + * @param[in] rdd_parameter parameters for chosen radial dose distribution (array of size 3) * @see AT_RDD.h for definition * @param[in] er_model index number for chosen electron-range model * @see AT_ElectronRange.h for definition - * @param[in] stopping_power_source_no TODO - * @param[in] nX TODO - * @param[in] pixel_size_m TODO - * @param[in] number_of_bins TODO - * @param[in] dose_bin_centers_Gy TODO - * @param[out] random_number_generator_seed TODO - * @param[out] zero_dose_fraction TODO - * @param[out] dose_frequency_Gy TODO + * @param[in] stopping_power_source_no stopping power source number (PSTAR,...) + * @see AT_DataMaterial.h for definition + * @param[in] nX number of pixels along one side + * @param[in] pixel_size_m pixel size [m] + * @param[in] number_of_bins number of bins in the histogram + * @param[in] dose_bin_centers_Gy edges in the output dose histogram (array of size number_of_bins) + * @param[out] random_number_generator_seed seed for the random number generator + * @param[out] zero_dose_fraction fraction of pixels with zero dose + * @param[out] dose_frequency_Gy values in the output dose histogram (array of size number_of_bins) */ void AT_GSM_local_dose_distrib( const long number_of_field_components, const double E_MeV_u[], diff --git a/src/AT_Algorithms_GSM.c b/src/AT_Algorithms_GSM.c index 1df72443..e6cabb0a 100644 --- a/src/AT_Algorithms_GSM.c +++ b/src/AT_Algorithms_GSM.c @@ -233,7 +233,11 @@ void AT_GSM_local_dose_distrib_from_dose_grid( const long nX, bin_no = AT_histoOld_bin_no( number_of_bins, bin_centers_Gy, grid[i][j]); - frequency[bin_no] += 1.0; + // user could provide bins not spanning whole dose range + // we skip the values outside the range + if((bin_no >= 0) && (bin_no < number_of_bins)){ + frequency[bin_no] += 1.0; + } } } }