PixelPositionProvider J2000 coordinates

Discussions on extending SharpCap using the built in Python scripting functionality
Jean-Francois
Posts: 859
Joined: Sun Oct 13, 2019 10:52 am
Location: Germany

PixelPositionProvider J2000 coordinates

#1

Post by Jean-Francois »

Hello Robin,

I wish to use some function from the PixelPositionProvider.
I remark some variation of the output of the calculation.

With the following script:

Code: Select all

import time
from SharpCap.Interfaces import PlateSolvePurpose
from System.Threading import CancellationToken

print("Plates Solve result:")
result = SharpCap.SafeGetAsyncResult(SharpCap.BlindSolver.SolveAsync(PlateSolvePurpose.Annotation, CancellationToken()))
print(result)
P = SharpCap.PixelPositionProvider.MapPixel(PointF(float(res[0])/2, float(res[1])/2))
print(P)
print(SharpCap.PixelPositionProvider.Orientation_UpDegreesEastOfNorth, "UpDegreesEastOfNorth")
print()
print("Map Coordinate of Plates Solve result:")
print(SharpCap.PixelPositionProvider.MapCoordinate(result))
time.sleep(1)
print(SharpCap.PixelPositionProvider.MapCoordinate(result))
time.sleep(1)
print(SharpCap.PixelPositionProvider.MapCoordinate(result))
time.sleep(1)
print(SharpCap.PixelPositionProvider.MapCoordinate(result))
... and the following steps ...

- I use the GSS Telescope Simulator
- I use the Test Camera 1 (Deep Sky) with the M42 image
- I connect the GSS Telescope Simulator
- I perform a GOTO to Target M42
- I start the preceding script
- I disconnect the GSS Telescope Simulator
- I restart the script
- I reconnect the GSS Telescope Simulator, but do not perform a GOTO to M42 (the mount is still at the Home position)
- I restart the script

Here the results:

>>>
Plates Solve result:
RA=05:35:21.0,Dec=-05:18:27
RA=05:35:21.0,Dec=-05:18:27
272.86781119025409 UpDegreesEastOfNorth

Map Coordinate of Plates Solve result:
{X=639.99945, Y=480.00537}
{X=639.9852, Y=479.96814}
{X=639.97577, Y=479.9702}
{X=639.9565, Y=480.04028}
>>>
Plates Solve result:
RA=05:35:21.0,Dec=-05:18:27
RA=05:35:21.0,Dec=-05:18:27
272.86781119025409 UpDegreesEastOfNorth

Map Coordinate of Plates Solve result:
{X=639.99945, Y=480.00537}
{X=639.99945, Y=480.00537}
{X=639.99945, Y=480.00537}
{X=639.99945, Y=480.00537}
>>>
Plates Solve result:
RA=05:35:21.0,Dec=-05:18:27
None
272.86781119025409 UpDegreesEastOfNorth

Map Coordinate of Plates Solve result:
None
None
None
None
>>>


It seems that the function "SharpCap.PixelPositionProvider.MapCoordinate()" ask some information from the mount.
Is that correct ?


Additional question ... UpDegreesEastOfNorth ??
I changed the orientation of the image with the Flip (Horiz, Vert, Both). The image of M42 is flipped.
The result of SharpCap.PixelPositionProvider.Orientation_UpDegreesEastOfNorth seems to be calculated only if a mount is connected and pointing near the image coordinates.

The angle result is the same with or without an horizontal flip.

Flip None:
Solution : RA=05:35:20.7,Dec=-05:18:31 (J2000)
Orientation : up is 272.8 degrees E of N

Flip Horizontal:
Solution : RA=05:35:21.0,Dec=-05:18:27 (J2000)
Orientation : up is 272.9 degrees E of N

But how to determine the image orientation ? (where is the North and the East direction ? if the result is always "up is 272.8 degrees E of N")



