<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <br>
    <div class="moz-cite-prefix">On 17/10/13 17:20, David Berry wrote:<br>
    </div>
    <blockquote
cite="mid:CAALafn5C22T+oawtqy12_8GLpOWwmsSN5A3KWE7aKA3ofQE1eQ@mail.gmail.com"
      type="cite">
      <div dir="ltr"><br>
        <div class="gmail_extra"><br>
          <br>
          <div class="gmail_quote">On 17 October 2013 15:28, Maik
            Riechert <span dir="ltr"><<a moz-do-not-send="true"
                href="mailto:maik.riechert@arcor.de" target="_blank">maik.riechert@arcor.de</a>></span>
            wrote:<br>
            <blockquote class="gmail_quote" style="margin:0 0 0
              .8ex;border-left:1px #ccc solid;padding-left:1ex">
              <div bgcolor="#FFFFFF" text="#000000">
                <div class="im"> <br>
                  <div>On 17/10/13 14:41, David Berry wrote:<br>
                  </div>
                </div>
                <blockquote type="cite">
                  <div dir="ltr">
                    <div class="im">On 17 October 2013 12:28, Maik
                      Riechert <span dir="ltr"><<a
                          moz-do-not-send="true"
                          href="mailto:maik.riechert@arcor.de"
                          target="_blank">maik.riechert@arcor.de</a>></span>
                      wrote:<br>
                    </div>
                    <div class="gmail_extra">
                      <div class="gmail_quote">
                        <blockquote class="gmail_quote" style="margin:0
                          0 0 .8ex;border-left:1px #ccc
                          solid;padding-left:1ex">
                          <div bgcolor="#FFFFFF" text="#000000">
                            <div class="im"> <br>
                              I tried to use trangrid (with
                              starlink-pyast) but I must be doing
                              something wrong:<br>
                            </div>
                            ...
                            <div class="im"><br>
                              [[-0.69877269 -0.69914315 -0.69951373 ...,
                              -1.22724324 -1.22756251<br>
                                -1.22788175]<br>
                               [ 0.83534859  0.83540118  0.83545372
                              ...,  0.5841799   0.58413968<br>
                                 0.58409942]]<br>
                              <br>
                              I am expecting coordinates ranging from
                              320..285 for RA and 48..33 for Dec.<br>
                              <br>
                            </div>
                          </div>
                        </blockquote>
                        <div class="im">
                          <div><br>
                          </div>
                          <div>Two issues:</div>
                          <div><br>
                          </div>
                          <div>1) AST uses radians to represent angles,
                            not degrees. The above values are consistent
                            with the ranges you quote taking this into
                            account. </div>
                          <div><br>
                          </div>
                          <div>2) The negative RA values need 2*PI added
                            to them. Longitude axes such as RA have the
                            inconvenient characteristic of having a
                            wrap-around discontinuity somewhere. When
                            reporting values to human beings is is usual
                            to put this discontinuity at RA=0. But this
                            is not always what you want when dealing
                            with RA values in code. For instance, if
                            your image contains zero longitude,
                            measuring RA intervals on your image is
                            awkward. In this case it would be much more
                            convenient to put the discontinuity at
                            RA=180, so that RA=-10 is used in place of
                            RA=350 (for instance).</div>
                          <div><br>
                          </div>
                          <div>In view of such uncertainty about the
                            best place to put the discontinuity, AST
                            takes a neutral view and makes no assumption
                            or guarantee about where the discontinuity
                            will be. Instead, it provides the astNorm
                            method (a method of the Frame class)  which
                            "normalises" the axis values representing a
                            position within the Frame, to the form
                            usually expected by human readers. So for
                            instance the SkyFrame class provides an
                            implementation of astNorm that puts
                            longitude into the range [0,2*PI] and
                            latitude into the range [-PI/2,+PI/2].</div>
                          <div><br>
                          </div>
                          <div>AST's expectation is that the bulk of
                            calculations performed on
                            (longitude,latitude) pairs will be
                            unaffected by the position of the
                            discontinuity, and so it saves time by not
                            performing normalisation automatically. In
                            the few cases where it really does matter
                            that the discontinuity is at a specific
                            place,  the astNorm method can be used (or
                            you can do the normalisation using your own
                            code if you know a priori that the axis
                            values represents a position on the sky).</div>
                          <div><br>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </blockquote>
                <br>
                Thanks David for this detailed explanation. I could
                confirm the results now too. When using for instance
                0.00005 as tolerance it is around 10 times faster than
                the exact algorithm, very nice!<br>
                <br>
                One more question though. I translated three single
                pixel coordinates to RA, Dec and then again to pixel
                coordinates using the tran() method. I expected that
                both sets of pixel coordinates are nearly identical
                (which they are when using astropy), but this is what I
                got:<br>
                <br>
                Input pixel coords:<br>
                [[ -196.,   735.,  4059.],<br>
                 [ -504.,   459.,  2328.]]<br>
                <br>
                Calculated pixel values:<br>
                [[ -205.93229216,   735.        ,  4179.93253144],<br>
                 [ -499.36855108,   459.        ,  2246.86209704]]<br>
                <br>
                Note that (735,459) is the WCS center reference.<br>
                <br>
                Any idea?<span class="HOEnZb"><font color="#888888"><br>
                    <br>
                  </font></span></div>
            </blockquote>
            <div><br>
            </div>
            <div><br>
            </div>
            <div style="">Hi Maik,</div>
            <div style="">              The tolerance you specify when
              running TranGrid is a distance in the output coordinate
              system, which in your case I presume is (ra,dec). So a
              tolerance value of 0.00005 is taken as a value in radians,
              which is about 10 arc-seconds. So errors of up to this
              sort of size could be expected from the linear
              approximations being used. What is the pixel size in your
              case? You should find that using a smaller tolerance
              results in smaller round-trip errors. If this is not the
              case, it may be a bug, in which case I'd be interested to
              see the FITS header you are using so that I can track it
              down.</div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
    I didn't use tranGrid here, just tran! So no tolerance involved. <br>
                               <br>
    NAXIS1  =                 1468 / image
    width                                    <br>
    NAXIS2  =                  916 / image
    height                                      <br>
    CTYPE1  = 'RA---TAN-SIP' / TAN (gnomic) projection + SIP distortions<br>
    CTYPE2  = 'DEC--TAN-SIP' / TAN (gnomic) projection + SIP distortions<br>
    EQUINOX =               2000.0 / Equatorial coordinates definition
    (yr)<br>
    LONPOLE =                180.0 / no
    comment                                     <br>
    LATPOLE =                  0.0 / no
    comment                                     <br>
    CRVAL1  =         302.88771538 / RA  of reference
    point                         <br>
    CRVAL2  =        41.8941029213 / DEC of reference
    point                         <br>
    CRPIX1  =                  735 / X reference
    pixel                              <br>
    CRPIX2  =                  459 / Y reference
    pixel                              <br>
    CUNIT1  = 'deg     ' / X pixel scale
    units                                      <br>
    CUNIT2  = 'deg     ' / Y pixel scale
    units                                      <br>
    CD1_1   =     -0.0157184611387 / Transformation
    matrix                          <br>
    CD1_2   =     0.00022032143241 / no
    comment                                     <br>
    CD2_1   =   -0.000284856284919 / no
    comment                                     <br>
    CD2_2   =     -0.0159943489114 / no
    comment                                     <br>
    IMAGEW  =                 1468 / Image width,  in
    pixels.                       <br>
    IMAGEH  =                  916 / Image height, in
    pixels.                       <br>
    A_ORDER =                    2 / Polynomial order, axis
    1                       <br>
    A_0_2   =   -5.10167355829E-05 / no
    comment                                     <br>
    A_1_1   =   -5.54267287337E-05 / no
    comment                                     <br>
    A_2_0   =    3.68095680847E-05 / no
    comment                                     <br>
    B_ORDER =                    2 / Polynomial order, axis
    2                       <br>
    B_0_2   =    2.49853669312E-05 / no
    comment                                     <br>
    B_1_1   =    6.07756179822E-05 / no
    comment                                     <br>
    B_2_0   =   -1.70350503136E-05 / no
    comment                                     <br>
    AP_ORDER=                    2 / Inv polynomial order, axis
    1                   <br>
    AP_0_1  =     -0.0014471978634 / no
    comment                                     <br>
    AP_0_2  =     5.0935282476E-05 / no
    comment                                     <br>
    AP_1_0  =    0.000641040653934 / no
    comment                                     <br>
    AP_1_1  =    5.54267224252E-05 / no
    comment                                     <br>
    AP_2_0  =     -3.674588665E-05 / no
    comment                                     <br>
    BP_ORDER=                    2 / Inv polynomial order, axis
    2                  <br>
    BP_0_1  =      0.0010860421788 / no
    comment                                     <br>
    BP_0_2  =   -2.49999638422E-05 / no
    comment                                     <br>
    BP_1_0  =   -0.000569392740582 / no
    comment                                     <br>
    BP_1_1  =   -6.07473585161E-05 / no comment   <br>
    BP_2_0  =     1.7000827442E-05 / no comment<br>
    <br>
    Maik<br>
    <blockquote
