A script to mark ALL Fridger's galaxies

All about writing scripts for Celestia in Lua and the .cel system
Avatar
selden
Developer
Posts: 10192
Joined: 04.09.2002
With us: 22 years 2 months
Location: NY, USA

Post #61by selden » 17.03.2007, 19:25

Note that the script marks everything that has a "hubbletype" defined. If you have some other DSC Addon that defines fake Galaxies for some reason, they'd be marked, too.
Selden

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

Post #62by Cham » 17.03.2007, 19:25

selden wrote:Please show what you see from a viewpoint in the plane of the Milky Way.


Here :

Image

EDIT : those markers may be related to one of your own addons, Selden. I'll investigate.
"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 10 months
Location: Montreal

Post #63by Cham » 17.03.2007, 19:31

Selden,

most markers inside the Milky Way are actually from your addon "galaxy_map". I removed it and most markers are gone. Some remains, however, and are from another of your addon.

So I think the script isn't right, since it doesn't mark galaxies only.
"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 #64by selden » 17.03.2007, 19:56

This suggests to me that the field "hubbleType" is defined for all DSC objects, not just for Galaxies.
The script should test the type of DSO, not test for a field that describes a characteristic of the DSO.

Unfortunately, this seems to be a deficiency in Celestia: a search through celx.cpp found this comment:

Code: Select all

    case Selection::Type_DeepSky:
        // TODO: return cluster, galaxy, or nebula as appropriate
        tname = "deepsky";
        break;


So this script can't do the right thing until after Celestia v1.5.0.
Selden

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

Post #65by chris » 18.03.2007, 04:48

selden wrote:This suggests to me that the field "hubbleType" is defined for all DSC objects, not just for Galaxies.
The script should test the type of DSO, not test for a field that describes a characteristic of the DSO.

Unfortunately, this seems to be a deficiency in Celestia: a search through celx.cpp found this comment:

Code: Select all

    case Selection::Type_DeepSky:
        // TODO: return cluster, galaxy, or nebula as appropriate
        tname = "deepsky";
        break;


So this script can't do the right thing until after Celestia v1.5.0.


The script should ignore objects other than galaxies if it is modified to check hubbleType against the empty string ("") instead of nil. But, I think it would be better to change celx so that hubbleType actually is nil instead of the empty string for anything except galaxies.

After 1.5.0, we can make the type property return "galaxy", "nebula", or "cluster" instead of the generic "deepsky". It's not required for the redshift script, but it would be useful (e.g. there's no way now to distinguish between nebulae and star clusters in celx scripts.)

--Chris

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

Post #66by t00fri » 18.03.2007, 10:36

I am pleased to see that we getting into a nice redshift
display despite some slight initial oddities related to the
difference between "" and nil ;-) .

There are several astrophysics comments that come to
mind after looking at the result.

1) I would take a value of H0 = 73.2, which is the current
best fit value of the 3years WMAP data (legacy archive) +
all other constraints.
http://lambda.gsfc.nasa.gov/product/map ... _param.pdf
(published January 5th, 2007)

It is also nicely compatible with the most up-to-date other
determinations of H0, including notably HST and other
advanced Cepheid-based methods.


2) The more tricky remaining question is how to take into
account the partially dominant "peculiar velocity"
components notably of certain galaxaies in the local group. In
general the total velocity vector is composed of a redshift
component (radial) due to the expansion of the Universe
plus a "peculiar" component associated with the
cumulative gravitational effects from other matter, like
e.g. galaxies within a cluster. Therefore there are some
galaxies that even appear blueshifted instead of
redshifted. This holds in particular for some galaxies in
the direction of the Virgo cluster, e.g.

Code: Select all

galaxy         radial velocity [km/sec]
M 90                 -383
M 86                 -340
IC3258               -517
...


3) Then there are corrections from general relativity to
the strict proportionality distance = 1/H0*( c*z +...)