Regards,
Jean-Francois
User avatar
admin
Site Admin
Posts: 17606
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: PixelPositionProvider J2000 coordinates

#2

Post by admin »

Hi,

firstly, yes, the mapping of pixel co-ordinates to/from the sky co-ordinates does take information from the mount (if connected). The idea is that is you have made small movements to the mount position since plate solving, these changes are taken into account by the calculations. What is going on with the pixel positions changing slightly is most likely that the mount co-ordinates being read back from the ASCOM driver are not perfectly steady, but are fluctuating slightly at a level below the accuracy shown in the user interface. These slight changes in RA/Dec are enough to make the pixel positions change by a few hundredths of a pixel.

It's also worth knowing that behind the scenes there are two PixelPositionProviders - one to handle this offset that is used when a mount is connected and one that is used when there is no mount connected and doesn't do any offsetting. If you plate solve with no mount connected, then connect the mount, it will switch from the 'no mount' one to the 'with mount' one, but the 'with mount' one will not have the plate solve info, so will be unable to map pixels until you plate solve again.

UpDegreesEastOfNorth...

Firstly, please make sure your SharpCap is right up-to-date, as there was a bug in the calculation of this that I only fixed recently (I had not realised that east-of-north should be counted anti-clockwise because you are looking up at the sky, rather than the usual clockwise as if you were looking down at a map).

The value for this is also not sensitive to *horizontal* flips in the image (left/right mirrored), because such a horizontal flip leaves the 'up' direction of the image unchanged. You should see a change in the value if the image is flipped in the vertical direction (up/down mirrored), since that changes the direction of 'up' in the image to (180 minus the old value) mod 360.

If you want to calculate the full orientation info of the image, the best bet is to map the center pixel, one 10 pixels to the right of center and one 10 pixels down (or up) from center and work from those 3 co-ordinate results. You could also (recent versions of SharpCap 4.1) get the CDHeaderInfo from the PixelPositionProvider - this is the data used to fill FITS WCS headers, so provides the full mapping CRVAL_n/CRPIX_n/CDn_m/etc information.

Hopefully this provides enough info for you to work on - if you need any more details then just ask :)

cheers,

Robin
Jean-Francois
Posts: 859
Joined: Sun Oct 13, 2019 10:52 am
Location: Germany

Re: PixelPositionProvider J2000 coordinates

#3

Post by Jean-Francois »

Hello Robin,

OK for the PixelPositionProvider ... it is like I was thinking.
That may be explain sometimes the (tiny) drift of the Deep Sky Annotation.

For the UpDegreesEastOfNorth ...
I can still not "view" it correctly.
The orientation of the image should have 2 information ... one the angle of the North direction relative to the image "up" direction.
The other is the direction of the East direction ... it can be on one side or the other of the North direction.

OK, I will have a look at the CDHeaderInfo.
I will come back with more questions or a success.

Note ... I use always the last version of SharpCap :-)

Regards,
Jean-Francois
Jean-Francois
Posts: 859
Joined: Sun Oct 13, 2019 10:52 am
Location: Germany

Re: PixelPositionProvider J2000 coordinates

#4

Post by Jean-Francois »

Hello Robin,

I tested the GetCDHeaderInfo() ... it works, but ...

When I use a real image (from last Saturday), I have some differences between the CDn_n and the calculated value.
Here an example with the following script:

Code: Select all

import math

from System.Threading import CancellationToken
from SharpCap.Base import Epoch
from SharpCap.Interfaces import PlateSolvePurpose

result = SharpCap.SafeGetAsyncResult(SharpCap.BlindSolver.SolveAsync(PlateSolvePurpose.Annotation, CancellationToken()))
info=SharpCap.PixelPositionProvider.GetCDHeaderInfo(Epoch.J2000)

w = math.radians(info.CROTA2)

