desihub / desisurvey

Code for desi survey planning and implementation
BSD 3-Clause "New" or "Revised" License
2 stars 7 forks source link

Found invalid plan_tiles in use_plan(). #104

Closed moustakas closed 3 years ago

moustakas commented 4 years ago

@dkirkby @sbailey I'm trying to execute some very simple survey simulations but running into trouble. I'm sure I'm missing something simple---could you advise?

Note that I'm using the desisurvey-config.yaml file from the minitest notebook and the master branches of all the DESI code.

Set one needed environment variable:

export DESISURVEY_OUTPUT=./survey
mkdir -p $DESISURVEY_OUTPUT

Build a simple tile file (here, with four tiles: two DARK, one GRAY, and one BRIGHT).

import os
from astropy.table import Table
import desimodel.io

alltiles = Table(desimodel.io.load_tiles())
ii = (150 < alltiles['RA']) & (alltiles['RA']<152) & (30<alltiles['DEC']) & (alltiles['DEC']<32)
tiles = Table(alltiles[ii])
tiles.write(os.path.join(os.getenv('DESISURVEY_OUTPUT'), 'test-tiles.fits'), overwrite=True)
tiles
<Table length=4>
TILEID         RA           DEC    PASS IN_DESI   EBV_MED    AIRMASS  STAR_DENSITY EXPOSEFAC PROGRAM OBSCONDITIONS
int32       float64       float64 int16  int16    float32    float32    float32     float32    str6      int32    
------ ------------------ ------- ----- ------- ----------- --------- ------------ --------- ------- -------------
 11108             150.87   31.23     1       1 0.018903468 1.0254319    1451.6671  1.157668    DARK             1
 16870 151.96000000000004   31.21     2       1  0.02075856 1.0254421    1403.4232 1.1708232    DARK             1
 28408 150.73000000000002   30.52     4       1 0.019678533 1.0258721    1478.4001 1.1637645    GRAY             2
 34170             151.82    30.5     5       1 0.021682816 1.0258868    1414.4895 1.1780643  BRIGHT             4

Run surveyinit:

surveyinit --config-file ./desisurvey-config.yaml
INFO:utils.py:76:freeze_iers: Freezing IERS table used by astropy time, coordinates.
INFO:ephem.py:84:get_ephem: Building ephemerides for (2019-01-01,2025-12-31)...
INFO:ephem.py:89:get_ephem: Saved ephemerides for (2019-01-01,2025-12-31) to ./survey/ephem_2019-01-01_2025-12-31.fits
INFO:tiles.py:288:get_tiles: Initialized tiles from "./test-tiles.fits".
INFO:tiles.py:293:get_tiles: DARK   passes(tiles): 1(1), 2(1).
INFO:tiles.py:293:get_tiles: GRAY   passes(tiles): 4(1).
INFO:tiles.py:293:get_tiles: BRIGHT passes(tiles): 5(1).
INFO:optimize.py:158:__init__: DARK: 125.6h for 2 tiles (texp_nom 1000.0 s).
INFO:optimize.py:232:__init__: Center flat initial HA assignments at LST -60 deg.
INFO:surveyinit.py:199:calculate_initial_plan: [001] dHA=1.000deg RMSE=400.64% LOSS=57.15% delta(score)= -0.9%
INFO:surveyinit.py:199:calculate_initial_plan: [002] dHA=0.950deg RMSE=396.36% LOSS=55.08% delta(score)= -1.4%
INFO:surveyinit.py:199:calculate_initial_plan: [003] dHA=0.902deg RMSE=405.42% LOSS=53.49% delta(score)= +1.7%
INFO:surveyinit.py:199:calculate_initial_plan: [004] dHA=0.857deg RMSE=405.01% LOSS=52.25% delta(score)= -0.4%
INFO:surveyinit.py:199:calculate_initial_plan: [005] dHA=0.815deg RMSE=413.06% LOSS=50.29% delta(score)= +1.3%
INFO:surveyinit.py:199:calculate_initial_plan: [006] dHA=0.774deg RMSE=405.65% LOSS=49.57% delta(score)= -1.8%
INFO:surveyinit.py:199:calculate_initial_plan: [007] dHA=0.735deg RMSE=409.29% LOSS=48.98% delta(score)= +0.7%
[snip]
INFO:surveyinit.py:199:calculate_initial_plan: [100] dHA=0.006deg RMSE=415.78% LOSS=43.91% delta(score)= +0.0%
INFO:surveyinit.py:211:calculate_initial_plan: DARK plan uses 1.1h with 125.6h avail (11470.9% margin).
INFO:optimize.py:158:__init__: GRAY: 33.3h for 1 tiles (texp_nom 1000.0 s).
INFO:optimize.py:232:__init__: Center flat initial HA assignments at LST -60 deg.
/Users/ioannis/repos/desihub/desisurvey/py/desisurvey/optimize.py:600: RuntimeWarning: invalid value encountered in true_divide
  avg_ha = self.smoothing_weights.dot(self.ha) / self.smoothing_sums
Found invalid plan_tiles in use_plan().
dkirkby commented 4 years ago

I suspect that 4 tiles is not enough for the fancy HA optimization algorithm that surveyinit uses by default. If you are happy with HA=0, this should work:

surveyinit --config-file ./desisurvey-config.yaml --init zero --max-cycles 0
moustakas commented 4 years ago

Thanks @dkirkby that worked. But the next step borked, surely related to the small number of tiles again. All I want/need is an exposures.fits file so I can test https://github.com/desihub/desitarget/pull/561 through the spectral simulations on my laptop without having to run the minitest notebook (which is not so "mini" for what I want to do, and only runs at NERSC!).

time surveysim --config-file ./desisurvey-config.yaml --save-restore
ERROR:rules.py:233:apply: No tiles covered by rule N10(2)
ERROR:rules.py:233:apply: No tiles covered by rule N10(3)
ERROR:rules.py:233:apply: No tiles covered by rule N10(4)
ERROR:rules.py:233:apply: No tiles covered by rule N10(7)
ERROR:rules.py:233:apply: No tiles covered by rule N10P1(1)
ERROR:rules.py:233:apply: No tiles covered by rule N10P0(0)
ERROR:rules.py:233:apply: No tiles covered by rule N10P6(6)
[snip]
ERROR:rules.py:233:apply: No tiles covered by rule SHI(7)
Traceback (most recent call last):
  File "/Users/ioannis/repos/desihub/surveysim/bin/surveysim", line 15, in <module>
    surveysim.scripts.surveysim.main(args)
  File "/Users/ioannis/repos/desihub/surveysim/py/surveysim/scripts/surveysim.py", line 162, in main
    night, scheduler, stats, explist, weather=weather, use_twilight=args.twilight)
  File "/Users/ioannis/repos/desihub/surveysim/py/surveysim/nightops.py", line 154, in simulate_night
    nightstats['nsetup'][passnum] += 1
IndexError: index 4 is out of bounds for axis 0 with size 4
schlafly commented 3 years ago

@moustakas, I'm trying to clean up some old desisurvey issues. Do you want me to take action here? Obviously there have been a lot of changes in the last two years. This may magically work now---certainly the change to no-pass means that the particular line where you're seeing an issue will no longer trigger this particular issue. But I haven't tried to do the equivalent to what you intended here and verified it still works. I'm nevertheless inclined to close unles you feel otherwise.

moustakas commented 3 years ago

Thanks for checking with me. This ticket is pretty stale so let's close.