topic: Weather

Weather Datarefs in X-Plane 12

Weather Datarefs in X-Plane 12

The old weather datarefs have been marked as deprecated in X-Plane 12 and replaced with two new sets. The old ones will remain in place but anything referencing them should be changed to use the new ones as soon as possible. The good news is that this should be fairly straightforward.

Previously the values returned in the datarefs were relative to the user's aircraft. This was fine for handling instrumentation but not ideal for working with the wider environment. There are now two similar sets of datarefs, one for the weather at the aircraft's exact position, and one for the surrounding region.

Aircraft

In general, all the old datarefs that lived under sim/aircraft/ have been moved under sim/weather/aircraft/ with very similar names. The only real thing to note here is that in some cases, units have changed. Also, all these aircraft-specific datarefs are read-only. This makes sense; the aircraft's immediate environment is a point sample from the regional weather.

Cloud, wind and turbulence datarefs are no longer represented by individual datarefs with an array-like notation, they are handled as real arrays. This means you should do proper array handling of these by querying the size of the array using XPLMGetDatavf() before your first read, and allocating enough space accordingly. Doing this will allow your code to continue to work with no changes if in the future the array size is changed. Temperature and wind arrays have already been increased to 13 elements from 3.

It's important to remember that the aircraft's immediate environment is a snapshot of a single point in a simulated 3D volume. This volume contains deliberate variations from whatever the base weather is, whether that's a fixed preset coming from the UI or a composite of available real-weather data if this is enabled. You should not, in other words, expect any value reported at the aircraft's position to exactly match any value you may see elsewhere that isn’t based on the aircraft’s position.

Region

New for X-Plane 12, the base weather that defines the aircraft's surrounding region is provided as a distinct set of datarefs under sim/weather/region/. Right now 'region' roughly corresponds to a square degree but this may vary in the future. The region base values determine a starting point for X-Plane's own weather simulation, which gets added on top. As with the aircraft's datarefs, this means that you should not expect any value returned in these datarefs to exactly match any value you see elsewhere since the weather at any given point is taken from the combination of the base weather and the weather simulation, not the starting data for that simulation.

Atmospheric Altitude Levels

Atmospheric temperatures are defined at preset altitudes which can be found in sim/weather/region/atmosphere_alt_levels_m . If you are working with temperatures aloft, please use the altitudes given in this array and don't hard-code them. The altitudes, or the number of layers, may change.

Modifying the Region

Most of the regional datarefs are writeable, meaning that you can use these to change the weather in a large volume surrounding the user's aircraft.

sim/weather/region/change_mode
This controls X-Plane's internal weather simulation, when used with static weather, by setting a general trend over time.

sim/weather/region/variability_pct
This controls the internal weather simulation's variability for those parts which use random noise to generate variation. The base weather also varies with distance from a given reference point. Typically the reference point would be the selected airport if you use the UI to select a weather preset, for example.

sim/weather/region/update_immediately
When this is non-zero, any changes to any regional dataref except clouds will take place immediately. Otherwise, the changes will start to fade in over a short period of time, currently 1-2 minutes. Clouds are handled a little differently because there is a delay between the cloud data being determined and the results of the GPU-based cloud simulation being returned. Even with update_immediately set to true, clouds will generally take a minute or so to update to the new values. When you absolutely, positively got to kill every cumulonimbus in the room, you can use the sim/operation/regen_weather command to trigger an immediate full reset of the current weather.

API Access

For simpler access if you are using a programming language that can use it, the X-Plane SDK contains some basic weather data access functions. These allow you to get a weather snapshot – that is, the equivalent of the aircraft datarefs, the output of the base weather plus the weather simulation – at a specific point.

While you are free to request weather for distant locations, the accuracy of the data returned will drop significantly outside of the current region. Errors are reported via the standard XPLMSetErrorCallback() mechanism.

Leave a comment

Weather Radar Data

To get the weather-radar data from x-plane, turn on the CONTROL PAD output in the net output screen, and expect this data to be sent by UDP:

 

if(puff15)
	{
		static xint lon_deg=-1;
		static xint lat_deg=-1;
		static xint lat_min=-1;

		if(++lat_min>=61)
		{
			lat_min=-1;
			if(++lon_deg>2)
			{
				lon_deg=-2;
				if(++lat_deg>1)
				{
					lat_deg=-1;
				}
			}
		}
		
		struct wxr_line_struct	// we send a scanline of 61 vertices of weather, spaced 1 minute x 1 minute of lon/lat! cool!
		{						// 61 to get both edges of the degree, since this is vertex-centered not cell-centered
			xint lon_deg_wes;	// vertex-centered not cell-centered is needed to plot radar without it looking blocky
			xint lat_deg_sou;
			xint lat_min_sou;
			xbyt storm_07[61];
		};
		wxr_line_struct wxr_line;

		wxr_line.lon_deg_wes=flt[p0].dat_lon+lon_deg;
		wxr_line.lat_deg_sou=flt[p0].dat_lat+lat_deg;
		wxr_line.lat_min_sou=				 lat_min;

		for(xint lon_min=0;lon_min<61;lon_min++) { xflt cloud_rat=0.0; xflt storm_rat=0.0; wxr_region_threaded_access->get_num_puffs(ct_radar_precip							,"X-IOS-gen",
															(xflt)wxr_line.lon_deg_wes+(xflt)lon_min/60.0	,
															(xflt)wxr_line.lat_deg_sou+(xflt)lat_min/60.0	,
															0.0												,0,NULL,&cloud_rat,&storm_rat);

			wxr_line.storm_07[lon_min]=intlim(storm_rat*9,0,9);	// we have 9 clear plus levels of precip in X-IOS
		}

		inet.inet_send("xRAD",(xchr*)&wxr_line,sizeof(wxr_line),en);
	}
