|
1 | | -import logging |
| 1 | +import argparse |
2 | 2 |
|
3 | 3 | import matplotlib.pyplot as plt |
4 | 4 |
|
5 | | -from rivretrieve import JapanFetcher, constants |
6 | | - |
7 | | -logging.basicConfig(level=logging.INFO) |
8 | | - |
9 | | -gauge_ids = [ |
10 | | - "301011281104010", |
11 | | -] |
12 | | -variable = constants.DISCHARGE_DAILY_MEAN |
13 | | -start_date = "2019-01-01" |
14 | | -end_date = "2019-12-31" # Fetching a few months to test |
15 | | - |
16 | | -plt.figure(figsize=(12, 6)) |
17 | | - |
18 | | -fetcher = JapanFetcher() |
19 | | -for gauge_id in gauge_ids: |
20 | | - print(f"Fetching data for {gauge_id} from {start_date} to {end_date}...") |
21 | | - data = fetcher.get_data(gauge_id=gauge_id, variable=variable, start_date=start_date, end_date=end_date) |
22 | | - if not data.empty: |
23 | | - print(f"Data for {gauge_id}:") |
24 | | - print(data.head()) |
25 | | - print(f"Time series from {data.index.min()} to {data.index.max()}") |
26 | | - plt.plot( |
27 | | - data.index, |
28 | | - data[constants.DISCHARGE_DAILY_MEAN], |
29 | | - label=gauge_id, |
30 | | - marker="o", |
31 | | - ) |
| 5 | +from rivretrieve import constants |
| 6 | +from rivretrieve.japan import JapanFetcher |
| 7 | + |
| 8 | + |
| 9 | +def main(): |
| 10 | + parser = argparse.ArgumentParser(description="Test JapanFetcher") |
| 11 | + parser.add_argument("--gauge_id", type=str, default="301011281104010", help="Gauge ID to test") |
| 12 | + parser.add_argument("--variable", type=str, default=constants.DISCHARGE_DAILY_MEAN, help="Variable to fetch") |
| 13 | + parser.add_argument("--start_date", type=str, default="2004-01-01", help="Start date YYYY-MM-DD") |
| 14 | + parser.add_argument("--end_date", type=str, default="2004-12-31", help="End date YYYY-MM-DD") |
| 15 | + args = parser.parse_args() |
| 16 | + |
| 17 | + fetcher = JapanFetcher() |
| 18 | + print(f"Fetching data for {args.gauge_id} from {args.start_date} to {args.end_date} for {args.variable}...") |
| 19 | + |
| 20 | + df = fetcher.get_data( |
| 21 | + gauge_id=args.gauge_id, variable=args.variable, start_date=args.start_date, end_date=args.end_date |
| 22 | + ) |
| 23 | + |
| 24 | + if not df.empty: |
| 25 | + print(f"Data for {args.gauge_id}:") |
| 26 | + print(df.head()) |
| 27 | + print(f"Time series from {df.index.min()} to {df.index.max()}") |
| 28 | + df.plot(y=args.variable) |
| 29 | + plt.title(f"{args.gauge_id} - {args.variable}") |
| 30 | + plt.xlabel("Time") |
| 31 | + plt.ylabel(args.variable) |
| 32 | + plt.legend() |
| 33 | + plot_filename = f"japan_{args.variable}_plot.png" |
| 34 | + plt.savefig(plot_filename) |
| 35 | + print(f"Plot saved to {plot_filename}") |
32 | 36 | else: |
33 | | - print(f"No data found for {gauge_id}") |
34 | | - |
35 | | -plt.xlabel(constants.TIME_INDEX) |
36 | | -plt.ylabel(f"{constants.DISCHARGE_DAILY_MEAN} (m3/s)") |
37 | | -plt.title("Japan River Discharge - Full Time Series") |
38 | | -plt.legend() |
39 | | -plt.grid(True) |
40 | | -plt.tight_layout() |
41 | | -plot_path = "japan_discharge_plot.png" |
42 | | -plt.savefig(plot_path) |
43 | | -print(f"Plot saved to {plot_path}") |
| 37 | + print(f"No data found for {args.gauge_id}") |
| 38 | + |
| 39 | + |
| 40 | +if __name__ == "__main__": |
| 41 | + main() |
0 commit comments