Archived

This topic is now archived and is closed to further replies.

Emerson67

Finally we have a visibility limiter plugin

Recommended Posts

An important plugin has been released for flight simmers that use on-line weather in X-Plane. It's important because X-plane has a basic primary flaw: it sets infinite visibility from the "9999" visibility tag, which causes frame rate drop - because the very distant scenery is rendered - and is unrealistic. This plugin fix it. The METAR "9999" tag means visibility 10km or above.

 

You can download the plugin here:

 

http://forums.x-plane.org/index.php?app=downloads&showfile=19748

 

Create a folder "PythonScripts" inside "resources\plugins" folder and put the file "PI_VisibilityLimit.py" there.

 

The plugin is a Python script, so you must install Python. For 64-bit X-Plane Windows, install "Python 2.7.5 Windows X86-64 Installer". Get it here:

 

http://www.python.org/download/

 

Then download "PythonInterface.zip" (the 2.7 version)  from here:

 

http://xpluginsdk.org/python_interface_latest_downloads.htm

 

Extract this file and put the folder "PythonInterface" inside the "resources\plugins" folder.

 

Start x-plane and check if the plugin is running (look on the "Plugins" menu, "Python interface").

 

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

And some guys complain about the limited visibility in altitude :-)  Now, there is a plugin to limit it even more ;-)

 

But, jokes aside, it makes sense, for surface visibility, although any limit imposed artificially when visibility set to 9999 in the METAR is always subjective because it might be 11km, 50km, etc...  

 

The same problem applies to cloud bases. If above your sector alt and not of Cb type they will not be reported, even if you have a OVC of stratocumulus...

Share this post


Link to post
Share on other sites

I think the "not so high" visibility at high altitude problem is something related to XP graphic engine.

 

Regarding the plugin: it relaxes the limit as altitude increases, and it does consider the dew point, etc, and the good thing is that the script is an open text file (as the LUA scripts), so you can edit it and modify the behavior... :rolleyes:

 

Actually I was about to write my own plugin to carry out such task, but this one was released first.

Share this post


Link to post
Share on other sites

 

 


and it does consider the dew point

 

Ah! That is indeed good to know, as well as the "ralaxation" with alt!  I will certainly try it ;-)

Share this post


Link to post
Share on other sites

I like it - seems to have a much more convincing haze effect than default.

 

However it keeps changing my weather setting from real weather to set weather uniformly for globe. Is that intended?

Share this post


Link to post
Share on other sites

I like it - seems to have a much more convincing haze effect than default.

 

However it keeps changing my weather setting from real weather to set weather uniformly for globe. Is that intended?

 

I also noticed this after installing the plugin. I have to go into weather settings after flight has loaded to set real-weather, and redo that every time i for instance swap airports etc.

 

Feels like quite a nice fps improvement too, not sure. Haven't noticed any visual difference yet thou (flew only in real weather with normal cloudy weather)

Share this post


Link to post
Share on other sites

I've noticed that i have to manually put the sim on "grab real weather from the net" mode and then click on "download right now" button if I want to refresh the weather (i.e download current weather) after some flying time. Yes, this is annoying. I´m going to write a note on the first post. Update: I can´t edit it. No edit button!

I also noticed this after installing the plugin. I have to go into weather settings after flight has loaded to set real-weather, and redo that every time i for instance swap airports etc.

 

Share this post


Link to post
Share on other sites

Actually not much so far, but there's some FPS gain :smile: indeed . You have to consider my PC hardware spec that is not "low-end".

 

Some tests:

 

SCSE 211700Z 31008KT 9999 FEW025 12/02 Q1020

Plugin off: 32 FPS (20SM)

Plugin on: 35 FPS (11.2SM)

 

MDPC 211800Z 09013KT 9999 SCT023 31/24 Q1018

Plugin off: 34 FPS (20SM)

Plugin on: 37 FPS (11.2SM)

 

No FPS gain on CAVOK:

ETNG 211750Z 06007KT CAVOK 31/16 Q1018

Plugin off: 34 FPS (20SM)

Plugin on: 34 FPS (11.2SM)

 

How much of a performance gain do you notice, if any?

Share this post


Link to post
Share on other sites

 

 


SCSE 211700Z 31008KT 9999 FEW025 12/02 Q1020
Plugin off: 32 FPS (20SM)
Plugin on: 35 FPS (11.2SM)

 

Honestly then, I'll pass, not because of the FPS but rather because of the fact that for such a wide range between T and Td I see no justification for "just" 11.2 SM horizontal visibility...

Share this post


Link to post
Share on other sites

jcomm,

 

This is the plugin logic (from the PY text file):

 
HIGH_MAX_VIS = 50000.0          # meters at high altitude (float)
NORMAL_MAX_VIS = 30000.0        # meters in normal conditions (float)
MEDIUM_DPRATIO_VIS = 21000.0    # meters when difference between temp and dp is less than 10
LOW_DPRATIO_VIS = 18000.0       # meters when difference between temp and dp is less than 5

