compassBox and refraction

Discuss Celestia's features, adaptations and Addons for use in educational environments
Avatar
Topic author
Fenerit M
Posts: 1880
Joined: 26.03.2007
Age: 17
With us: 17 years 7 months
Location: Thyrrenian sea

compassBox and refraction

Post #1by Fenerit » 10.03.2011, 19:51

With the code below, I've insert the atmospheric refraction within the compassBox.lua for having the apparent elevation of the bodies. These equations are from Jean Meeus (Astronomical Algorithms)

Code: Select all

-----------      START REFRACTION        ----------------------

local get_refraction = function(obs, refObj)

--[[ Calculate the adjustment in altitude of a body due to atmosphric
   refraction. This value varies over altitude, pressure and temperature.

   Note: Default values for pressure and temperature are 1010 mBar and 10C
   respectively.]]--
         
   local my_atm_press = 980; -- mBar (user define parameter)
   local my_temp = 20; -- degree Celsius (user define parameter)
         
   R = 1.0 / math.tan(math.rad(elev + (7.31 / (elev + 4.4))));
   R = R - (0.06 * math.sin (math.rad (14.7 * (R / 60.0) + 13.0)));
   -- take into account of atm press and temp
   R = R * ((1010 / my_atm_press) * (283.15 / (273.15 + my_temp)));
   -- convert from arcminutes to degrees
   R = math.abs(R/60.0);
   -- no refraction when the elevation is less of zero
   if elev < 0 then R = 0.000 end
   return R;      
   
-- Citation and code port from LIBNOVA, C++ astronomical library (SOURCEFORGE.net)

end

-----------      END REFRACTION        ------------------------


The code is a function called when the longlatBox is drawn and displayed with a new textlayout label. The refraction's value will be zero for elevations less than zero. Refraction behave (based on custom location's pressure and temperature) from a maximum for low bodies' elevations to a minimum for high bodies' elevations. Such value is added to the true elevation.

Image

If someone wish to test the code, a zip with the improved compassBox.lua is here
Notice that I've put the labels in such a position, but nonetheless it can be as is it in the default file. Just fit the refraction's text string for you needs.
Last edited by Fenerit on 22.01.2012, 11:32, edited 2 times in total.
Never at rest.
Massimo

Avatar
jogad
Posts: 458
Joined: 17.09.2008
With us: 16 years 2 months
Location: Paris France

Re: compassBox and refraction

Post #2by jogad » 11.03.2011, 15:31

 
Very useful and didactic tool ! :)
Very nice, simple and beautiful idea !

Thanks.


just a little observation:
The line

Code: Select all

R = R * ((1010 / my_atm_press) * (283.15 / (273.15 + my_temp)));

looks like a bug. :( (pressure must vary in the same way as the refraction)

And I don't know if providing your modif with your special values for the temperature and pressure is a good idea. In my opinion, the user himself should not have to tweak the code of an addon. (Maybe report the user's parameters in config.lua?)

Fenerit wrote:The refraction's value will be zero for elevations less than zero.
Maybe instead of using the true elevation, it'd be interesting to use the apparent elevation to limit the computations. This way we can see the apparent elevation of the visible body even if it is actually under the horizon. This gives a way to show the exact moment where a star or a planet becomes visible.
I suggest to replace the test with : if elev + R < 0 then R = 0 end.

Some instructions to install this neat tool it in Celestia?
:mrgreen:

Avatar
Topic author
Fenerit M
Posts: 1880
Joined: 26.03.2007
Age: 17
With us: 17 years 7 months
Location: Thyrrenian sea

Re: compassBox and refraction

Post #3by Fenerit » 11.03.2011, 19:59

jogad wrote: 
Very useful and didactic tool ! :)
Very nice, simple and beautiful idea !

Thanks.


Well, fortunately there were already the equations, because whether you were aspecting me for that, I say you goodbye. :wink:

jogad wrote:
just a little observation:
The line

Code: Select all

R = R * ((1010 / my_atm_press) * (283.15 / (273.15 + my_temp)));

looks like a bug. :( (pressure must vary in the same way as the refraction)

And I don't know if providing your modif with your special values for the temperature and pressure is a good idea. In my opinion, the user himself should not have to tweak the code of an addon. (Maybe report the user's parameters in config.lua?)

The default "standardized" values for pressure and temperature are 1010 mBar and 10 °C respectively. My values are indicative (as experiment) for that of the true user's location, which must be specified and does changes the refraction. If they are 1010 mBar and 10 °C respectively, then R = R * 1. Of course, the mBar and the °C specified by users are based on their true location (home); if one do travel around the world and then posit itself on the surface, such point always will have such value, either in the desert as well as in the jungle. The default values encompass such cases.

