cxcsds / ciao-contrib

Extra scripts and code to enhance the capabilities of CIAO.
GNU General Public License v3.0
8 stars 6 forks source link

scrflux, psf_contour et al.: Should we guess `MARX_ROOT` from "which marx"? #848

Closed hamogu closed 1 month ago

hamogu commented 8 months ago

srcflux has a marx_root parameter and will default to the environment variable MARX_ROOT. However, if marx is installed and in the path, we can get that directory automatically:

import shutils
import os
marx_root = os.dirname(os.dirname(shutils.which('marx')))

I suggest that we just get the path that way when neither the marx_root parameter nor the MARX_ROOT environment variable is set. As far as I can see, that would just silently do the right thing of grabbing the correct directory. In particular if marx is installed using conda (which is almost always will be since most users just copy the line from our installation instructions and that includes the conda marx package), users may not have path set and may not actually know where their marx installation is located on disk.

I can open a PR for this, but I wanted to give @kglotfelty a chance to weigh in first, since he's written all the contrib scripts that use marx and there might be some good reason not to do that that I don't see.

kglotfelty commented 8 months ago

Part of the reason for having marx_root was if marx was not in the PATH; simulate_psf adds $marx_root/bin to the PATH. For example on our network marx is installed separate from CIAO so users need to do something extra to get it.

Either way it's still something extra that users have to do: either add marx to PATH or set MARX_ROOT.

hamogu commented 8 months ago

If users install marx as a conda package compiled by DS, then marx will be in their path (because it's in the same .../bin where all the other executibles live). I image that, going forward, that's the most common way to install marx and might in fact be the only practical way in the future (I intend to make changes to marx such that it uses other libraries installed with CIAO, e.g. cfitsio, for reading the CALDB etc.). Even without those future changes, I just suggest to use my code above only as a fall-back: If marx is in the path (which it will be for many users) and the users did nothing extra (like set up a separate MARX_ROOT - which users won't do unless we tell them to), then we can figure out the directories we need from the path to the marx executable.