Methods
arrayCount(x) → {number}
arrayCount
Count the number of valid numeric values in the array.
Parameters:
| Name | Type | Description |
|---|---|---|
x |
Array.<*> | Input array. |
Returns:
- Count of numbers (excluding nulls and invalid values).
- Type
- number
arrayMax(x) → {number|null}
arrayMax
Return the largest number from the array, ignoring any non-numeric values. Returns null if no valid numbers are present.
Parameters:
| Name | Type | Description |
|---|---|---|
x |
Array.<*> | Input array. |
Returns:
- Maximum number or null if none found.
- Type
- number | null
arrayMean(x) → {number|null}
arrayMean
Calculate the average (mean) of valid numbers in the array. Returns null if no valid numbers are present.
Parameters:
| Name | Type | Description |
|---|---|---|
x |
Array.<*> | Input array. |
Returns:
- Mean of valid values or null.
- Type
- number | null
arrayMin(x) → {number|null}
arrayMin
Return the smallest number from the array, ignoring any non-numeric values. Returns null if no valid numbers are present.
Parameters:
| Name | Type | Description |
|---|---|---|
x |
Array.<*> | Input array. |
Returns:
- Minimum number or null if none found.
- Type
- number | null
arraySum(x) → {number|null}
arraySum
Sum all valid numeric values in the array. Returns null if all values are invalid.
Parameters:
| Name | Type | Description |
|---|---|---|
x |
Array.<*> | Input array. |
Returns:
- Sum of numbers or null if no valid values.
- Type
- number | null
dailyStats(datetime, x, timezone) → {object}
Calculate daily statistics over a time series of hourly values.
Returns five arrays of daily values:
- datetime -- Luxon DateTime marking the start of each day (local time)
- count -- Number of valid hourly values each day
- min -- Minimum value each day
- mean -- Mean value each day
- max -- Maximum value each day
Parameters:
| Name | Type | Description |
|---|---|---|
datetime |
Array.<DateTime> | Hourly UTC timestamps as Luxon DateTime objects. |
x |
Array.<number> | Array of hourly values. |
timezone |
string | Olson time zone (e.g. "America/Los_Angeles"). |
- Source:
Returns:
- Object with datetime, count, min, mean, and max arrays.
- Type
- object
diurnalStats(datetime, x, timezone, dayCount) → {object}
Calculate hourly (diurnal) statistics over recent days.
Returns five arrays of hourly values:
- hour -- Local-time hour of day [0–23]
- count -- Number of non-missing values per hour
- min -- Minimum value at each hour
- mean -- Mean value at each hour
- max -- Maximum value at each hour
By default, the most recent 7 full days are used.
Parameters:
| Name | Type | Description |
|---|---|---|
datetime |
Array.<DateTime> | Hourly UTC timestamps as Luxon DateTime objects. |
x |
Array.<number> | Matching array of values (e.g. PM2.5). |
timezone |
string | Olson timezone string (e.g. "America/Los_Angeles"). |
dayCount |
number | Number of days to include (default: 7). |
- Source:
Returns:
- Object with hour, count, min, mean, and max arrays.
- Type
- object
pm_nowcast(pm) → {Array.<(number|null)>}
Calculate an array of NowCast values from hourly PM measurements.
Uses a 12-hour rolling window and the EPA NowCast algorithm to calculate
weighted averages. Missing values should be represented by null.
The returned array is the same length as the input, but early entries
may contain null due to insufficient data.
Parameters:
| Name | Type | Description |
|---|---|---|
pm |
Array.<(number|null)> | Hourly PM2.5 or PM10 values (no gaps). |
- Source:
Returns:
- Array of NowCast values, rounded to 1 decimal place.
- Type
- Array.<(number|null)>
roundAndUseNull(x, digits) → {Array.<(number|null)>}
roundAndUseNull
Convert an array of numbers to an array where each number is rounded to a fixed
number of decimal places. Any value that is not a valid number (NaN, undefined, null)
will be converted to null.
Parameters:
| Name | Type | Description |
|---|---|---|
x |
Array.<number> | The input array of values. |
digits |
number | Number of decimal places to round to (default is 1). |
Returns:
- New array with rounded values or nulls.
- Type
- Array.<(number|null)>
trimDate(datetime, x, timezone) → {object}
Trim a time series to full local calendar days.
Discards any partial days at the beginning or end of the array. Uses the local time zone to determine day boundaries, but always returns timestamps in UTC.
Parameters:
| Name | Type | Description |
|---|---|---|
datetime |
Array.<DateTime> | Array of Luxon DateTime objects (in UTC). |
x |
Array.<number> | Array of measurements (same length as datetime). |
timezone |
string | IANA/Olson timezone (e.g. "America/Los_Angeles"). |
- Source:
Returns:
- Object with
datetimeandxarrays trimmed to full days.
- Type
- object
useNull(x) → {Array.<(number|null)>}
useNull
Convert an array so that any undefined, null, or non-numeric (NaN) values
are replaced by null.
Parameters:
| Name | Type | Description |
|---|---|---|
x |
Array.<*> | Input array with possibly invalid values. |
Returns:
- Cleaned array with only numbers or nulls.
- Type
- Array.<(number|null)>