jogad wrote:
Fenerit wrote:The refraction's value will be zero for elevations less than zero.
Maybe instead of using the true elevation, it'd be interesting to use the apparent elevation to limit the computations. This way we can see the apparent elevation of the visible body even if it is actually under the horizon. This gives a way to show the exact moment where a star or a planet becomes visible.
I suggest to replace the test with : if elev + R < 0 then R = 0 end.

Absolutely you are in right. Such a concern was "hidden" onto it. :wink:

jogad wrote:Some instructions to install this neat tool it in Celestia?
:mrgreen:


I never will play with the Celestia's code, I'm unable with C++ and should be a shame. :wink: Just in LUATOOLS/PLUGINS and whether Vincent agree, otherwise do consider it just a code "modding". :)
Never at rest.
Massimo

Avatar
jogad
Posts: 458
Joined: 17.09.2008
With us: 16 years 2 months
Location: Paris France

Re: compassBox and refraction

Post #4by jogad » 11.03.2011, 22:02

Oh! Sorry!
I see that I was not clear.

When I said : "pressure must vary in the same way as the refraction" I thought to replace this line

Code: Select all

R = R * ((1010 / my_atm_press) * (283.15 / (273.15 + my_temp)));
with:

Code: Select all

R = R * ((my_atm_press / 1010) * (283.15 / (273.15 + my_temp)));


And my opinion about personal parameters is just... my opinion :? And does not relate in anything with the "bug" above.

And lastly:
I was not talking about changing the code of celestia :!:
I think that this tool can be useful to many people, not just to those who are used to manipulate the files of Celestia.
It would certainly useful for some people to know how to install your program to use it in Celestia.

Avatar
Topic author
Fenerit M
Posts: 1880
Joined: 26.03.2007
Age: 17
With us: 17 years 7 months
Location: Thyrrenian sea

Re: compassBox and refraction

Post #5by Fenerit » 11.03.2011, 23:45

As "proof" I can quote from the original c++ string:


R *= ((1010 /atm_press) * (283. / (273. + temp)));


where the "atm_press" and "temp" are peer-user settings. Moreover, to the K degree I've added the decimals.

As for to install such a program, it's just the compassBox.lua file; a file shipped within the LUA_EDU_TOOLs (version from the 1.1 beta8 and after ---- Celestia 1.6.0/1.6.1) or with the last LUAPLUGIN pack. Simply backup the existent and unzip the new inside their suited folders. Or, at least, compare the two file to take up just what is necessary (since the text labels are disposed in different manner on the screen). Basically, the function, one string for its call and one string for the label. They are easy recognizables within the code text.
Finally, indeed the user-define values can be placed inside the config.lua for either the LUATOOLS or the LUAPLUGINS, but this assessment should be matter and must have the permission of Vincent, since he is the "boss" here.
Never at rest.
Massimo

Avatar
jogad
Posts: 458
Joined: 17.09.2008
With us: 16 years 2 months
Location: Paris France

Re: compassBox and refraction

Post #6by jogad » 12.03.2011, 08:16

Hi,

As "proof" I can quote from the (holy) original c++ string
At this point this is a matter of faith! Am I a heretic because I do not believe in your formula? :lol:

The question is:
Do you really believe that the refraction decreases when the pressure increases :?:



