Skip to content

Commit

Permalink
Initial fa-on-the-fly commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
schlafly committed Jun 4, 2021
1 parent 58e4cc2 commit 365b111
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 8 deletions.
62 changes: 62 additions & 0 deletions bin/fba-main.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash

# this script is a wrapper for a fba_launch call for one main tile
# there is no "svn up" here, no SVN checks
# the code will exit if a TILEID already existing in the official SVN folder exists

TILEID=$1 # e.g. 1000
QA=$2 # y or n

OUTDIR=$FA_HOLDING_PEN
TILESFN=$SURVEYOPS/ops/tiles-main.ecsv
DTCATVER=1.1.1

# setting the proper environment
# https://desi.lbl.gov/trac/wiki/SurveyOps/FiberAssignAtKPNO version #18
if [ -z $NERSC_HOST ]; then
# at KPNO
export DESI_PRODUCT_ROOT=/software/datasystems/desiconda/20200924
export DESI_ROOT=/data/datasystems
export DESI_TARGET=$DESI_ROOT/target
export DESI_SURVEYOPS=$DESI_ROOT/survey/ops/surveyops/trunk
module use $DESI_PRODUCT_ROOT/modulefiles
module load desiconda
module load desimodules/21.5
module swap desitarget/1.1.1
module swap fiberassign/5.0.0
module swap desimodel/master
else
echo Doing nothing at NERSC.
# source /global/cfs/cdirs/desi/software/desi_environment.sh 21.5
fi

if [ -z $FIBER_ASSIGN_DIR ]; then
SVNTILEDIR=$DESI_TARGET/fiberassign/tiles/trunk
else
SVNTILEDIR=$FIBER_ASSIGN_DIR
fi

# grabbing the RA, DEC, PROGRAM, STATUS, HA for TILEID
LINE=`awk '{if ($1 == '$TILEID') print $0}' $TILESFN`
RA=`echo $LINE | awk '{print $3}'`
DEC=`echo $LINE | awk '{print $4}'`
PROGRAM=`echo $LINE | awk '{print $5}'`
STATUS=`echo $LINE | awk '{print $8}'`
HA=`echo $LINE | awk '{print $10}'`

# small sanity check
if [[ "$STATUS" != "unobs" ]]
then
echo "TILEID=$TILEID has already been observed; exiting"
exit
fi

# calling fba_launch
if [[ "$QA" == "y" ]]
then
CMD="fba_launch --outdir $OUTDIR --tileid $TILEID --tilera $RA --tiledec $DEC --survey main --program $PROGRAM --ha $HA --dtver $DTCATVER --steps qa --log-stdout --doclean y --svntiledir $SVNTILEDIR --worldreadable"
else
CMD="fba_launch --outdir $OUTDIR --tileid $TILEID --tilera $RA --tiledec $DEC --survey main --program $PROGRAM --ha $HA --dtver $DTCATVER --nosteps qa --doclean n --svntiledir $SVNTILEDIR --worldreadable --log-stdout"
fi
echo $CMD
eval $CMD
59 changes: 51 additions & 8 deletions py/desisurvey/NTS.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
from astropy import units as u
from astropy import time
import numpy as np
import subprocess

try:
import DOSlib.logger as Log
Expand Down Expand Up @@ -177,6 +178,15 @@ def azinrange(az, low, high):
return (az >= low) & (az <= high)


def get_fiberassign_dir():
fadir = os.environ.get('DOS_DESI_TILES', None)
if fadir is None:
fadir = os.environ.get('FIBER_ASSIGN_DIR', None)
if fadir is None:
logob.error('DOS_DESI_TILES and FIBER_ASSIGN_DIR not set!')
return fadir


def move_tile_into_place(tileid, speculative=False):
"""Move fiberassign file into place if not already there.
Expand All @@ -192,11 +202,8 @@ def move_tile_into_place(tileid, speculative=False):
speculative : bool
if True, do not perform the actual copy; just check existence.
"""
fadir = os.environ.get('DOS_DESI_TILES', None)
fadir = get_fiberassign_dir()
if fadir is None:
fadir = os.environ.get('FIBER_ASSIGN_DIR', None)
if fadir is None:
logob.error('DOS_DESI_TILES and FIBER_ASSIGN_DIR not set!')
return False
tileidstr = '%06d' % tileid
fabasefn = os.path.join(tileidstr[0:3], 'fiberassign-%s' % tileidstr)
Expand Down Expand Up @@ -236,6 +243,29 @@ def move_tile_into_place(tileid, speculative=False):
return True


def design_tile_on_fly(tileid, speculative=False):
# don't actually design the tile, but say we did
# not sure what else we might want to check here.
if speculative:
return True
fadir = get_fiberassign_dir()
if fadir is None:
return False
tileidpad = '%06d' % tileid
subdir = tileidpad[:3]
outfnnogz = os.path.join(fadir, subdir, 'fiberassign-%s.fits' % tileidpad)
outfn = os.path.join(fadir, subdir, 'fiberassign-%s.fits.gz' % tileidpad)
if os.path.exists(outfnnogz) or os.path.exists(outfn):
return True
subprocess.call(['fba-main.sh', str(tileid), 'n'],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
subprocess.Popen(['fba-main.sh', str(tileid), 'y'],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
if os.path.exists(outfn):
return True
return False


class NTS():
def __init__(self, obsplan=None, defaults={}, night=None,
nts_survey=None):
Expand Down Expand Up @@ -287,6 +317,8 @@ def __init__(self, obsplan=None, defaults={}, night=None,
raise ValueError('Could not find obsplan configuration!')
desisurvey.config.Configuration.reset()
config = desisurvey.config.Configuration(obsplan)
self.log.info('Loading obsplan from {}, desisurvey version {}'.format(
obsplan, desisurvey.__version__))
_ = desisurvey.tiles.get_tiles(use_cache=False, write_cache=True)

self.default_seeing = defaults.get('seeing', 1.1)
Expand All @@ -296,6 +328,11 @@ def __init__(self, obsplan=None, defaults={}, night=None,
self.rules = desisurvey.rules.Rules(
config.get_path(config.rules_file()))
self.config = config
fa_on_the_fly = getattr(config, 'fa_on_the_fly', None)
if fa_on_the_fly is not None:
self.fa_on_the_fly = fa_on_the_fly()
else:
self.fa_on_the_fly = False
try:
self.planner = desisurvey.plan.Planner(
self.rules, restore=config.tiles_file(),
Expand Down Expand Up @@ -468,10 +505,16 @@ def next_tile(self, conditions=None, exposure=None, constraints=None,
self.requestlog.logresponse(badtile)
return badtile

if not move_tile_into_place(tileid, speculative=speculative):
self.log.error('Could not find tile {}!'.format(tileid))
self.requestlog.logresponse(badtile)
return badtile
if self.fa_on_the_fly and not constraints.get('static_fa_only', False):
if not design_tile_on_fly(tileid, speculative=speculative):
self.log.error('fa-on-the-fly failed!')
self.requestlog.logresponse(badtile)
return badtile
else:
if not move_tile_into_place(tileid, speculative=speculative):
self.log.error('Could not find tile {}!'.format(tileid))
self.requestlog.logresponse(badtile)
return badtile

self.scheduler.plan.add_pending_tile(tileid)

Expand Down

0 comments on commit 365b111

Please sign in to comment.