meteostat-cli 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- meteo/__init__.py +3 -0
- meteo/cli.py +71 -0
- meteo/commands/__init__.py +0 -0
- meteo/commands/config.py +95 -0
- meteo/commands/daily.py +72 -0
- meteo/commands/hourly.py +79 -0
- meteo/commands/inventory.py +98 -0
- meteo/commands/monthly.py +72 -0
- meteo/commands/nearby.py +40 -0
- meteo/commands/normals.py +70 -0
- meteo/commands/station.py +175 -0
- meteo/config.py +175 -0
- meteo/plotting.py +172 -0
- meteo/utils.py +473 -0
- meteostat_cli-0.1.0.dist-info/METADATA +249 -0
- meteostat_cli-0.1.0.dist-info/RECORD +19 -0
- meteostat_cli-0.1.0.dist-info/WHEEL +4 -0
- meteostat_cli-0.1.0.dist-info/entry_points.txt +2 -0
- meteostat_cli-0.1.0.dist-info/licenses/LICENSE +21 -0
meteo/__init__.py
ADDED
meteo/cli.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""Main CLI entry point for the Meteostat CLI."""
|
|
2
|
+
|
|
3
|
+
import typer
|
|
4
|
+
|
|
5
|
+
from meteo import __version__
|
|
6
|
+
|
|
7
|
+
app = typer.Typer(
|
|
8
|
+
name="meteo",
|
|
9
|
+
help="Access weather and climate data through the terminal.",
|
|
10
|
+
no_args_is_help=True,
|
|
11
|
+
add_completion=True,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _version_callback(value: bool) -> None:
|
|
16
|
+
if value:
|
|
17
|
+
typer.echo(f"meteo {__version__}")
|
|
18
|
+
raise typer.Exit()
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@app.callback()
|
|
22
|
+
def callback(
|
|
23
|
+
version: bool | None = typer.Option(
|
|
24
|
+
None,
|
|
25
|
+
"--version",
|
|
26
|
+
"-V",
|
|
27
|
+
callback=_version_callback,
|
|
28
|
+
is_eager=True,
|
|
29
|
+
help="Show version and exit.",
|
|
30
|
+
),
|
|
31
|
+
) -> None:
|
|
32
|
+
"""Access weather and climate data through the terminal."""
|
|
33
|
+
from meteo.config import apply_config
|
|
34
|
+
|
|
35
|
+
apply_config()
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _register_commands() -> None:
|
|
39
|
+
"""Register all command modules with the Typer app."""
|
|
40
|
+
from meteo.commands.config import config_cmd
|
|
41
|
+
from meteo.commands.daily import daily_cmd, daily_cmd_alias
|
|
42
|
+
from meteo.commands.hourly import hourly_cmd, hourly_cmd_alias
|
|
43
|
+
from meteo.commands.inventory import inventory_cmd, inventory_cmd_alias
|
|
44
|
+
from meteo.commands.monthly import monthly_cmd, monthly_cmd_alias
|
|
45
|
+
from meteo.commands.nearby import nearby_cmd
|
|
46
|
+
from meteo.commands.normals import normals_cmd, normals_cmd_alias
|
|
47
|
+
from meteo.commands.station import station_cmd
|
|
48
|
+
|
|
49
|
+
app.command("config")(config_cmd)
|
|
50
|
+
app.command("station")(station_cmd)
|
|
51
|
+
app.command("stations")(station_cmd)
|
|
52
|
+
app.command("s", hidden=True)(station_cmd)
|
|
53
|
+
app.command("nearby")(nearby_cmd)
|
|
54
|
+
app.command("inventory")(inventory_cmd)
|
|
55
|
+
app.command("i", hidden=True)(inventory_cmd_alias)
|
|
56
|
+
app.command("hourly")(hourly_cmd)
|
|
57
|
+
app.command("h", hidden=True)(hourly_cmd_alias)
|
|
58
|
+
app.command("daily")(daily_cmd)
|
|
59
|
+
app.command("d", hidden=True)(daily_cmd_alias)
|
|
60
|
+
app.command("monthly")(monthly_cmd)
|
|
61
|
+
app.command("m", hidden=True)(monthly_cmd_alias)
|
|
62
|
+
app.command("normals")(normals_cmd)
|
|
63
|
+
app.command("n", hidden=True)(normals_cmd_alias)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
_register_commands()
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def main() -> None:
|
|
70
|
+
"""Entry point for the CLI."""
|
|
71
|
+
app()
|
|
File without changes
|
meteo/commands/config.py
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"""Configuration command for the Meteostat CLI."""
|
|
2
|
+
|
|
3
|
+
import typer
|
|
4
|
+
|
|
5
|
+
from meteo.config import (
|
|
6
|
+
CLI_CONFIG_KEYS,
|
|
7
|
+
coerce_value,
|
|
8
|
+
format_value,
|
|
9
|
+
get_meteostat_config_keys,
|
|
10
|
+
load_config,
|
|
11
|
+
save_config,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def config_cmd(
|
|
16
|
+
key: str | None = typer.Argument(None, help="Configuration key (dot notation)."),
|
|
17
|
+
value: str | None = typer.Argument(None, help="Value to set."),
|
|
18
|
+
list_all: bool = typer.Option(
|
|
19
|
+
False,
|
|
20
|
+
"--list",
|
|
21
|
+
"-l",
|
|
22
|
+
help="List all configuration values.",
|
|
23
|
+
),
|
|
24
|
+
) -> None:
|
|
25
|
+
"""Get or set Meteostat configuration values."""
|
|
26
|
+
if list_all:
|
|
27
|
+
_list_config()
|
|
28
|
+
return
|
|
29
|
+
|
|
30
|
+
if key is None:
|
|
31
|
+
typer.echo("Error: Provide a config key, or use --list.", err=True)
|
|
32
|
+
raise typer.Exit(2)
|
|
33
|
+
|
|
34
|
+
if value is None:
|
|
35
|
+
# Get mode
|
|
36
|
+
_get_config(key)
|
|
37
|
+
else:
|
|
38
|
+
# Set mode
|
|
39
|
+
_set_config(key, value)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _list_config() -> None:
|
|
43
|
+
"""List all configuration keys with their current values."""
|
|
44
|
+
import meteostat as ms
|
|
45
|
+
|
|
46
|
+
ms_keys = get_meteostat_config_keys()
|
|
47
|
+
saved = load_config()
|
|
48
|
+
|
|
49
|
+
# Meteostat library keys
|
|
50
|
+
for attr, default in sorted(ms_keys.items()):
|
|
51
|
+
current = saved.get(attr, getattr(ms.config, attr, default))
|
|
52
|
+
typer.echo(f"{attr} = {format_value(current)}")
|
|
53
|
+
|
|
54
|
+
# CLI-specific keys
|
|
55
|
+
for attr, default in sorted(CLI_CONFIG_KEYS.items()):
|
|
56
|
+
current = saved.get(attr, default)
|
|
57
|
+
typer.echo(f"{attr} = {format_value(current)}")
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _get_config(key: str) -> None:
|
|
61
|
+
"""Get and display a single config value."""
|
|
62
|
+
import meteostat as ms
|
|
63
|
+
|
|
64
|
+
saved = load_config()
|
|
65
|
+
ms_keys = get_meteostat_config_keys()
|
|
66
|
+
|
|
67
|
+
if key in saved:
|
|
68
|
+
typer.echo(format_value(saved[key]))
|
|
69
|
+
elif key in ms_keys:
|
|
70
|
+
typer.echo(format_value(getattr(ms.config, key, ms_keys[key])))
|
|
71
|
+
elif key in CLI_CONFIG_KEYS:
|
|
72
|
+
typer.echo(format_value(CLI_CONFIG_KEYS[key]))
|
|
73
|
+
else:
|
|
74
|
+
typer.echo(f"Error: Unknown config key '{key}'.", err=True)
|
|
75
|
+
raise typer.Exit(2)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _set_config(key: str, value: str) -> None:
|
|
79
|
+
"""Set a config value and persist it."""
|
|
80
|
+
ms_keys = get_meteostat_config_keys()
|
|
81
|
+
|
|
82
|
+
if key not in ms_keys and key not in CLI_CONFIG_KEYS:
|
|
83
|
+
typer.echo(f"Error: Unknown config key '{key}'.", err=True)
|
|
84
|
+
raise typer.Exit(2)
|
|
85
|
+
|
|
86
|
+
try:
|
|
87
|
+
coerced = coerce_value(key, value)
|
|
88
|
+
except (ValueError, TypeError) as exc:
|
|
89
|
+
typer.echo(f"Error: {exc}", err=True)
|
|
90
|
+
raise typer.Exit(2) from None
|
|
91
|
+
|
|
92
|
+
data = load_config()
|
|
93
|
+
data[key] = coerced
|
|
94
|
+
save_config(data)
|
|
95
|
+
typer.echo(f"{key} = {format_value(coerced)}")
|
meteo/commands/daily.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"""Daily time series command for the Meteostat CLI."""
|
|
2
|
+
|
|
3
|
+
from typing import Annotated
|
|
4
|
+
|
|
5
|
+
import typer
|
|
6
|
+
|
|
7
|
+
from meteo.utils import fetch_timeseries
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _daily(
|
|
11
|
+
stations: Annotated[
|
|
12
|
+
list[str],
|
|
13
|
+
typer.Argument(
|
|
14
|
+
help="Station ID(s), or coordinates as lat,lon (e.g. 48.1,11.6)."
|
|
15
|
+
),
|
|
16
|
+
],
|
|
17
|
+
start: str | None = typer.Option(
|
|
18
|
+
None, "--start", "-s", help="Start date (YYYY-MM-DD, YYYY-MM, or YYYY)."
|
|
19
|
+
),
|
|
20
|
+
end: str | None = typer.Option(None, "--end", "-e", help="End date."),
|
|
21
|
+
parameters: str | None = typer.Option(
|
|
22
|
+
None, "--parameters", "-p", help="Comma-separated list of parameters."
|
|
23
|
+
),
|
|
24
|
+
providers: str | None = typer.Option(
|
|
25
|
+
None, "--providers", "-P", help="Comma-separated list of providers."
|
|
26
|
+
),
|
|
27
|
+
no_models: bool = typer.Option(False, "--no-models", help="Exclude model data."),
|
|
28
|
+
with_sources: bool = typer.Option(
|
|
29
|
+
False, "--with-sources", "-S", help="Include data source information."
|
|
30
|
+
),
|
|
31
|
+
fmt: str | None = typer.Option(
|
|
32
|
+
None,
|
|
33
|
+
"--format",
|
|
34
|
+
"-f",
|
|
35
|
+
help="Output format (csv, json, xlsx, parquet, png, svg).",
|
|
36
|
+
),
|
|
37
|
+
output: str | None = typer.Option(None, "--output", "-o", help="Output file path."),
|
|
38
|
+
no_header: bool = typer.Option(
|
|
39
|
+
False, "--no-header", help="Omit header row from CSV output."
|
|
40
|
+
),
|
|
41
|
+
no_cache: bool = typer.Option(False, "--no-cache", help="Disable caching."),
|
|
42
|
+
show_all: bool = typer.Option(
|
|
43
|
+
False, "--all", "-A", help="Print full table instead of truncated display."
|
|
44
|
+
),
|
|
45
|
+
agg: str | None = typer.Option(
|
|
46
|
+
None,
|
|
47
|
+
"--agg",
|
|
48
|
+
help="Aggregation function to apply via pandas .agg() (e.g. mean, sum, min, max).",
|
|
49
|
+
),
|
|
50
|
+
) -> None:
|
|
51
|
+
"""Fetch daily weather data."""
|
|
52
|
+
fetch_timeseries(
|
|
53
|
+
granularity="daily",
|
|
54
|
+
stations=stations,
|
|
55
|
+
start=start,
|
|
56
|
+
end=end,
|
|
57
|
+
parameters=parameters,
|
|
58
|
+
providers=providers,
|
|
59
|
+
no_models=no_models,
|
|
60
|
+
with_sources=with_sources,
|
|
61
|
+
no_cache=no_cache,
|
|
62
|
+
fmt=fmt,
|
|
63
|
+
output=output,
|
|
64
|
+
no_header=no_header,
|
|
65
|
+
show_all=show_all,
|
|
66
|
+
agg=agg,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
# Expose for registration in cli.py
|
|
71
|
+
daily_cmd = _daily
|
|
72
|
+
daily_cmd_alias = _daily
|
meteo/commands/hourly.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"""Hourly time series command for the Meteostat CLI."""
|
|
2
|
+
|
|
3
|
+
from typing import Annotated
|
|
4
|
+
|
|
5
|
+
import typer
|
|
6
|
+
|
|
7
|
+
from meteo.utils import fetch_timeseries
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _hourly(
|
|
11
|
+
stations: Annotated[
|
|
12
|
+
list[str],
|
|
13
|
+
typer.Argument(
|
|
14
|
+
help="Station ID(s), or coordinates as lat,lon (e.g. 48.1,11.6)."
|
|
15
|
+
),
|
|
16
|
+
],
|
|
17
|
+
start: str | None = typer.Option(
|
|
18
|
+
None,
|
|
19
|
+
"--start",
|
|
20
|
+
"-s",
|
|
21
|
+
help="Start date (YYYY-MM-DD, YYYY-MM, YYYY, or ISO 8601).",
|
|
22
|
+
),
|
|
23
|
+
end: str | None = typer.Option(None, "--end", "-e", help="End date."),
|
|
24
|
+
timezone: str | None = typer.Option(
|
|
25
|
+
None, "--timezone", "-t", help="Timezone for output timestamps."
|
|
26
|
+
),
|
|
27
|
+
parameters: str | None = typer.Option(
|
|
28
|
+
None, "--parameters", "-p", help="Comma-separated list of parameters."
|
|
29
|
+
),
|
|
30
|
+
providers: str | None = typer.Option(
|
|
31
|
+
None, "--providers", "-P", help="Comma-separated list of providers."
|
|
32
|
+
),
|
|
33
|
+
no_models: bool = typer.Option(False, "--no-models", help="Exclude model data."),
|
|
34
|
+
with_sources: bool = typer.Option(
|
|
35
|
+
False, "--with-sources", "-S", help="Include data source information."
|
|
36
|
+
),
|
|
37
|
+
fmt: str | None = typer.Option(
|
|
38
|
+
None,
|
|
39
|
+
"--format",
|
|
40
|
+
"-f",
|
|
41
|
+
help="Output format (csv, json, xlsx, parquet, png, svg).",
|
|
42
|
+
),
|
|
43
|
+
output: str | None = typer.Option(None, "--output", "-o", help="Output file path."),
|
|
44
|
+
no_header: bool = typer.Option(
|
|
45
|
+
False, "--no-header", help="Omit header row from CSV output."
|
|
46
|
+
),
|
|
47
|
+
no_cache: bool = typer.Option(False, "--no-cache", help="Disable caching."),
|
|
48
|
+
show_all: bool = typer.Option(
|
|
49
|
+
False, "--all", "-A", help="Print full table instead of truncated display."
|
|
50
|
+
),
|
|
51
|
+
agg: str | None = typer.Option(
|
|
52
|
+
None,
|
|
53
|
+
"--agg",
|
|
54
|
+
help="Aggregation function to apply via pandas .agg() (e.g. mean, sum, min, max).",
|
|
55
|
+
),
|
|
56
|
+
) -> None:
|
|
57
|
+
"""Fetch hourly weather data."""
|
|
58
|
+
fetch_timeseries(
|
|
59
|
+
granularity="hourly",
|
|
60
|
+
stations=stations,
|
|
61
|
+
start=start,
|
|
62
|
+
end=end,
|
|
63
|
+
timezone=timezone,
|
|
64
|
+
parameters=parameters,
|
|
65
|
+
providers=providers,
|
|
66
|
+
no_models=no_models,
|
|
67
|
+
with_sources=with_sources,
|
|
68
|
+
no_cache=no_cache,
|
|
69
|
+
fmt=fmt,
|
|
70
|
+
output=output,
|
|
71
|
+
no_header=no_header,
|
|
72
|
+
show_all=show_all,
|
|
73
|
+
agg=agg,
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
# Expose for registration in cli.py
|
|
78
|
+
hourly_cmd = _hourly
|
|
79
|
+
hourly_cmd_alias = _hourly
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"""Inventory command for the Meteostat CLI."""
|
|
2
|
+
|
|
3
|
+
import typer
|
|
4
|
+
|
|
5
|
+
from meteo.utils import detect_format, output_df, parse_parameters, parse_providers
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def _inventory(
|
|
9
|
+
station_id: str = typer.Argument(..., help="Meteostat station ID."),
|
|
10
|
+
parameters: str | None = typer.Option(
|
|
11
|
+
None, "--parameters", "-p", help="Comma-separated list of parameters."
|
|
12
|
+
),
|
|
13
|
+
providers: str | None = typer.Option(
|
|
14
|
+
None, "--providers", "-P", help="Comma-separated list of providers."
|
|
15
|
+
),
|
|
16
|
+
granularity: str | None = typer.Option(
|
|
17
|
+
None,
|
|
18
|
+
"--granularity",
|
|
19
|
+
"-g",
|
|
20
|
+
help="Granularity filter (hourly/h, daily/d, monthly/m).",
|
|
21
|
+
),
|
|
22
|
+
fmt: str | None = typer.Option(None, "--format", "-f", help="Output format."),
|
|
23
|
+
output: str | None = typer.Option(None, "--output", "-o", help="Output file path."),
|
|
24
|
+
no_header: bool = typer.Option(
|
|
25
|
+
False, "--no-header", help="Omit header row from CSV output."
|
|
26
|
+
),
|
|
27
|
+
show_all: bool = typer.Option(
|
|
28
|
+
False, "--all", "-A", help="Print full table instead of truncated display."
|
|
29
|
+
),
|
|
30
|
+
) -> None:
|
|
31
|
+
"""Get inventory data for a weather station."""
|
|
32
|
+
import meteostat as ms
|
|
33
|
+
from meteostat.enumerations import Granularity
|
|
34
|
+
|
|
35
|
+
provider_list = parse_providers(providers)
|
|
36
|
+
|
|
37
|
+
inv = ms.stations.inventory(station_id, providers=provider_list)
|
|
38
|
+
|
|
39
|
+
if inv.df is None or inv.df.empty:
|
|
40
|
+
typer.echo(f"No inventory data found for station '{station_id}'.", err=True)
|
|
41
|
+
raise typer.Exit(1)
|
|
42
|
+
|
|
43
|
+
df = inv.df.reset_index()
|
|
44
|
+
|
|
45
|
+
# Filter by granularity if specified
|
|
46
|
+
if granularity:
|
|
47
|
+
gran_map = {
|
|
48
|
+
"hourly": Granularity.HOURLY,
|
|
49
|
+
"h": Granularity.HOURLY,
|
|
50
|
+
"daily": Granularity.DAILY,
|
|
51
|
+
"d": Granularity.DAILY,
|
|
52
|
+
"monthly": Granularity.MONTHLY,
|
|
53
|
+
"m": Granularity.MONTHLY,
|
|
54
|
+
}
|
|
55
|
+
gran = gran_map.get(granularity.lower())
|
|
56
|
+
if gran is None:
|
|
57
|
+
typer.echo(
|
|
58
|
+
f"Error: Unknown granularity '{granularity}'. Use hourly/h, daily/d, or monthly/m.",
|
|
59
|
+
err=True,
|
|
60
|
+
)
|
|
61
|
+
raise typer.Exit(2)
|
|
62
|
+
# Filter providers that match the granularity
|
|
63
|
+
from meteostat.core.providers import provider_service
|
|
64
|
+
|
|
65
|
+
valid_providers = []
|
|
66
|
+
for p in df["provider"].unique():
|
|
67
|
+
try:
|
|
68
|
+
spec = provider_service.get_provider(p)
|
|
69
|
+
if spec and spec.granularity == gran:
|
|
70
|
+
valid_providers.append(p)
|
|
71
|
+
except (KeyError, ValueError):
|
|
72
|
+
pass
|
|
73
|
+
df = df[df["provider"].isin(valid_providers)]
|
|
74
|
+
|
|
75
|
+
# Filter by parameters if specified
|
|
76
|
+
if parameters:
|
|
77
|
+
param_list = parse_parameters(parameters)
|
|
78
|
+
if param_list:
|
|
79
|
+
param_values = [p.value for p in param_list]
|
|
80
|
+
df = df[df["parameter"].isin(param_values)]
|
|
81
|
+
|
|
82
|
+
if df.empty:
|
|
83
|
+
typer.echo("No matching inventory data found.", err=True)
|
|
84
|
+
raise typer.Exit(1)
|
|
85
|
+
|
|
86
|
+
actual_fmt = detect_format(fmt, output)
|
|
87
|
+
output_df(
|
|
88
|
+
df.set_index(["station", "provider", "parameter"]),
|
|
89
|
+
actual_fmt,
|
|
90
|
+
output,
|
|
91
|
+
no_header,
|
|
92
|
+
show_all=show_all,
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
# Expose for registration in cli.py
|
|
97
|
+
inventory_cmd = _inventory
|
|
98
|
+
inventory_cmd_alias = _inventory
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"""Monthly time series command for the Meteostat CLI."""
|
|
2
|
+
|
|
3
|
+
from typing import Annotated
|
|
4
|
+
|
|
5
|
+
import typer
|
|
6
|
+
|
|
7
|
+
from meteo.utils import fetch_timeseries
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _monthly(
|
|
11
|
+
stations: Annotated[
|
|
12
|
+
list[str],
|
|
13
|
+
typer.Argument(
|
|
14
|
+
help="Station ID(s), or coordinates as lat,lon (e.g. 48.1,11.6)."
|
|
15
|
+
),
|
|
16
|
+
],
|
|
17
|
+
start: str | None = typer.Option(
|
|
18
|
+
None, "--start", "-s", help="Start date (YYYY-MM-DD, YYYY-MM, or YYYY)."
|
|
19
|
+
),
|
|
20
|
+
end: str | None = typer.Option(None, "--end", "-e", help="End date."),
|
|
21
|
+
parameters: str | None = typer.Option(
|
|
22
|
+
None, "--parameters", "-p", help="Comma-separated list of parameters."
|
|
23
|
+
),
|
|
24
|
+
providers: str | None = typer.Option(
|
|
25
|
+
None, "--providers", "-P", help="Comma-separated list of providers."
|
|
26
|
+
),
|
|
27
|
+
no_models: bool = typer.Option(False, "--no-models", help="Exclude model data."),
|
|
28
|
+
with_sources: bool = typer.Option(
|
|
29
|
+
False, "--with-sources", "-S", help="Include data source information."
|
|
30
|
+
),
|
|
31
|
+
fmt: str | None = typer.Option(
|
|
32
|
+
None,
|
|
33
|
+
"--format",
|
|
34
|
+
"-f",
|
|
35
|
+
help="Output format (csv, json, xlsx, parquet, png, svg).",
|
|
36
|
+
),
|
|
37
|
+
output: str | None = typer.Option(None, "--output", "-o", help="Output file path."),
|
|
38
|
+
no_header: bool = typer.Option(
|
|
39
|
+
False, "--no-header", help="Omit header row from CSV output."
|
|
40
|
+
),
|
|
41
|
+
no_cache: bool = typer.Option(False, "--no-cache", help="Disable caching."),
|
|
42
|
+
show_all: bool = typer.Option(
|
|
43
|
+
False, "--all", "-A", help="Print full table instead of truncated display."
|
|
44
|
+
),
|
|
45
|
+
agg: str | None = typer.Option(
|
|
46
|
+
None,
|
|
47
|
+
"--agg",
|
|
48
|
+
help="Aggregation function to apply via pandas .agg() (e.g. mean, sum, min, max).",
|
|
49
|
+
),
|
|
50
|
+
) -> None:
|
|
51
|
+
"""Fetch monthly weather data."""
|
|
52
|
+
fetch_timeseries(
|
|
53
|
+
granularity="monthly",
|
|
54
|
+
stations=stations,
|
|
55
|
+
start=start,
|
|
56
|
+
end=end,
|
|
57
|
+
parameters=parameters,
|
|
58
|
+
providers=providers,
|
|
59
|
+
no_models=no_models,
|
|
60
|
+
with_sources=with_sources,
|
|
61
|
+
no_cache=no_cache,
|
|
62
|
+
fmt=fmt,
|
|
63
|
+
output=output,
|
|
64
|
+
no_header=no_header,
|
|
65
|
+
show_all=show_all,
|
|
66
|
+
agg=agg,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
# Expose for registration in cli.py
|
|
71
|
+
monthly_cmd = _monthly
|
|
72
|
+
monthly_cmd_alias = _monthly
|
meteo/commands/nearby.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""Nearby stations command for the Meteostat CLI."""
|
|
2
|
+
|
|
3
|
+
import typer
|
|
4
|
+
|
|
5
|
+
from meteo.utils import detect_format, output_df
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def nearby_cmd(
|
|
9
|
+
lat: float = typer.Argument(..., help="Latitude."),
|
|
10
|
+
lon: float = typer.Argument(..., help="Longitude."),
|
|
11
|
+
limit: int = typer.Option(5, "--limit", "-l", help="Maximum number of stations."),
|
|
12
|
+
radius: int = typer.Option(5000, "--radius", "-r", help="Search radius in meters."),
|
|
13
|
+
fmt: str | None = typer.Option(
|
|
14
|
+
None, "--format", "-f", help="Output format (csv, json, xlsx, parquet)."
|
|
15
|
+
),
|
|
16
|
+
output: str | None = typer.Option(None, "--output", "-o", help="Output file path."),
|
|
17
|
+
no_header: bool = typer.Option(
|
|
18
|
+
False, "--no-header", help="Omit header row from CSV output."
|
|
19
|
+
),
|
|
20
|
+
show_all: bool = typer.Option(
|
|
21
|
+
False, "--all", "-A", help="Print full table instead of truncated display."
|
|
22
|
+
),
|
|
23
|
+
) -> None:
|
|
24
|
+
"""Find weather stations near a location."""
|
|
25
|
+
import meteostat as ms
|
|
26
|
+
|
|
27
|
+
if not (-90 <= lat <= 90):
|
|
28
|
+
typer.echo(f"Error: Latitude must be between -90 and 90, got {lat}.", err=True)
|
|
29
|
+
raise typer.Exit(2)
|
|
30
|
+
if not (-180 <= lon <= 180):
|
|
31
|
+
typer.echo(
|
|
32
|
+
f"Error: Longitude must be between -180 and 180, got {lon}.", err=True
|
|
33
|
+
)
|
|
34
|
+
raise typer.Exit(2)
|
|
35
|
+
|
|
36
|
+
point = ms.Point(lat, lon)
|
|
37
|
+
df = ms.stations.nearby(point, radius=radius, limit=limit)
|
|
38
|
+
|
|
39
|
+
actual_fmt = detect_format(fmt, output)
|
|
40
|
+
output_df(df, actual_fmt, output, no_header, show_all=show_all)
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""Climate normals command for the Meteostat CLI."""
|
|
2
|
+
|
|
3
|
+
from typing import Annotated
|
|
4
|
+
|
|
5
|
+
import typer
|
|
6
|
+
|
|
7
|
+
from meteo.utils import fetch_timeseries
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _normals(
|
|
11
|
+
stations: Annotated[
|
|
12
|
+
list[str],
|
|
13
|
+
typer.Argument(
|
|
14
|
+
help="Station ID(s), or coordinates as lat,lon (e.g. 48.1,11.6)."
|
|
15
|
+
),
|
|
16
|
+
],
|
|
17
|
+
start: str | None = typer.Option(None, "--start", "-s", help="Start year (YYYY)."),
|
|
18
|
+
end: str | None = typer.Option(None, "--end", "-e", help="End year (YYYY)."),
|
|
19
|
+
parameters: str | None = typer.Option(
|
|
20
|
+
None, "--parameters", "-p", help="Comma-separated list of parameters."
|
|
21
|
+
),
|
|
22
|
+
providers: str | None = typer.Option(
|
|
23
|
+
None, "--providers", "-P", help="Comma-separated list of providers."
|
|
24
|
+
),
|
|
25
|
+
no_models: bool = typer.Option(False, "--no-models", help="Exclude model data."),
|
|
26
|
+
with_sources: bool = typer.Option(
|
|
27
|
+
False, "--with-sources", "-S", help="Include data source information."
|
|
28
|
+
),
|
|
29
|
+
fmt: str | None = typer.Option(
|
|
30
|
+
None,
|
|
31
|
+
"--format",
|
|
32
|
+
"-f",
|
|
33
|
+
help="Output format (csv, json, xlsx, parquet, png, svg).",
|
|
34
|
+
),
|
|
35
|
+
output: str | None = typer.Option(None, "--output", "-o", help="Output file path."),
|
|
36
|
+
no_header: bool = typer.Option(
|
|
37
|
+
False, "--no-header", help="Omit header row from CSV output."
|
|
38
|
+
),
|
|
39
|
+
no_cache: bool = typer.Option(False, "--no-cache", help="Disable caching."),
|
|
40
|
+
show_all: bool = typer.Option(
|
|
41
|
+
False, "--all", "-A", help="Print full table instead of truncated display."
|
|
42
|
+
),
|
|
43
|
+
agg: str | None = typer.Option(
|
|
44
|
+
None,
|
|
45
|
+
"--agg",
|
|
46
|
+
help="Aggregation function to apply via pandas .agg() (e.g. mean, sum, min, max).",
|
|
47
|
+
),
|
|
48
|
+
) -> None:
|
|
49
|
+
"""Fetch climate normals data."""
|
|
50
|
+
fetch_timeseries(
|
|
51
|
+
granularity="normals",
|
|
52
|
+
stations=stations,
|
|
53
|
+
start=start,
|
|
54
|
+
end=end,
|
|
55
|
+
parameters=parameters,
|
|
56
|
+
providers=providers,
|
|
57
|
+
no_models=no_models,
|
|
58
|
+
with_sources=with_sources,
|
|
59
|
+
no_cache=no_cache,
|
|
60
|
+
fmt=fmt,
|
|
61
|
+
output=output,
|
|
62
|
+
no_header=no_header,
|
|
63
|
+
show_all=show_all,
|
|
64
|
+
agg=agg,
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
# Expose for registration in cli.py
|
|
69
|
+
normals_cmd = _normals
|
|
70
|
+
normals_cmd_alias = _normals
|