In the domain of small-z galaxies that we are considering
in our catalog, these corrections should be small.

The underlying point is that there are various definitions
of "distance", like e.g. the comoving distance or the
luminosity distance etc...Usually one consideres the
comoving distance in relativity and the context of the
Hubble law.

4) Some resulting z-values should be compared to the
ones given by Simbad, to check on the quality of the
presently used Hubble-law approximation and/or the
correctness of the script ;-) . I expect significant
deviations from the correct values in quite a few cases. Of
course there are often large uncertainties that one has to
keep in mind!

5) Looking at Vincent's nice redshift plot (or at one's own
display in Celestia ;-) ) one notices a striking asymmetry
of the red galaxies wrto the equatorial plane. Reason?


Bye Fridger
Image

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

Post #67by ElChristou » 19.03.2007, 22:54

BTW, just a parenthesis, could the markers been antialiased just like the orbits?
Image

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

Post #68by Vincent » 21.03.2007, 21:29

chris wrote:The script should ignore objects other than galaxies if it is modified to check hubbleType against the empty string ("") instead of nil. But, I think it would be better to change celx so that hubbleType actually is nil instead of the empty string for anything except galaxies.

I've just checked in a patch that makes hubbleType nil instead of the empty string for anything except galaxies.
Note that some addons may contain galaxies that have no Hubble Type declaration in their .ssc. In this case, getinfo().hubbleType also returns nil.

Here's the right version of the redshift_z.celx script, with the corrected value for H0, as suggested by Fridger :wink: :
[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 = 73.2 (km/s)/Mpc
   -- http://lambda.gsfc.nasa.gov/product/map/dr2/pub_papers/threeyear/parameters/wmap_3yr_param.pdf
   local H0 = 73.2
   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.136250      -- z value for IC 4170-2
   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()
celestia:setrenderflags { markers = true }
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



Cham, could you please confirm that the script now runs fine on your system ?
Last edited by Vincent on 22.05.2007, 10:23, 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

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

Post #69by t00fri » 21.03.2007, 22:24

Vincent at al.,

I have also hacked a .celx script in my own way. It is quite
a bit longer and knows a few more things. It also has a
number of different features:

1) well the best Hubble constant 73.2 (km/s)/Mpc along
with full relativistic correction for a flat Universe Omega=1.
Image
This formula can still be inverted analytically and allows to
calculate z from the (comoving) distance d.

2) When started, the script positions the observer at a
distance of 1000 Mpc from the Milky Way in good viewing
position...Also the marking is activated with a celx
command, etc. So no additional manual action required.

3) The script determines the galaxy with the largest
redshift and normalizes the colors by this value.

4) The colors range from white (z=0) to dark red
(z=z_max)

5) The output text does not clutter over the command line
anymore

6) Initially the MilkyWay is marked by a fat green dot. Any
other galaxy may be entered into the command line,
whence it will be marked (green dot) and it's redshift
displayed

7) From that plot I noticed that my galaxy database
urgently needs a thorough overhaul! That's what I have
been busy with during the last few days. Among many
improvements, I now implemented the new NED-1D
/precise/ galaxy distance data base with 1073 (additional)
VERY accurate distances, each being calculated as an
average over numerous individual results using different
methods!

8 ) As a consequence, my new deepsky.dsc is much
improved in accuracy and in the redshift display this
strange asymmetry wrto the galactic plane has gone!

The new galaxies will go to CVS after some further testing.

Here is a view of what Celestia looks like after starting my
z-dist.celx:
Image

Here comes my script

Code: Select all

function get_distance(obj_pos,ref_pos)
   -- Returns distance Earth-object in Mpc.
   distance = ref_pos:distanceto(obj_pos) * km2Mpc
   return distance
end