def FlightLoopCallback(self, elapsedMe, elapsedSim, counter, refcon):

        visibility = XPLMGetDataf(self.VisibilityDataRef)

        maxVis = HIGH_MAX_VIS

        diff = XPLMGetDatai(self.TemperatureSL) - XPLMGetDatai(self.DewPointSL)

        elev = XPLMGetDatad(self.elevation) / 0.3

        if (elev < 8000):

            if (diff < 5):

                maxVis = LOW_DPRATIO_VIS

            elif (diff < 10):

                maxVis = MEDIUM_DPRATIO_VIS

        if (visibility > maxVis):

            XPLMSetDataf(self.VisibilityDataRef, maxVis)

        # Return 1.0 to indicate that we want to be called again in 1 second.

        return 1.0

You can have good ideas...

Now I see the plugin considers the elevation as well

Share this post


Link to post
Share on other sites

Jcomm, the logic and code of the plugin is very very simple. You could download it and then change the values of just HIGH_MAX_VIS, NORMAL_MAX_VIS, MEDIUM_DPRATIO_VIS, LOW_DPRATIO_VIS, to tune its behaviour.

Share this post


Link to post
Share on other sites

Yes Murmur and Emerson, I agree, it's easy to edit ant tune to one's preferences.

 

The original idea is an excellent one too. It makes me think that other interesting "weather interventions" could be made through dataref access...  I confess I didn't even know the Td made part of the internal variables, since it is not listed in the Weather menus...

Share this post


Link to post
Share on other sites

If one of you guys could tweak the logic to make it more realistic...:)

Share this post


Link to post
Share on other sites

If one of you guys could tweak the logic to make it more realistic...:)

 

Well I found this pdf with a nice graph at the end ("VISIBILITY VERSUS PRECIPITATION RATE AND RELATIVE HUMIDITY"):

 

https://www.google.it/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&ved=0CCoQFjAA&url=https%3A%2F%2Fams.confex.com%2Fams%2Fpdfpapers%2F113177.pdf&ei=v5vsUYOENunJ4ASQiYHIDg&usg=AFQjCNE6hJ4r8jk9yr_zQ0HM9kYXyPFpCw&sig2=IUgbylEoYzqjnEmiUDB2RQ&bvm=bv.49478099,d.bGE

 

Seems perfect to tune the plugin! I'll see tomorrow what can I do.

Share this post


Link to post
Share on other sites

Well I found this pdf with a nice graph at the end ("VISIBILITY VERSUS PRECIPITATION RATE AND RELATIVE HUMIDITY"):

 

https://www.google.it/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&ved=0CCoQFjAA&url=https%3A%2F%2Fams.confex.com%2Fams%2Fpdfpapers%2F113177.pdf&ei=v5vsUYOENunJ4ASQiYHIDg&usg=AFQjCNE6hJ4r8jk9yr_zQ0HM9kYXyPFpCw&sig2=IUgbylEoYzqjnEmiUDB2RQ&bvm=bv.49478099,d.bGE

 

Seems perfect to tune the plugin! I'll see tomorrow what can I do.

 

Good source. ELITE uses a similar algorithm since it doesn't even model precipitation graphically but rather in the form of visibility.

 

In real life, for instance, there's a difference between the conditions that favor the formation of mist vs haze, the later being associated with situation where the relative humidity exceeds 70% in the classical texts... sometimes higher values for other authors.

 

I'll try to find some time to think about it too, but the base in this source is already very good.

Share this post


Link to post
Share on other sites

I can't pretend to understand what you need to do, but thanks for your work anyway!

Share this post


Link to post
Share on other sites

Here's the modified code:



 
HIGH_MAX_VIS = 60000.0          # meters at high altitude (float)

def FlightLoopCallback(self, elapsedMe, elapsedSim, counter, refcon):

        visibility = XPLMGetDataf(self.VisibilityDataRef)

        maxVis = HIGH_MAX_VIS

        diff = XPLMGetDatai(self.TemperatureSL) - XPLMGetDatai(self.DewPointSL)

        RH = 100 - 5 * diff

        if (RH > 50) :

            maxVis = ( - 0.0177 * RH ^ 2 + 1.462 * RH + 30.8 ) * 1000

        if (maxVis > HIGH_MAX_VIS) :
   
            maxVis = HIGH_MAX_VIS

        if (visibility > maxVis):

            XPLMSetDataf(self.VisibilityDataRef, maxVis)

        # Return 1.0 to indicate that we want to be called again in 1 second.

        return 1.0

Now, the plugin smoothly varies visibility with T-Td, according to empirical equations. A max visibility of 60 miles is reached for T-Td > 10.

 