print("Calculate CD matrix")
print()
print(" CDELT1*cos(CROTA2) =",  info.CDELT1 * math.cos(w))
print("-CDELT2*sin(CROTA2) =", -info.CDELT2 * math.sin(w))
print(" CDELT1*sin(CROTA2) =",  info.CDELT1 * math.sin(w))
print(" CDELT2*cos(CROTA2) =",  info.CDELT2 * math.cos(w))
print()
print("CD1_1 =", info.CD1_1)
print("CD1_2 =", info.CD1_2)
print("CD2_1 =", info.CD2_1)
print("CD2_2 =", info.CD2_2)
print()
It is fine with the image directly, but I have different value with Horizontal/Vertical flip.
WCS_FITS_info.jpg
WCS_FITS_info.jpg (636.4 KiB) Viewed 1465 times
Regards,
Jean-Francois
User avatar
admin
Site Admin
Posts: 17606
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: PixelPositionProvider J2000 coordinates

#5

Post by admin »

Hi Jean-Francois,

no quick answer for that one I'm afraid, but I will look into it and see what I can work out :)

cheers,

Robin
User avatar
admin
Site Admin
Posts: 17606
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: PixelPositionProvider J2000 coordinates

#6

Post by admin »

Hi Jean-Francois,

had a look at this and I think the problem is that I was using the values from the displayed orientation as the source for the CROTA values (with some adjustments that I thought were correct).

I am going to change the code so that it calculates CROTA1/2 (and CDELT1/2) from the CDX_Y values, since those are the *definitive* ones for the mapping matrix. Strictly speaking the CROTA values should be ignored when the CD values are present (apparently there was ambiguity in the original definition of the CROTA values, which led to them being used in different ways by different software, so it is best to avoid them now). As far as I know the CDX_Y values *are* correct ( I have tested using them to back-calculated the co-ordinates of a known star in an image).

The convention I am finding online and in your code is to use CROTA2, so I am going to calculate that from CD2_1 and CD1_1. The CD mapping matrix however might not be a pure rotation, so there might be a mirroring if the image is flipped or some slight skew. In the case of mirroring, calculating results from CDELT1/2 and CROTA2 will give badly wrong answers. If there is just a bit of skew then the CD figures back calculated via the Sin/Cos equations will just be a bit out.

cheers,

Robin
Jean-Francois
Posts: 859
Joined: Sun Oct 13, 2019 10:52 am
Location: Germany

Re: PixelPositionProvider J2000 coordinates

#7

Post by Jean-Francois »

Hello Robin,

Thanks for updating the code for the CROTA calculation. I did not test it yet.

UpDegreesEastOfNorth ...
I did some additional tests.
I open the M42 Camera Test image in Prism software and I did some analysis.
It was clear that other software has different definition of the image rotation (not something with the UP-North, but the image +X and RA+ direction).

I inserted the M42 image in the star chart.

M42_North_orientation_1.jpg
M42_North_orientation_1.jpg (271.36 KiB) Viewed 1404 times

In addition, I have my script with the calculation of the angle between the North and image UP direction.
I generated a rotated (15°) new image. I have sometimes the same angle, but not all the time.

My script shows a line with 2 circles. One circle in the centre the other in the +DEC (= North) direction.
We can see that my script gives the same result as the tool "Pixel Position/Click to Recentre".
I have 252.3°. SharpCap shows 108°. (252° + 108° = 360°) ... OK, it means I have the angle from the UP direction, clockwise 252°.
SharpCap has the angle from UP direction, counter-clockwise 108°. The question is how to know when it is clockwise or counter-clockwise ?

M42_North_orientation_2.jpg
M42_North_orientation_2.jpg (303.21 KiB) Viewed 1404 times

Additional question ... is it possible to show a colour line on the mono camera image ?
I have the following code with a "Red" pen ... but it is white on the image.

Code: Select all

# ...
    dbitmap = args.Frame.GetDrawableBitmap()
    gbitmap = dbitmap.GetGraphics()
