Board index FlightGear Development Weather

Smoothing wind changes in adanced weather

Everything related to weather simulation, visuals should be discussed in the shader subforum.

Smoothing wind changes in adanced weather

Postby alge » Sat Nov 14, 2015 9:49 pm

Hi,

I've been flying small-ish airplanes in AW lately, and whenever there's a little bit of turbulence or wind direction change, the instruments tend to go a bit haywire. After some experimentation I found a pretty cheap way to smooth down the change from gusts and wind direction changes a bit, which I think helps a lot. (For example the variometer on the glider doesn't jump to a different value at once, but transitions semi-smoothly.)

Paging Thorsten here for input. Is this something I should submit as a merge request for fgdata?

Code: Select all
diff --git a/Nasal/local_weather/compat_layer.nas b/Nasal/local_weather/compat_layer.nas
index e5ca6b2..5e56fc4 100644
--- a/Nasal/local_weather/compat_layer.nas
+++ b/Nasal/local_weather/compat_layer.nas
@@ -415,10 +415,23 @@ setprop("/environment/clouds/layer[0]/elevation-ft",0.0);
 # interpolating across several frames
 ###########################################################
 
+var smoothDirection = func (dir0, dir1, factor) {
+   var diff = ( math.mod( dir0 - dir1 + 180 + 360, 360 ) - 180 );
+   diff *= factor;
+   return math.mod( 360 + dir1 + ( diff / 2), 360);
+}
+
 
 var setWindSmoothly = func (dir, speed) {
+   var curHdg = getprop("/environment/wind-from-heading-deg");
+   var curSpeed = getprop("/environment/wind-speed-kt");
+
+   dir = math.mod(dir, 360);
+
+   var newSpeed = (curSpeed * 29 + speed) / 30;
+   var newDir = smoothDirection(dir, curHdg, 0.1);
 
-setWind(dir, speed);   
+   setWind(newDir, newSpeed);
 }
alge
 
Posts: 77
Joined: Thu Aug 30, 2012 12:45 am

Re: Smoothing wind changes in adanced weather

Postby Thorsten » Sun Nov 15, 2015 7:08 am

Could you give me some context, i.e. in which wind mode this is running and what input you're feeding it?

Usually wind changes should be smooth (because they're driven by an interpolation which is faded in over time) unless they're intentionally not (like for gusts, windshear,...).

What the vario of a glider shows is a concern of the instrument code and shouldn't be fixed weather-side - if it jumps in a gust, there should be lag added to the instrument.
Thorsten
 
Posts: 10239
Joined: Mon Nov 02, 2009 8:33 am

Re: Smoothing wind changes in adanced weather

Postby alge » Sun Nov 15, 2015 9:26 am

Sure. It started with trying to get a little more realistic flying experience out of the ASK-13 - it's oh-so-stable in normal flightgear, and I just had my first flight in the real deal and had to continuously work on keeping it straight & level. (I tried to modify the yasim properties without much improvement.) So I put in a little variation in the wind in the METAR, ala "25007G10KT" and/or "25007KT 220V270". That had a very dramatic effect and the airplane bounced around a lot, with some brutal changes in pitch and heading. Hence trying to smooth these changes.

After than, when flying around in "live weather" METAR in the c172p, I've noticed that if the weather includes varying winds, the ride will be very bumpy with almost instant changes especially in pitch.

On the instrument thing, I agree. I had thoughts like "this doesn't seem correct, surely the vario must take change over some time and not instantaneous". I guess you're the expert there. (= It also applies to the ASI though, the needle moves from the one position to the other position from one frame to another. Is the change when flying through changing winds really that abrupt?

Flying with the "smoothed" code in moderately gusty conditions (like what I'm used to from real life), it feels a bit better because the pitch change happens over say half a second instead of instantly. Still enough to bump your head if you hit a bad one.

When you ask about "wind mode", what exactly do you mean? I may be missing something in the code here. I just turn on advanced weather and adjust the METAR a bit to make it slightly more varying.

By the way, maybe there should be some variation in the wind anyway? Not really gusts, but just smaller changes? I believe METAR doesn't report gust before they become really gusty, and wind variation before it exceeds 60 degrees in 2 minutes, but reality is often not a constant wind, at least where I am in the world.

I have to admit I'm not super-happy with the gusts after my change either - they lack some of that whip-effect you get from a real gust. Overall it seems more realistic to me, but maybe that should done as a "random wind variation" effect based on reported wind speed and gusts, and then massively reduce the frequency of gusts but keep them instantaneous.
alge
 
Posts: 77
Joined: Thu Aug 30, 2012 12:45 am

Re: Smoothing wind changes in adanced weather

Postby Thorsten » Sun Nov 15, 2015 2:21 pm

Okay - the gusts are intentionally modeled that way.

Admittedly I've never managed to find a measured time series of gusty winds with a good resolution, so I've used the following reasoning:

What happens in reality is that you move through a windfield with vortices and eddies, these are small-scale phenomena (out of my head, the funnel of a fully-developed Tornado can be 50 m across only, dust devils are some 10 m across), you're typically moving through them at 100 km/h at least (usually faster), so it takes you ~0.3 seconds to resolve the whole eddy. If you associate each gust with an eddy wall crossing, you'd get sudden wind changes in a fraction of a second.

Standing in gusty winds on a cliff facing the sea, that's certainly how it felt to me - there was no smoothness at all to the gusts.

You're usually not flying a glider in gusty winds, and on the one (uncomfortable) occasion I have done that, it was during a mass landing of all planes in the vicinity due to an approaching storm. So the experience should most definitely not feel comfortable in an ASK-13.

I just had my first flight in the real deal and had to continuously work on keeping it straight & level


Yes, that's one the things I've never really liked about YaSim - it feels unnaturally smooth, in reality you're busy with minute changes all the time. JSBSim does that for you, it has little to do with the weather as far as I know, it's how real planes behave.

Is the change when flying through changing winds really that abrupt?


I've been lifted from the seat till I hung in the safety belt and saw my lunchbox smashed against the canopy top by a sudden wind change in the mountains. It can be very violent, it can also be very smooth. METAR reports of varying winds usually mean the gusty type as far as I know, which is why you get hard, short-timescale variations when you try to set wind variation in the METAR.

When you ask about "wind mode", what exactly do you mean?


There's various modes to set the wind, starting from a constant overall wind to a 3-d interpolation over a pre-specified windfield. But since you're specifically referring to gusts, that's not relevant here.

By the way, maybe there should be some variation in the wind anyway?


Maybe, but smooth variations you wouldn't notice anyway - and you do get wind variation by the boundary layer effect close to the ground, by the altitude variation as you rise and by the spatial interpolation as you change position - which you didn't seem to notice so far, thus making my point...

and then massively reduce the frequency of gusts but keep them instantaneous.


Based on what? If you manage to dig up actual time series of gusty winds so that we have some good data to model them, any time. Otherwise it's your word and experience that it doesn't feel right against my experience and semi-quantitative reasoning that it does.

(you can adjust gust frequency user-side by the way, since it's not reported, I added that freedom....)
Thorsten
 
Posts: 10239
Joined: Mon Nov 02, 2009 8:33 am

Re: Smoothing wind changes in adanced weather

Postby alge » Sun Nov 15, 2015 4:08 pm

Thorsten wrote in Sun Nov 15, 2015 2:21 pm:Okay - the gusts are intentionally modeled that way.


Understood. Which is why I was thinking we maybe should have some other variance which is not gusts, but still causes variance. From looking at METAR specs, gusts are only reported if they're 10kts more than the average, which is pretty gusty. (Wind direction variance is not reported unless it's more than 60° of variance as well...)

Thorsten wrote in Sun Nov 15, 2015 2:21 pm:Admittedly I've never managed to find a measured time series of gusty winds with a good resolution, so I've used the following reasoning:

What happens in reality is that you move through a windfield with vortices and eddies, these are small-scale phenomena (out of my head, the funnel of a fully-developed Tornado can be 50 m across only, dust devils are some 10 m across), you're typically moving through them at 100 km/h at least (usually faster), so it takes you ~0.3 seconds to resolve the whole eddy. If you associate each gust with an eddy wall crossing, you'd get sudden wind changes in a fraction of a second.


Right. My code isn't too far off from ~0.3 or a fraction of a second (depending on which fraction), and when looking at the windsock for a while, there's two things happening:
- If it manages to not have two gusts in a second, then it takes about a second for the wind to stabilize
- This rarely happens, because gusts come maybe on average twice per second

I changed my code to make changes happen quicker, and then grabbed some video of a flightgear windsock with my changes, as that might make it easier to talk around: https://goo.gl/photos/s1vvLdc4hcRnjR56A This is with "27007KT 210V290" METAR.

(Ideally the windsock should be modelled and controlled in a very different way as well, and I'm not trying to optimize the weather for the windsock looking good. It's just a convenient visualization.)

Thorsten wrote in Sun Nov 15, 2015 2:21 pm:
By the way, maybe there should be some variation in the wind anyway?


Maybe, but smooth variations you wouldn't notice anyway - and you do get wind variation by the boundary layer effect close to the ground, by the altitude variation as you rise and by the spatial interpolation as you change position - which you didn't seem to notice so far, thus making my point...

and then massively reduce the frequency of gusts but keep them instantaneous.


Based on what? If you manage to dig up actual time series of gusty winds so that we have some good data to model them, any time. Otherwise it's your word and experience that it doesn't feel right against my experience and semi-quantitative reasoning that it does.


So, I think I might be looking for something in-between the 3d interpolation and gusts. Something that keeps the pilot working, without being the metar-defined instant gusts.

I actually sit on data for my airport (since I set up the weather gathering), and I'll share the link with you on PM. It's collecting a wind reading every second, and then uploading the average of the readings (as "wind") and the maximum reading (as "gust") for 10 readings. So I have data at 10s resolution, with max and average wind readings, going back 5 months.

Here's a snapshot from a pretty gusty night:

Image

You can see that even though there were some pretty severe gusts here (nothing I'd want to fly in), there are still plenty of periods of less extreme gusts, although a METAR would report it as the maximum. Zooming in shows the same kind of patterns - it's relatively calmer for a while, and then a spike happens. These "rare spikes" is something I can't achieve with the current AW - the smallest gust frequency still gives me a gust around maximum at least every few seconds.
alge
 
Posts: 77
Joined: Thu Aug 30, 2012 12:45 am

Re: Smoothing wind changes in adanced weather

Postby Thorsten » Sun Nov 15, 2015 4:37 pm

This sounds like pretty good material - thanks!

Let me take a look and see whether I can analyze it and come up with a parametrization that reproduces something closer to it.
Thorsten
 
Posts: 10239
Joined: Mon Nov 02, 2009 8:33 am

Re: Smoothing wind changes in adanced weather

Postby Thorsten » Sun Nov 15, 2015 5:46 pm

Hm. Would you have access to the raw wind data? Say in a 10 minute interval during a gusty period, that'd be 600 data points?

The most striking feature of the plot you posted is the high degree of correlation between upper and lower curve - whenever the upper curve fluctuates up or down, the lower curve does so as well. Okay - to some degree this must be driven by the max. value being part of the average value in a 10 sec interval. But the fact of the matter seems to be that max. wind and average wind in a 10 second bin are almost never the same - i.e. there is variability on the second level, possibly much smaller, we don't see this resolved. Sometimes the peak winds in a 10 second interval are twice as high as the mean winds.

Mean winds also show a strong variability on the 10 second level - I guess a 30-60 second average would be fairly smooth however. You're right in that we don't generate modulation at this timescale.

So, what I really don't see is a period in which gusts don't occur (i.e. the blue and green curve approximately coincide). It's never quieting down in this plot, although there is this minute-scale variation of the overall strength.

(Which is why I'd like to have the raw data, because that can be e.g. fourier-transformed to look for characteristic scales).

Edit: In other matters: I think when dealing with small sized fluctuations, we have to be careful. Any real instrument will have inertia and hence lag. If you'd feed the same wind pattern to FG and reality, you'd see different movement of a windsock, for the simple reason that the real thing needs some time to adjust to the new equilibrium, the FG version reacts instantaneously. So by comparing a real windsock and a FG windsock, you could not conclude that you see a different windfield when we talk about small timescales. Same with an anemometer - the thing doesn't resolve very small timescales, so even if a real gust ramps up in 0.1 second, the measurement is not going to show that unless the instrument is specifically made to resolve such small times.
Thorsten
 
Posts: 10239
Joined: Mon Nov 02, 2009 8:33 am

Re: Smoothing wind changes in adanced weather

Postby alge » Sun Nov 15, 2015 8:58 pm

Hmm. I hope you saw the PM I sent you? If you zoom in enough on calm periods, I think you'll find that the blue line gets close to the green one, when they're both very low. (The visualization has to put data into buckets, and it uses averaging for creating the green bucket, and maximum to create the blue one.)

I exported the data for all of November for you and put it in a csv: http://www.pvv.org/~titlesta/ENOP-wind-data-csv.zip - this includes other things such as wind direction and qnh and such as well. I hope you'll find it useful.
alge
 
Posts: 77
Joined: Thu Aug 30, 2012 12:45 am

Re: Smoothing wind changes in adanced weather

Postby Thorsten » Mon Nov 16, 2015 6:49 am

I did see the PN and tried to look at the plots, but my browser (Opera) did funny things with the visualized graph so I decided to sleep over it and try another browser. But since I have plenty of plotting and visualization software here, I actually prefer to work with the raw data.
Thorsten
 
Posts: 10239
Joined: Mon Nov 02, 2009 8:33 am

Re: Smoothing wind changes in adanced weather

Postby erik » Mon Nov 16, 2015 12:47 pm

While searching whether there is a specific noise function that applies to wind gusts (probably Gaussian, or pink noise bit I've not found it yet) I found the following link.

Section 16.2.3 and further looks quite interesting:
http://www.wrds.uwyo.edu/sco/climateatl ... ation.html

Update: Gaussian seems to be the general consensus.


Erik
erik
 
Posts: 1510
Joined: Thu Nov 01, 2007 1:41 pm

Re: Smoothing wind changes in adanced weather

Postby Thorsten » Mon Nov 16, 2015 1:18 pm

I'm working on this right now - I have plotted a five minute interval of real data sampled each 4 seconds, and I'm trying to get FG to give me a qualitatively similar behavior by tweaking the gust generation routine.
Thorsten
 
Posts: 10239
Joined: Mon Nov 02, 2009 8:33 am

Re: Smoothing wind changes in adanced weather

Postby Thorsten » Mon Nov 16, 2015 3:40 pm

Try now - there is some of your smoothing being applied, and there's a longer-term (~30 seconds) modulation of the overall wind strength in - individual hard changes of windspeed should now be a little rarer.
Thorsten
 
Posts: 10239
Joined: Mon Nov 02, 2009 8:33 am

Re: Smoothing wind changes in adanced weather

Postby alge » Mon Nov 16, 2015 7:13 pm

Awesome! Thanks! That seriously went from "meh, I'm not really convinced by this" in the original form, to "meh, maybe a bit better?" in my attempt to "yes, that's it!" in your version.
alge
 
Posts: 77
Joined: Thu Aug 30, 2012 12:45 am

Re: Smoothing wind changes in adanced weather

Postby Thorsten » Tue Nov 17, 2015 6:52 am

Well, thanks for helping me to clear up this point with good data - I've been looking for a while, but I've never managed to find something before.
Thorsten
 
Posts: 10239
Joined: Mon Nov 02, 2009 8:33 am


Return to Weather

Who is online

Users browsing this forum: No registered users and 1 guest