Draw Star Catalog Data

Graphics Library

Use graphics.py. For more information click HERE . (download, install, documentation, etc.)

Project #1

Read the Star Catalog and create a CSV files. (One star per line.)

Calculate the XYZ coordinates of each star from its galactic lat/lon.

Each line in the CSV file should have (at a minimum)

To test if you have read the data correctly, create a program that draws every star using their XYZ coordinates. This should generate a sphere of stars around the origin (0,0,0). (Graphics Window 801,801, Sphere radius 300 pixels, Normal stars black, Double/Multiple stars red)

Note: The code examples provided view the sphere of stars from the galactic center (+ infinity) looking towards the origin (0,0,0).

Project #2

Modify project #1. Select one star from each quadrant. (There are 8 quadrants in the XYZ coordinate system.) Draw each star with a different color. Do they appear in their correct position?

Project #3

Modify project #2. Allow the user to rotate the sphere of stars to view it from different angles. (Rotate around X,Y,Z axes.)

Project #4

Write a program to view stars from the data in a star catalog. Use the graphics.py module to display part of the sky in a window.

Obviously there are problems. For example

  1. View the sphere of stars from the origin (0,0,0) looking toward the galactic center (+X infinity).

  2. Converting from lat/lon to XYZ coordinates.

  3. Mapping 3D XYZ coordinates to 2D window coordinates.

  4. Scale the part of the sphere of stars (window of stars) we want to view to fit in the graphics window.

  5. Limiting distortion by limiting the size of the window of stars. Perhaps 20° x 20° (measured at the equator) of the sphere of stars?

  6. Color the stars to reflect their natural color, size, temperature, ...?

  7. How does the user control the program? (I suggest using a menu to start with.)

Star Catalog

A location where you can download a star catalog ...

Yale Bright Star Catalog (9110 stars)

bsc5.dat.gz is the ASCII star catalog data file. (one star per line)

bsc5.readme is the star catalog description (includes the catalog data format).

Another star catalog download location ...

Bright Star Catalogue, 5th Revised Ed. : V/50 (9110 stars)

Extracting data from the catalog records (one line, one star) has some quirks. I suggest you look at Python slice strings. Slice strings are indexed starting with zero (0). The data description indexing starts with one (1). Also slice strings starting index is inclusive and the ending index is exclusive.

For example
slice indexdata description index
01
12
23
......

Converting Galactic Latitude/Longitude to X,Y,Z Coordinates

Galactic Longitude is measured from an imaginary line drawn from the sun to the galactic center. It is a 0° to 360° angle. It is a counter-clockwise angle when looking down from the galactic north pole. (From the sun towards the galactic center defines the +X axis.)

Galactic Latitude is measured from the imaginary plane of the galaxy. Its value can vary between +90° to -90°. It is a counter-clockwise angle when looking from the galactic center towards the Sun. (Galactic north pole is the +Z axis.)

The "Right Hand Rule" defines the direction of the +Y axis.

image missing image missing
image missing image missing

See Galactic coordinate system (Wikipedia)
Galactic Coordinate System
Drawing stars in a 3D space

Using galactic latitude and longitude, stars appear as a sphere around the sun. For this project the Earth and the Sun are one.

Using a star's latitude and longitude we can calculate the X,Y,Z coordinates of each star with the Sun in the center (coordinates origin).

the right hand rule
image missing

Note: In the following equations the abbreviations lat and lon will be used.

x = cos(lat) * cos(lon) y = sin(lat) * cos(lon) z = sin(lat)

From Converting from longitude\latitude to Cartesian coordinates

Lat/lon define the location of stars as a sphere around the sun. Using the equations we can find each star's XYZ coordinates on that sphere. The sphere has a radius of one (1).

Notes on Galactic Latitude and Longitude

North Pole+90° latitude
South Pole−90° latitude
Galactic Center0° longitude
Anti-center180° longitude

The AOI / Graphics Window

image missing

Design?

Using the stars galactic Lat/Lon ...

  1. The user selects a galactic lat/lon as a Point of Interest (POI).
  2. The POI is used to defines the center of an Area of Interest (AOI). Limit the size of the AOI (perhaps 20° x 20°) to minimize the parallax and other distortions.
  3. Select the star in the AOI using their galactic lat/lon.
  4. Use the X,Y,Z coordinates to draw the selected stars in the graphics window.

This only works near the equator. In higher latitudes and especially the poles, defining an AOI is a problem using lat/lon.

Using the stars XYZ coordinates ...

The following used XYZ coordinates to eliminate the "pole problem".

  1. The user selects a galactic lat/lon as a Point of Interest (POI).
  2. The POI is used to defines the center of an Area of Interest (AOI). Limit the size of the AOI (perhaps 20° x 20°) to minimize the parallax and other distortions.
  3. Get the POI's XYZ coordinates.
  4. Create a transformation matrix to rotate The POI so it is on the +X axis.
  5. Assume the viewer is at the origin looking at the galactic center.
  6. Transform and calculate the AOI's XYZ limits.
  7. Test every star to see if it is in the AOI.
    • Only stars with a positive X coordinate are eligible for selection.
      (-X coordinates are behind the viewer)
    • Transform (rotate) every star and select the stars in the AOI.
      (Use XYZ coordinates to select stars)
  8. Use the X,Y,Z coordinates to draw the selected stars in the graphics window.

For a program to test lat/lon conversion to X,Y,Z click HERE

Code Snippets

# -------------------------------------------------------------- # ---- convert galactic lat/lon to Cartesian X,Y,Z coordinates # -------------------------------------------------------------- import math as m def convert_lat_lon_to_xyz(lat_deg,lon_deg): lat_rad = m.radians(lat_deg) # radians lon_rad = m.radians(lon_deg) # radians x = m.cos(lat_rad) * m.cos(lon_rad) y = m.cos(lat_rad) * m.sin(lon_rad) z = m.sin(lat_rad) return (x,y,z)

# -------------------------------------------------------------- # ---- draw a circle # -------------------------------------------------------------- import graphics as gr import coordinate_conversion as cc def draw_circle(win,x,y,color="black",raidus=2): wx,wy = cc.center_to_win_coords(x,y,win.width,win.height) c = gr.Circle(gr.Point(wx,wy),raidus) c.setFill(color) c.setWidth(1) c.setOutline(color) c.draw(win) return c

# -------------------------------------------------------------- # ---- draw the stars (small circles) # ---- # ---- a. viewer is assumed to be at the origin (0,0,0) looking # ---- along the +X axis # ---- b. skip drawing "back side of sphere of stars" # ---- (X coord <= 0.0) # ---- c. if star is double/multiple-star draw red circle # ---- else draw black circle # ---- d. star's tuple format: (x,y,z,code) # ---- e. AOI is centered around the POI # ---- # ---- add selecting only stars that are in the AOI # ---- # ---- graphics window coordinates (viewer is at +z infinity) # ---- # ---- (0,0) # ---- +------------- +x # ---- | # ---- | # ---- | # ---- | # ---- | # ---- +y # ---- # -------------------------------------------------------------- def draw_stars(win,stars): for s in stars: x = s[0] # X coord y = s[1] # Y coord z = s[2] # Z coord c = s[3] # double/multiple-star code if x > 0.0: if c == '': draw_circle(win,y,z) else: draw_circle(win,y,z,'red')

For a program to test lat/lon conversion to graphics window points click HERE