Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- Added checks of invalid configuration combinations [!22](https://github.com/dmidk/sunflow/pull/22), @KristianHMoller
- Added `{second}` and `{munite}` as a filename formatting variable [!15](https://github.com/dmidk/sunflow/pull/15), @JoachimKoenigslieb
- Use `.expand_dims` instead of `.assign_coords` to make sure we have both time dimension and time coordinates when loading from files [!15](https://github.com/dmidk/sunflow/pull/15), @JoachimKoenigslieb
- Added a `clearsky` config object which can load clear-sky data from files via `clearsky.path` or generate it with `pvlib` via the `simplified_solis` method [!15](https://github.com/dmidk/sunflow/pull/15), @JoachimKoenigslieb
- `check_solar_elevation` now does not assume location is in Copenhagen by default [!15](https://github.com/dmidk/sunflow/pull/15), @JoachimKoenigslieb
- Added `MIN_SOLAR_ELEVATION_DEGREES` (defaulting to 6 degrees) to configure the minimum maximum-corner solar elevation required to run [!15](https://github.com/dmidk/sunflow/pull/15), @JoachimKoenigslieb

### Changed

- Use `.expand_dims` instead of `.assign_coords` to make sure we have both time dimension and time coordinates when loading from files [!15](https://github.com/dmidk/sunflow/pull/15), @JoachimKoenigslieb
- `check_solar_elevation` now does not assume location is in Copenhagen by default [!15](https://github.com/dmidk/sunflow/pull/15), @JoachimKoenigslieb

## [v1.2.0]

Expand Down
5 changes: 5 additions & 0 deletions sunflow/downloaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ def download_current_data(
merged_ds = subset_to_bbox(ds, bbox)
current_time = merged_ds.time.values[0]

else:
raise ValueError(
f"Unsupported dataset_name: {dataset_name} " f"for run_mode 'download'"
)

# Save data
current_time_dt = current_time.astype("datetime64[s]").astype(datetime)
filename = generate_input_filename(
Expand Down
28 changes: 16 additions & 12 deletions sunflow/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from dataclasses import dataclass
from datetime import datetime, timedelta, timezone
from enum import Enum
from typing import Any

import isodate
import numpy as np
Expand Down Expand Up @@ -221,6 +222,7 @@ def run_nowcast(
domain_satellite_name: str,
nowcast_config: NowcastConfig,
s3_config: S3Config,
clearsky_config: dict[str, Any],
full_ensemble: bool = False,
custom_time: bool = True,
) -> RunResult:
Expand All @@ -236,6 +238,7 @@ def run_nowcast(
domain_satellite_name: Domain identifier used for input filenames.
nowcast_config: NowcastConfig object.
s3_config: S3Config object.
clearsky_config: Clearsky configuration dict.
full_ensemble: If True, save all ensemble members. If False,
save configured ensemble statistics over ensemble members.
custom_time: If True, skip the retry wait loop on missing data.
Expand All @@ -247,10 +250,6 @@ def run_nowcast(
time_step_str = time_step.strftime("%Y-%m-%dT%H:%M:%SZ")
logger.info(f"--- Running nowcast for {time_step_str} ---")
nc_variable_names = config["nc_variable_names"].copy()
clearsky_config = config.get(
"clearsky",
{"method": "file", "path": config["filename_format"]},
)

# Fetch current data (with retry loop in operational mode)
fetch_current_data_with_retry(
Expand Down Expand Up @@ -349,7 +348,7 @@ def run_nowcast(
nowcast_config.max_clearsky_fallback_days,
clearsky_config["path"],
config,
domain_nowcast,
domain_satellite,
dataset_name,
domain_satellite_name,
nowcast_config,
Expand Down Expand Up @@ -553,14 +552,20 @@ def cli() -> None:
f"Starting solarnowcasting.main (with configuration version: {model_version})..."
)

# Load configuration
args = parse_arguments()
nowcast_config = NowcastConfig.from_env(ensemble_members=args.ensemble_members)
s3_config = S3Config.from_env()

run_mode = args.run_mode
dataset_name = args.dataset
domain_satellite_name = args.domain_satellite

# Load configurations
nowcast_config = NowcastConfig.from_env(ensemble_members=args.ensemble_members)
s3_config = S3Config.from_env()
config = yaml.safe_load(open("config.yaml"))[dataset_name]
clearsky_config = config.get(
"clearsky",
{"method": "file", "path": config["filename_format"]},
)

domain_satellite = resolve_domain_bbox(
domain_satellite_name,
args.custom_domain_satellite,
Expand Down Expand Up @@ -593,8 +598,6 @@ def cli() -> None:
f"domain_nowcast={domain_nowcast}."
)

config = yaml.safe_load(open("config.yaml"))[dataset_name]

if run_mode != "s3":
os.makedirs(nowcast_config.nowcast_directory, exist_ok=True)

Expand Down Expand Up @@ -627,7 +630,7 @@ def cli() -> None:
"Consider setting alpha=0.0 and beta=0.0 for a single-member run."
)

validate_run_mode(run_mode, dataset_name)
validate_run_mode(run_mode, dataset_name, clearsky_config)
validate_config(config, dataset_name)
validate_nowcast_config(nowcast_config)
verify_environment_variables(run_mode, dataset_name)
Expand Down Expand Up @@ -681,6 +684,7 @@ def cli() -> None:
domain_satellite_name,
nowcast_config,
s3_config,
clearsky_config,
full_ensemble=args.full_ensemble,
custom_time=custom_time,
)
Expand Down
12 changes: 11 additions & 1 deletion sunflow/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ def validate_nowcast_config(nowcast_config: NowcastConfig) -> None:
sys.exit(1)


def validate_run_mode(run_mode: str, dataset_name: str) -> None:
def validate_run_mode(
run_mode: str, dataset_name: str, clearsky_config: dict[str, Any]
) -> None:
"""Validate that the run mode is compatible with the dataset.

Exits immediately if the combination of run mode and dataset name
Expand All @@ -100,6 +102,7 @@ def validate_run_mode(run_mode: str, dataset_name: str) -> None:
Args:
run_mode: The requested run mode ('download', 'files', or 's3').
dataset_name: Name of the dataset.
clearsky_config: Clearsky configuration dictionary.

Raises:
SystemExit: If the run mode is incompatible with the dataset.
Expand All @@ -111,6 +114,13 @@ def validate_run_mode(run_mode: str, dataset_name: str) -> None:
"Use run_mode 'files' or 's3' instead. Exiting.\n"
)
sys.exit(1)
if run_mode == "download" and clearsky_config["method"] == "pvlib":
logger.error(
"Currently the pvlib clearsky method is not supported "
"for run_mode 'download'. "
"Use run_mode 'files' or 's3' instead. Exiting.\n"
)
sys.exit(1)


def verify_environment_variables(run_mode: str, dataset_name: str) -> None:
Expand Down
Loading