Hiparcos and Tycho starts catalogs display

Share your advanced PureBasic knowledge/code with the community.
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Hiparcos and Tycho starts catalogs display

Post by fweil »

Duno about 2024, but the previous one was not so funny. I hope and wish the best for you all.

Read comments in source code to know more about this post card.

Code: Select all

;
; https://www.cosmos.esa.int/
; https://www.cosmos.esa.int/web/hipparcos/links
; http://cdsarc.u-strasbg.fr/viz-bin/Cat?cat=I%2F239&target=brief&#/browse
;
; http://cdsarc.u-strasbg.fr/ftp/I/239/hip_main.dat
; this is main file for Hipparcos start catalog : http://cdsarc.u-strasbg.fr/viz-bin/nph-Cat/txt.gz?I/239/hip_main.dat
; (about 100.000 stars)
;
; http://cdsarc.u-strasbg.fr/ftp/I/239/tyc_main.dat
; this is main file for Tycho start catalog : http://cdsarc.u-strasbg.fr/viz-bin/nph-Cat/txt.gz?I/239/tyc_main.dat
; (about 1.000.000 stars)
;
; Both mentionned main files are free for download. Beware of any possible URLs changes.
;
; This is a framework to parse and get basic information for defined stars in both Hipparcos and Tycho stars catalogs : my 2024 new year's gift for PureBasic community
;
; Generated images are saved using static names. If you use this code as it is, because images size is definitely the largest possible size in PureBasic, you might have some
; trouble to display it easily. I recommand IrfanView to display it (or build your own PureBasic code lines to open it in a scrollable window.
;
; Should be easy to adapt and enhance to your own wishes.
; This code just parse and catch RA / DE (right ascension and declination) and visual magnitude of stars. For Hipparcos catalog, it takes spectral type main category too.
; Then a flat skymap is drawn in an image which is jpeg saved.
;
; Adaptation should make possible to dress a skydome view for a 3D experiment (ie using OGRE)
;
; Stars colors rendering is something that can be reworked depending on what you want to foreground.
; Stars with undefined visual magnitude are skipped (my choice).
;
; Hipparcos catalog indexes less stars, but give a bit more information (spectral type).
; Read sites referenced below to know more about Hipparcos and Tycho european missions.
;
; Enjoy and have fun with it. Definitely free of all, wether you put my name somwhere or not.
;
; by fweil ...
;              ... for the kind PureBasic community and a new year's postcard especially to Fred and colls. You always have done a lot, buddies.
;
Global NewMap FileName.s()    ; a way to index catalgos files names, which is not so much useful except for code readability
Global NewList columns.s()    ; a list to catch columns of a character separated values for a given record
NewMap unknown.i()            ; inventory of unknown spectral types, for future possible use to embed Hipparcos catalog process with stars color rendering

UseJPEGImageEncoder()         ; use image encoder for jpeg, here, my choice, but it's up to you to change it.

Procedure.s Split(s.s, d.s)
  n.i = CountString(s, d)
  ClearList(columns())
  For i.i = 1 To n + 1
    AddElement(columns())
    columns() = StringField(s, i, d)
  Next
EndProcedure

  ImageWidth.i = 32000 ; yeah ... large image. You may adapt it to your needs.
  ImageHeight.i = 16000
  Imagenumber.i = CreateImage(#PB_Any, ImageWidth, ImageHeight, 32, #Black)
  ImageID.i = ImageID(ImageNumber)
  
  zoom_level.d = 1.0 ; of no use here but could be useful in any enhancements
  
  FileName("Hipparcos") = "I_239_hip_main.dat.txt"  ; this way to reference files is interesting ... notice you may adapt files access path
  FileName("Tycho") = "I_239_tyc_main.dat.txt"
  
  ;
  ; Hipparcos stars catalog processing and build image saving
  ;
  FileNumber.i = ReadFile(#PB_Any, FileName("Hipparcos"), #PB_File_SharedRead | #PB_Ascii)
  If FileNumber
    ipt.i = 0
    Repeat
      Record.s = ReadString(FileNumber)
    Until Left(Record, 6) = "-|----"
    StartDrawing(ImageOutput(ImageNumber))
    Vmin.d = 1e9
    Vmax.d = -1e9
    While Not Eof(FileNumber)
      Record.s = ReadString(FileNumber)
      If Left(Record, 6) = "------"
        Break
      EndIf
      Split(Record, "|")            ; have done this way to extract all fields of a CSV file, which is not performing so much but is interesting.
      SelectElement(columns(), 4)
      If Len(Trim(columns())) = 0
        Continue
      EndIf
      Vmag.d = ValD(columns())
      If Vmin > Vmag
        Vmin = Vmag
      EndIf
      If VMax < Vmag
        Vmax = Vmag
      EndIf
      SelectElement(columns(), 7)
      RAdeg.d = ValD(Mid(columns(), 1, 12))
      DEdeg.d = ValD(Mid(columns(), 14, 12))
      SelectElement(columns(), 72)
      SType.s = columns()
      Select Left(SType, 1)
        Case "O"
          color.i = $FF8080
        Case "B"
          color.i = $FFBFBF
        Case "A"
          color.i = $FFFFFF
        Case "F"
          color.i = $80FFFF
        Case "G"
          color.i = $80CCFF
        Case "K"
          color.i = $BFBFFF
        Case "M"
          color.i = $8080FF
        Default
          color.i = $FFFFFF
          unknown(Left(SType, 1)) + 1
      EndSelect
      
      x.i = ImageWidth - (ImageWidth * RAdeg / 360)
      y.i = ImageHeight - (ImageHeight * (DEdeg + 90) / 180)
      
      base_diameter.d = 15 - Vmag
      radius.d = base_diameter * zoom_level * (ImageWidth / 32000)
      
      radius = Pow(1.2, radius)
      If radius < 1
        If x >= 0 And x < ImageWidth And y >= 0 And y < ImageHeight
          Plot(x, y, color)
        EndIf
      Else
        Circle(x, y, radius, color)
      EndIf
      ipt + 1
      If ipt % 1000 = 0
        Debug Str(ipt) + #TAB$ + StrD(RAdeg) + #TAB$ + StrD(DEdeg) + #TAB$ + StrD(Vmag) + #TAB$ + StrD(x) + #TAB$ + StrD(y) + #TAB$ + StrD(radius)
      EndIf
    Wend
    StopDrawing()
    CloseFile(FileNumber)
    Debug ipt
  EndIf
  
  SaveImage(Imagenumber, "Stars_Hipparcos.jpg", #PB_ImagePlugin_JPEG, 10, 32)
  Debug Vmin
  Debug Vmax
  
  ;
  ; Tycho stars catalog processing and build image saving
  ;
  FileNumber.i = ReadFile(#PB_Any, FileName("Tycho"), #PB_File_SharedRead | #PB_Ascii)
  If FileNumber
    ipt.i = 0
    Repeat
      Record.s = ReadString(FileNumber)
    Until Left(Record, 6) = "-|----"
    StartDrawing(ImageOutput(ImageNumber))
    Vmin.d = 1e9
    Vmax.d = -1e9
    While Not Eof(FileNumber)
      Record.s = ReadString(FileNumber)
      If Left(Record, 6) = "------"
        Break
      EndIf
      
      smag.s = Trim(Mid(Record, 42, 7)) ; fields extraction in Tycho catalog is not made the same way than in Hipparcos because of performance (about 10 times more records)
      If Len(smag) > 0
        Vmag.d = ValD(smag)
      Else
        Continue
      EndIf
      If Vmin > Vmag
        Vmin = Vmag
      EndIf
      If VMax < Vmag
        Vmax = Vmag
      EndIf
      RAdeg.d = ValD(Mid(Record, 50, 12))
      DEdeg.d = ValD(Mid(Record, 63, 12))
      
      If Vmag = 0.0
        Debug Record
        Debug RAdeg
        Debug DEdeg
      EndIf
      
      color.i = $FFFFFF
      If Vmag > 5
        color.i - ($101010 * (Vmag - 5))
      EndIf
      x.i = ImageWidth - (ImageWidth * RAdeg / 360)
      y.i = ImageHeight - (ImageHeight * (DEdeg + 90) / 180)
      
      base_diameter.d = 15 - Vmag
      radius.d = base_diameter * zoom_level * (ImageWidth / 32000)
      radius = Pow(1.2, radius)
      
      If radius < 1
        If x >= 0 And x < ImageWidth And y >= 0 And y < ImageHeight
          Plot(x, y, color)
        EndIf
      Else
        Circle(x, y, radius, color)
      EndIf
      ipt + 1
      If ipt % 10000 = 0
        Debug Str(ipt) + #TAB$ + StrD(RAdeg) + #TAB$ + StrD(DEdeg) + #TAB$ + StrD(Vmag) + #TAB$ + StrD(x) + #TAB$ + StrD(y) + #TAB$ + StrD(radius)
      EndIf
    Wend
    StopDrawing()
    CloseFile(FileNumber)
    Debug ipt
  EndIf
  
  SaveImage(Imagenumber, "Stars_Tycho.jpg", #PB_ImagePlugin_JPEG, 10, 32)
  Debug Vmin
  Debug Vmax
  
  CallDebugger
End
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Hiparcos and Tycho starts catalogs display

Post by idle »

thanks for sharing that and happy new year from nz
User avatar
jacdelad
Addict
Addict
Posts: 1991
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Hiparcos and Tycho starts catalogs display

Post by jacdelad »

The program crashed, so I reduced the image size. Then I got a blank picture, so I read the instructions and downloaded the catalogues. Then I got a blank picture again, so I read in the code and renamed the catalogues. Now I still get a blank picture, but the program takes more time to create it.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Re: Hiparcos and Tycho starts catalogs display

Post by fweil »

Sad to see you cannot get it work fine, but maybe you could check it using debugger and see if something is easier to catch as error condition ?

By the way, if you get catalogs ready in memory, without drawing anything, first, maybe you will understand what's wrong on your deployment. On my PC I just run this program using actually PB 6.03 beta, and it does not crash or make any bads.

Possibly, the downloadable catalogs have changed in the meanwhile between my first post and today, and I checked source code with debug.

I noticed that the files I got today were not exactly the same alignment so that I had to change substrings positions for data extraction.

Maybe you will get more successfull trying this update. But do not forget that this program does not draw on screen, it draws in a file that you can then open when program has finished.

About catalgos downloads, it is possible the files design change, which should be explained in website pages.

Try this and let me know.
;
; https://www.cosmos.esa.int/
; https://www.cosmos.esa.int/web/hipparcos/links
; http://cdsarc.u-strasbg.fr/viz-bin/Cat? ... f&#/browse
;
; http://cdsarc.u-strasbg.fr/ftp/I/239/hip_main.dat
; this is main file for Hipparcos start catalog : http://cdsarc.u-strasbg.fr/viz-bin/nph- ... p_main.dat
; (about 100.000 stars)
;
; http://cdsarc.u-strasbg.fr/ftp/I/239/tyc_main.dat
; this is main file for Tycho start catalog : http://cdsarc.u-strasbg.fr/viz-bin/nph- ... c_main.dat
; (about 1.000.000 stars)
;
; Both mentionned main files are free for download. Beware of any possible URLs changes.
;
; This is a framework to parse and get basic information for defined stars in both Hipparcos and Tycho stars catalogs : my 2024 new year's gift for PureBasic community
;
; Generated images are saved using static names. If you use this code as it is, because images size is definitely the largest possible size in PureBasic, you might have some
; trouble to display it easily. I recommand IrfanView to display it (or build your own PureBasic code lines to open it in a scrollable window.
;
; Should be easy to adapt and enhance to your own wishes.
; This code just parse and catch RA / DE (right ascension and declination) and visual magnitude of stars. For Hipparcos catalog, it takes spectral type main category too.
; Then a flat skymap is drawn in an image which is jpeg saved.
;
; Adaptation should make possible to dress a skydome view for a 3D experiment (ie using OGRE)
;
; Hipparcos catalog indexes less stars, but give a bit more information (spectral type).
; Read sites referenced below to know more about Hipparcos and Tycho european missions.
;
; Enjoy and have fun with it. Definitely free of all, wether you put my name somwhere or not.
;
; by fweil for the kind PureBasic community and a new year's postcard espacially to Fred and colls. You always have done a lot, buddies.
;
Global NewMap FileName.s() ; a way to index catalgos files names, which is not so much useful except for code readability
Global NewList columns.s() ; a list to catch columns of a character separated values for a given record
NewMap unknown.i() ; inventory of unknown spectral types, for future possible use to embed Hipparcos catalog process with stars color rendering

UseJPEGImageEncoder() ; use image encoder for jpeg, here, my choice, but it's up to you to change it.

Procedure.s Split(s.s, d.s)
n.i = CountString(s, d)
ClearList(columns())
For i.i = 1 To n + 1
AddElement(columns())
columns() = StringField(s, i, d)
Next
EndProcedure

ImageWidth.i = 32000 ; yeah ... large image. You may adapt it to your needs.
ImageHeight.i = 16000
Imagenumber.i = CreateImage(#PB_Any, ImageWidth, ImageHeight, 32, #Black)
ImageID.i = ImageID(ImageNumber)

zoom_level.d = 1.0 ; of no use here but could be useful in any enhancements

FileName("Hipparcos") = "I_239_hip_main.dat.txt" ; this way to reference files is interesting ... notice you may adapt files access path
FileName("Tycho") = "I_239_tyc_main.dat.txt"

;
; Hipparcos stars catalog processing and build image saving
;
FileNumber.i = ReadFile(#PB_Any, FileName("Hipparcos"), #PB_File_SharedRead | #PB_Ascii)
If FileNumber
ipt.i = 0
StartDrawing(ImageOutput(ImageNumber))
Vmin.d = 1e9
Vmax.d = -1e9
While Not Eof(FileNumber)
Record.s = ReadString(FileNumber)
If Left(Record, 6) = "------"
Break
EndIf
Split(Record, "|") ; have done this way to extract all fields of a CSV file, which is not performing so much but is interesting.
SelectElement(columns(), 5)
If Len(Trim(columns())) = 0
Continue
EndIf
Vmag.d = ValD(columns())
If Vmin > Vmag
Vmin = Vmag
EndIf
If VMax < Vmag
Vmax = Vmag
EndIf
SelectElement(columns(), 8 )
RAdeg.d = ValD(columns())
SelectElement(columns(), 9 )
DEdeg.d = ValD(columns())
SelectElement(columns(), 76)
SType.s = columns()
Select Left(SType, 1)
Case "O"
color.i = $FF8080
Case "B"
color.i = $FFBFBF
Case "A"
color.i = $FFFFFF
Case "F"
color.i = $80FFFF
Case "G"
color.i = $80CCFF
Case "K"
color.i = $BFBFFF
Case "M"
color.i = $8080FF
Default
color.i = $FFFFFF
unknown(Left(SType, 1)) + 1
EndSelect

x.i = ImageWidth - (ImageWidth * RAdeg / 360)
y.i = ImageHeight - (ImageHeight * (DEdeg + 90) / 180)

base_diameter.d = 15 - Vmag
radius.d = base_diameter * zoom_level * (ImageWidth / 32000)

radius = Pow(1.2, radius)
If radius < 1
If x >= 0 And x < ImageWidth And y >= 0 And y < ImageHeight
Plot(x, y, color)
EndIf
Else
Circle(x, y, radius, color)
EndIf
ipt + 1
If ipt % 1000 = 0
Debug Str(ipt) + #TAB$ + StrD(RAdeg) + #TAB$ + StrD(DEdeg) + #TAB$ + StrD(Vmag) + #TAB$ + StrD(x) + #TAB$ + StrD(y) + #TAB$ + StrD(radius)
EndIf
Wend
StopDrawing()
CloseFile(FileNumber)
Debug ipt
EndIf

SaveImage(Imagenumber, "Stars_Hipparcos.jpg", #PB_ImagePlugin_JPEG, 10, 32)
Debug Vmin
Debug Vmax

;
; Tycho stars catalog processing and build image saving
;
FileNumber.i = ReadFile(#PB_Any, FileName("Tycho"), #PB_File_SharedRead | #PB_Ascii)
If FileNumber
ipt.i = 0
StartDrawing(ImageOutput(ImageNumber))
Vmin.d = 1e9
Vmax.d = -1e9
While Not Eof(FileNumber)
Record.s = ReadString(FileNumber)
If Left(Record, 6) = "------"
Break
EndIf

smag.s = Trim(Mid(Record, 42, 5)) ; fields extraction in Tycho catalog is not made the same way than in Hipparcos because of performance (about 10 times more records)
If Len(smag) > 0
Vmag.d = ValD(smag)
Else
Continue
EndIf
If Vmin > Vmag
Vmin = Vmag
EndIf
If VMax < Vmag
Vmax = Vmag
EndIf
RAdeg.d = ValD(Mid(Record, 52, 12))
DEdeg.d = ValD(Mid(Record, 65, 12))

If Vmag = 0.0
Debug Record
Debug RAdeg
Debug DEdeg
EndIf

color.i = $FFFFFF
If Vmag > 5
color.i - ($101010 * (Vmag - 5))
EndIf
x.i = ImageWidth - (ImageWidth * RAdeg / 360)
y.i = ImageHeight - (ImageHeight * (DEdeg + 90) / 180)

base_diameter.d = 15 - Vmag
radius.d = base_diameter * zoom_level * (ImageWidth / 32000)
radius = Pow(1.2, radius)

If radius < 1
If x >= 0 And x < ImageWidth And y >= 0 And y < ImageHeight
Plot(x, y, color)
EndIf
Else
Circle(x, y, radius, color)
EndIf
ipt + 1
If ipt % 10000 = 0
Debug Str(ipt) + #TAB$ + StrD(RAdeg) + #TAB$ + StrD(DEdeg) + #TAB$ + StrD(Vmag) + #TAB$ + StrD(x) + #TAB$ + StrD(y) + #TAB$ + StrD(radius)
EndIf
Wend
StopDrawing()
CloseFile(FileNumber)
Debug ipt
EndIf

SaveImage(Imagenumber, "Stars_Tycho.jpg", #PB_ImagePlugin_JPEG, 10, 32)
Debug Vmin
Debug Vmax

CallDebugger
End
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
User avatar
jacdelad
Addict
Addict
Posts: 1991
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Hiparcos and Tycho starts catalogs display

Post by jacdelad »

The

Code: Select all

Repeat
      Record.s = ReadString(FileNumber)
    Until Left(Record, 6) = "-|----"
cause the program to skip all lines and freeze at the end of the first file.

Aye, this one works! And procduces a great result. Mind if I play with it and adapt it into an interactive map? You already mentioned this code is free, but better ask one more time. Also, I would post the result here and need time of course.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Re: Hiparcos and Tycho starts catalogs display

Post by fweil »

feel free to play with this code, adapt it, and just let me know the good work !

Don't know where I put it, but some years ago I had a 3D demo with a stars catalog. Hipparcos and Tycho data are not adapted for 3D, but just 2D.

Enhancements are numerous even with 2D. Maybe you will find a way to add planets, nebulae, ... ;)
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
Post Reply