function get_z(distance)
   -- Returns redshift z.
   -- Hubble constant = 73.2 (km/s)/Mpc, WMAP 3years, best
   -- http://map.gsfc.nasa.gov/m_mm/tp_links.html
   local H0 = 73.2
   local c = 299792.458
   z0 = (H0 * distance)/c
   z = z0*(1 - z0/4)/(1 - z0/2)^2
   -- d <= 2 * c/H0
   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_rel)
   -- Returns Hex color code from z_rel
   if z_rel > 1 then
       z_rel = 1
   end
   --local green = 255 * (1 - z_rel)/(1 + math.sqrt(z_rel))
   local green = 255 * (1 - z_rel)^2
   local red   = 255
   local blue  = 255* math.sqrt(green/255)
   hex_color   = rgb2hex(red, green, blue)
   return hex_color
end
   
function mark_galaxies(sel_pos)
   zz = z_max(sel_pos)
   for dso in celestia:dso() do
      hubbleType = dso:getinfo().hubbleType
      if hubbleType ~= "" then
         dso_pos = dso:getposition()
         local d = get_distance(dso_pos,sel_pos)
         local z_rel = get_z(d)/zz
         local hex_color = get_color(z_rel)
         dso:mark( hex_color, "disk",2, 1 )
      end
   end
end
function z_max(ref_pos)
   -- determine maximal redshift in catalog wrto ref_pos
   z_old = 0
   for dso in celestia:dso() do
      hubbleType = dso:getinfo().hubbleType
      if hubbleType ~= "" then
         dso_pos = dso:getposition()
         local d = get_distance(dso_pos,ref_pos)
         local z = get_z(d)
         if z > z_old then
             z_max = z
             z_old = z_max
             dsomax = dso
         end   
      end
   end
   return z_max
end

----------
-- main --
----------
celestia:unmarkall()

celestia:show("markers")
km2Mpc = 1/3.08568025e19
MW = celestia:find("Milky Way")
MW_pos = MW:getposition()
--
-- select and specially mark Milky Way
--
celestia:select(MW)
celestia:mark(MW)
--
-- color encode all other galaxies according to their redshift
-- relative to Milky Way
--
mark_galaxies(MW_pos)
--
-- move observer to a distance of 1000 Mpc from Milky Way
--
observer = celestia:getobserver()
observer:gotodistance(MW, 1000/km2Mpc,5)

sel_old = MW
   
while true do   
   sel = celestia:getselection()
   --
   -- specially mark possible new selection, unmark the old one
   --
   if sel ~= sel_old then
       sel:unmark()
       sel_old:unmark()
       sel:mark("#00FF00","disk",10,1)
       sel_old = sel
   end   
   
   sel_pos = sel:getposition()
   
   -- obs_pos = observer:getposition()
   
   if sel:getinfo().hubbleType ~= "" then
      local d = get_distance(MW_pos,sel_pos)
      local z = get_z(d)
      celestia:print(sel:name()..": "..string.format("redshift z = %5.3f,  distance = %5.2f  Mpc", z,d).."\nmax. redshift: "..dsomax:name(),5,-1,-1,0,6)
   end
   wait(0)
end


Bye Fridger
Last edited by t00fri on 22.03.2007, 00:52, edited 1 time in total.
Image

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

Post #70by ElChristou » 21.03.2007, 23:20

Vincent wrote:...Here's the right version of the redshift_z.celx script, with the corrected value for H0, as suggested by Fridger...


The script works fine on my config only if I use "" instead of nill, else it crash Celestia; now if I let nill but remove the line:

celestia:setrenderflags { markers = true }

the script just do nothing... strange.

@ Fridger, your script also don't run on my config, nothing happen, nada... :x (but btw, it's suppose to only work with your new deepsky.dsc?)
Last edited by ElChristou on 21.03.2007, 23:41, edited 1 time in total.
Image

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

Post #71by t00fri » 21.03.2007, 23:32

ElChristou wrote:
Vincent wrote:...Here's the right version of the redshift_z.celx script, with the corrected value for H0, as suggested by Fridger...

The script works fine on my config only if I use "" instead of nill; now if I let nill but remove the line:

