sot / proseco

Probabilistic star evaluation and catalog optimization
https://sot.github.io/proseco
BSD 3-Clause "New" or "Revised" License
1 stars 0 forks source link

Issues with roll optimization of a catalog with monitor windows #364

Closed jeanconn closed 3 years ago

jeanconn commented 3 years ago

The sparkles roll optimization code works from the call_args of the aca (ACACatalogTable) to run star selection and review on roll options. It looks like this conflicts with the current proseco monitor code in a couple of ways.

  1. It looks like in _get_aca_catalog_monitors the use of the "stub" catalog monitors as a reference causes inconsistencies

https://github.com/sot/proseco/blob/175eeeea561adff3561ccfd29e77fa64c5321dfa/proseco/catalog.py#L273

means that even for a case when the "try this as a guide star" case has failed, the kwargs are still set with a "run this as a guide star" in the returned aca_mon object at

https://github.com/sot/proseco/blob/175eeeea561adff3561ccfd29e77fa64c5321dfa/proseco/catalog.py#L288

  1. For either aca_mon or aca_gui returned from from _get_aca_catalog_monitors, the original monitors keyword call arg is lost. Thus even if the value was "right" and function set to 2 for an aca_mon version of the catalog, would that be the most useful thing in the call args? I think the actual original requested monitor type is the thing that, say, the sparkles roll optimization should have handy.

For a fix for both of these issues, I suggest that the kwargs_orig should just be copied back into the call args of the returned object.

For a test I was working with @jskrist 's

kw_dict = {'att': [ 0.32916333, -0.50759709,  0.07481427,  0.79271655],
 'date': '2021:116:16:42:09.065', 'detector': 'ACIS-I',
 'dither_acq': (7.9992, 7.9992), 'dither_guide': (7.9992, 7.9992),
 'man_angle': 86.49934496445843, 'n_acq': 8, 'n_fid': 3, 'n_guide': 5,
 'obsid': 23050.0, 'sim_offset': 0.0, 'focus_offset': 0.0,
 't_ccd_acq': -9.067548914167258, 't_ccd_guide': -8.616156814261098,
 't_ccd_penalty_limit': -6.8, 
 'monitors': [[335.516667,  58.675556,   0.      ,   9.63    ,   0.      ]]}

And running roll optimization and also seeing the BadMonitorError.

jeanconn commented 3 years ago

More debug output characterizing what we're getting now. Note that for the returned first catalog that the monitors call args that originally asks for an AUTO monitor window gets set to 1 / GUIDE and then the call to get the same and similar catalogs for roll optimization fail.

ska3-fido$ ipython
Python 3.8.3 (default, Jul  2 2020, 16:21:59) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import proseco                                                                                                                       

In [2]: kw_dict = {'att': [ 0.32916333, -0.50759709,  0.07481427,  0.79271655], 
   ...:  'date': '2021:116:16:42:09.065', 'detector': 'ACIS-I', 
   ...:  'dither_acq': (7.9992, 7.9992), 'dither_guide': (7.9992, 7.9992), 
   ...:  'man_angle': 86.49934496445843, 'n_acq': 8, 'n_fid': 3, 'n_guide': 5, 
   ...:  'obsid': 23050.0, 'sim_offset': 0.0, 'focus_offset': 0.0, 
   ...:  't_ccd_acq': -9.067548914167258, 't_ccd_guide': -8.616156814261098, 
   ...:  't_ccd_penalty_limit': -6.8,  
   ...:  'monitors': [[335.516667,  58.675556,   0.      ,   9.63    ,   0.      ]]}                                                         

In [3]: aca = proseco.get_aca_catalog(**kw_dict)                                                                                             

In [4]: aca                                                                                                                                  
Out[4]: 
<ACATable length=12>
 slot  idx      id    type  sz   p_acq    mag    maxmag   yang     zang    dim   res  halfw
