|
| 1 | +import logging |
| 2 | + |
| 3 | +import matplotlib.pyplot as plt |
| 4 | + |
| 5 | +from rivretrieve import PortugalFetcher, constants |
| 6 | + |
| 7 | +logging.basicConfig(level=logging.INFO) |
| 8 | + |
| 9 | +# Example gauge IDs from the SITE_MAP in portugal.py |
| 10 | +gauge_ids = [ |
| 11 | + "19B/01H", # A known gauge ID from the map |
| 12 | +] |
| 13 | +variables = [constants.STAGE_DAILY_MEAN] |
| 14 | +start_date = "1980-01-01" |
| 15 | +end_date = None # Defaults to today |
| 16 | + |
| 17 | +fetcher = PortugalFetcher() |
| 18 | + |
| 19 | +for variable in variables: |
| 20 | + plt.figure(figsize=(12, 6)) |
| 21 | + print(f"\n--- Testing variable: {variable} ---") |
| 22 | + for gauge_id in gauge_ids: |
| 23 | + print(f"Fetching {variable} for {gauge_id} from {start_date} to {end_date}...") |
| 24 | + data = fetcher.get_data(gauge_id=gauge_id, variable=variable, start_date=start_date, end_date=end_date) |
| 25 | + if not data.empty: |
| 26 | + print(f"Data for {gauge_id}:") |
| 27 | + print(data.head()) |
| 28 | + print(f"Time series from {data.index.min()} to {data.index.max()}") |
| 29 | + plt.plot( |
| 30 | + data.index, |
| 31 | + data[variable], |
| 32 | + label=f"{gauge_id} - {variable}", |
| 33 | + marker=".", |
| 34 | + linestyle="-", |
| 35 | + ) |
| 36 | + else: |
| 37 | + print(f"No {variable} data found for {gauge_id}") |
| 38 | + |
| 39 | + if plt.gca().has_data(): |
| 40 | + plt.xlabel(constants.TIME_INDEX) |
| 41 | + plt.ylabel(variable) |
| 42 | + plt.title(f"Portugal River Data ({start_date} to {end_date})") |
| 43 | + plt.legend() |
| 44 | + plt.grid(True) |
| 45 | + plt.tight_layout() |
| 46 | + plot_path = f"portugal_{variable}_plot.png" |
| 47 | + plt.savefig(plot_path) |
| 48 | + print(f"Plot saved to {plot_path}") |
| 49 | + else: |
| 50 | + print(f"No data to plot for {variable}.") |
| 51 | + |
| 52 | +print("Test finished.") |
0 commit comments