If you think 60 miles is too much and causes too low FPS on your system, just lower the HIGH_MAX_VIS value. E.g. if you set

HIGH_MAX_VIS = 30000.0, the max visibility will be 30 miles, reached when T-Td > 3.4.

 

The modified version does not consider altitude, since X-Plane should automatically increase visibility with altitude.

 

It also does not lower visibility according to precipitation rate. I think that could be easily implemented, but I don't have time right now...

 

Marco

 

 

Share this post


Link to post
Share on other sites

Here's the modified code:

 

 
HIGH_MAX_VIS = 60000.0          # meters at high altitude (float)

def FlightLoopCallback(self, elapsedMe, elapsedSim, counter, refcon):

        visibility = XPLMGetDataf(self.VisibilityDataRef)

        maxVis = HIGH_MAX_VIS

        diff = XPLMGetDatai(self.TemperatureSL) - XPLMGetDatai(self.DewPointSL)

        RH = 100 - 5 * diff

        if (RH > 50) :

            maxVis = ( - 0.0177 * RH ^ 2 + 1.462 * RH + 30.8 ) * 1000

        if (maxVis > HIGH_MAX_VIS) :
   
            maxVis = HIGH_MAX_VIS

        if (visibility > maxVis):

            XPLMSetDataf(self.VisibilityDataRef, maxVis)

        # Return 1.0 to indicate that we want to be called again in 1 second.

        return 1.0

Now, the plugin smoothly varies visibility with T-Td, according to empirical equations. A max visibility of 60 miles is reached for T-Td > 10.

 

If you think 60 miles is too much and causes too low FPS on your system, just lower the HIGH_MAX_VIS value. E.g. if you set

HIGH_MAX_VIS = 30000.0, the max visibility will be 30 miles, reached when T-Td > 3.4.

 

The modified version does not consider altitude, since X-Plane should automatically increase visibility with altitude.

 

It also does not lower visibility according to precipitation rate. I think that could be easily implemented, but I don't have time right now...

 

Marco

 

 

Great work Marco!

 

Thx  a lot!  Tell Austin - he will certainly like to know, and since you and the original author did most of the work already, he has the material required to implement it into a future release of X-Plane10.

 

I am also talking to a colleague here at the aeronautical meteorology dept because she did precisely a study on visibility determination for aviation weather forecasts. We may end with even more material including various type of precipitation and it's impact on visibility.

 

Of course we will not be able to go as far as to take into account aerosols and pollution, but, X-Plane's World is not polluted!!!!! :-)

Share this post


Link to post
Share on other sites

Hmmm,

 

tried it but there's something wrong?

 

First I had to replace the "^" operator by a call to "pow"... because it was generating an error...

 

Then, there is always very low vis ?  I'll have a look at it again...

 

That nasty effect of clearing the downloaded weather is still the reason I had to disable it... It zeroed winds, turned everything to ISA...

Share this post


Link to post
Share on other sites

Yeah there are a couple of stupid errors I made in the code! D'oh!

 

Unfortunately I couldn't try it since I should install Python etc.

 

Here's the corrected code, this time it should work, except for the problem of clearing the downloaded weather that you mentioned. I don't know the reason for that.

 


 
HIGH_MAX_VIS = 60000.0          # meters at high altitude (float)

def FlightLoopCallback(self, elapsedMe, elapsedSim, counter, refcon):

        visibility = XPLMGetDataf(self.VisibilityDataRef)

        maxVis = HIGH_MAX_VIS

        diff = XPLMGetDatai(self.TemperatureSL) - XPLMGetDatai(self.DewPointSL)

        RH = (100 - (5 * diff) ) / 100

        if (RH > 50) :

            maxVis = ( (- 0.0177 * RH * RH) + (1.462 * RH) + 30.8 ) * 1000

        if (maxVis > HIGH_MAX_VIS) :
   
            maxVis = HIGH_MAX_VIS

        if (visibility > maxVis):

            XPLMSetDataf(self.VisibilityDataRef, maxVis)

        # Return 1.0 to indicate that we want to be called again in 1 second.

        return 1.0

Marco

 

Share this post


Link to post
Share on other sites

Another little error.. ehm... Instead of:

RH = (100 - (5 * diff) ) / 100

It was correct as in the first version, so delete "/ 100":


RH = (100 - (5 * diff) )
 

 

Now if it doesn't work, the error must be in the original code, not my modifications.

Share this post


Link to post
Share on other sites

So is this creating a better effect and if so can you tell us how to insert the code into the plugin?

 

edit - actually I think I'm going to stop using the plugin as it is. I really like the haze effect but getting a bit tired with it continually reverting back to set weather uniformly and deleting the real weather.

 

It seems like it might be a problem with Python rather than the script itself, as the problem only goes away when I stopped Python, not when I simply disabled the script. Is the author aware of this?

Share this post


Link to post
Share on other sites