Thank you for the explanations to use this modified file. For me this works great with the luaplugins :) but fails with the lua_edu_tools. :(

Regards

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

Re: compassBox and refraction

Post #7by Vincent » 12.03.2011, 09:18

Fenerit wrote:Finally, indeed the user-define values can be placed inside the config.lua for either the LUATOOLS or the LUAPLUGINS, but this assessment should be matter and must have the permission of Vincent, since he is the "boss" here.
Massimo,

I haven't tested your code yet, but it's good to read that you, Jo?l, Martin, ... keep on adding great enhancements to the Lua Tools/Plugins.
When I started working on them, I mainly considered them as a basic extension from which anybody could build his/her own plugin without
having to deal with the C++ code. And I'm glad to see that this is what happened actually.
So, as to modifying the config.lua file, I'm not the boss of anything here, so please feel free to do it without asking my permission,
in the limits specified in the Credits section of the readme :

--------------------------------------------------------
CREDITS:
--------------------------------------------------------
- The Lua Edu Tools can be freely used/copied/modified/distributed for non-commercial activities.
Please keep a copy of the original version of this 'readme.txt' file within your 'lua_edu_tools' folder.

- You must contact the author <vince.gian@free.fr> if you want to use the original or a modified version
of the Lua Edu Tools for any commercial activity.
@+
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
Fenerit M
Posts: 1880
Joined: 26.03.2007
Age: 17
With us: 17 years 7 months
Location: Thyrrenian sea

Re: compassBox and refraction

Post #8by Fenerit » 12.03.2011, 19:33

jogad wrote:Hi,

As "proof" I can quote from the (holy) original c++ string
At this point this is a matter of faith! Am I a heretic because I do not believe in your formula? :lol:

The question is:
Do you really believe that the refraction decreases when the pressure increases :?:

No. the refraction is a function of the air density d = P/T so the formula should be (at least):
R = R * ((atm_press /1010) / ((273. + temp) / 283.)); I do not know why the astronomical library borrow that formula: I must just suppose that it has been inverted. :roll:

jogad wrote:Thank you for the explanations to use this modified file. For me this works great with the luaplugins :) but fails with the lua_edu_tools. :(
Regards

The compass.Box.lua of the LUATOOLS is indeed a bit different. For that, I suggest to compare the two file and to make target insertions.

@ Vincent.
Yes, I'm aware of; but a bit of "general clarification" for the user who wish to enhance the code is welcome. :wink:
Never at rest.
Massimo

Avatar
Topic author
Fenerit M
Posts: 1880
Joined: 26.03.2007
Age: 17
With us: 17 years 7 months
Location: Thyrrenian sea

Re: compassBox and refraction

Post #9by Fenerit » 12.03.2011, 21:49

AAAARRRRRGGGHHHHHHHH!!!!!!!! :x :x :x :cry: :cry: :cry: :twisted: :twisted: :( :(

The quoting is wrong. Jo?l, gimme five. The correct equation is:

R = R * ((my_atm_press / 1010) * (283.15 / (273.15 + my_temp)));

Neither the copy I've write correct! :cry: :cry: :| I apologize for this. The link above has been updated.
Never at rest.
Massimo

Avatar
Topic author
Fenerit M
Posts: 1880
Joined: 26.03.2007
Age: 17
With us: 17 years 7 months
Location: Thyrrenian sea

Re: compassBox and refraction

Post #10by Fenerit » 14.03.2011, 06:14

Hi! Further enhancement of the compassBox.lua (plug-ins version)

- Added Zenith for northern emisphere and Nadir for the southern one;
- Added Airmass;
- Insert the Jogad's suggestion about the display of the apparent elevation for bodies not yet true rised.

Image

When one is on the northern emisphere the string will display the Zenith, when one is on the southern one, the text will change in Nadir. Maybe I'm remained back, but as educational purpose I think can be funny. The airmass is pretty aimed-for-itself, since it serves for computing the brightness extintion through absorption/scattering of the atmospheric's compounds by summing up Rayleigh scattering etc. into Beer-Lambert-Bouguer law and accounting for magnitudes; but it's best to set down the computations soon.

P.S.
I've checked the port of the airmass code pixel-by-pixel, so I can declare that it has been correctly accomplished. :wink:

ZIP here.
Never at rest.
Massimo

Avatar
PlutonianEmpire M
Posts: 1374
Joined: 09.09.2004
Age: 40
With us: 20 years 2 months
Location: MinneSNOWta
Contact:

Re: compassBox and refraction

Post #11by PlutonianEmpire » 11.11.2012, 21:23

The link in the OP isn't working. :?

EDIT: And the file provided by the zip in the post directly above doesn't work either. :?
Terraformed Pluto: Now with New Horizons maps! :D

Avatar
Topic author
Fenerit M
Posts: 1880
Joined: 26.03.2007
Age: 17
With us: 17 years 7 months
Location: Thyrrenian sea

Re: compassBox and refraction

Post #12by Fenerit » 11.11.2012, 23:11

PlutonianEmpire wrote:The link in the OP isn't working. :?

EDIT: And the file provided by the zip in the post directly above doesn't work either. :?

That is working for plugins' "compassBox.lua" only, not for LUATOOLS' "compassBox.lua".
Never at rest.
Massimo

Avatar
PlutonianEmpire M
Posts: 1374
Joined: 09.09.2004
Age: 40
With us: 20 years 2 months
Location: MinneSNOWta
Contact:

Re: compassBox and refraction

Post #13by PlutonianEmpire » 11.11.2012, 23:13

Fenerit wrote:
PlutonianEmpire wrote:The link in the OP isn't working. :?

EDIT: And the file provided by the zip in the post directly above doesn't work either. :?

That is working for plugins' "compassBox.lua" only, not for LUATOOLS' "compassBox.lua".
Ah, makes sense then. Thanks. :)
Terraformed Pluto: Now with New Horizons maps! :D


Return to “Celestia in Education”