# ...
    pen_color = Pen(Color.FromName("Red"), 3)
    gbitmap.DrawEllipse(pen_color, start_x - R, start_y - R, 2*R, 2*R)
    gbitmap.DrawLine(pen_color, ls_x, ls_y, le_x, le_y)
    gbitmap.DrawEllipse(pen_color, end_x - R, end_y - R, 2*R, 2*R)
# ...
Regards,
Jean-Francois
User avatar
admin
Site Admin
Posts: 17606
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: PixelPositionProvider J2000 coordinates

#8

Post by admin »

Hi Jean-Francois,

yes, I think that counter-clockwise is what I am aiming for in SharpCap - if you stand looking southwards and look up at the sky, north is 'up' over your head for you and east is to your left. So, if you imagine an arrow in the sky that starts at the point you are looking at and points north, if you rotate it to start pointing a bit east as well as north, it is moving anticlockwise as you look at it from below. Of course, if you were looking from above (like you look down on a map), the rotation would be clockwise). I looked at a number of other pieces of software that worked out an orientation for the image and I struggled to find any agreement between them, with differences in definition of 'up' in the image, clockwise/counterclockwise and plain bugs in some...

For drawing on the image using the drawable bitmap approach, you are limited to monochrome because the base image is monochrome. Anything that you draw just gets converted down to grey as you draw it. I have an alternative approach for overlaying colour which instead records the list of things to draw (positions, sizes, colours, shapes, etc) and then draws it onto the screen on top of the image when the image gets displayed. It's not available to scripting at the moment, but I can't see why it shouldn't be... It would just be a simple change...

Code: Select all

    	#dbitmap = args.Frame.GetDrawableBitmap()
    	#gbitmap = dbitmap.GetGraphics()
	gbitmap = args.Frame.GetAnnotationGraphics()
The DrawLine/DrawEllipse/DrawText are all the same regardless of which you use (delibrate as it made converting from one to the other easy for me). I can add that for the next update, but you will have to be prepared for a missing method error if you are on an older version and fall back to getting the drawablebitmap and only having monochrome.

cheers,

Robin
Jean-Francois
Posts: 859
Joined: Sun Oct 13, 2019 10:52 am
Location: Germany

Re: PixelPositionProvider J2000 coordinates

#9

Post by Jean-Francois »

Hello Robin,

OK for the drawable bitmap in the next version.

I think that I will check the SharpCap version and simply not start the script if the version is too old.
I'm all the time surprised to see people still using a 3.2 or 4.0 version.

Jean-Francois
Jean-Francois
Posts: 859
Joined: Sun Oct 13, 2019 10:52 am
Location: Germany

Re: PixelPositionProvider J2000 coordinates

#10

Post by Jean-Francois »

Hello Robin,

For UpDegreesEastOfNorth ... here with the rotated M42 image, the angles for the 4 Flip cases:
Orientation_angle.jpg
Orientation_angle.jpg (36.99 KiB) Viewed 1382 times

In red my calculation with SharpCap.PixelPositionProvider.MapCoordinate(), in green the result of UpDegreesEastOfNorth.

Orientation_angle_None.jpg
Orientation_angle_None.jpg (181.58 KiB) Viewed 1382 times
Orientation_angle_Horiz.jpg
Orientation_angle_Horiz.jpg (181.19 KiB) Viewed 1382 times
Orientation_angle_Vert.jpg
Orientation_angle_Vert.jpg (183.75 KiB) Viewed 1382 times
Orientation_angle_Both.jpg
Orientation_angle_Both.jpg (185.06 KiB) Viewed 1382 times

All my results are counter-clockwise on the image ... but mathematically "a positive rotation" while the vertical axis pixel coordinates grow downwards.

The UpDegreesEastOfNorth results are on the image 2x clockwise and 2x counter-clockwise ... why ?

Regards,
Jean-Francois
Post Reply