celestia:setrenderflags { markers = true }

the script just do nothing... strange.

@ Fridger, your script also don't run on my config, nothing happen, nada... :x (but btw, it's suppose to only work with your new deepsky.dsc?)


No it should work with the standad one, too.
Perhaps you copied something incorrectly from the screen (mind the line wrapping!!)

Bye Fridger
Image

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

Post #72by ElChristou » 21.03.2007, 23:40

t00fri wrote:...Perhaps you copied something incorrectly from the screen (mind the line wrapping!!)...


Sorry for the noob question... what's this "line wrapping"?
I tried many time some copy/paste but nothing... re strange indeed... :?
Image

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

Post #73by t00fri » 21.03.2007, 23:56

ElChristou wrote:
t00fri wrote:...Perhaps you copied something incorrectly from the screen (mind the line wrapping!!)...

Sorry for the noob question... what's this "line wrapping"?
I tried many time some copy/paste but nothing... re strange indeed... :?


If a line is longer than the width ...if a carriage return is inserted this way accidentally, then the script does not work.

I send it to you by email. NOW

Bye Fridger
Image

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

Post #74by ElChristou » 22.03.2007, 00:02

t00fri wrote:
ElChristou wrote:
t00fri wrote:...Perhaps you copied something incorrectly from the screen (mind the line wrapping!!)...

Sorry for the noob question... what's this "line wrapping"?
I tried many time some copy/paste but nothing... re strange indeed... :?

If a line is longer than the width ...if a carriage return is inserted this way accidentally, then the script does not work.

I send it to you by email. NOW

Bye Fridger


Ah ok... I haven't touch anything during the copy/paste process so I'll go for a try with the one by mail... Tx!
Image

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

Post #75by t00fri » 22.03.2007, 00:13

Does you Celestia version have the recent CVS additions by Vincent!??

Bye Fridger
Image

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

Post #76by ElChristou » 22.03.2007, 00:59

t00fri wrote:Does you Celestia version have the recent CVS additions by Vincent!??

Bye Fridger


Sure, and your script (sent by mail) works perfectly! :D

I'll try to find out what I was doing wrong... Tx!
Image

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

Post #77by t00fri » 22.03.2007, 01:13

Here is a nice view using my script:

Looking from the galaxy ngc1262 (having the largest redshift of 0.126) onto the Milky Way that is 477 Mpc away. In the background on the lower right you see lots of redshifted galaxies (red dots). The closer galaxies are white.

Image
Bye Fridger
Image

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

Post #78by Cham » 22.03.2007, 01:19

Fridger,

your script is working nicely on my system. However, it also marks many objects in our Milky-Way, which aren't galaxies (yes, I recompiled the CVS Celestia few minutes ago, to use Vincent's recent modification) :

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
t00fri
Developer
Posts: 8772
Joined: 29.03.2002
Age: 22
With us: 22 years 7 months
Location: Hamburg, Germany

Post #79by t00fri » 22.03.2007, 01:21

ElChristou wrote:
t00fri wrote:Does you Celestia version have the recent CVS additions by Vincent!??

Bye Fridger

Sure, and your script (sent by mail) works perfectly! :D

I'll try to find out what I was doing wrong... Tx!


Good!

So here is the script for everyone to download. This is way safer....

http://www.celestiaproject.net/~t00fri/images/z-dist.celx.zip

Bye Fridger
Image

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

Post #80by t00fri » 22.03.2007, 01:26

Cham wrote:Fridger,

your script is working nicely on my system. However, it also marks many objects in our Milky-Way, which aren't galaxies (yes, I recompiled the CVS Celestia few minutes ago, to use Vincent's recent modification)


Cham,

well my script was written for Vincent's modification being ABSENT. I used "" instead of nil. As Chris wrote, this has to be coded right, eventually. That's not my concern right now.

That script was just for fun ;-)

Bye Fridger
Image


Return to “Scripting”