Recent

Author Topic: Weather forecasting in Pascal  (Read 3111 times)

MarkMLl

  • Hero Member
  • *****
  • Posts: 6692
Weather forecasting in Pascal
« on: April 09, 2022, 01:49:39 pm »
Allowing for the ready availability of the station data that underpins e.g. https://earth.nullschool.net/#current/wind/isobaric/850hPa/orthographic and the limited availability of analysis charts that overlay fronts onto observations e.g. https://www.met.ie/latest-reports/surface-analysis , has anybody ever come across Pascal code which attempts to locate the major frontal systems and describes them as e.g. Beziers?

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Weather forecasting in Pascal
« Reply #1 on: April 09, 2022, 09:18:18 pm »
Hi!

I try to understand:

Do you got the worldwide isobaric data or do you want to make a picture analysis?

I am just playing around with WWW (World Wide Weather)

Winni


MarkMLl

  • Hero Member
  • *****
  • Posts: 6692
Re: Weather forecasting in Pascal
« Reply #2 on: April 09, 2022, 10:55:35 pm »
The temperature and pressure data (hence isobars) that underlies e.g the Nullschool presentation is freely available, and my understanding is that there's various international agreements involved.

What I'm specifically interested in is how to perform the airmass analysis, i.e. determine the position of the cold and warm fronts. This does appear to be deterministic and reasonably well understood, but is reputed to be a manual operation until (at least) comparatively recently.

My suspicion is that the various local meteorological offices consider generation of a frontal diagram, which gives a fairly good idea of the weather for the next few hours, as almost as commercially sensitive as longer-term forecasts. I've seen a couple of papers about using neural nets etc. to forecast based on the current synopsis, but nothing about preparing the sort of synoptic chart that most newspapers published daily until comparatively recently (i.e. a map overlaid with fronts).

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Weather forecasting in Pascal
« Reply #3 on: April 09, 2022, 11:46:58 pm »
Hi!

The weather gods themselves are not shure about that:

-----snip-----
While the
term front refers to a sharp transition between air masses of
different characteristics (e.g. in terms of temperature and hu-
midity), there is unfortunately not a generally accepted defi-
nition of a front. This is also reflected in many different ap-
proaches to detect fronts automatically, e.g. using (multiple)
gradients of thermodynamic variables, or even recently using
machine learning techniques.
-----snap------

from:   https://wcd.copernicus.org/articles/3/113/2022/wcd-3-113-2022.pdf

That's why the meteorologists have the biggest mainframes ....

Besides the fact that Europes weather comes for more that 60% from the west. And there are too less weather stations in the Atlantic. Especially in the air.

Seems you are looking for a real hard job.
If you solve it you are member in one of the last well paid voodoo buisiness:
the weather forecast ....

Good luck!

Winni
« Last Edit: April 09, 2022, 11:51:49 pm by winni »

MarkMLl

  • Hero Member
  • *****
  • Posts: 6692
Re: Weather forecasting in Pascal
« Reply #4 on: April 10, 2022, 09:49:21 am »
The weather /forecast/ is, as you say, deep magic: large-scale computer systems running predictions of forthcoming state, and a flood of papers analysing every significant storm to see whether there's any way the models can be tweaked.

However there does appear to be a consensus about getting a "good enough" analysis of the current observations, see for example http://www.atmo.arizona.edu/students/courselinks/spring08/atmo336s1/courses/spring18/atmo170a1s1/lecture_notes/fronts/locating_fronts.html

Subsequent interpretation relies on a great deal of skill since much depends on whether the airflow has been over cold land or warm ocean and so on.

There's various charts etc. which the UK's Met Office doesn't make available for local consumption (after all, they have to have some source of income), but gives to cooperating authorities abroad. So if I want a chart in a form that I can overlay onto e.g. Google Earth, I have to go to e.g. https://www.weathercharts.org/ukmomslp.htm which I believe comes via Germany.

It should, in principle, be possible to apply the method shown in that lecture note and pencil in an approximation of the dominant fronts onto a global map. Allowing that Pascal used to be fairly popular as an implementation language, even if latterly surpassed by the likes of Python, I'm sure that /somewhere/ there's a thesis attempt which could be used as a foundation.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Weather forecasting in Pascal
« Reply #5 on: April 10, 2022, 12:51:06 pm »
Hi!

For the base data:

meteostat  offers the hourly data for 16.000 worldwide station.

Each record consist of

Date
UTC
Air °C
Dewpoint °C
Humidity %
Precipitation mm
Snow mm
Wind degrees
Wind km/h
Wind peak speed km/h
Air pressure
Sunshine minutes/hour
Coco - the describing weather code (1..27)

If you use the data of some surrounding stations then you could make a local map of your position

meteostat has a site for developers:

https://dev.meteostat.net/


Your need the WMO code of the stations (5 digits)

Then you do this sniplet:

Code: Pascal  [Select][+][-]
  1. DecodeDate(NowUTC,year,month,day);
  2.   //    https://bulk.meteostat.net/v2/hourly/{year}/{station}.csv.gz
  3.   URL := 'https://bulk.meteostat.net/v2/hourly/'+IntToStr(year)+
  4. '/'+wmo+'.csv.gz';
  5.   fname := wmo+'.csv.gz';
  6.    try
  7.       try
  8.        ht := TFPHttpClient.Create(nil);
  9.        ht.AllowRedirect := true;
  10.        ht.get(URL,fname);
  11.      finally
  12.        ht.free;
  13.      end;
  14.    except
  15.       on E: Exception do begin
  16.                         showMessage ('http error! No Data!');
  17.                          Label3.caption := 'No Data';
  18.                         exit; end;
  19.    end;                                    
  20.  
  21.  


Winni
« Last Edit: April 10, 2022, 01:01:17 pm by winni »

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Weather forecasting in Pascal
« Reply #6 on: April 10, 2022, 01:19:41 pm »
Great link, winni.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6692
Re: Weather forecasting in Pascal
« Reply #7 on: April 10, 2022, 02:48:29 pm »
Thanks for the link, looks useful.

There's still the troublesome analysis stage: interpolating, locating local pressure minima, orbiting them to find airmass transitions, and then working out an approximate- and I must stress approximate at this stage- presentation of fronts based on Beziers or whatever.

I don't see anybody doing this, except for the national met offices for their own region (which is, after all, what they're being paid for). I have in the past distorted a UK Met Office map from their chosen conformal conic projection to Google Earth's "Web Mercator", but although useful it's hardly pretty and only covers a small fraction of the globe.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: Weather forecasting in Pascal
« Reply #8 on: April 11, 2022, 08:59:21 am »
You can use vectors, starting at the lowest and highest pressure. Divide the difference into an amount of steps and draw your fronts there. At certain intervals along those fronts you draw a new vector and interpolate them for the next "frame". Relatively easy to do (2D), but not very accurate. You need to add radar images and such for the best results.

You can also use finite-element analysis, where you divide the air mass into cubes. This is what they do with clouds, for example, but you need a supercomputer to run a relatively small-scale simulation. Good for understanding the mechanics, but not very practical.

An additional problem is the coverage: weather stations aren't distributed uniformly. So you have to come up with a method to smear that data out in an uniform way.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6692
Re: Weather forecasting in Pascal
« Reply #9 on: April 11, 2022, 09:20:36 am »
I suspect that in practical terms- and considering that the intended result is a display rather than a derivative dataset- it would be useful to interpolate onto a grid with the final resolution early.

That would undoubtedly lose subtlety. My suspicion is that professionally it's an iterative process: estimate (pressure etc.) gradients from features in the raw information and use that to guide interpolation: that would prevent high-impact features (e.g. a region of high-speed wind on the offshore side of a low pressure area) being smeared out.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: Weather forecasting in Pascal
« Reply #10 on: April 11, 2022, 09:56:45 am »
You could use each pixel as an element with its own vector, and use a quadratic gradient for the interpolation. Nice and simple to run on a GPU.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6692
Re: Weather forecasting in Pascal
« Reply #11 on: April 11, 2022, 10:24:13 am »
Consideration of GPUs is (at least) some way down the line... where does FPC stand on such things?

The display device I'm looking at appears happiest with a resolution of (slightly less than) 800x600, and I suspect that in practice I'm not going to be able to display single pixels sharply- which is obviously no problem for temperature gradients, but will be a bit limiting for front etc. overlays. I'm still waiting for a couple of optical components to arrive.

That resolution effectively rules out the animated wind shown by the nullschool webpage (which I think is something like a 256-frame loop), and in practical terms I think I'm talking about a static display apart from possibly allowing the user to change viewpoint to some extent. So something like interpolating to display resolution, walking from random points to find the lows, reinterpolating with fudged gradients and then orbiting lows to locate potential fronts would appear eminently doable.

800x600 = 480 kPoints... hell, that's almost small enough to run on a 16-bit system. Although in practice I might need to use more than that when considering the distortion needed for the final projection.

MarkMLl
« Last Edit: April 11, 2022, 10:41:39 am by MarkMLl »
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Weather forecasting in Pascal
« Reply #12 on: April 11, 2022, 10:47:26 am »
Hi!

For creating the image a hint:

* BGRAbitmap can handle subpixels
* It also is prepared for handling layers
* You can draw direct to a BGRAcontrol like BGRAvirtualScreen

Winni

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: Weather forecasting in Pascal
« Reply #13 on: April 11, 2022, 10:57:08 am »
And we do have an OpenGL subforum, if you want animation ;)

MarkMLl

  • Hero Member
  • *****
  • Posts: 6692
Re: Weather forecasting in Pascal
« Reply #14 on: April 11, 2022, 11:17:08 am »
For creating the image a hint:

* BGRAbitmap can handle subpixels
* It also is prepared for handling layers
* You can draw direct to a BGRAcontrol like BGRAvirtualScreen

Noted, thanks. First thing though is to get the analysis done, which is more of a classical finite element etc. problem.

Depending on how deep I get into this... it might turn out to be possible to guess Beziers for fronts by locating the control vectors relative to neighbouring pressure features (i.e. one end looks at the local low, the control points look at other highs and lows). I'm very much looking for a "good enough" approximation and if a user wants to know what's really happening in a region he should visit the met office in whose jurisdiction it lies.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018