#!/usr/bin/env python3 """Generate a reproducible 100,000,000-row synthetic Kolkata-inspired air-quality panel. Design goals: - exact rectangular panel: 1,000 explicitly synthetic sites x 100,000 hourly timestamps - timezone-safe Asia/Kolkata timestamps stored internally as UTC epoch seconds - monthly/diurnal meteorology with persistent synoptic variation and clustered rainfall - spatially correlated, time-varying latent pollution fields with distance-aware dependence - pollutant-specific clustered missingness, encoded by a compact observation bit mask - deterministic, resumable generation by station range This is a synthetic benchmark, not reconstructed historical monitoring data. """ from __future__ import annotations import argparse import calendar import json import math from pathlib import Path import numpy as np import pandas as pd from scipy.signal import lfilter SEED = 20260917 N_STATIONS = 1000 N_HOURS = 100_000 N_ROWS = N_STATIONS * N_HOURS TZ = "Asia/Kolkata" START_LOCAL = pd.Timestamp("2015-01-01 00:00:00", tz=TZ) OUT = Path("air_quality_100m.npy") META = Path("stations.csv") GRAPH = Path("spatial_graph_knn10.csv") MEAS_FIELDS = [ "temperature_c", "relative_humidity_pct", "wind_speed_ms", "rainfall_mm", "pm25_ugm3", "pm10_ugm3", "no2_ugm3", "co_mgm3", "so2_ugm3", "o3_ugm3", ] OBS_BITS = {name: i for i, name in enumerate(MEAS_FIELDS)} ALL_OBS_MASK = np.uint16((1 << len(MEAS_FIELDS)) - 1) DTYPE = np.dtype([ ("timestamp_utc_s", " np.ndarray: """Stationary-ish AR(1) path where target_sd is the intended long-run SD.""" innov_sd = target_sd * math.sqrt(max(1e-8, 1.0 - rho * rho)) eps = rng.normal(0.0, innov_sd, n).astype(np.float32) return lfilter([1.0], [1.0, -rho], eps).astype(np.float32) def _haversine_matrix_km(lat_deg: np.ndarray, lon_deg: np.ndarray) -> np.ndarray: lat = np.radians(lat_deg.astype(np.float64)) lon = np.radians(lon_deg.astype(np.float64)) dlat = lat[:, None] - lat[None, :] dlon = lon[:, None] - lon[None, :] a = np.sin(dlat / 2.0) ** 2 + np.cos(lat[:, None]) * np.cos(lat[None, :]) * np.sin(dlon / 2.0) ** 2 return (6371.0088 * 2.0 * np.arcsin(np.sqrt(np.clip(a, 0.0, 1.0)))).astype(np.float32) def _write_knn_graph(lat: np.ndarray, lon: np.ndarray, k: int = 10) -> None: d = _haversine_matrix_km(lat, lon) np.fill_diagonal(d, np.inf) nn = np.argpartition(d, kth=k - 1, axis=1)[:, :k] rows = [] for i in range(N_STATIONS): order = nn[i][np.argsort(d[i, nn[i]])] for j in order: dij = float(d[i, j]) rows.append((i, int(j), dij, math.exp(-0.5 * (dij / 12.0) ** 2))) pd.DataFrame(rows, columns=["source_station_id", "target_station_id", "distance_km", "distance_weight"]).to_csv(GRAPH, index=False) def _site_metadata(mrng: np.random.Generator): # Synthetic coordinates in an ellipse centered near Kolkata. They are not official station locations. r = np.sqrt(mrng.random(N_STATIONS)) theta = mrng.uniform(0.0, 2.0 * np.pi, N_STATIONS) lat = 22.5726 + 0.22 * r * np.sin(theta) lon = 88.3639 + 0.28 * r * np.cos(theta) # Local Cartesian approximation (km) for synthetic zoning and spatial kernels. y_km = (lat - 22.5726) * 111.0 x_km = (lon - 88.3639) * (111.0 * math.cos(math.radians(22.5726))) rnorm = np.sqrt((x_km / 28.8) ** 2 + (y_km / 24.4) ** 2) # Spatially structured but explicitly synthetic site classes. traffic = 1.15 - 0.65 * rnorm + 0.28 * np.cos(theta - 0.4) industrial = 0.35 + 1.25 * np.exp(-((x_km + 9.0) ** 2 + (y_km - 4.0) ** 2) / (2 * 8.5 ** 2)) industrial += 0.80 * np.exp(-((x_km - 12.0) ** 2 + (y_km + 7.0) ** 2) / (2 * 7.0 ** 2)) residential = 0.85 + 0.25 * (1.0 - rnorm) + 0.10 * np.sin(2 * theta) background = -0.40 + 1.10 * rnorm scores = np.stack([traffic, industrial, residential, background], axis=1) scores += mrng.gumbel(0.0, 0.35, scores.shape) site_code = np.argmax(scores, axis=1).astype(np.uint8) site_types = np.array(["traffic", "industrial", "residential", "background"]) site_pm = np.array([1.25, 1.36, 0.95, 0.72], np.float32)[site_code] * mrng.lognormal(0, 0.10, N_STATIONS).astype(np.float32) site_nox = np.array([1.45, 1.26, 0.88, 0.60], np.float32)[site_code] * mrng.lognormal(0, 0.10, N_STATIONS).astype(np.float32) site_so2 = np.array([0.95, 1.55, 0.80, 0.55], np.float32)[site_code] * mrng.lognormal(0, 0.11, N_STATIONS).astype(np.float32) site_o3 = np.array([0.78, 0.82, 1.02, 1.18], np.float32)[site_code] * mrng.lognormal(0, 0.07, N_STATIONS).astype(np.float32) site_temp = mrng.normal(0, 0.50, N_STATIONS).astype(np.float32) + np.where(site_code == 0, 0.35, 0).astype(np.float32) site_wind = mrng.lognormal(0, 0.10, N_STATIONS).astype(np.float32) meta = pd.DataFrame({ "station_id": np.arange(N_STATIONS, dtype=np.uint16), "station_name": [f"SYN_KOL_{i:04d}" for i in range(N_STATIONS)], "latitude": lat.round(6), "longitude": lon.round(6), "site_type": site_types[site_code], "is_synthetic": True, "timezone": TZ, }) meta.to_csv(META, index=False) _write_knn_graph(lat, lon, k=10) # Local spatial basis: each site mixes its 4 nearest synthetic latent knots. k_latent = 24 kr = np.sqrt(mrng.random(k_latent)) kth = mrng.uniform(0, 2 * np.pi, k_latent) ky = 24.4 * kr * np.sin(kth) kx = 28.8 * kr * np.cos(kth) d2 = (x_km[:, None] - kx[None, :]) ** 2 + (y_km[:, None] - ky[None, :]) ** 2 nearest = np.argpartition(d2, kth=3, axis=1)[:, :4] local_w = np.empty((N_STATIONS, 4), dtype=np.float32) for sid in range(N_STATIONS): dd = np.sqrt(d2[sid, nearest[sid]]) w = np.exp(-0.5 * (dd / 8.5) ** 2) + 1e-6 local_w[sid] = (w / w.sum()).astype(np.float32) return locals() def globals_(): rng = np.random.default_rng(SEED) idx = pd.date_range(START_LOCAL, periods=N_HOURS, freq="h") month = idx.month.to_numpy() hour = idx.hour.to_numpy() dow = idx.dayofweek.to_numpy() doy = idx.dayofyear.to_numpy() midx = month - 1 # Kolkata/Alipore-inspired monthly climatological means, used as broad synthetic constraints. tmin = np.array([14.1, 17.1, 21.6, 25.0, 26.5, 27.0, 26.6, 26.5, 25.9, 23.5, 18.8, 14.8], np.float32) tmax = np.array([25.8, 29.1, 33.8, 35.7, 35.4, 33.8, 32.5, 32.4, 32.5, 32.3, 29.4, 26.5], np.float32) rhm = np.array([72, 68, 64, 67, 75, 82, 86, 86, 84, 78, 72, 70], np.float32) rainm = np.array([10.4, 21, 35, 60, 135, 285, 325, 330, 290, 165, 20, 10], np.float32) rd = np.array([1.1, 1.5, 2.5, 4, 7, 14, 19, 18, 15, 8, 1.5, 1], np.float32) mean_t = (tmin[midx] + tmax[midx]) / 2.0 amp_t = (tmax[midx] - tmin[midx]) / 2.0 nd = math.ceil(N_HOURS / 24) daily_temp_anom = ar1_path(rng, nd, rho=0.82, target_sd=1.6) daily_temp_anom = np.clip(daily_temp_anom, -4.5, 4.5) hourly_temp_anom = np.repeat(daily_temp_anom, 24)[:N_HOURS] temp = (mean_t + amp_t * np.cos(2 * np.pi * (hour - 15) / 24) + hourly_temp_anom).astype(np.float32) temp = np.clip(temp, tmin[midx] - 5.5, tmax[midx] + 5.5).astype(np.float32) # Markov wet/dry process with stationary wet-day probability matching monthly climatology. day_idx = idx[::24][:nd] day_month = day_idx.month.to_numpy() daily_rain = np.zeros(nd, np.float32) prev_wet = False for d in range(nd): m = day_month[d] - 1 pbar = min(0.88, float(rd[m]) / 30.4375) p_wet = min(0.94, 0.70 * pbar + (0.30 if prev_wet else 0.0)) wet = rng.random() < p_wet if wet: shape = 1.55 if m in (5, 6, 7, 8) else 1.30 scale = max(1.0, float(rainm[m]) / max(float(rd[m]), 1.0) / shape) daily_rain[d] = min(float(rng.gamma(shape, scale)), 180.0) prev_wet = wet # Scale each calendar month to a stochastic monthly total around climatology. periods = day_idx.tz_localize(None).to_period("M") for per in periods.unique(): inds = np.where(periods == per)[0] m = per.month - 1 days_in_month = calendar.monthrange(per.year, per.month)[1] hour_count = int(np.count_nonzero((idx.year == per.year) & (idx.month == per.month))) coverage = hour_count / float(days_in_month * 24) sigma = 0.32 if m in (5, 6, 7, 8) else 0.48 factor = float(rng.lognormal(-0.5 * sigma * sigma, sigma)) target = float(rainm[m]) * coverage * factor total = float(daily_rain[inds].sum()) if total <= 0.0 and target >= 5.0: daily_rain[int(rng.choice(inds))] = target elif total > 0.0: daily_rain[inds] *= np.float32(np.clip(target / total, 0.25, 4.0)) rain = np.zeros(N_HOURS, np.float32) for d, amount in enumerate(daily_rain): if amount <= 0: continue st = d * 24 if st >= N_HOURS: break L = int(rng.integers(2, 12)) h0 = int(rng.integers(0, max(1, 24 - L + 1))) weights = rng.gamma(1.6, 1.0, L).astype(np.float32) weights /= weights.sum() a = st + h0 b = min(a + L, N_HOURS) rain[a:b] += np.float32(amount) * weights[: b - a] rh = rhm[midx] + 9.0 * np.cos(2 * np.pi * (hour - 5) / 24) - 1.10 * (temp - mean_t) rh += 9.0 * np.minimum(rain, 5.0) / 5.0 + rng.normal(0, 2.8, N_HOURS) rh = np.clip(rh, 25, 100).astype(np.float32) wb = np.array([1.25, 1.35, 1.65, 2.0, 2.1, 2.3, 2.4, 2.3, 2.0, 1.55, 1.25, 1.15], np.float32)[midx] wind = rng.gamma(2.0, wb / 2.0).astype(np.float32) + 0.22 * np.sqrt(rain) wind = np.clip(wind, 0.05, 14).astype(np.float32) # Explicit synthetic event labels. Multipliers below are stress-test choices, not causal estimates. event = np.zeros(N_HOURS, np.uint8) lockdown = (idx >= pd.Timestamp("2020-03-25", tz=TZ)) & (idx < pd.Timestamp("2020-06-01", tz=TZ)) event[lockdown] = 2 for ds in ["2015-11-11", "2016-10-30", "2017-10-19", "2018-11-07", "2019-10-27", "2020-11-14", "2021-11-04", "2022-10-24", "2023-11-12", "2024-11-01", "2025-10-20"]: t0 = pd.Timestamp(ds, tz=TZ) + pd.Timedelta(hours=18) event[(idx >= t0) & (idx < t0 + pd.Timedelta(hours=12))] = 1 for ds in ["2019-05-03", "2020-05-20", "2021-05-26", "2024-05-26"]: t0 = pd.Timestamp(ds, tz=TZ) mask = (idx >= t0 - pd.Timedelta(hours=12)) & (idx < t0 + pd.Timedelta(hours=36)) event[mask] = 3 wind[mask] = np.clip(wind[mask] + rng.uniform(4, 9, mask.sum()), 0.05, 20) rain[mask] += rng.gamma(2.2, 6, mask.sum()).astype(np.float32) rh[mask] = np.clip(rh[mask] + 8, 25, 100) event[(temp >= 38) & np.isin(month, [3, 4, 5, 6]) & (event == 0)] = 4 mrng = np.random.default_rng(SEED + 1) site = _site_metadata(mrng) pm25m = np.array([150, 130, 95, 67, 52, 38, 28, 28, 36, 62, 108, 145], np.float32)[midx] no2m = np.array([48, 45, 39, 34, 31, 28, 26, 26, 29, 35, 43, 48], np.float32)[midx] so2m = np.array([11, 10.5, 10, 9, 8.5, 7.5, 7, 7, 7.5, 8.5, 9.5, 10.5], np.float32)[midx] com = np.array([1.75, 1.6, 1.35, 1.12, 0.95, 0.78, 0.68, 0.68, 0.78, 1.02, 1.35, 1.65], np.float32)[midx] o3m = np.array([32, 38, 50, 57, 55, 43, 34, 34, 38, 42, 36, 31], np.float32)[midx] rush = (1 + 0.34 * np.exp(-0.5 * ((hour - 9) / 2) ** 2) + 0.32 * np.exp(-0.5 * ((hour - 20) / 2.2) ** 2)).astype(np.float32) weekend = np.where(dow == 6, 0.88, np.where(dow == 5, 0.95, 1.0)).astype(np.float32) solar = np.maximum(0, np.sin(np.pi * (hour - 6) / 12)).astype(np.float32) night = (1 + 0.20 * np.exp(-0.5 * ((hour - 5) / 3) ** 2) + 0.16 * np.exp(-0.5 * ((hour - 22) / 3) ** 2)).astype(np.float32) rain_lag = lfilter([0.62, 0.25, 0.13], [1.0], rain).astype(np.float32) vent = np.clip(np.exp(-0.13 * wind - 0.045 * np.minimum(rain_lag, 20)), 0.18, 1).astype(np.float32) common_log = ar1_path(rng, N_HOURS, rho=0.94, target_sd=0.11) common = np.exp(np.clip(common_log, -0.32, 0.32)).astype(np.float32) # Time-varying local spatial latent processes. Nearby sites share knot mixtures; distant sites share fewer. k_latent = site["k_latent"] spatial_pm = np.stack([ar1_path(rng, N_HOURS, 0.985, 0.22) for _ in range(k_latent)]).astype(np.float32) spatial_comb = np.stack([ar1_path(rng, N_HOURS, 0.975, 0.15) for _ in range(k_latent)]).astype(np.float32) spatial_dust = np.stack([ar1_path(rng, N_HOURS, 0.965, 0.23) for _ in range(k_latent)]).astype(np.float32) spatial_o3 = np.stack([ar1_path(rng, N_HOURS, 0.980, 0.13) for _ in range(k_latent)]).astype(np.float32) ts = idx.tz_convert("UTC").tz_localize(None).to_numpy(dtype="datetime64[s]").astype(np.int64) split = np.where(np.arange(N_HOURS) < 80_000, 0, np.where(np.arange(N_HOURS) < 90_000, 1, 2)).astype(np.uint8) return locals() def _clear_runs(mask: np.ndarray, bit: int, target_missing: int, rng: np.random.Generator, geom_p: float, max_run: int) -> None: """Clear one observation bit in clustered runs until target_missing timestamps are missing.""" flag = np.uint16(1 << bit) missing = int(np.count_nonzero((mask & flag) == 0)) guard = 0 while missing < target_missing: st = int(rng.integers(0, N_HOURS)) L = int(min(rng.geometric(geom_p), max_run, target_missing - missing)) en = min(N_HOURS, st + max(1, L)) before = (mask[st:en] & flag) != 0 newly = int(before.sum()) mask[st:en] &= np.uint16(~flag & 0xFFFF) missing += newly guard += 1 if guard > 100_000: raise RuntimeError("missingness run generator did not converge") def observation_mask(sid: int) -> np.ndarray: """Pollutant-/variable-specific structured missingness plus station-wide outages.""" rng = np.random.default_rng(SEED + 10_000 + sid) mask = np.full(N_HOURS, ALL_OBS_MASK, dtype=np.uint16) # Whole-site telemetry outages first. station_target = int(N_HOURS * rng.uniform(0.008, 0.020)) cleared_all = 0 while cleared_all < station_target: st = int(rng.integers(0, N_HOURS)) L = int(min(rng.geometric(0.08), 120, station_target - cleared_all)) en = min(N_HOURS, st + max(1, L)) new = int(np.count_nonzero(mask[st:en] != 0)) mask[st:en] = 0 cleared_all += new # Total target missingness by variable, with site-to-site heterogeneity. base_rates = np.array([0.018, 0.020, 0.024, 0.025, 0.032, 0.038, 0.055, 0.065, 0.075, 0.060], dtype=np.float64) geom_p = np.array([0.18, 0.18, 0.15, 0.15, 0.12, 0.12, 0.085, 0.075, 0.065, 0.080], dtype=np.float64) for bit in range(len(MEAS_FIELDS)): rate = float(np.clip(base_rates[bit] * rng.lognormal(-0.5 * 0.22**2, 0.22), base_rates[bit] * 0.55, base_rates[bit] * 1.8)) target = int(round(N_HOURS * rate)) target = max(target, int(np.count_nonzero((mask & np.uint16(1 << bit)) == 0))) _clear_runs(mask, bit, target, rng, float(geom_p[bit]), max_run=168) return mask def _spatial_log_factor(G, sid: int, key: str) -> np.ndarray: inds = G["site"]["nearest"][sid] w = G["site"]["local_w"][sid] z = G[key] return (w[0] * z[inds[0]] + w[1] * z[inds[1]] + w[2] * z[inds[2]] + w[3] * z[inds[3]]).astype(np.float32) def generate_station(G, sid: int) -> np.ndarray: rng = np.random.default_rng(SEED + 100_000 + sid) out = np.empty(N_HOURS, dtype=DTYPE) out["timestamp_utc_s"] = G["ts"] out["station_id"] = sid sc = G["site"]["site_code"][sid] temp = G["temp"] + G["site"]["site_temp"][sid] + ar1_path(rng, N_HOURS, 0.55, 0.34) rh = G["rh"] - 1.2 * G["site"]["site_temp"][sid] + ar1_path(rng, N_HOURS, 0.50, 1.4) rh = np.clip(rh, 20, 100).astype(np.float32) wind = G["wind"] * G["site"]["site_wind"][sid] + ar1_path(rng, N_HOURS, 0.40, 0.16) wind = np.clip(wind, 0.03, 22).astype(np.float32) rain = np.clip(G["rain"] * rng.lognormal(0, 0.035, N_HOURS), 0, 300).astype(np.float32) out["temperature_c"] = temp out["relative_humidity_pct"] = rh out["wind_speed_ms"] = wind out["rainfall_mm"] = rain rain_lag = lfilter([0.62, 0.25, 0.13], [1.0], rain).astype(np.float32) local_vent = np.clip(G["vent"] * np.exp(-0.035 * (wind - G["wind"])), 0.12, 1.05).astype(np.float32) sp = np.sin(2 * np.pi * (G["doy"] / 365.25)).astype(np.float32) humid = 1 + (0.0009 + 0.00035 * sp) * np.maximum(rh - 65, 0) traffic_profile = G["rush"] * G["weekend"] * np.float32(0.92 + 0.08 * (sc in (0, 1))) local_pm = np.clip(_spatial_log_factor(G, sid, "spatial_pm"), -0.55, 0.55) local_comb = np.clip(_spatial_log_factor(G, sid, "spatial_comb"), -0.45, 0.45) local_dust = np.clip(_spatial_log_factor(G, sid, "spatial_dust"), -0.50, 0.50) local_o3 = np.clip(_spatial_log_factor(G, sid, "spatial_o3"), -0.40, 0.40) epm = np.exp(np.clip(ar1_path(rng, N_HOURS, 0.68, 0.11), -0.35, 0.35)).astype(np.float32) ecoarse = np.exp(np.clip(ar1_path(rng, N_HOURS, 0.58, 0.22), -0.60, 0.60)).astype(np.float32) eno2 = np.exp(np.clip(ar1_path(rng, N_HOURS, 0.58, 0.10), -0.32, 0.32)).astype(np.float32) eco = np.exp(np.clip(ar1_path(rng, N_HOURS, 0.55, 0.11), -0.35, 0.35)).astype(np.float32) eso2 = np.exp(np.clip(ar1_path(rng, N_HOURS, 0.60, 0.12), -0.38, 0.38)).astype(np.float32) eo3 = np.exp(np.clip(ar1_path(rng, N_HOURS, 0.62, 0.08), -0.28, 0.28)).astype(np.float32) pm25 = G["pm25m"] * G["site"]["site_pm"][sid] * G["night"] * (0.52 + 0.58 * local_vent) * humid * G["common"] pm25 *= np.exp(local_pm) * epm pm25 *= np.exp(-0.025 * np.minimum(rain_lag, 30) - 0.035 * np.maximum(wind - 3, 0)).astype(np.float32) coarse = (18 + 0.36 * G["pm25m"]) * (0.85 + 0.20 * (sc in (0, 1))) * np.exp(0.75 * local_dust) * ecoarse coarse *= np.exp(-0.032 * np.minimum(rain_lag, 30) - 0.020 * np.maximum(wind - 4, 0)).astype(np.float32) pm10 = pm25 + coarse no2 = G["no2m"] * G["site"]["site_nox"][sid] * traffic_profile * (0.60 + 0.52 * local_vent) * G["common"] no2 *= np.exp(0.85 * local_comb) * eno2 co = G["com"] * (0.72 * G["site"]["site_nox"][sid] + 0.28 * G["site"]["site_pm"][sid]) * traffic_profile * (0.68 + 0.45 * local_vent) co *= np.exp(0.62 * local_comb) * eco so2 = G["so2m"] * G["site"]["site_so2"][sid] * (0.70 + 0.42 * local_vent) * np.exp(0.60 * local_comb) * eso2 o3 = G["o3m"] * G["site"]["site_o3"][sid] * (0.35 + 1.15 * G["solar"]) * np.exp(0.018 * (temp - 28)) o3 *= np.exp(local_o3 - 0.12 * local_comb) * np.exp(-0.0045 * np.maximum(no2 - 25, 0)) * eo3 e = G["event"] diw, lck, cyc = e == 1, e == 2, e == 3 pm25[diw] *= 2.4; pm10[diw] *= 2.6; so2[diw] *= 1.7; no2[diw] *= 1.35; co[diw] *= 1.45; o3[diw] *= 0.78 pm25[lck] *= 0.62; pm10[lck] *= 0.64; no2[lck] *= 0.58; co[lck] *= 0.68; so2[lck] *= 0.75; o3[lck] *= 1.08 pm25[cyc] *= 0.38; pm10[cyc] *= 0.40; no2[cyc] *= 0.62; co[cyc] *= 0.70; so2[cyc] *= 0.58; o3[cyc] *= 0.72 pm25 = np.clip(pm25, 1, 950).astype(np.float32) pm10 = np.clip(pm10, 2, 1200).astype(np.float32) no2 = np.clip(no2, 0.5, 250).astype(np.float32) co = np.clip(co, 0.02, 12).astype(np.float32) so2 = np.clip(so2, 0.2, 120).astype(np.float32) o3 = np.clip(o3, 0.5, 300).astype(np.float32) out["pm25_ugm3"] = pm25 out["pm10_ugm3"] = pm10 out["no2_ugm3"] = no2 out["co_mgm3"] = co out["so2_ugm3"] = so2 out["o3_ugm3"] = o3 out["event_code"] = e out["split_code"] = G["split"] obs_mask = observation_mask(sid) out["obs_mask"] = obs_mask for field, bit in OBS_BITS.items(): miss = (obs_mask & np.uint16(1 << bit)) == 0 out[field][miss] = np.nan return out def main(): ap = argparse.ArgumentParser() ap.add_argument("--start-station", type=int, default=0) ap.add_argument("--end-station", type=int, default=N_STATIONS) ap.add_argument("--init", action="store_true") ap.add_argument("--output", type=Path, default=OUT) args = ap.parse_args() G = globals_() if args.init or not args.output.exists(): mm = np.lib.format.open_memmap(args.output, mode="w+", dtype=DTYPE, shape=(N_ROWS,)) mm.flush(); del mm mm = np.lib.format.open_memmap(args.output, mode="r+", dtype=DTYPE, shape=(N_ROWS,)) for sid in range(args.start_station, args.end_station): mm[sid * N_HOURS : (sid + 1) * N_HOURS] = generate_station(G, sid) if sid % 25 == 0: mm.flush(); print(f"WROTE {sid}", flush=True) mm.flush(); del mm print("DONE", args.start_station, args.end_station) if __name__ == "__main__": main()