Hiparcos and Tycho starts catalogs display
Posted: Sun Dec 31, 2023 5:05 pm
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.
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