Skip to content

Instantly share code, notes, and snippets.

@boozeman
Last active October 12, 2023 17:43
Show Gist options
  • Select an option

  • Save boozeman/a20e1a1354e260fbaad429c49daf96cf to your computer and use it in GitHub Desktop.

Select an option

Save boozeman/a20e1a1354e260fbaad429c49daf96cf to your computer and use it in GitHub Desktop.

Revisions

  1. boozeman revised this gist Oct 12, 2023. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions FMIWeather.py
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,7 @@
    # Examples:
    # FMIWeather.py Tampere windspeed
    # FMIWeather.py Hämeenlinna rain1h
    # NOTE! If you live place without FMI weather station, like Turenki, Renko or Lammi, It takes the readings for the closest station.
    # You can find the stations here: https://www.tuulikartta.info/#lang=fi#latlon=61.04,24.29,9#parameter=ws_10min for example
    # All data with 10 min resolution
    # ws_10min = Wind Speed 10min avg (in m/s)
  2. boozeman revised this gist Oct 12, 2023. 1 changed file with 11 additions and 8 deletions.
    19 changes: 11 additions & 8 deletions FMIWeather.py
    Original file line number Diff line number Diff line change
    @@ -2,16 +2,19 @@
    # Correct the file sensor paths for configuration.yaml if needed
    # Usage: python3 FMIWeather.py station parameter
    # Examples:
    # FMIWeather.py Tampere windspeed
    # FMIWeather.py Tampere windspeed
    # FMIWeather.py Hämeenlinna rain1h
    # You can find the stations here: https://www.tuulikartta.info/#lang=fi#latlon=61.04,24.29,9#parameter=ws_10min for example
    # All data with 10 min resolution
    # t2m = Temperature
    # rh = Humidity
    # td = Devpoint
    # r_1h = Rain 1 hour
    # ri_10min = Rain intensity
    # snow_aws = Snow Depth
    # ws_10min = Wind Speed 10min avg (in m/s)
    # wg_10min = Wind Gusts 1omin avg (in m/s)
    # wd_10min = Wind Direction 10min avg (in degrees)
    # t2m = Temperature (in Celcius)
    # rh = Humidity (in hPa)
    # td = Devpoint (in Celcius)
    # r_1h = Rain 1 hour (in millimeters)
    # ri_10min = Rain intensity (in millimeters)
    # snow_aws = Snow Depth (in centimeters)
    # p_sea = Atmospheric Pressure (Hpa)
    # vis = Visibility (in meters)
    # n_man = Cloud Coverage (1 to 8 meaning 1/8 to 8/8)
    @@ -27,7 +30,7 @@ def fetch_data(station, parameter):
    "windspeed": "ws_10min",
    "windgust": "wg_10min",
    "winddirection": "wd_10min",
    "temperature": "t2_m",
    "temperature": "t2m",
    "humidity": "rh",
    "devpoint": "td",
    "rain1h": "r_1h",
  3. boozeman revised this gist Oct 12, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion FMIWeather.py
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@
    # p_sea = Atmospheric Pressure (Hpa)
    # vis = Visibility (in meters)
    # n_man = Cloud Coverage (1 to 8 meaning 1/8 to 8/8)
    # wawa = weather code
    # wawa = weather code -> Weathersymbol3 https://www.ilmatieteenlaitos.fi/latauspalvelun-pikaohje

    import requests
    import xml.etree.ElementTree as ET
  4. boozeman revised this gist Oct 12, 2023. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions FMIWeather.py
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,11 @@
    # Copy this on root of config directory or any place you want
    # Correct the file sensor paths for configuration.yaml if needed
    # Usage: python3 wind_data.py station speed|direction|gust
    # Example: wind_data.py Tampere speed
    # Usage: python3 FMIWeather.py station parameter
    # Examples:
    # FMIWeather.py Tampere windspeed
    # FMIWeather.py Hämeenlinna rain1h
    # You can find the stations here: https://www.tuulikartta.info/#lang=fi#latlon=61.04,24.29,9#parameter=ws_10min for example
    # Orher possible measurements. All data with 10 min resolution
    # All data with 10 min resolution
    # t2m = Temperature
    # rh = Humidity
    # td = Devpoint
  5. boozeman revised this gist Oct 12, 2023. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions FMIWeather.py
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    # Example: wind_data.py Tampere speed
    # You can find the stations here: https://www.tuulikartta.info/#lang=fi#latlon=61.04,24.29,9#parameter=ws_10min for example
    # Orher possible measurements. All data with 10 min resolution
    # t2_m = Temperature
    # t2m = Temperature
    # rh = Humidity
    # td = Devpoint
    # r_1h = Rain 1 hour
    @@ -22,9 +22,9 @@

    def fetch_data(station, parameter):
    parameter_mapping = {
    "windspeed": "ws",
    "windgust": "wg",
    "winddirection": "wd",
    "windspeed": "ws_10min",
    "windgust": "wg_10min",
    "winddirection": "wd_10min",
    "temperature": "t2_m",
    "humidity": "rh",
    "devpoint": "td",
    @@ -43,7 +43,7 @@ def fetch_data(station, parameter):

    parameter_name = parameter_mapping[parameter]

    url = f"https://opendata.fmi.fi/wfs/fin?service=WFS&version=2.0.0&request=getFeature&storedquery_id=fmi::observations::weather::timevaluepair&place={station}&parameters={parameter_name}_10min&"
    url = f"https://opendata.fmi.fi/wfs/fin?service=WFS&version=2.0.0&request=getFeature&storedquery_id=fmi::observations::weather::timevaluepair&place={station}&parameters={parameter_name}&"
    response = requests.get(url)
    root = ET.fromstring(response.content)
    json_data = []
  6. boozeman renamed this gist Oct 12, 2023. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  7. boozeman revised this gist Oct 12, 2023. 1 changed file with 15 additions and 5 deletions.
    20 changes: 15 additions & 5 deletions Wind_Data.py
    Original file line number Diff line number Diff line change
    @@ -22,13 +22,23 @@

    def fetch_data(station, parameter):
    parameter_mapping = {
    "speed": "ws",
    "gust": "wg",
    "direction": "wd"
    "windspeed": "ws",
    "windgust": "wg",
    "winddirection": "wd",
    "temperature": "t2_m",
    "humidity": "rh",
    "devpoint": "td",
    "rain1h": "r_1h",
    "rainintensity": "ri_10min",
    "snowdepth": "snow_aws",
    "pressure": "p_sea",
    "visibility": "vis",
    "cloudcoverage": "n_man",
    "weathercode": "wawa"
    }

    if parameter not in parameter_mapping:
    print("Invalid parameter. Please provide speed, gust, or direction.")
    print("Invalid parameter. Please provide windspeed, windgust, winddirection, temperature, humidity, devpoint, rain1h, rainintensity, snowdepth, pressure, visibilty, cloudcoverage or weathercode.")
    sys.exit(1)

    parameter_name = parameter_mapping[parameter]
    @@ -45,7 +55,7 @@ def fetch_data(station, parameter):

    def main():
    if len(sys.argv) != 3:
    print("Please provide two arguments: station and parameter (speed, gust, or direction).")
    print("Please provide two arguments: station and parameter (windspeed, windgust, winddirection, temperature, humidity, devpoint, rain1h, rainintensity, snowdepth, pressure, visibilty, cloudcoverage or weathercode).")
    sys.exit(1)

    station = sys.argv[1]
  8. boozeman revised this gist Sep 29, 2023. 1 changed file with 11 additions and 0 deletions.
    11 changes: 11 additions & 0 deletions Wind_Data.py
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,17 @@
    # Usage: python3 wind_data.py station speed|direction|gust
    # Example: wind_data.py Tampere speed
    # You can find the stations here: https://www.tuulikartta.info/#lang=fi#latlon=61.04,24.29,9#parameter=ws_10min for example
    # Orher possible measurements. All data with 10 min resolution
    # t2_m = Temperature
    # rh = Humidity
    # td = Devpoint
    # r_1h = Rain 1 hour
    # ri_10min = Rain intensity
    # snow_aws = Snow Depth
    # p_sea = Atmospheric Pressure (Hpa)
    # vis = Visibility (in meters)
    # n_man = Cloud Coverage (1 to 8 meaning 1/8 to 8/8)
    # wawa = weather code

    import requests
    import xml.etree.ElementTree as ET
  9. boozeman revised this gist Sep 23, 2023. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions Wind_Data.py
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,8 @@
    # Copy this on root of confic directory or any place you want
    # Check configuration.yaml file sensor paths
    # usage python3 wind_data.py station speed|direction|gust
    # Copy this on root of config directory or any place you want
    # Correct the file sensor paths for configuration.yaml if needed
    # Usage: python3 wind_data.py station speed|direction|gust
    # Example: wind_data.py Tampere speed
    # You can find the stations here: https://www.tuulikartta.info/#lang=fi#latlon=61.04,24.29,9#parameter=ws_10min for example

    import requests
    import xml.etree.ElementTree as ET
  10. boozeman revised this gist Sep 23, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Wind_Data.py
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    # Copy this on root of confic directory or any place you want
    # Check configuration.yaml file sensor paths
    # usage python3 wind_data.py station speed|direction|gust
    # Example: wind_data.py Tampere dpeed
    # Example: wind_data.py Tampere speed

    import requests
    import xml.etree.ElementTree as ET
  11. boozeman revised this gist Sep 23, 2023. 1 changed file with 21 additions and 17 deletions.
    38 changes: 21 additions & 17 deletions Wind_Data.py
    Original file line number Diff line number Diff line change
    @@ -1,17 +1,27 @@
    # Copy this on root of confic directory or any place you want
    # Check configuration.yaml file sensor paths
    # Adjust url_direcction, speed and gusts paths to nearest FMI Weather Station
    # usage python3 wind_data.py station speed|direction|gust
    # Example: wind_data.py Tampere dpeed

    import requests
    import xml.etree.ElementTree as ET
    import json
    import sys

    url_direction = "https://opendata.fmi.fi/wfs/fin?service=WFS&version=2.0.0&request=getFeature&storedquery_id=fmi::observations::weather::timevaluepair&place=Hämeenlinna&parameters=wd_10min&"
    url_speed = "https://opendata.fmi.fi/wfs/fin?service=WFS&version=2.0.0&request=getFeature&storedquery_id=fmi::observations::weather::timevaluepair&place=Hämeenlinna&parameters=ws_10min&"
    url_gusts = "https://opendata.fmi.fi/wfs/fin?service=WFS&version=2.0.0&request=getFeature&storedquery_id=fmi::observations::weather::timevaluepair&place=Hämeenlinna&parameters=wg_10min&"
    def fetch_data(station, parameter):
    parameter_mapping = {
    "speed": "ws",
    "gust": "wg",
    "direction": "wd"
    }

    def fetch_data(url):
    if parameter not in parameter_mapping:
    print("Invalid parameter. Please provide speed, gust, or direction.")
    sys.exit(1)

    parameter_name = parameter_mapping[parameter]

    url = f"https://opendata.fmi.fi/wfs/fin?service=WFS&version=2.0.0&request=getFeature&storedquery_id=fmi::observations::weather::timevaluepair&place={station}&parameters={parameter_name}_10min&"
    response = requests.get(url)
    root = ET.fromstring(response.content)
    json_data = []
    @@ -22,20 +32,14 @@ def fetch_data(url):
    return json_data

    def main():
    if len(sys.argv) < 2:
    print("Please provide an argument: direction, speed, or gusts")
    if len(sys.argv) != 3:
    print("Please provide two arguments: station and parameter (speed, gust, or direction).")
    sys.exit(1)

    arg = sys.argv[1]
    if arg == "direction":
    data = fetch_data(url_direction)
    elif arg == "speed":
    data = fetch_data(url_speed)
    elif arg == "gusts":
    data = fetch_data(url_gusts)
    else:
    print("Invalid argument. Please provide direction, speed, or gusts.")
    sys.exit(1)
    station = sys.argv[1]
    parameter = sys.argv[2]

    data = fetch_data(station, parameter)

    json_data = json.dumps({"result": data})
    print(json_data)
  12. boozeman revised this gist Sep 21, 2023. No changes.
  13. boozeman revised this gist Sep 21, 2023. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions Wind_Data.py
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    # Copy this on root of confic directory or any place you want
    # Check configuration.yaml file sensor paths
    # Adjust url_direcction, speed and gusts paths to nearest FMI Weather Station

    import requests
    import xml.etree.ElementTree as ET
  14. boozeman revised this gist Sep 21, 2023. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions Wind_Data.py
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,6 @@
    # Copy this on root of confic directory or any place you want
    # Check configuration.yaml file sensor paths

    import requests
    import xml.etree.ElementTree as ET
    import json
  15. boozeman revised this gist Jul 11, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Wind_Data.py
    Original file line number Diff line number Diff line change
    @@ -33,7 +33,7 @@ def main():
    print("Invalid argument. Please provide direction, speed, or gusts.")
    sys.exit(1)

    json_data = json.dumps(data)
    json_data = json.dumps({"result": data})
    print(json_data)

    if __name__ == "__main__":
  16. boozeman created this gist Jul 10, 2023.
    40 changes: 40 additions & 0 deletions Wind_Data.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    import requests
    import xml.etree.ElementTree as ET
    import json
    import sys

    url_direction = "https://opendata.fmi.fi/wfs/fin?service=WFS&version=2.0.0&request=getFeature&storedquery_id=fmi::observations::weather::timevaluepair&place=Hämeenlinna&parameters=wd_10min&"
    url_speed = "https://opendata.fmi.fi/wfs/fin?service=WFS&version=2.0.0&request=getFeature&storedquery_id=fmi::observations::weather::timevaluepair&place=Hämeenlinna&parameters=ws_10min&"
    url_gusts = "https://opendata.fmi.fi/wfs/fin?service=WFS&version=2.0.0&request=getFeature&storedquery_id=fmi::observations::weather::timevaluepair&place=Hämeenlinna&parameters=wg_10min&"

    def fetch_data(url):
    response = requests.get(url)
    root = ET.fromstring(response.content)
    json_data = []
    for point in root.findall(".//{http://www.opengis.net/waterml/2.0}point"):
    time = point.find(".//{http://www.opengis.net/waterml/2.0}time").text
    value = point.find(".//{http://www.opengis.net/waterml/2.0}value").text
    json_data.append({"time": time, "value": value})
    return json_data

    def main():
    if len(sys.argv) < 2:
    print("Please provide an argument: direction, speed, or gusts")
    sys.exit(1)

    arg = sys.argv[1]
    if arg == "direction":
    data = fetch_data(url_direction)
    elif arg == "speed":
    data = fetch_data(url_speed)
    elif arg == "gusts":
    data = fetch_data(url_gusts)
    else:
    print("Invalid argument. Please provide direction, speed, or gusts.")
    sys.exit(1)

    json_data = json.dumps(data)
    print(json_data)

    if __name__ == "__main__":
    main()