UCL / STIR-GATE-Connection

Example files on how to run STIR on GATE data
16 stars 11 forks source link

Scripts are depenant on running from SGC VoxelisedSimulation directory #73

Closed robbietuk closed 3 years ago

robbietuk commented 3 years ago

Related to #56 (3) [PATHS... and setting enviromental variables. The idea here is to define things like $SGC_HOME as the STIR-GATE-Connection project directory and then set all paths from there. In some places paths are defined relatively e.g.../PATH/TO/FILE]

Currently if scripts want to be run from an alternative directory, or away from the SGC project entirely, a number of scripts will fail due to path problems.

It might be of interest to add a sourceable script that sets the enviromental variable SGC_Home, or let the user define it. Then all subscript calls can be referenced from SGC_Home, e.g. ${SGC_Home}/VoxelisedSimulation/ExampleSTIR-GATE.sh

Any ideas, I havent done this before for a project.

robbietuk commented 3 years ago

I am liking this idea more and more. It gives a lot of control over the path manipluation.

The alternative is to do something like what ROOT does when you custom install, which is to use a this_root.sh script. https://github.com/root-project/root/blob/master/config/thisroot.sh However, this runs into problems such as different problems when run by different shells. It would be easier to add a line to the documentation saying, define SGC_Home proir to running scripts.

robbietuk commented 3 years ago

The final point of interest is the name of the enviromental variable. I have mentioned SGC_Home until now. I now prefer SGCPATH.

KrisThielemans commented 3 years ago

there's 2 things here.

  1. how do people call it if it's not in their PATH
  2. how do the scripts call eachother

If you don't care about the 1st (i.e. tell them to specify the full path, or put the directory in the PATH), then the second problem can be solved internally by doing stuff like

#! /usr/bin/env bash
# some doc

# find location of current script
scriptdir=$(dirname $0)
...

2 lines extra in each script of course, but it means people don't have to define `SGCPATH`.
robbietuk commented 3 years ago
  1. how do the scripts call eachother

This is what I tried to hotfix with https://github.com/UCL/STIR-GATE-Connection/commit/7c2b222dc371dfa633f58222c26238a413638910 . I would like it if everything worked top down, from the main STIR-GATE-Connection directory.

scriptdir=$(dirname $0)

The trouble with this is as you mentioned, this is bash. You can autofind the SGC home and set it using the following this_SGC.sh

SGCPATH=$(cd "$(dirname "$0")"; pwd)/$(basename "$1")
export SGCPATH

given by: https://stackoverflow.com/a/44084533 but then every script needs to know where this_SGC.sh is.

Alternatively, the STIR-GATE-Connection directory can be added to the $PATH, e.g. PATH=$PATH:/path/to/STIR-GATE-Connection. Then every scripts look to see if $SGCPATH is defined, and if not , looks for this_SGC.sh in the $PATH before source this_SGC.sh.

Either way, a PATH has to beed added as an enviromental variable, so I definitely perfer setting SGCPATH as a variable prior to any script calls.

robbietuk commented 3 years ago

Closed by #74 and #78