Overview
Implement performance optimizations for the murgtools/getdata module.
2.1 Cache Server Detection
Move server detection from getnc() to module-level with caching. Currently re-runs socket operations on every call.
Problem: Every getnc() call runs socket operations to detect FRF vs external network.
Solution: Cache at module load with thread-safe implementation.
2.2 Convert Lookup Tables to Dictionaries
Replace 144-line if-elif chain in _waveGaugeURLlookup() with O(1) dictionary lookup.
Methods to update:
_waveGaugeURLlookup() (~144 lines)
_wlGageURLlookup() (~56 lines)
2.3 Add Dataset Caching with TTL
Add simple cache for getnc() results (5-minute TTL default) to avoid redundant network calls.
2.4 Consolidate Try-Except Fallback Pattern
Create helper function for the 40+ duplicate FRF/CHL server fallback patterns:
def _fetch_with_fallback(self, primary_url, fallback_url, error_message=None):
"""Fetch dataset with automatic fallback from FRF to CHL server."""
try:
return nc.Dataset(primary_url)
except IOError:
try:
return nc.Dataset(fallback_url)
except IOError:
if error_message:
print(error_message)
return None
Files to Modify
murgtools/getdata/getDataFRF.py
Acceptance Criteria
Overview
Implement performance optimizations for the
murgtools/getdatamodule.2.1 Cache Server Detection
Move server detection from
getnc()to module-level with caching. Currently re-runs socket operations on every call.Problem: Every
getnc()call runs socket operations to detect FRF vs external network.Solution: Cache at module load with thread-safe implementation.
2.2 Convert Lookup Tables to Dictionaries
Replace 144-line if-elif chain in
_waveGaugeURLlookup()with O(1) dictionary lookup.Methods to update:
_waveGaugeURLlookup()(~144 lines)_wlGageURLlookup()(~56 lines)2.3 Add Dataset Caching with TTL
Add simple cache for
getnc()results (5-minute TTL default) to avoid redundant network calls.2.4 Consolidate Try-Except Fallback Pattern
Create helper function for the 40+ duplicate FRF/CHL server fallback patterns:
Files to Modify
murgtools/getdata/getDataFRF.pyAcceptance Criteria