desihub / specex

DESI spectrograph PSF fitting
BSD 3-Clause "New" or "Revised" License
0 stars 4 forks source link

Print usage #67

Closed marcelo-alvarez closed 2 years ago

marcelo-alvarez commented 2 years ago

Fixes issue raised in desihub/desispec#1794 by printing a usage statement and returning a non-zero value when --help or -h is in the list of options provide as an argument to run_specex. This was just a matter of cleaning up and using the existing PrintHelp C++ function.

It would have been cleaner to move the argparsing entirely to the python side, and then have run_specex take multiple input options like in_psf, out_psf, first_bundle, etc. rather than having run_specex do argument parsing, but this would take a lot more time and testing than we have at the moment, so I've left it for a future update.

I tested this and it works fine, e.g.,

source /global/common/software/desi/desi_environment.sh
switch_to_repo(){
  repo=$1
  branch=$2
  branchdir=$SCRATCH/$repo
  rm -rf $branchdir
  git clone -b $branch git@github.com:desihub/$repo.git $branchdir
  if [ $repo == "specex" ] ; then
    cd $branchdir
    python setup.py build_ext --inplace 
  fi
  export PYTHONPATH=$branchdir/py:$PYTHONPATH 
  export PATH=$branchdir/bin:$PATH    
}
switch_to_repo specex   PrintHelp
switch_to_repo desispec desi_psf_fit
desi_fit_psf -h

results in the following printed to the terminal:

usage: desi_psf_fit [options]
  --help,-h             display usage information
  --arc,-a              preprocessed fits image file name (mandatory)
  --in-psf              input psf file name (fits or xml, can contain
                        only the traces, mandatory)
  --out-psf             output psf fits file name (mandatory)
  --lamp-lines          input lamp lines file name (mandatory)
  --only-trace-fit      only fit the trace coordinates (default is
                        trace,sigma,psf)
  --no-trace-fit        do not fit the trace coordinates (default is
                        trace,sigma,psf)
  --no-sigma-fit        do not fit the gaussian sigma (default is
                        trace,sigma,psf)
  --no-psf-fit          do not fit the psf (default is trace,sigma,psf)
  --flux-hdu            flux hdu in input arc fits, for unusual data format
  --ivar-hdu            ivar hdu in input arc fits, for unusual data format
  --mask-hdu            mask hdu in input arc fits, for unusual data format
  --header-hdu          header hdu in input arc fits, for unusual data format
  --xcoord-hdu          hdu of x trace legendre polynomial of wavelength
                        (default is extension XTRACE)
  --ycoord-hdu          hdu of y trace legendre polynomial of wavelength
                        (default is extension YTRACE)
  --first-bundle        first fiber bundle to fit
  --last-bundle         last fiber bundle to fit
  --single-bundle       fit a single bundle with all fibers
  --first-fiber         first fiber (must be in bundle)
  --last-fiber          last fiber (must be in bundle)
  --half-size-x         half size of PSF stamp (full size is 2*half_size+1)
  --half-size-y         half size of PSF stamp (full size is 2*half_size+1)
  --psfmodel            PSF model, default is GAUSSHERMITE
  --positions           fit positions of each spot individually after global
                        fit for debugging
  --verbose,v           turn on verbose mode (deprecated, true by default)
  --quiet               no info message, only warning
  --debug               turn on debug mode
  --trace-prior-deg     force equal trace coeff in bundle starting at this
                        degree
  --lamplines           lamp lines ASCII file name (def. is
                        $SPECEXDATA/specex_linelist_desi.txt)
  --core                dump core files when an exception is thrown
  --gauss-hermite-deg   degree of Hermite polynomials (same for x and y,
                        only if GAUSSHERMITE psf)
  --gauss-hermite-deg2  degree of Hermite polynomials (same for x and y,
                        only if GAUSSHERMITE2 psf)
  --legendre-deg-wave   degree of Legendre polynomials along wavelength
                        (can be reduced if missing data)
  --legendre-deg-x      degree of Legendre polynomials along x_ccd (can be
                        reduced if missing data)
  --trace-deg-wave      degree of Legendre polynomials along wavelength for
                        fit of traces
  --trace-deg-x         degree of Legendre polynomials along x_ccd for fit of
                        traces
  --psf-error           psf fractional uncertainty (default is 0.01, for
                        weights in the fit)
  --psf-core-wscale     scale up the weight of pixels in 5x5 PSF core
  --broken-fibers       broken fibers (comma separated list)
  --variance-model      refit at the end with a model of the variance to
                        avoid Poisson noise bias
  --out-psf-xml         output psf xml file name
  --out-spots           output spots file name
  --prior               gaussian prior on a param : 'name' value error
  --tmp_results         write tmp results
  --fit-psf-tails       unable fit of psf tails
  --fit-continuum       unable fit of continuum
  --nlines              max # emission lines used (uses an algorithm to
                        select best ones
                        based on S/N and line coverage

@sbailey