Skip to content

Instantly share code, notes, and snippets.

@stephenc
Created July 14, 2025 21:10
Show Gist options
  • Save stephenc/6a17545e23eaf7b2c5efac683462db84 to your computer and use it in GitHub Desktop.
Save stephenc/6a17545e23eaf7b2c5efac683462db84 to your computer and use it in GitHub Desktop.
Finger saver
https://www.ncei.noaa.gov/pub/data/uscrn/products/subhourly01/2025/CRNS0101-05-2025-CO_Boulder_14_W.txt
https://www.ncei.noaa.gov/pub/data/uscrn/products/subhourly01/2025/CRNS0101-05-2025-CO_Nunn_7_NNE.txt
https://www.ncei.noaa.gov/pub/data/uscrn/products/subhourly01/2025/CRNS0101-05-2025-SC_McClellanville_7_NE.txt
column_names = [
'WBANNO', 'UTC_DATE', 'UTC_TIME', 'LST_DATE', 'LST_TIME',
'CRX_VN', 'LONGITUDE', 'LATITUDE', 'AIR_TEMPERATURE',
'PRECIPITATION', 'SOLAR_RADIATION', 'SR_FLAG',
'SURFACE_TEMPERATURE', 'ST_TYPE', 'ST_FLAG',
'RELATIVE_HUMIDITY', 'RH_FLAG', 'SOIL_MOISTURE_5',
'SOIL_TEMPERATURE_5', 'WETNESS', 'WET_FLAG', 'WIND_1_5',
'WIND_FLAG'
]
colspecs = [
(0, 5), (6, 14), (15, 19), (20, 28), (29, 33), (34, 40),
(41, 48), (49, 56), (57, 64), (65, 72), (73, 79), (80, 81),
(82, 89), (90, 91), (92, 93), (94, 99), (100, 101),
(102, 109), (110, 117), (118, 123), (124, 125), (126, 132),
(133, 134)
]
df_boulder = pd.read_fwf('boulder.txt', colspecs=colspecs, ↵ header=None, names=column_names, na_values=['-99.000', ↵
'-9999.0'])
df_nunn = pd.read_fwf('nunn.txt', colspecs=colspecs, ↵
header=None, names=column_names, na_values=['-99.000', ↵
'-9999.0'])
df_sc = pd.read_fwf('sc.txt', colspecs=colspecs, ↵
header=None, names=column_names, na_values=['-99.000', ↵
'-9999.0'])
plt.figure(figsize=(12, 6))
plt.scatter(full_lags_hours, full_corrs, color='blue', label='Cross-Correlation')
plt.plot(max_lag_hours, max_corr_value, 'ro')
plt.annotate(f'{max_lag_hours:.1f} hours\n(corr: {max_corr_value:.2f})',
xy=(max_lag_hours, max_corr_value),
xytext=(max_lag_hours + 1, max_corr_value - 0.25),
arrowprops=dict(arrowstyle='->', color='red'),
color='red')
plt.axhline(0, color='black', linewidth=1)
plt.axvline(0, color='gray', linestyle='--')
plt.title("Cross-Correlation: Boulder vs McCellanville Temperatures")
plt.xlabel("Lag (hours) - Positive means McCellanville temperature follows Boulder's changes")
plt.ylabel("Correlation (how similar the patterns are)")
plt.grid(True)
plt.legend()
plt.tight_layout()
plt.savefig('cross-corr-us.png', dpi=150)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment