A script to mark ALL Fridger's galaxies

All about writing scripts for Celestia in Lua and the .cel system
Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 9 months
Location: Nancy, France

Post #41by Vincent » 14.03.2007, 17:26

t00fri wrote:As I wrote already elsewhere, another similarly interesting application would be scripts that mark the 10000+ asteroids from the official catalog (once they are all implemented ;-) ).

I had done such a plot of the asteroid belt already years ago


Fridger,

Here's a celx script that marks all asteroids in our Solar System :

Code: Select all

function mark_asteroids()
    sol = celestia:find("Sol")
    sol_bodies = sol:getchildren()
    for k,v in pairs(sol_bodies) do
      if v:getinfo().type == "asteroid" then
         v:mark( "yellow", "disk", 1, 1)
      end
   end
end

celestia:unmarkall()
mark_asteroids()


I tested it with the MainBeltAsteroidsAbridged.ssc file, and here's the result (click to enlarge):
Image

I'm really looking forward to testing it with your 10000+ asteroids catalog ! :)
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 9 months
Location: Nancy, France

Post #42by Vincent » 14.03.2007, 17:37

We can even resize the markers according to the asteroids' size :

Image

Just replace line 6 of the previous script with :

Code: Select all

         v:mark( "yellow", "disk", v:getinfo().radius/1e5, 1)
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

Avatar
Topic author
Cham M
Posts: 4324
Joined: 14.01.2004
Age: 60
With us: 20 years 9 months
Location: Montreal

Post #43by Cham » 14.03.2007, 19:12

Vincent,

apparently, that last line of code doesn't work for me.

The edited script works, but I don't see any larger dots.

EDIT : Ok, it now works, but I had to change the 1e5 scale parameter to 1e2. And it may be a bit weird on screen, when you also see the very large Kuyper objects as large dots !
Last edited by Cham on 14.03.2007, 19:29, edited 1 time in total.
"Well! I've often seen a cat without a grin", thought Alice; "but a grin without a cat! It's the most curious thing I ever saw in all my life!"

Avatar
t00fri
Developer
Posts: 8772
Joined: 29.03.2002
Age: 22
With us: 22 years 7 months
Location: Hamburg, Germany

Post #44by t00fri » 14.03.2007, 19:25

Yeah, Vincent, that looks great and is also a very simple script.

Unfortunately, my original asteroid data + the PERL extraction file (from 2002!) were somehow lost. Reproducing the PERL extraction script is close to trivial. I have not yet done it, since there is still the not-so-simple culling issue which first calls for en elegant solution, before we can add in > 10000 asteroids and comets.

It's very nice to bin the asteroids into various size categories and then display them the way you did.

Bye Fridger
Image

Avatar
t00fri
Developer
Posts: 8772
Joined: 29.03.2002
Age: 22
With us: 22 years 7 months
Location: Hamburg, Germany

Post #45by t00fri » 14.03.2007, 19:39

ElChristou wrote:
t00fri wrote:...Another nice
apllication would be to color the galaxies according to their
redshift z that one may easily obtain. One may color
them increasingly read for increasing redshift, for
example...

Could you release a new deepsky.dsc with those new datas?
I'm pretty sure Vincent could modify CVS just like he does
recently to extract and use those new arguments via
celx...


Christophe,

as I wrote earlier: for many galaxies we do have the
required information already in the default deepsky.dsc.

For all galaxies without a large 'peculiar velocity'
component, one can simply use Hubble's law

Code: Select all


v = H_0 * d

v = z * c

d is the /proper/ distance (general relativity!) that the
light had traveled from the galaxy in the rest frame of the
observer. v is the recessional velocity due to redshift,
typically expressed in km/s. H0 is Hubble's constant
(taken at the time of observation denoted by the subscript
0) .

For relatively nearby galaxies, the velocity v can be
expressed by the galaxy's redshift z using the formula v
= z * c where c is the speed of light. There are more
fancy relations between z and v, but to make the point I
chose the simplest one.

++++++++++++++
In other words, knowing the value of H_0, we can convert
the distances in deepsky.dsc for many galaxies into
redshifts z within a script.
++++++++++++++

Bye Fridger
Image

chris
Site Admin
Posts: 4211
Joined: 28.01.2002
With us: 22 years 9 months
Location: Seattle, Washington, USA

Post #46by chris » 14.03.2007, 20:25

I checked in some code that introduces a star iterator to celx. It's convenient for iterating over the entire star database. For example, here's a script to mark stars of a particular spectral type:

Code: Select all

function mark_spectraltype(x)
    local nstars = celestia:getstarcount()
    local i = 0
    while i < nstars do
        star = celestia:getstar(i)
        first, last = string.find(star:spectraltype(), x, 1, true)
        if first == 1 then
            star:mark("#ff99ff", "triangle", 10)
        end
        i = i + 1
    end
end


It can be rewritten more simply using the stars iterator:

Code: Select all

function mark_spectraltype(x)
    for star in celestia:stars() do
        first, last = string.find(star:spectraltype(), x, 1, true)
        if first == 1 then
            star:mark("#ff99ff", "triangle", 10)
        end
    end
end


It should be easy to implement this for DSOs as well.

--Chris

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 9 months
Location: Nancy, France

Post #47by Vincent » 14.03.2007, 20:31

Cham wrote:EDIT : Ok, it now works, but I had to change the 1e5 scale parameter to 1e2. And it may be a bit weird on screen, when you also see the very large Kuyper objects as large dots !
Cham,

You're right. If you use a different asteroids catalog, you have to tune the scale parameter according to the asteroids' size in your .ssc.

t00fri wrote:++++++++++++++
In other words, knowing the value of H_0, we can convert
the distances in deepsky.dsc for many galaxies into
redshifts z within a script.
++++++++++++++

Fridger,

Thanks for providing the maths background. I'll give it a try...
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

Avatar
Topic author
Cham M
Posts: 4324
Joined: 14.01.2004
Age: 60
With us: 20 years 9 months
Location: Montreal

Post #48by Cham » 14.03.2007, 20:55

It may be usefull to have a script that marks all the stars which are within the sphere of a given radius (input parameter asked by the script), and centered on the actual observer's position.
"Well! I've often seen a cat without a grin", thought Alice; "but a grin without a cat! It's the most curious thing I ever saw in all my life!"

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 9 months
Location: Nancy, France

Post #49by Vincent » 14.03.2007, 20:57

chris wrote:I checked in some code that introduces a star iterator to celx.


Chris,

This is great, thanks !
I've commited the changes that introduces the DSO iterator.

The previous script that marks all galaxies according to their Hubble Type becomes even simplier and shorter :
[Edited on 22/05/07]

Code: Select all

function mark_dso()
   for dso in celestia:dsos() do
      hubbleType = dso:getinfo().hubbleType
      if string.find(hubbleType, "E") then
         dso:mark( "red", "disk", 1, 0.7 )
      elseif string.find(hubbleType, "Irr") then
         dso:mark( "yellow", "disk", 1, 0.7 )
      elseif string.find(hubbleType, "SB") then
         dso:mark( "green", "disk", 1, 0.7 )
      elseif string.find(hubbleType, "S") then
         dso:mark( "blue", "disk", 1, 0.7 )
      end
    end
end

celestia:unmarkall()
mark_dso()


EDIT : I've replaced the "circle" markers with "disk" markers. This gives an even better result on screen.
Last edited by Vincent on 22.05.2007, 10:24, edited 2 times in total.
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

ElChristou
Developer
Posts: 3776
Joined: 04.02.2005
With us: 19 years 9 months

Post #50by ElChristou » 14.03.2007, 23:03

Strangely I see no new entries in CVS update since the 21/02... and I'm unable to update my source at this moment... Any problem at SourceForge?
Image

Avatar
t00fri
Developer
Posts: 8772
Joined: 29.03.2002
Age: 22
With us: 22 years 7 months
Location: Hamburg, Germany

Post #51by t00fri » 14.03.2007, 23:04

ElChristou wrote:Strangely I see no new entries in CVS update since the 21/02... and I'm unable to update my source at this moment... Any problem at SourceForge?


I have just updated 1.5 hours ago (Vincent's commit) , without a problem.

Bye Fridger
Image

ElChristou
Developer
Posts: 3776
Joined: 04.02.2005
With us: 19 years 9 months

Post #52by ElChristou » 14.03.2007, 23:08

t00fri wrote:
ElChristou wrote:Strangely I see no new entries in CVS update since the 21/02... and I'm unable to update my source at this moment... Any problem at SourceForge?

I have just updated 1.5 hours ago (Vincent's commit) , without a problem.

Bye Fridger


... strange... what about the mail archive?
http://sourceforge.net/mailarchive/forum.php?forum_id=38991

The last commit I see is Grant on 21/02 for extrasolar.ssc...
Image

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 9 months
Location: Nancy, France

Post #53by Vincent » 17.03.2007, 12:44

Vincent wrote:
t00fri wrote:++++++++++++++
In other words, knowing the value of H_0, we can convert
the distances in deepsky.dsc for many galaxies into
redshifts z within a script.
++++++++++++++
Fridger,

Thanks for providing the maths background. I'll give it a try...


OK, here's a first try of a script that marks all galaxies according to their redshift z.
This script also displays the redshift z value of the current selection when this selection is a galaxy.

I hope everything is OK with this script... For example, I was not sure whether the reference had to be the position of Earth or the position of the Celestia observer... Well, just let me know...

Image
[Edited on 22/05/07]

Code: Select all

function get_distance(obj)
   -- Returns distance Earth-object in Mpc.
   obj_pos = obj:getposition()
   earth = celestia:find("Sol/Earth")
   earth_pos = earth:getposition()
   local km2Mpc = 1/3.08568025e19
   distance = obj_pos:distanceto(earth_pos) * km2Mpc
   return distance
end

function get_z(distance)
   -- Returns redshift z.
   -- Hubble constant = 76.9 (km/s)/Mpc
   -- http://chandra.harvard.edu/photo/2006/clusters/
   local H0 = 77
   local c = 299792.458
   z = (H0 * distance)/c
   return z
end

function rgb2hex(r,g,b)
   -- Converts color code from RGB to Hex
   local hex = string.format("#%.2x%.2x%.2x", r,g,b)
   return hex
end

function get_color(z)
   -- Returns Hex color code from z
   local z_max = 0.143323
   local red = (z/z_max)*255
   local blue = (255 - red)/3
   local green = blue/2
   hex_color = rgb2hex(red, green, blue)
   return hex_color
end
   
function mark_galaxies()
   for dso in celestia:dsos() do
      if dso:type() == "galaxy" then
         local d = get_distance(dso)
         local z = get_z(d)
         local hex_color = get_color(z)
         dso:mark( hex_color, "disk", 1, 1 )
      end
   end
end

celestia:unmarkall()
mark_galaxies()

while true do
   sel = celestia:getselection()
   if sel:type() == "galaxy" then
      local d = get_distance(sel)
      local z = get_z(d)
      celestia:print(sel:name().."\n"..string.format("redshift z = %f", z))
   end
   wait(0)
end
Last edited by Vincent on 22.05.2007, 10:24, edited 2 times in total.
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

starfleetengineer
Posts: 41
Joined: 18.01.2007
With us: 17 years 9 months

Post #54by starfleetengineer » 17.03.2007, 15:39

Vincent wrote:... For example, I was not sure whether the reference had to be the position of Earth or the position of the Celestia observer... Well, just let me know...

Neither.

IMO, the reference should be the currently selected object (regardless of the observer's position). This would be most useful, as the observer could then 'back away' from the selected object in order to get an overview of the reshifts as they relate to that object. (Of course one would need to re-run the script to re-calculate the redshifts after changing selected object).
Any other ideas anyone??
"Once you're in Earth orbit you're half way to almost anywhere in the Universe" - Robert Heinlein

CLICK HERE TO DOWNLOAD THE WARPDRIVE

Avatar
Topic author
Cham M
Posts: 4324
Joined: 14.01.2004
Age: 60
With us: 20 years 9 months
Location: Montreal

Post #55by Cham » 17.03.2007, 17:43

Vincent,

your last script doesn't work on my system. I don't know why. It just do nothing :-(
"Well! I've often seen a cat without a grin", thought Alice; "but a grin without a cat! It's the most curious thing I ever saw in all my life!"

ElChristou
Developer
Posts: 3776
Joined: 04.02.2005
With us: 19 years 9 months

Post #56by ElChristou » 17.03.2007, 18:11

Cham wrote:Vincent,

your last script doesn't work on my system. I don't know why. It just do nothing :-(


I'm pretty sure you need a fresh built to make it run (I cannot test, I'm still unable to update my source :evil:)
Image

Avatar
selden
Developer
Posts: 10192
Joined: 04.09.2002
With us: 22 years 2 months
Location: NY, USA

Post #57by selden » 17.03.2007, 18:25

Vincent's script works fine for me, using Celestia built from current CVS code.

Note that the disks are only 1 pixel wide and rather dim. You probably won't be able to see them unless the viewpoint is far enough away from everything that only the markers are visible. A distance of 2000 Mpc is about right.

If you increase the disk size to 5 pixels, for example, they're more visible when seen from nearby.
Selden

Avatar
Topic author
Cham M
Posts: 4324
Joined: 14.01.2004
Age: 60
With us: 20 years 9 months
Location: Montreal

Post #58by Cham » 17.03.2007, 18:36

Something is wrong. All other scripts are working fine, except the last one (whatever the position where I'm located). No dots.
"Well! I've often seen a cat without a grin", thought Alice; "but a grin without a cat! It's the most curious thing I ever saw in all my life!"

Avatar
Topic author
Cham M
Posts: 4324
Joined: 14.01.2004
Age: 60
With us: 20 years 9 months
Location: Montreal

Post #59by Cham » 17.03.2007, 18:48

Ok, I just recompiled Celestia from CVS (ElChristou : you then have a connection problem).

The script is now working.

However, what are these markers inside our Milky Way ?

Image
"Well! I've often seen a cat without a grin", thought Alice; "but a grin without a cat! It's the most curious thing I ever saw in all my life!"

Avatar
selden
Developer
Posts: 10192
Joined: 04.09.2002
With us: 22 years 2 months
Location: NY, USA

Post #60by selden » 17.03.2007, 19:22

On my system there is only one marker inside the Milky Way -- the one at its center.

Please show what you see from a viewpoint in the plane of the Milky Way. When looking from above or below the plane, there may be many galaxies in the background and in the foreground. Very few can be seen in the plane of the Milky Way because of the obscuring dust clouds.
Selden


Return to “Scripting”