Skip to content

Commit

Permalink
Allow setting AcaReviewTable target offset and use it in roll opt
Browse files Browse the repository at this point in the history
  • Loading branch information
taldcroft committed May 14, 2020
1 parent d1a64cc commit 159142f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 2 additions & 0 deletions sparkles/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ class ACAReviewTable(ACATable, RollOptimizeMixin):
roll_options = MetaAttribute()
roll_info = MetaAttribute()
messages = MetaAttribute()
target_offset_y = MetaAttribute(default=0.0)
target_offset_z = MetaAttribute(default=0.0)

def __init__(self, *args, **kwargs):
"""Init review methods and attrs in ``aca`` object *in-place*.
Expand Down
16 changes: 9 additions & 7 deletions sparkles/roll_optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def _calc_aca_from_targ(self, q_att, y_off, z_off):
q_out = calc_aca_from_targ(q_att, y_off, z_off) if self.is_OR else q_att
return q_out

def get_roll_intervals(self, cand_idxs, y_off=0, z_off=0, d_roll=0.25,
def get_roll_intervals(self, cand_idxs, d_roll=0.25,
method='uniq_ids', max_roll_dev=None):
"""Find a list of rolls that might substantially improve guide or acq catalogs.
If ``roll_nom`` is not specified then an approximate value is computed
Expand Down Expand Up @@ -166,7 +166,8 @@ def get_ids_list(roll_offsets):
att_targ_rolled = Quat([att_targ.ra, att_targ.dec, att_targ.roll + roll_offset])

# Transform back to ACA pointing for computing star positions.
att_rolled = self._calc_aca_from_targ(att_targ_rolled, y_off, z_off)
att_rolled = self._calc_aca_from_targ(
att_targ_rolled, self.target_offset_y, self.target_offset_z)

# Get yag/zag row/col for candidates
yag, zag = radec_to_yagzag(cands['ra'], cands['dec'], att_rolled)
Expand All @@ -182,13 +183,12 @@ def get_ids_list(roll_offsets):
pitch = Ska.Sun.pitch(att.ra, att.dec, self.date)
roll_nom = Ska.Sun.nominal_roll(att.ra, att.dec, self.date)
att_nom = Quat([att.ra, att.dec, roll_nom])
att_nom_targ = self._calc_targ_from_aca(att_nom, y_off, z_off)
att_nom_targ = self._calc_targ_from_aca(att_nom, self.target_offset_y, self.target_offset_z)
roll_nom = att_nom_targ.roll
roll_dev = allowed_rolldev(pitch)

if max_roll_dev is not None:
roll_dev = min(roll_dev, max_roll_dev)


# Ensure roll_nom in range 0 <= roll_nom < 360 to match att_targ.roll.
# Also ensure that roll_min < roll < roll_max. It can happen that the
Expand Down Expand Up @@ -221,6 +221,7 @@ def get_ids_list(roll_offsets):
'roll_max': roll_max,
'roll_nom': roll_nom}

print(roll_intervals)
return sorted(roll_intervals, key=lambda x: x['roll']), roll_info

@staticmethod
Expand Down Expand Up @@ -293,8 +294,8 @@ def _get_roll_intervals_uniq_ids(ids0, ids_list, roll, roll_max, roll_min,
roll_intervals.append(roll_interval)
return roll_intervals

def get_roll_options(self, min_improvement=-300, d_roll=0.25, method='uniform',
max_roll_dev=2.5):
def get_roll_options(self, min_improvement=0.3, d_roll=0.25, method='uniq_ids',
max_roll_dev=None):
"""
Get roll options for this catalog.
Expand Down Expand Up @@ -388,6 +389,7 @@ def improve_metric(n_stars, P2, n_stars_new, P2_new):
count_9th=self.is_ER)

improvement = improve_metric(n_stars, P2, n_stars_rolled, P2_rolled)
print(roll, P2_rolled, n_stars_rolled, improvement)

if improvement > min_improvement:
acar = self.__class__(aca_rolled, obsid=self.obsid,
Expand Down

0 comments on commit 159142f

Please sign in to comment.