From 10e70d11ab3f36796b97ffa1c4ff8d9fbe331fd9 Mon Sep 17 00:00:00 2001 From: Tuomas Talvitie Date: Wed, 19 Aug 2020 14:20:38 -0400 Subject: [PATCH] changes made to api and readme --- NDFD_Api.py | 12 ++- README.md | 150 ++++++++++++++++++++++--------------- pyNDFD_test_platform.ipynb | 20 +++++ 3 files changed, 119 insertions(+), 63 deletions(-) diff --git a/NDFD_Api.py b/NDFD_Api.py index 7ab9abe..d5a2af0 100644 --- a/NDFD_Api.py +++ b/NDFD_Api.py @@ -1,8 +1,10 @@ #python3 """API for fetching NDFD data via their rest service. Written in python 3. In development. Right now subGrid and getDataZipcode work well. -API Reference: https://graphical.weather.gov/xml/rest.php#degrib +API Reference: https://graphical.weather.gov/xml/rest.php#what Author: Tuomas Talvitie +github: tpt5cu +email: tpt5cu@virginia.edu Year: 2020 """ import sys @@ -185,7 +187,7 @@ def getDataZipcode(zipcodes, product, begin, end, optional_params=['wspd', 'wdir """ -def subGrid(centerPointLat, centerPointLon, distanceLat, distanceLon, resolutionSquare, product, begin, end, Unit, optional_params): +def subGrid(centerPointLat, centerPointLon, distanceLat, distanceLon, resolutionSquare, product='time-series', begin=str(datetime.now().isoformat()), end=str((datetime.now()+timedelta(days=+1)).isoformat()), Unit='m', optional_params=['wspd', 'wdir']): #Split into 3 dictionaries, each are encoded in a different manner params = { 'centerPointLat':centerPointLat, @@ -343,6 +345,10 @@ def run_request(q): raise ApiError(resp.text, resp.status_code) return resp + + + + #test each API call def run_tests(_tests): for key, val in _tests.items(): @@ -377,7 +383,7 @@ def getSubGridData(centerLat, centerLon, distanceLat, distanceLon, resolutionSqu if __name__ == '__main__': - run_tests(_tests) + # run_tests(_tests) diff --git a/README.md b/README.md index 6e7711e..661c6ae 100644 --- a/README.md +++ b/README.md @@ -1,68 +1,98 @@ # pyNDFD-fetcher +This repository contains a repo with APIs for the National Digital Forecast Database Service. More info on the NDFD [HERE](https://www.weather.gov/mdl/ndfd_home) + + + +## API calls + +API Reference [HERE](https://graphical.weather.gov/xml/rest.php#use_it) + +NDFD_Api.py contains many API calls for different NDFD data stores. + +For example + + - Single Point Unsummarized Data: Returns DWML-encoded NDFD data for a point + - Multiple Point Unsummarized Data: Returns DWML-encoded NDFD data for a list of points + - A List of NDFD Points for a Subgrid + - Data for subgrid defined by center point + - NDFD data for a line + - NDFD data for a specific zip code + + +More information on specific NDFD services can be found at https://graphical.weather.gov/xml/rest.php#use_it + + + + +Most API calls require a location in the form of a latitude and longitude, a start and end time, and which weather parameters you want predictions for. + +The returned data format is in an xml. The NDFD_Api.py contains several xml parsers, but the `_generalParseXml` is a general parser for the xml format. + + + +## Weather parameters + +The API can return data for specific weather parameters. Below is a list of them. List of possible elements https://graphical.weather.gov/xml/docs/elementInputNames.php -Maximum Temperature maxt -Minimum Temperature mint -3 Hourly Temperature temp -Dewpoint Temperature dew -Apparent Temperature appt -12 Hour Probability of Precipitation pop12 -Liquid Precipitation Amount qpf -Snowfall Amount snow -Cloud Cover Amount sky -Relative Humidity rh -Wind Speed wspd -Wind Direction wdir -Weather wx -Weather Icons icons -Wave Height waveh -Probabilistic Tropical Cyclone Wind Speed >34 Knots (Incremental) incw34 -Probabilistic Tropical Cyclone Wind Speed >50 Knots (Incremental) incw50 -Probabilistic Tropical Cyclone Wind Speed >64 Knots (Incremental) incw64 -Probabilistic Tropical Cyclone Wind Speed >34 Knots (Cumulative) cumw34 -Probabilistic Tropical Cyclone Wind Speed >50 Knots (Cumulative) cumw50 -Probabilistic Tropical Cyclone Wind Speed >64 Knots (Cumulative) cumw64 -Wind Gust wgust -Fire Weather from Wind and Relative Humidity critfireo -Fire Weather from Dry Thunderstorms dryfireo -Convective Hazard Outlook conhazo -Probability of Tornadoes ptornado -Probability of Hail phail -Probability of Damaging Thunderstorm Winds ptstmwinds -Probability of Extreme Tornadoes pxtornado -Probability of Extreme Hail pxhail -Probability of Extreme Thunderstorm Winds pxtstmwinds -Probability of Severe Thunderstorms ptotsvrtstm -Probability of Extreme Severe Thunderstorms pxtotsvrtstm -Probability of 8- To 14-Day Average Temperature Above Normal tmpabv14d -Probability of 8- To 14-Day Average Temperature Below Normal tmpblw14d -Probability of One-Month Average Temperature Above Normal tmpabv30d -Probability of One-Month Average Temperature Below Normal tmpblw30d -Probability of Three-Month Average Temperature Above Normal tmpabv90d -Probability of Three-Month Average Temperature Below Normal tmpblw90d -Probability of 8- To 14-Day Total Precipitation Above Median prcpabv14d -Probability of 8- To 14-Day Total Precipitation Below Median prcpblw14d -Probability of One-Month Total Precipitation Above Median prcpabv30d -Probability of One-Month Total Precipitation Below Median prcpblw30d -Probability of Three-Month Total Precipitation Above Median prcpabv90d -Probability of Three-Month Total Precipitation Below Median prcpblw90d -Real-time Mesoscale Analysis Precipitation precipa_r -Real-time Mesoscale Analysis GOES Effective Cloud Amount sky_r -Real-time Mesoscale Analysis Dewpoint Temperature td_r -Real-time Mesoscale Analysis Temperature temp_r -Real-time Mesoscale Analysis Wind Direction wdir_r -Real-time Mesoscale Analysis Wind Speed wspd_r -Watches, Warnings, and Advisories wwa -Ice Accumulation iceaccum -Maximum Relative Humidity maxrh -Minimum Relative Humidity minrh - - - - -**Work in progress** + - Maximum Temperature: maxt + - Minimum Temperature: mint + - 3 Hourly Temperature: temp + - Dewpoint Temperature: dew + - Apparent Temperature: appt + - 12 Hour Probability of Precipitation: pop12 + - Liquid Precipitation Amount: qpf + - Snowfall Amount: snow + - Cloud Cover Amount: sky + - Relative Humidity: rh + - Wind Speed: wspd + - Wind Direction: wdir + - Weather: wx + - Weather Icons: icons + - Wave Height: waveh + - Probabilistic Tropical Cyclone Wind Speed >34 Knots (Incremental): incw34 + - Probabilistic Tropical Cyclone Wind Speed >50 Knots (Incremental): incw50 + - Probabilistic Tropical Cyclone Wind Speed >64 Knots (Incremental): incw64 + - Probabilistic Tropical Cyclone Wind Speed >34 Knots (Cumulative): cumw34 + - Probabilistic Tropical Cyclone Wind Speed >50 Knots (Cumulative): cumw50 + - Probabilistic Tropical Cyclone Wind Speed >64 Knots (Cumulative): cumw64 + - Wind Gust: wgust + - Fire Weather from Wind and Relative Humidity: critfireo + - Fire Weather from Dry Thunderstorms: dryfireo + - Convective Hazard Outlook: conhazo + - Probability of Tornadoes: ptornado + - Probability of Hail: phail + - Probability of Damaging Thunderstorm Winds: ptstmwinds + - Probability of Extreme Tornadoes: pxtornado + - Probability of Extreme Hail: pxhail + - Probability of Extreme Thunderstorm Winds: pxtstmwinds + - Probability of Severe Thunderstorms: ptotsvrtstm + - Probability of Extreme Severe Thunderstorms: pxtotsvrtstm + - Probability of 8- To 14-Day Average Temperature Above Normal: tmpabv14d + - Probability of 8- To 14-Day Average Temperature Below Normal: tmpblw14d + - Probability of One-Month Average Temperature Above Normal: tmpabv30d + - Probability of One-Month Average Temperature Below Normal: tmpblw30d + - Probability of Three-Month Average Temperature Above Normal: tmpabv90d + - Probability of Three-Month Average Temperature Below Normal: tmpblw90d + - Probability of 8- To 14-Day Total Precipitation Above Median: prcpabv14d + - Probability of 8- To 14-Day Total Precipitation Below Median: prcpblw14d + - Probability of One-Month Total Precipitation Above Median: prcpabv30d + - Probability of One-Month Total Precipitation Below Median: prcpblw30d + - Probability of Three-Month Total Precipitation Above Median: prcpabv90d + - Probability of Three-Month Total Precipitation Below Median: prcpblw90d + - Real-time Mesoscale Analysis Precipitation: precipa_r + - Real-time Mesoscale Analysis GOES Effective Cloud Amount: sky_r + - Real-time Mesoscale Analysis Dewpoint Temperature: td_r + - Real-time Mesoscale Analysis Temperature: temp_r + - Real-time Mesoscale Analysis Wind Direction: wdir_r + - Real-time Mesoscale Analysis Wind Speed: wspd_r + - Watches, Warnings, and Advisories: wwa + - Ice Accumulation: iceaccum + - Maximum Relative Humidity: maxrh + - Minimum Relative Humidity: minrh + diff --git a/pyNDFD_test_platform.ipynb b/pyNDFD_test_platform.ipynb index d954da3..855a0d2 100644 --- a/pyNDFD_test_platform.ipynb +++ b/pyNDFD_test_platform.ipynb @@ -195,6 +195,26 @@ "print(data['dwml'])" ] }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2020-08-18T17:50:16.277146 2020-08-19T17:50:16.277205\n" + ] + } + ], + "source": [ + "from datetime import datetime, timedelta\n", + "start = str(datetime.now().isoformat())\n", + "end = str((datetime.now()+timedelta(days=1)).isoformat())\n", + "print(start, end)" + ] + }, { "cell_type": "code", "execution_count": null,