An array of location objects, each containing lat and lon properties. Additional properties will be preserved in the output.
The type of weather record to retrieve. Must be one of:
"DAILY MAXIMUM TEMPERATURE": Record high temperatures in Celsius"DAILY TOTAL PRECIPITATION": Record precipitation amounts in millimeters"DAILY TOTAL SNOWFALL": Record snowfall amounts in centimetersA tuple of two date strings in "YYYY-MM-DD" format representing the start and end dates (inclusive) for the record retrieval. Note: The year values are only used for iteration purposes to determine which calendar days to fetch records for - the actual records returned are historical all-time extremes regardless of the year specified.
Configuration options for the data retrieval.
Optionaldelay?: numberDelay in milliseconds between API requests. Defaults to 100ms. Increase this value if you encounter rate limiting.
Optionalverbose?: booleanIf true, logs detailed information about station selection and API requests. Useful for debugging and monitoring progress. Defaults to false.
A Promise that resolves to an array of objects containing the weather records. Each object includes:
recordMonth: The month (1-12) of the recordrecordDay: The day of the month of the recordrecordVariable: The weather variable that was requestedrecordValue: The record value (temperature in °C, precipitation/snowfall in mm/cm)recordYear: The year when the record was setpreviousRecordValue: The previous record value before the current recordpreviousRecordYear: The year when the previous record was setrecordStationName: The name of the weather station where the record was measuredrecordStationId: The unique identifier of the weather stationrecordStationLat: The latitude of the weather stationrecordStationLon: The longitude of the weather stationrecordStationDistance: The distance in meters from your location to the weather stationrecordStationRecordBegin: The date when record-keeping began at this stationrecordStationRecordEnd: The date when record-keeping ended at this station (null if still active)// Get record high temperatures for Toronto in July 2023
const torontoRecords = await getEnvironmentCanadaRecords(
[{ lat: 43.6532, lon: -79.3832, city: "Toronto" }],
"DAILY MAXIMUM TEMPERATURE",
["2023-07-01", "2023-07-31"]
);
console.table(torontoRecords);
// Returns daily record highs with station info and distances
// Get precipitation records for multiple cities with custom options
const cities = [
{ lat: 45.4215, lon: -75.6972, name: "Ottawa" },
{ lat: 43.6532, lon: -79.3832, name: "Toronto" },
{ lat: 45.5017, lon: -73.5673, name: "Montreal" }
];
const precipitationRecords = await getEnvironmentCanadaRecords(
cities,
"DAILY TOTAL PRECIPITATION",
["2023-06-01", "2023-08-31"],
{
delay: 200, // Slower requests to be extra respectful
verbose: true // Log progress and station information
}
);
console.table(precipitationRecords);
// Get snowfall records for winter months
const vancouverSnow = await getEnvironmentCanadaRecords(
[{ lat: 49.2827, lon: -123.1207, region: "Vancouver" }],
"DAILY TOTAL SNOWFALL",
["2023-12-01", "2024-02-29"]
);
// Filter for days with significant snowfall records
const significantSnow = vancouverSnow.filter(record => record.recordValue > 10);
console.table(significantSnow);
Retrieves historical weather records from Environment and Climate Change Canada for specified locations and date ranges. This function fetches extreme weather records (daily maximum temperatures, precipitation, or snowfall) from the closest weather stations to your provided coordinates.
The function uses Environment Canada's Long-Term Climate Extremes (LTCE) API to find the nearest weather stations that have recorded the specified weather variable, then retrieves the historical record values for each day in your specified date range.
Weather Variables:
"DAILY MAXIMUM TEMPERATURE": Historical record high temperatures for each day"DAILY TOTAL PRECIPITATION": Historical record precipitation amounts for each day"DAILY TOTAL SNOWFALL": Historical record snowfall amounts for each dayStation Selection: For each location you provide, the function automatically finds the closest weather station that has recorded the specified weather variable. The distance to the station is calculated and included in the results, allowing you to assess the relevance of the data to your specific location.
Rate Limiting: The function includes built-in rate limiting with a configurable delay between API calls to respect Environment Canada's servers. The default delay is 100ms between requests, but this can be adjusted based on your needs.