cite="mid:CAALafn5C22T+oawtqy12_8GLpOWwmsSN5A3KWE7aKA3ofQE1eQ@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div class="gmail_extra">
          <div class="gmail_quote">
            <div style=""><br>
            </div>
            <div style="">David </div>
            <div><br>
            </div>
            <div><br>
            </div>
            <div> </div>
            <blockquote class="gmail_quote" style="margin:0 0 0
              .8ex;border-left:1px #ccc solid;padding-left:1ex">
              <div bgcolor="#FFFFFF" text="#000000">
                <span class="HOEnZb"><font color="#888888"> Maik</font></span>
                <div>
                  <div class="h5"><br>
                    <br>
                    <blockquote type="cite">
                      <div dir="ltr">
                        <div class="gmail_extra">
                          <div class="gmail_quote">
                            <div><br>
                            </div>
                            <div>David <br>
                            </div>
                            <div><br>
                            </div>
                            <div><br>
                            </div>
                            <blockquote class="gmail_quote"
                              style="margin:0 0 0 .8ex;border-left:1px
                              #ccc solid;padding-left:1ex">
                              <div bgcolor="#FFFFFF" text="#000000"> For
                                comparison, my astropy code looks like
                                that:<br>
                                <br>
                                wcs = WCS(hdulist[0].header)<br>
                                x, y = np.meshgrid(np.arange(width),
                                np.arange(height)) <br>
                                ra, dec = wcs.wcs_pix2world(x, y, 0)<br>
                                <br>
                                Cheers<br>
                                Maik<br>
                                <br>
                                <blockquote type="cite">
                                  <div dir="ltr">
                                    <div class="gmail_extra">
                                      <div class="gmail_quote">
                                        <div> David</div>
                                        <div><br>
                                        </div>
                                        <div> </div>
                                        <blockquote class="gmail_quote"
                                          style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Cheers,<br>
                                          Tom<br>
                                          <br>
                                          ><br>
                                          > Maik<br>
                                          ><br>
                                          ><br>
                                          > On 16/10/13 15:15, Thomas
                                          Robitaille wrote:<br>
                                          >><br>
                                          >> Hi Maik,<br>
                                          >><br>
                                          >> Someone asked a very
                                          similar question just
                                          yesterday on GitHub:<br>
                                          >><br>
                                          >> <a
                                            moz-do-not-send="true"
                                            href="https://github.com/astropy/astropy/issues/1587"
                                            target="_blank">https://github.com/astropy/astropy/issues/1587</a><br>
                                          >><br>
                                          >> In short, the
                                          solution in your case is:<br>
                                          >><br>
                                          >> NAXIS1 = 4256<br>
                                          >> NAXIS2 = 2832<br>
                                          >> x = np.arange(NAXIS1)<br>
                                          >> y = np.arange(NAXIS2)<br>
                                          >> X, Y = np.meshgrid(x,
                                          y)<br>
                                          >> ra, dec =
                                          wcs.wcs_pix2world(X, Y, 0)<br>
                                          >><br>
                                          >> Any luck?<br>
                                          >><br>
                                          >> Tom<br>
                                          >><br>
                                          >><br>
                                          >><br>
                                          >><br>
                                          >> On 16 October 2013
                                          14:48, Maik Riechert <<a
                                            moz-do-not-send="true"
                                            href="mailto:maik.riechert@arcor.de"
                                            target="_blank">maik.riechert@arcor.de</a>>


                                          wrote:<br>
                                          >>><br>
                                          >>> Hi,<br>
                                          >>><br>
                                          >>> I'm quite new to
                                          python and astropy and got
                                          stuck at the following which<br>
                                          >>> probably is
                                          extremely easy to do.<br>
                                          >>><br>
                                          >>> I created a WCS
                                          object out of a FITS header
                                          and wanted to get the RA/Dec<br>
                                          >>> coordinates of
                                          each image pixel. I tried:<br>
                                          >>><br>
                                          >>>
                                          w.wcs_pix2world(np.ndindex(4256,
                                          2832), 0)<br>
                                          >>><br>
                                          >>> where 4256x2832
                                          are the image dimensions. This
                                          returns 'ValueError:<br>
                                          >>> object of too
                                          small depth for desired
                                          array'. I was trying to avoid<br>
                                          >>> allocating an
                                          array with all pixel
                                          coordinates and thought an
                                          iterator<br>
                                          >>> would work too.<br>
                                          >>><br>
                                          >>> What would you
                                          recommend for my case
                                          (translating every pixel)?<br>
                                          >>><br>
                                          >>> Cheers and
                                          thanks,<br>
                                          >>> Maik<br>
                                          >>><br>
                                          >>><br>
                                          >>>
                                          _______________________________________________<br>
                                          >>> AstroPy mailing
                                          list<br>
                                          >>> <a
                                            moz-do-not-send="true"
                                            href="mailto:AstroPy@scipy.org"
                                            target="_blank">AstroPy@scipy.org</a><br>
                                          >>> <a
                                            moz-do-not-send="true"
                                            href="http://mail.scipy.org/mailman/listinfo/astropy"
                                            target="_blank">http://mail.scipy.org/mailman/listinfo/astropy</a><br>
                                          ><br>
                                          ><br>
_______________________________________________<br>
                                          AstroPy mailing list<br>
                                          <a moz-do-not-send="true"
                                            href="mailto:AstroPy@scipy.org"
                                            target="_blank">AstroPy@scipy.org</a><br>
                                          <a moz-do-not-send="true"
                                            href="http://mail.scipy.org/mailman/listinfo/astropy"
                                            target="_blank">http://mail.scipy.org/mailman/listinfo/astropy</a><br>
                                        </blockquote>
                                      </div>
                                      <br>
                                    </div>
                                  </div>
                                </blockquote>
                                <br>
                              </div>
                            </blockquote>
                          </div>
                          <br>
                        </div>
                      </div>
                    </blockquote>
                    <br>
                  </div>
                </div>
              </div>
            </blockquote>
          </div>
          <br>
        </div>
      </div>
    </blockquote>
    <br>
  </body>
</html>