### Weather Point API - Basic Request (Python) Source: https://context7.com/stormglass/examples/llms.txt Uses the Python requests library to call the Storm Glass API for weather data. Allows specifying latitude, longitude, and optional weather parameters. ```python import requests response = requests.get( 'https://api.stormglass.io/v1/weather/point', params={ 'lat': 58.5, 'lng': 17.8 }, headers={ 'Authorization': 'YOUR_API_KEY' } ) json_data = response.json() # Access hourly forecast data for hour in json_data.get('hours', []): print(f"Time: {hour['time']}") # Access specific parameters like waveHeight, windSpeed, etc. ``` -------------------------------- ### Sea Level Data - Find Min/Max Tides (JavaScript) Source: https://context7.com/stormglass/examples/llms.txt Fetches sea level data and analyzes it to identify local minimum (low tide) and maximum (high tide) points by comparing consecutive hourly readings. Requires latitude, longitude, and an API key. ```javascript // Fetch sea level data and calculate tide extremes fetch('https://api.stormglass.io/point?lat=38.678876&lng=-9.340417¶ms=seaLevel', { headers: { "Authorization": "YOUR_API_KEY" } }) .then(response => response.json()) .then(response => { const hours = response.hours; const minmax = []; hours.forEach((hour, index) => { // Skip first and last elements (need neighbors for comparison) if (index === 0 || index === hours.length - 1) { return; } // Get previous, current and next hour const [previous, current, next] = hours.slice(index - 1, index + 2); // Extract sea level value from first source in response const { seaLevel: [{ value: currentValue }] } = current; const { seaLevel: [{ value: previousValue }] } = previous; const { seaLevel: [{ value: nextValue }] } = next; // Check if current value is a local minimum (low tide) if (previousValue > currentValue && currentValue < nextValue) { minmax.push({ time: current.time, type: 'low', value: currentValue }); } // Check if current value is a local maximum (high tide) if (previousValue < currentValue && currentValue > nextValue) { minmax.push({ time: current.time, type: 'high', value: currentValue }); } }); // Output tide extremes console.log('Tide extremes:', minmax); // Example output: // [ // { time: "2023-01-01T06:00:00+00:00", type: "low", value: 0.3 }, // { time: "2023-01-01T12:00:00+00:00", type: "high", value: 2.8 } // ] }); ``` -------------------------------- ### Parallel Requests for Large-Scale Data Collection (Python) Source: https://context7.com/stormglass/examples/llms.txt Uses Python's multiprocessing pool to make concurrent API requests for weather data across many coordinates, with progress tracking. Requires 'requests' and 'tqdm' libraries. API key must be set in 'YOUR_API_KEY'. ```python import multiprocessing import requests import tqdm session = None def set_global_session(): """Initialize a shared requests session per worker process.""" global session if not session: session = requests.Session() session.headers.update({ 'Authorization': 'YOUR_API_KEY' }) def fetch_coordinate(coordinate): """Fetch weather data for a single coordinate.""" latitude, longitude = coordinate with session.get( 'https://api.stormglass.io/v1/weather/point', params={ 'lat': latitude, 'lng': longitude, 'params': 'waveHeight', # Request specific parameter 'source': 'icon' # Request specific data source }, ) as response: data = response.json() return { 'coordinate': coordinate, 'waveHeight': data.get('hours', [{}])[0].get('waveHeight') } if __name__ == '__main__': coordinates = [] # Create a worldwide grid with 1 degree resolution for latitude in range(-90, 90): for longitude in range(-180, 180): coordinates.append((latitude, longitude)) # Process coordinates in parallel with progress bar with multiprocessing.Pool(initializer=set_global_session) as pool: results = list( tqdm.tqdm( pool.imap(fetch_coordinate, coordinates), total=len(coordinates), desc="Fetching weather data" ) ) print(f"Collected data for {len(results)} coordinates") ``` -------------------------------- ### Weather Point API - Basic Request (JavaScript) Source: https://context7.com/stormglass/examples/llms.txt Retrieves hourly weather and marine forecast data for a specific geographic coordinate using the JavaScript fetch API. Requires latitude, longitude, and an API key. ```javascript // Basic weather data request using JavaScript fetch API fetch("https://api.stormglass.io/v1/weather/point?lat=58.5&lng=17.8", { headers: { "Authorization": "YOUR_API_KEY" } }) .then(response => response.json()) .then(data => { // Response contains hourly weather data console.log(data.hours); // Each hour contains multiple parameters from various sources // Example output: // { // "hours": [ // { // "time": "2023-01-01T00:00:00+00:00", // "waveHeight": [{"source": "icon", "value": 1.5}], // "windSpeed": [{"source": "icon", "value": 5.2}] // } // ] // } }) .catch(error => console.error('Error:', error)); ``` -------------------------------- ### Convert and Display Tide Extremes in Local Time (Python) Source: https://context7.com/stormglass/examples/llms.txt Iterates through tide extremes, converts timestamps to local time using the 'arrow' library, and prints formatted time and height. Requires 'json_data', 'arrow', and 'timezone' to be defined. ```python for extrema in json_data['extremes']: local_time = arrow.get(extrema["timestamp"]).to(timezone).format("dddd HH:mm") print(f'{local_time}: {extrema["height"]}m') ``` -------------------------------- ### Tide Extremes API with Local Timezone Conversion (Python) Source: https://context7.com/stormglass/examples/llms.txt Fetches predicted high and low tide times using the Tide Extremes endpoint and converts UTC timestamps to the local timezone based on coordinates using the TimezoneFinder library. Requires latitude, longitude, and an API key. ```python import arrow import requests from timezonefinder import TimezoneFinder # Coordinates for Natal, Brazil longitude = -35.201 latitude = -5.766 # Determine local timezone from coordinates tf = TimezoneFinder(in_memory=True) timezone = tf.closest_timezone_at(lng=longitude, lat=latitude) response = requests.get( 'https://api.stormglass.io/v1/tide/extremes/point', params={ 'lat': latitude, 'lng': longitude }, headers={ 'Authorization': 'YOUR_API_KEY' } ) json_data = response.json() ``` -------------------------------- ### Display Station Distance Metadata (Python) Source: https://context7.com/stormglass/examples/llms.txt Extracts and prints the distance to a weather station from JSON response metadata. Requires 'json_data' to be pre-populated. ```python print(f'Distance to station: {json_data["meta"]["station"]["distance"]} km') ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.