sot / chandra_aca

Chandra Aspect Camera Tools
https://sot.github.io/chandra_aca
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

Implement data model numerical operators using ACA coordinates #46

Closed taldcroft closed 6 years ago

taldcroft commented 6 years ago

This requires opt-in by only doing this if one of the operands is in ACA coords, i.e. a.aca + b or a + b.aca or a.aca + b.aca.

**Initialize images (different shape and offset)**

  >>> from chandra_aca.aca_image import *
  >>> a = ACAImage(shape=(6, 6), row0=10, col0=20) + 1
  >>> a
  <ACAImage row0=10 col0=20
  array([[1, 1, 1, 1, 1, 1],
         [1, 1, 1, 1, 1, 1],
         [1, 1, 1, 1, 1, 1],
         [1, 1, 1, 1, 1, 1],
         [1, 1, 1, 1, 1, 1],
         [1, 1, 1, 1, 1, 1]])>
  >>> b = ACAImage(np.arange(1, 17).reshape(4, 4), row0=8, col0=18) * 10
  >>> b
  <ACAImage row0=8 col0=18
  array([[ 10,  20,  30,  40],
         [ 50,  60,  70,  80],
         [ 90, 100, 110, 120],
         [130, 140, 150, 160]])>

**Add images (output has shape and row0/col0 of left side input)**

  >>> a + b.aca
  <ACAImage row0=10 col0=20
  array([[111, 121,   1,   1,   1,   1],
         [151, 161,   1,   1,   1,   1],
         [  1,   1,   1,   1,   1,   1],
         [  1,   1,   1,   1,   1,   1],
         [  1,   1,   1,   1,   1,   1],
         [  1,   1,   1,   1,   1,   1]])>
  >>> b + a.aca
  <ACAImage row0=8 col0=18
  array([[ 10,  20,  30,  40],
         [ 50,  60,  70,  80],
         [ 90, 100, 111, 121],
         [130, 140, 151, 161]])>

  >>> b += a.aca
  >>> b
  <ACAImage row0=8 col0=18
  array([[ 10,  20,  30,  40],
         [ 50,  60,  70,  80],
         [ 90, 100, 111, 121],
         [130, 140, 151, 161]])>

**Make ``b`` image be fully contained in ``a``**

  >>> b.row0 = 11
  >>> b.col0 = 21
  >>> a += b.aca
  >>> a
  <ACAImage row0=10 col0=20
  array([[  1,   1,   1,   1,   1,   1],
         [  1,  11,  21,  31,  41,   1],
         [  1,  51,  61,  71,  81,   1],
         [  1,  91, 101, 112, 122,   1],
         [  1, 131, 141, 152, 162,   1],
         [  1,   1,   1,   1,   1,   1]])>
taldcroft commented 6 years ago

BTW this started off as a teeny project to move https://github.com/sot/annie/blob/master/annie/aca.py#L121 into ACAImage. It expanded.

taldcroft commented 6 years ago

@jeanconn @malgosias - ready for final review.

I believe this is fully back-compatible with existing code in that it requires doing an arithmetic operation using the .aca version of at least one of the two operands. I'm guessing that was not done in existing code.

taldcroft commented 6 years ago

I checked in $ska/analysis/dependencies/repos that there are no dependencies on ACAImage in flight-configured tools. I'm merging this now to install along with #45 for Larry. Post-merge review still welcome.