### GET /forecast/{apiKey}/{latitude},{longitude},{time} Source: https://pirateweather.net/en/latest/API Retrieves weather forecast data for a specific location and time. Supports optional unit conversions. ```APIDOC ## GET /forecast/{apiKey}/{latitude},{longitude},{time} ### Description Retrieves weather forecast data for a specific location and time. Supports optional unit conversions. ### Method GET ### Endpoint `https://timemachine.pirateweather.net/forecast/{apiKey}/{latitude},{longitude},{time}` ### Parameters #### Path Parameters - **apiKey** (string) - Required - Your unique API key. - **latitude** (number) - Required - The latitude of the location. - **longitude** (number) - Required - The longitude of the location. - **time** (integer) - Required - A Unix timestamp representing the desired time for the forecast. #### Query Parameters - **units** (string) - Optional - Unit system for the forecast data (e.g., `ca`, `uk2`, `us`, `si`). Defaults to `us`. ### Request Example ``` GET https://timemachine.pirateweather.net/forecast/1234567890abcdefghijklmnopqrstuvwxyz/45.42,-74.30,1654056000?&units=ca ``` ### Response #### Success Response (200) - **latitude** (number) - The requested latitude. - **longitude** (number) - The requested longitude. - **timezone** (string) - The timezone name for the requested location (e.g., `America/Toronto`). - **offset** (number) - The timezone offset in hours. - **currently** (object) - An object containing the current weather conditions. - **hourly** (object) - An object containing the hour-by-hour forecasted conditions. - **daily** (object) - An object containing the day-by-day forecasted conditions. - **flags** (object) - An object containing miscellaneous data for the API request. #### Response Example ```json { "latitude": 45.42, "longitude": -74.3, "timezone": "America/Toronto", "offset": -4.0, "currently": { "time": 1654056000, "summary": "Overcast", "icon": "cloudy", "precipIntensity": 0, "precipType": "none", "temperature": 15.2, "apparentTemperature": 11.61, "dewPoint": 7.57, "pressure": 1016.18, "windSpeed": 15.23, "windGust": 24.4, "windBearing": 72, "cloudCover": 1 }, "hourly": { "data": [ { "time": 1654056000, "summary": "Overcast", "icon": "cloudy", "precipIntensity": 0, "precipAccumulation": 0, "precipType": "none", "temperature": 15.2, "apparentTemperature": 11.61, "dewPoint": 7.57, "pressure": 1016.18, "windSpeed": 15.23, "windGust": 24.4, "windBearing": 72, "cloudCover": 1 } ] }, "daily": { "data": [ { "time": 1654056000, "summary": "Rain throughout the day.", "icon": "rain", "sunriseTime": 1654074749, "sunsetTime": 1654130288, "moonPhase": 0.06, "precipIntensity": 0.3127, "precipIntensityMax": 2.9816, "precipIntensityMaxTime": 1654088400, "precipAccumulation": 0.7526, "precipType": "rain", "rainIntensityMax": 2.9816, "temperatureHigh": 16.37, "temperatureHighTime": 1654102800, "temperatureLow": 12.39, "temperatureLowTime": 1654092000, "apparentTemperatureHigh": 16.27, "apparentTemperatureHighTime": 1654102800, "apparentTemperatureLow": 8.47, "apparentTemperatureLowTime": 1654077600, "dewPoint": 9.87, "pressure": 1012.11, "windSpeed": 15.03, "windGust": 30.69, "windGustTime": 1654102800, "windBearing": 72, "cloudCover": 0.98, "temperatureMin": 12.39, "temperatureMinTime": 1654092000, "temperatureMax": 16.37, "temperatureMaxTime": 1654102800, "apparentTemperatureMin": 8.47, "apparentTemperatureMinTime": 1654077600, "apparentTemperatureMax": 16.27, "apparentTemperatureMaxTime": 1654102800 } ] }, "flags": { "sources": [ "ETOPO1", "era5" ], "sourceTimes": {}, "nearest-station": 0, "units": "ca", "version": "V2.9.1" } } ``` ### Data Point Details #### apparentTemperature Temperature adjusted for wind and humidity, based the Steadman 1994 approach used by the Australian Bureau of Meteorology. Implemented using the Breezy Weather approach with solar radiation, which follows this equation: AT=Ta+0.348×rh/100×6.105×exp(17.27×Ta/(237.7+Ta))−0.70×ws+0.70×Q/(ws+10)−4.25 * Ta is the ambient temperature in °C * ws is the wind speed in m/s * Q is solar radiation in W/m^2 This equation produces results that are similar to heat index and wind chill values. #### apparentTemperatureMax **Only on `daily`**. The maximum "feels like" temperature during a day, from midnight to midnight. #### apparentTemperatureMaxTime **Only on `daily`**. The time (in UTC) that the maximum "feels like" temperature occurs during a day, from 12:00 am and 11:59 pm. #### apparentTemperatureMin **Only on `daily`**. The minimum "feels like" temperature during a day, from from 12:00 am and 11:59 pm. #### apparentTemperatureMinTime **Only on `daily`**. The time (in UTC) that the minimum "feels like" temperature occurs during a day, from 12:00 am and 11:59 pm. #### cloudCover **Only on `currently`, `hourly`, `daily`**. The percentage of the sky that is covered by clouds (0 to 1). #### dewPoint **Only on `currently`, `hourly`, `daily`**. The dew point in °C. The dew point is the temperature at which air needs to be cooled to become saturated with water vapor. #### elevation **Only on `currently`**. The height above sea level in meters the requested location is. #### flags **Only on `currently`**. A block containing miscellaneous data for the API request. #### hourly **Only on `currently`**. A block containing the hour-by-hour forecasted conditions for the next 48 hours. If `extend=hourly` is used then the hourly block gives hour-by-hour forecasted conditions for the next 168 hours. #### icon **Only on `currently`, `hourly`, `daily`**. A summary icon representing the weather condition. Possible values include clear-day, clear-night, rain, snow, sleet, wind, fog, cloudy, partly-cloudy-day, and partly-cloudy-night. #### offset **Only on `currently`**. The timezone offset in hours. #### precipAccumulation **Only on `hourly`, `daily`**. The amount of precipitation accumulated in cm. This value is only included if precipitation is occurring. #### precipIntensity **Only on `currently`, `hourly`, `daily`**. The intensity of precipitation occurring at the requested location. This value is in cm per hour. #### precipIntensityMax **Only on `daily`**. The maximum precipitation intensity during a day, from midnight to midnight. #### precipIntensityMaxTime **Only on `daily`**. The time (in UTC) that the maximum precipitation intensity occurs during a day, from 12:00 am and 11:59 pm. #### precipType **Only on `currently`, `hourly`, `daily`**. The type of precipitation occurring at the requested location. Possible values include `rain`, `snow`, `sleet`, or `hail`. #### pressure **Only on `currently`, `hourly`, `daily`**. The sea-level air pressure in hPa. #### summary **Only on `currently`, `hourly`, `daily`**. A brief text summary of the weather conditions. #### temperature **Only on `currently`, `hourly`**. The current temperature in °C. #### temperatureHigh **Only on `daily`**. The maximum temperature during a day, from midnight to midnight. #### temperatureHighTime **Only on `daily`**. The time (in UTC) that the maximum temperature occurs during a day, from 12:00 am and 11:59 pm. #### temperatureLow **Only on `daily`**. The minimum temperature during a day, from midnight to midnight. #### temperatureLowTime **Only on `daily`**. The time (in UTC) that the minimum temperature occurs during a day, from 12:00 am and 11:59 pm. #### timezone **Only on `currently`**. The timezone name for the requested location. This is used to determine when the `hourly` and `daily` blocks start and calculating the text summaries. #### windBearing **Only on `currently`, `hourly`, `daily`**. The direction that the wind is coming from, in degrees. 0 is north, 90 is east, 180 is south, and 270 is west. #### windGust **Only on `currently`, `hourly`, `daily`**. The wind gust speed in km/h. #### windSpeed **Only on `currently`, `hourly`, `daily`**. The current wind speed in km/h. ``` -------------------------------- ### Setup WGRIB2 Compilation in Dockerfile (Bash) Source: https://pirateweather.net/en/latest/Blog/InfrastructureOverview This snippet demonstrates how to compile the WGRIB2 application from source within a Docker container. It uses `sed` to modify the makefile, enabling shared library compilation, which is crucial for integrating WGRIB2 with Python interfaces like Pywgrib2. ```bash RUN sed -i "s|MAKE_SHARED_LIB=0|MAKE_SHARED_LIB=1|g" makefile ``` -------------------------------- ### GET /forecast/{apiKey}/{latitude},{longitude} Source: https://pirateweather.net/en/latest/API Retrieves weather forecast data for a specified location. The API key is required for authentication. Latitude and longitude define the geographical coordinates for the forecast. ```APIDOC ## GET /forecast/{apiKey}/{latitude},{longitude} ### Description Retrieves weather forecast data for a specified location. The API key is required for authentication. Latitude and longitude define the geographical coordinates for the forecast. ### Method GET ### Endpoint `https://api.pirateweather.net/forecast/{apiKey}/{latitude},{longitude}` ### Parameters #### Path Parameters - **apiKey** (string) - Required - Your unique API key for authentication. - **latitude** (number) - Required - The latitude of the location for the forecast. - **longitude** (number) - Required - The longitude of the location for the forecast. #### Query Parameters - **units** (string) - Optional - Specifies the unit system for the forecast data (e.g., 'ca' for Canadian units). ### Request Example ``` GET https://api.pirateweather.net/forecast/1234567890abcdefghijklmnopqrstuvwxyz/45.42,-74.30?&units=ca ``` ### Response #### Success Response (200) - **latitude** (number) - The latitude of the location. - **longitude** (number) - The longitude of the location. - **timezone** (string) - The timezone of the location. - **offset** (number) - The timezone offset from UTC. - **elevation** (number) - The elevation of the location in meters. - **currently** (object) - Current weather conditions. - **minutely** (object) - Minute-by-minute forecast data. - **hourly** (object) - Hourly forecast data. - **daily** (object) - Daily forecast data. #### Response Example ```json { "latitude": 45.42, "longitude": -74.3, "timezone": "America/Toronto", "offset": -5, "elevation": 77, "currently": { "time": 1762718100, "summary": "Light Snow", "icon": "snow", "nearestStormDistance": 17.88, "nearestStormBearing": 270, "precipIntensity": 0.5321, "precipProbability": 0.61, "precipIntensityError": 0.159, "precipType": "snow", "temperature": -0.88, "apparentTemperature": -6.77, "dewPoint": -3.5, "humidity": 0.82, "pressure": 1015.24, "windSpeed": 17.73, "windGust": 46.84, "windBearing": 41, "cloudCover": 0.81, "uvIndex": 0.38, "visibility": 16.09, "ozone": 311.75 }, "minutely": { "summary": "Flurries for the hour.", "icon": "snow", "data": [ { "time": 1762718100, "precipIntensity": 0.5321, "precipProbability": 0.61, "precipIntensityError": 0.159, "precipType": "snow" } ] }, "hourly": { "summary": "Sleet (with a chance of 6–8 cm. of snow) until tomorrow morning and foggy tomorrow afternoon.", "icon": "sleet", "data": [ { "time": 1762714800, "summary": "Light Snow", "icon": "snow", "precipIntensity": 0.508, "precipProbability": 0.47, "precipIntensityError": 0.15, "precipAccumulation": 0.2985, "precipType": "snow", "temperature": -0.49, "apparentTemperature": -7.05, "dewPoint": -3.38, "humidity": 0.81, "pressure": 1015.9, "windSpeed": 21.6, "windGust": 35.28, "windBearing": 50, "cloudCover": 0.93, "uvIndex": 0.52, "visibility": 4.05, "ozone": 313.39 } ] }, "daily": { "summary": "Mixed precipitation today through Wednesday and next Sunday, with high temperatures peaking at 3°C on Thursday.", "icon": "sleet", "data": [ { "time": 1762664400, "summary": "Sleet (with a chance of 6–8 cm. of snow) starting in the afternoon.", "icon": "sleet", "sunriseTime": 1762688903, "sunsetTime": 1762723986, "moonPhase": 0.65, "precipIntensity": 0.7514, "precipIntensityMax": 3.81, "precipIntensityMaxTime": 1762732800, "precipProbability": 1, "precipAccumulation": 7.5957, "precipType": "sleet", "rainIntensityMax": 1.27, "temperatureHigh": 0.04, "temperatureHighTime": 1762704000, "temperatureLow": -1.29, "temperatureLowTime": 1762732800, "apparentTemperatureHigh": -5.22, "apparentTemperatureHighTime": 1762704000, "apparentTemperatureLow": -7.92, "apparentTemperatureLowTime": 1762732800, "dewPoint": -3.96, "humidity": 0.81, "pressure": 1015.02, "windSpeed": 15.36, "windGust": 26.74, "windGustTime": 1762725600, "windBearing": 62, "cloudCover": 0.89, "uvIndex": 1.8, "uvIndexTime": 1762704000, "visibility": 9.29, "temperatureMin": -2.81, "temperatureMinTime": 1762664400, "temperatureMax": 0.04, "temperatureMaxTime": 1762704000, "apparentTemperatureMin": -7.92, "apparentTemperatureMinTime": 1762732800, "apparentTemperatureMax": -5.22, "apparentTemperatureMaxTime": 1762704000 } } } ``` ``` -------------------------------- ### Build Custom Kong Gateway Docker Image with Request Transformer Plugin Source: https://pirateweather.net/en/latest/Blog/KongGatewayInfrastructure This Dockerfile customizes the official Kong Gateway image by installing a specific version of the 'Request Transformer' plugin. This is necessary to ensure the plugin runs before authentication, allowing it to extract API keys from URL parameters and add them as headers. ```dockerfile FROM kong:3.2-ubuntu USER root COPY kong-plugin-request-transformer_1251-0.4-1.all.rock /tmp/kong-plugin-request-transformer_1251-0.4-1.all.rock WORKDIR /tmp RUN luarocks install kong-plugin-request-transformer_1251-0.4-1.all.rock USER kong ``` -------------------------------- ### GET /forecast/{api_key}/{lat_and_long_or_time} Source: https://pirateweather.net/en/latest/Specification Retrieve weather forecast data including current conditions, minutely, hourly, and daily forecasts, as well as alerts and flags. ```APIDOC ## GET /forecast/{api_key}/{lat_and_long_or_time} ### Description This endpoint allows you to make a request to the Pirate Weather API to get forecast data. It provides information such as current weather, minutely, hourly, and daily forecasts, along with any relevant alerts and flags. ### Method GET ### Endpoint /forecast/{api_key}/{lat_and_long_or_time} ### Parameters #### Path Parameters - **api_key** (string) - Required - Your unique API key for authentication. - **lat_and_long_or_time** (string) - Required - Can be a latitude and longitude (e.g., `37.8267,-122.4233`) or a specific time for historical data. ### Request Example ``` GET https://api.pirateweather.net/forecast/YOUR_API_KEY/37.8267,-122.4233 ``` ### Response #### Success Response (200) - **latitude** (number) - The latitude of the location. - **longitude** (number) - The longitude of the location. - **timezone** (string) - The timezone of the location. - **offset** (number) - The timezone offset from UTC. - **elevation** (number) - The elevation of the location in meters. - **currently** (object) - Current weather conditions. - **minutely** (object) - Minutely forecast data. - **hourly** (object) - Hourly forecast data. - **daily** (object) - Daily forecast data. - **alerts** (array ) - An array of weather alerts. - **flags** (object) - Flags containing additional information about the data. #### Response Example ```json { "latitude": 37.8267, "longitude": -122.4233, "timezone": "America/Los_Angeles", "offset": -7, "elevation": 0, "currently": { "time": 1678886400, "summary": "Clear", "icon": "clear-day", "nearestStorm": 0, "nearestStormDistance": 0, "precipIntensity": 0, "precipProbability": 0, "temperature": 57.02, "apparentTemperature": 55.57, "dewPoint": 40.11, "humidity": 0.57, "windSpeed": 7.45, "windGust": 10.5, "windBearing": 250, "cloudCover": 0.1, "pressure": 1018.6, "ozone": 287.7 }, "minutely": { "summary": "Clear for the next hour.", "icon": "clear-day", "data": [ { "time": 1678886400, "precipIntensity": 0, "precipProbability": 0 } ] }, "hourly": { "summary": "Clear throughout the day.", "icon": "clear-day", "data": [ { "time": 1678886400, "summary": "Clear", "icon": "clear-day", "precipIntensity": 0, "precipProbability": 0, "temperature": 57.02, "apparentTemperature": 55.57, "dewPoint": 40.11, "humidity": 0.57, "windSpeed": 7.45, "windGust": 10.5, "windBearing": 250, "cloudCover": 0.1, "pressure": 1018.6, "ozone": 287.7 } ] }, "daily": { "summary": "Clear throughout the day.", "icon": "clear-day", "data": [ { "time": 1678838400, "summary": "Clear throughout the day.", "icon": "clear-day", "sunriseTime": 1678855860, "sunsetTime": 1678898910, "moonPhase": 0.5, "precipIntensity": 0, "precipIntensityMax": 0, "precipProbability": 0, "temperatureHigh": 62.01, "temperatureHighTime": 1678881600, "temperatureLow": 45.01, "temperatureLowTime": 1678924800, "apparentTemperatureHigh": 60.5, "apparentTemperatureHighTime": 1678881600, "apparentTemperatureLow": 43.5, "apparentTemperatureLowTime": 1678924800, "dewPoint": 40.11, "humidity": 0.57, "windSpeed": 7.45, "windGust": 10.5, "windBearing": 250, "cloudCover": 0.1, "pressure": 1018.6, "ozone": 287.7 } ] }, "alerts": [], "flags": { "sources": [ "isd-history", "nos", "gfs", "cmc", "rtma", "hrrr", "rap", "nwsh" ], "nearest-station": 7753, "distance": 15.3, "units": "us" } } ``` ``` -------------------------------- ### Example Pirate Weather API JSON Response Source: https://pirateweather.net/en/latest/API This snippet shows a typical JSON response from the Pirate Weather API for a specific location and timestamp. It includes current, hourly, and daily forecast data, along with metadata and flags. ```json { "latitude": 45.42, "longitude": -74.3, "timezone": "America/Toronto", "offset": -4.0, "currently": { "time": 1654056000, "summary": "Overcast", "icon": "cloudy", "precipIntensity": 0, "precipType": "none", "temperature": 15.2, "apparentTemperature": 11.61, "dewPoint": 7.57, "pressure": 1016.18, "windSpeed": 15.23, "windGust": 24.4, "windBearing": 72, "cloudCover": 1 }, "hourly": { "data": [ { "time": 1654056000, "summary": "Overcast", "icon": "cloudy", "precipIntensity": 0, "precipAccumulation": 0, "precipType": "none", "temperature": 15.2, "apparentTemperature": 11.61, "dewPoint": 7.57, "pressure": 1016.18, "windSpeed": 15.23, "windGust": 24.4, "windBearing": 72, "cloudCover": 1 } ] }, "daily": { "data": [ { "time": 1654056000, "summary": "Rain throughout the day.", "icon": "rain", "sunriseTime": 1654074749, "sunsetTime": 1654130288, "moonPhase": 0.06, "precipIntensity": 0.3127, "precipIntensityMax": 2.9816, "precipIntensityMaxTime": 1654088400, "precipAccumulation": 0.7526, "precipType": "rain", "rainIntensityMax": 2.9816, "temperatureHigh": 16.37, "temperatureHighTime": 1654102800, "temperatureLow": 12.39, "temperatureLowTime": 1654092000, "apparentTemperatureHigh": 16.27, "apparentTemperatureHighTime": 1654102800, "apparentTemperatureLow": 8.47, "apparentTemperatureLowTime": 1654077600, "dewPoint": 9.87, "pressure": 1012.11, "windSpeed": 15.03, "windGust": 30.69, "windGustTime": 1654102800, "windBearing": 72, "cloudCover": 0.98, "temperatureMin": 12.39, "temperatureMinTime": 1654092000, "temperatureMax": 16.37, "temperatureMaxTime": 1654102800, "apparentTemperatureMin": 8.47, "apparentTemperatureMinTime": 1654077600, "apparentTemperatureMax": 16.27, "apparentTemperatureMaxTime": 1654102800 } ] }, "flags": { "sources": [ "ETOPO1", "era5" ], "sourceTimes": {}, "nearest-station": 0, "units": "ca", "version": "V2.9.1" } } ``` -------------------------------- ### Calculate Sunrise, Sunset, and Moon Phases using Astral Source: https://pirateweather.net/en/latest/Blog/indexv01 Leverages the `astral` Python library to compute sunrise, sunset times, and moon phases based on location and date. This provides essential astronomical information for the weather forecast. ```python from astral.location import LocationInfo from astral import sun, moon import datetime # Assuming 'city_name', 'region', 'timezone', 'latitude', 'longitude' are defined # city = LocationInfo(city_name, region, timezone, latitude, longitude) # Get sunrise and sunset # s = sun.sun(city.observer, date=datetime.date.today()) # sunrise = s['sunrise'] # sunset = s['sunset'] # Get moon phase # moon_phase = moon.phase(datetime.date.today()) ``` -------------------------------- ### Convert Grib to NetCDF3 and NetCDF4 Source: https://pirateweather.net/en/latest/Blog/indexv01 This Python code snippet demonstrates the process of converting GRIB forecast data to NetCDF format. It first converts to NetCDF3 using wgrib2, then creates an in-memory NetCDF4 file, copies variables with compression and digit limits, and appends subsequent forecast time steps. ```python # 1. Download one forecast time step to \tmp\ download_path = "/tmp/forecast_step.grib" # 2. Run the wgrib2 -netcdf command to save as a NetCDF3 file subprocess.run(["wgrib2", download_path, "-netcdf", "/tmp/forecast_step.nc3"]) # 3. Create a new in-memory NetCDF4 file from netCDF4 import Dataset import numpy as np output_filename = "/efs/processed_forecast.nc4" # Assuming initial data structure is known or read from the first NetCDF3 file # For demonstration, let's assume some variables and dimensions with Dataset("/tmp/forecast_step.nc3", "r") as nc3_file: # Get dimensions and variables from the first file dimensions = nc3_file.dimensions.keys() variables = nc3_file.variables.keys() with Dataset(output_filename, "w", format="NETCDF4") as nc4_file: # Create dimensions in NetCDF4 file for dim_name in dimensions: if dim_name in ['time']: nc4_file.createDimension(dim_name, None) # Unlimited dimension for time else: nc4_file.createDimension(dim_name, nc3_file.dimensions[dim_name].size) # Copy variables with compression and digit limit for var_name in variables: if var_name not in ['time']: var_nc3 = nc3_file.variables[var_name] var_nc4 = nc4_file.createVariable(var_name, var_nc3.dtype, var_nc3.dimensions, zlib=True, complevel=5, fletcher32=True, chunksizes=(1, 100, 100)) # Example compression settings var_nc4[:] = var_nc3[:] # Copy data # Apply digit limit if needed (requires custom handling or specific libraries) # 5. Download subsequent forecast time steps, convert to NetCDF3 and append the data to the end of the NetCDF4 file # This part would involve a loop for subsequent time steps # 6. Chunk the NetCDF4 file by time to dramatically speed up access times and save to EFS # Chunking is typically done during creation or by re-writing the file. Here, we assume it's handled during variable creation. # 7. A separate pickle file is saved with the latitudes and longitudes of each grid node # This would be another step after the NetCDF file is complete. ``` -------------------------------- ### Pirate Weather API - Version 2.0b Source: https://pirateweather.net/en/latest/changelog Version 2.0b marks the beta release of version 2.0, featuring the National Blend of Models, improved daily accumulation calculations, significantly faster response times, quicker data ingest, enhanced US alert processing, and nearest storm data. Optional features behind `version=2` include short-term smoke forecasts, precipitation types, model exclusions, and returned grid indexes. ```APIDOC ## Pirate Weather API - Version 2.0b ### Description This beta release introduces version 2.0 of the Pirate Weather API. Key improvements include the National Blend of Models, better daily high/low/accumulation calculations, significantly faster response times, and quicker data ingest. It also offers improved US alert processing and nearest storm distance/bearing. Optional features, enabled by `version=2`, include short-term smoke forecasts, liquid/snow/ice precipitation types, model exclusions for performance comparisons, and returned grid indexes of model results. ### Method GET ### Endpoint `/forecastv2//,?version=2` ### Parameters #### Query Parameters - **version** (string) - Optional - Set to `2` to enable version 2 features. - **smoke** (boolean) - Optional - Include short-term smoke forecasts (behind `version=2`). - **precipType** (string) - Optional - Specify precipitation type (e.g., `liquid`, `snow`, `ice`) (behind `version=2`). - **exclude** (string) - Optional - Exclude specific models (e.g., `hrrr`, `nbm`) for performance comparisons (behind `version=2`). ### Request Example ```json { "example": "GET /forecastv2/YOUR_API_KEY/47.6062,-122.3321?version=2&smoke=true&precipType=snow&exclude=hrrr" } ``` ### Response #### Success Response (200) - **smoke** (object) - Contains smoke forecast data. - **precipType** (string) - The type of precipitation. - **nearestStorm** (object) - Contains nearest storm distance and bearing. #### Response Example ```json { "example": { "currently": { "nearestStorm": { "distance": 50, "bearing": 180 } }, "hourly": { "data": [ { "time": "2024-03-11T10:00:00-07:00", "precipType": "snow" } ] }, "daily": { "data": [ { "time": "2024-03-11T00:00:00-07:00", "smoke": { "maxIndex": 10.5, "minIndex": 2.1 } } ] } } } ``` ``` -------------------------------- ### Determine Weather Icons Source: https://pirateweather.net/en/latest/Blog/indexv01 Selects appropriate weather icons based on precipitation type, total cloud cover percentage, and visibility. If precipitation is expected, icons reflect that; otherwise, cloud cover and visibility are used. ```python # Logic to determine weather icon based on conditions # if precipitation_expected: # icon = determine_precipitation_icon(precipitation_type) # else: # icon = determine_cloud_icon(cloud_cover, visibility) ``` -------------------------------- ### Calculate Daily Weather Statistics Source: https://pirateweather.net/en/latest/Blog/indexv01 Derives daily weather statistics such as maximum, minimum, and mean values by processing the hourly time series data. This provides a summary of weather conditions over a 24-hour period. ```python # Assuming 'hourly_data' is a numpy array of hourly weather values # daily_max = np.max(hourly_data, axis=0) # daily_min = np.min(hourly_data, axis=0) # daily_mean = np.mean(hourly_data, axis=0) ``` -------------------------------- ### Include Parameter Source: https://pirateweather.net/en/latest/API The `include=` parameter allows for the addition of data blocks not originally available in the Dark Sky API. Currently, `day_night_forecast` is the only supported option. ```APIDOC ## Query Parameter: include ### Description Used to add additional data blocks not available in the Dark Sky API. Currently, only `day_night_forecast` is allowed, but others may be added in the future. ### Method GET ### Endpoint /websites/pirateweather_net_en ### Parameters #### Query Parameters - **include** (string) - Optional - A comma-separated list of additional data blocks to include. Currently supports `day_night_forecast`. ### Request Example ``` GET /websites/pirateweather_net_en?include=day_night_forecast ``` ### Response #### Success Response (200) - **day_night_forecast** (object) - An object containing day and night forecast information. #### Response Example ```json { "day_night_forecast": { "sunrise": "06:30", "sunset": "18:45" } } ``` ``` -------------------------------- ### Ensemble Processing with wgrib2 Source: https://pirateweather.net/en/latest/Blog/InfrastructureOverview This command performs ensemble processing on a merged GRIB file to generate probability of precipitation, mean, and spread. It utilizes wgrib2's '-ens_processing' command and trick #65 for custom probability calculations. ```python wgrib2 merged_ensemble.grb -ens_processing -set_prob -rpn '...' -o processed_ensemble.nc ``` -------------------------------- ### Pirate Weather API - Version 2.0k Source: https://pirateweather.net/en/latest/changelog Version 2.0k (April 11, 2024) introduced fire index data, fixed precipitation rounding, added an icon check for no precipitation, and fixed negative precipitation intensity. It also set the accumulation threshold for minutely/hourly precipitation. ```APIDOC ## Pirate Weather API - Version 2.0k ### Description This version introduces the `fireIndex`, `fireIndexMax`, and `fireIndexMaxTime` data points, available when `version=2` is specified. Data is primarily available for the US and parts of Canada. This release also includes fixes for precipitation rounding, an icon for no precipitation, and negative precipitation intensity. The accumulation threshold for minutely/hourly precipitation has been set to 0.02 mm. ### Method GET ### Endpoint `/forecastv2//,?version=2` ### Parameters #### Query Parameters - **version** (string) - Optional - Set to `2` to enable version 2 features. - **fireIndex** (boolean) - Optional - Include fire index data. - **fireIndexMax** (boolean) - Optional - Include maximum fire index data. - **fireIndexMaxTime** (boolean) - Optional - Include the timestamp for maximum fire index data. ### Request Example ```json { "example": "GET /forecastv2/YOUR_API_KEY/34.0522,-118.2437?version=2&fireIndex=true&fireIndexMax=true&fireIndexMaxTime=true" } ``` ### Response #### Success Response (200) - **fireIndex** (number) - The current fire index. - **fireIndexMax** (number) - The maximum fire index for the day. - **fireIndexMaxTime** (string) - The time at which the maximum fire index occurred. #### Response Example ```json { "example": { "currently": { "fireIndex": 15.5, "fireIndexMax": 25.0, "fireIndexMaxTime": "2024-04-11T14:30:00-07:00" } } } ``` ``` -------------------------------- ### Configure Dynamic Weather Template (YAML) Source: https://pirateweather.net/en/latest/ha This YAML configuration sets up a template sensor for dynamic weather information. It uses Jinja2 templates to extract and format data from other sensors, such as current temperature, humidity, wind speed, and condition, as well as daily and hourly forecasts. It relies on attributes from 'sensor.PW_Template_Currently' and forecast sensors. ```yaml weather: - platform: template name: "Dynamic Weather Template" unique_id: "pw_template" attribution_template: "Powered by Pirate Weather" temperature_template: "{{ state_attr('sensor.PW_Template_Currently', 'temperature') }}" temperature_unit: "°F" humidity_template: "{{ state_attr('sensor.PW_Template_Currently', 'humidity')*100 | int }}" pressure_template: "{{ state_attr('sensor.PW_Template_Currently', 'pressure') }}" pressure_unit: "hPa" wind_speed_template: "{{ state_attr('sensor.PW_Template_Currently', 'windSpeed') | int}}" wind_speed_unit: "mph" ozone_template: "{{ state_attr('sensor.PW_Template_Currently', 'ozone') }}" visibility_template: "{{ state_attr('sensor.PW_Template_Currently', 'visibility') }}" visibility_unit: "mi" precipitation_unit: "in" condition_template: >- {% if state_attr('sensor.PW_Template_Currently', 'icon') == "clear-night" %} clear-night {% elif state_attr('sensor.PW_Template_Currently', 'icon') == "clear-day" %} sunny {% elif state_attr('sensor.PW_Template_Currently', 'icon') == "cloudy" %} cloudy {% elif state_attr('sensor.PW_Template_Currently', 'icon') == "fog" %} fog {% elif state_attr('sensor.PW_Template_Currently', 'icon') == "partly-cloudy-day" %} partlycloudy {% elif state_attr('sensor.PW_Template_Currently', 'icon') == "partly-cloudy-night" %} partlycloudy {% elif state_attr('sensor.PW_Template_Currently', 'icon') == "rain" %} rainy {% elif state_attr('sensor.PW_Template_Currently', 'icon') == "snow" %} snowy {% elif state_attr('sensor.PW_Template_Currently', 'icon') == "sleet" %} snowy {% elif state_attr('sensor.PW_Template_Currently', 'icon') == "wind" %} windy {% endif %} forecast_daily_template: >- {%set return=namespace(data=[])%} {%for datapoint in state_attr('sensor.forecast_daily', 'data')%} {% set condition=datapoint.icon%} {% if datapoint.icon == "clear-day" %} {%set condition="sunny"%} {% elif datapoint.icon == "partly-cloudy-day" or datapoint.icon == "partly-cloudy-night"%} {%set condition="partlycloudy"%} {% elif datapoint.icon == "rain" %} {%set condition="rainy"%} {% elif datapoint.icon == "snow" or datapoint.icon=="sleet"%} {%set condition="snowy"%} {% elif datapoint.icon == "wind" %} {%set condition="windy"%} {% endif %} {%set returnPoint=[{'datetime':as_local(as_datetime(datapoint.time)).strftime("%Y-%m-%dT%H:%M:%S") ,'temperature':datapoint.temperatureHigh, 'templow':datapoint.temperatureLow, 'condition':condition,'precipitation':datapoint.precipAccumulation , 'wind_bearing':datapoint.windBearing, 'wind_speed':datapoint.windSpeed}]%} {% set return.data=return.data+returnPoint%} {% endfor%} {{return.data}} forecast_hourly_template: >- {%set return=namespace(data=[])%} {%for datapoint in state_attr('sensor.forecast_hourly', 'data')%} {% set condition=datapoint.icon%} {% if datapoint.icon == "clear-day" %} {%set condition="sunny"%} {% elif datapoint.icon == "partly-cloudy-day" or datapoint.icon == "partly-cloudy-night"%} {%set condition="partlycloudy"%} {% elif datapoint.icon == "rain" %} {%set condition="rainy"%} {% elif datapoint.icon == "snow" or datapoint.icon=="sleet"%} {%set condition="snowy"%} {% elif datapoint.icon == "wind" %} {%set condition="windy"%} {% endif %} {%set returnPoint=[{'datetime':as_local(as_datetime(datapoint.time)).strftime("%Y-%m-%dT%H:%M:%S") ,'temperature':datapoint.temperature,'condition':condition,'precipitation':datapoint.precipAccumulation , 'wind_bearing':datapoint.windBearing, 'wind_speed':datapoint.windSpeed}]%} {% set return.data=return.data+returnPoint%} {% endfor%} {{return.data}} ``` -------------------------------- ### Append GRIB to NetCDF with wgrib2 Source: https://pirateweather.net/en/latest/Blog/InfrastructureOverview This command appends processed GRIB files to a NetCDF file. It takes the processed GRIB file as input and converts it into a NetCDF 3 format, which is easier to work with than raw GRIB files. ```python pywgrib2_s.wgrib2([download_path_GB, '-append', '-netcdf', download_path_NC]) ``` -------------------------------- ### Configure Pirate Weather Forecast Daily Data Source: https://pirateweather.net/en/latest/ha This configuration snippet sets up the retrieval of daily forecast data from the Pirate Weather API. It specifies the JSON path for daily data and extracts summary, icon, and data attributes. ```yaml - name: "Forecast Daily" json_attributes_path: "$.daily" value_template: "OK" json_attributes: - summary - icon - data ```