9 Comments

Custom Wind & Weather in X-Plane 10

A grid of 16×16 weather envelopes make up the X-Plane weather system. Each of these 256 weather “buckets” is about 1.0 degrees of longitude by 0.6 degrees of latitude, or about 35 miles or so. Custom weather can be created by modifying the METAR.rwx & winds.rwx files in a text editor. Real weather files are initially downloaded via the last tab in the Weather screen in X-Plane.

File Types

METAR.rwx

This file contains weather in METAR form at countless airports, but with a far higher density in the USA.  METAR data contains weather at the surface, with cloud bases for various elevations above the airport. X-Plane can only guess at cloud TOPS and WINDS ALOFT based on this limited data from the surface.

Winds.rwx

This file loads custom winds 10,000 ft and 34,000 ft into X-Plane, so you have winds aloft for both light planes and airliners, with interpolation for turboprops that fly in between. (Note that this file is only used if global_turbulence.grib & global_winds.grib are NOT in the main X-Plane folder.)

global_turbulence.grib and global_winds.grib

Starting with X-Plane 10.50, these are GLOBAL winds-aloft files that are also downloaded so you can get winds anywhere on Earth. As with winds.rwx, these files loads winds 10,000 ft and 34,000 ft into X-Plane, so you have winds aloft for both light planes and airliners, with interpolation for turboprops that fly in between.

Modifying the Files

Now, you can make your own METAR.rwx file and winds.rwx file. First turn off the download option in the weather screen so X-Plane does not over-write your file.

To test the files that you make, tie command “sim/operation/load_real_weather” to a joystick button or key to test loading the weather at any moment to scan the files you made, or issue the command via plugin. Or just hit the “read right now” button right there in the real-weather screen.

Weather

For global weather coverage of any level of detail you like, add your own entries into the METAR.rwx file. Enter an airport ID of MDEG, followed by the longitude, latitude, and elevation in meters of the imaginary airport you just created for the purposes of setting weather at this location.

For example, if we wanted to change the weather for the South Carolina area, we would specify the area in the METAR.rwx file as: “MDEG -81.235425 34.5647 80.0”. After that we’d enter the information for our weather, such as “24031KT 2SM CLR 10/M10 A3011”.

Let’s parse the first few items in our example above. Note that X-Plane uses longitude first, then latitude; thus the location is 81.235425 degrees West, 34.5647 degrees North. Altitude is 80 meters. The wind direction is 240, with a speed of 31 knots. The visibility is 2 statue miles and the sky is clear (no ceiling). The temperature is 10 degrees Celsius and the dew point is minus 10. The altimeter setting is 30.11inHg. Continue on in this manner when you are adding custom winds or interpreting the report.

You can enter all the MDEG airports you like in a single file, to set the weather anywhere you like. If you put an MDEG airport every degree of longitude and every half degree of latitude, you will be entering about the right number of MDEG airports to get all the detail you can out of the X-Plane weather engine.

Note that if you are customizing weather for an airport that is already listed in the METAR file you will need to delete all other instances aside from your MDEG entry.

Winds

For global coverage of any level of detail you like, you can add your own entries into a winds.rwx file. If you do not have one from an older version of X-Plane 10, you can simply start a new text file. Make sure to remove the global_turbulence.grib & global_winds.grib files to avoid conflicts.

In winds.rwx, enter a wind reporting-station ID of DEG (NOT MDEG! These are 3-letter IDs!), followed by the longitude, latitude, and winds aloft, then X-Plane will set the winds aloft at this location as you enter.

Each of the numbers after the latitude represent the direction, speed and temperature. Each column of wind information corresponds to a specific altitude: 3000, 6000, 9000, 12000, 18000, 24000, 30000, 34000, and 39,000 feet. Note that you may leave a lower altitude column blank if the location is already above that altitude.

Example:

DEG -82.235 34.345 2910 3117+14 2925+08 2934+04 2924-07 2836-20 284436 284946

Let’s parse the first few items in our example above. Note that X-Plane uses longitude first, then latitude; thus the location is 82.235 degrees West, 34.345 degrees North. At 3000 feet, the wind direction is 290, with a speed of 10 knots. At 6000 feet, the wind direction is 310, speed 17 knots, and a temperature of +14 degrees Celsius. Continue on in this manner when you are adding custom winds or interpreting the report.

Enter all the DEG wind-reporting station you like in a single file, to set the weather anywhere you like. If you put DEG wind-reporting station every degree of longitude and every half degree of latitude, you will be entering about the right number of wind-reporting station to get all the detail you can out of the X-Plane weather engine.

NOTE: YOU MUST ENTER A FULL WINDS-ALOFT REPORT AT ALL THE ALTITUDES YOU SEE IN THE DOWNLOADED WINDS.RWX FILE FOR IT TO BE READ!

X-Plane will only USE the data at 12,000 ft and 34,000 ft (with interpolation in between them) but you have to ENTER all altitudes for the wind file to be scanned properly. (It’s valid to use a dummy value such as 0 for all data at all altitudes that are not 12,000 ft and 34,000 ft.)

3 Comments