int64 int64   int64   str3 str3 float64 float64 float64 float64  float64  int64 int64 int64
----- ----- --------- ---- ---- ------- ------- ------- -------- -------- ----- ----- -----
    0     1         1  FID  8x8   0.000    7.00    8.00   919.83  -844.17     1     1    25
    1     2         5  FID  8x8   0.000    7.00    8.00 -1828.23  1053.81     1     1    25
    2     3         6  FID  8x8   0.000    7.00    8.00   385.81  1697.85     1     1    25
    3     4 523514120  BOT  6x6   0.983    6.32    7.82 -1093.14   139.05    28     1   160
    4     5 523508160  BOT  6x6   0.979    8.22    9.72   -68.70  -236.22    28     1   160
    5     6 522978208  BOT  6x6   0.971    8.23    9.73 -2216.71 -2451.23    28     1   160
    6     7 523635184  BOT  6x6   0.976    8.48    9.98  2205.82 -2236.27    28     1   160
    7     8      1000  MON  8x8   0.000    9.63   13.94    69.60    56.40     3     0    20
    0     9 523503664  ACQ  6x6   0.974    8.56   10.06 -2327.71   742.30    28     1   160
    1    10 523634384  ACQ  6x6   0.948    9.34   10.84  2159.85 -1514.93    28     1   160
    2    11 523511392  ACQ  6x6   0.935    9.50   11.00 -2139.86  2008.08    28     1   160
    7    12 523502080  ACQ  6x6   0.935    9.50   11.00  -944.95  -834.04    28     1   160

In [5]: aca.call_args['monitors']                                                                                                            
Out[5]: 
<Table length=1>
  coord0     coord1  coord_type   mag   function ...    dec          yang              zang               row                col        
 float64    float64    uint8    float64  uint8   ...  float64      float64           float64            float64            float64      
---------- --------- ---------- ------- -------- ... --------- ---------------- ------------------ ------------------ ------------------
335.516667 58.675556          0    9.63        1 ... 58.675556 69.5987818215093 56.398970393800944 -7.827762664177882 16.240681416732727

In [6]: acar = aca.get_review_table()                                                                                                        

In [7]: acar.run_aca_review()                                                                                                                

In [8]: acar.messages                                                                                                                        
Out[8]: []

In [9]: acar.get_roll_options()                                                                                                              
---------------------------------------------------------------------------
BadMonitorError                           Traceback (most recent call last)
<ipython-input-9-30fa1e568fd2> in <module>
----> 1 acar.get_roll_options()

~/git/sparkles/sparkles/roll_optimize.py in get_roll_options(self, min_improvement, d_roll, method, max_roll_dev)
    363             kwargs['att'] = att_rolled
    364 
--> 365             aca_rolled = get_aca_catalog(**kwargs)
    366 
    367             P2_rolled = -np.log10(aca_rolled.acqs.calc_p_safe())

~/git/proseco/proseco/__init__.py in get_aca_catalog(*args, **kwargs)
      6 def get_aca_catalog(*args, **kwargs):
      7     from .catalog import get_aca_catalog
----> 8     return get_aca_catalog(*args, **kwargs)
      9 
     10 

~/git/proseco/proseco/catalog.py in get_aca_catalog(obsid, **kwargs)
    125 
    126         if 'monitors' in kwargs:
--> 127             aca = _get_aca_catalog_monitors(obsid=obsid, raise_exc=raise_exc, **kwargs)
    128         else:
    129             aca = _get_aca_catalog(obsid=obsid, raise_exc=raise_exc, **kwargs)

~/git/proseco/proseco/catalog.py in _get_aca_catalog_monitors(**kwargs)
    263     monitors = aca.monitors
    264     if np.all(monitors['function'] != MonFunc.AUTO):
--> 265         return _get_aca_catalog(**kwargs_orig)
    266 
    267     # Find the entries with auto-convert

~/git/proseco/proseco/catalog.py in _get_aca_catalog(**kwargs)
    204 
    205     aca.log('Starting get_mon_catalog')
--> 206     aca.mons = get_mon_catalog(stars=aca.acqs.stars, **kwargs)
    207 
    208     aca.log('Starting get_guide_catalog')

~/git/proseco/proseco/monitor.py in get_mon_catalog(obsid, **kwargs)
     66     # Process monitor window requests, converting them into fake stars that
     67     # are added to the include_ids list.
---> 68     mons.process_monitors()
     69 
     70     return mons

~/git/proseco/proseco/monitor.py in process_monitors(self)
    153                     monitor['mag'] = star['mag']
    154                 elif monitor['function'] == MonFunc.GUIDE:
--> 155                     raise BadMonitorError('no acceptable AGASC star within '
    156                                           '2 arcsec of monitor position')
    157 

BadMonitorError: no acceptable AGASC star within 2 arcsec of monitor position