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
4 changes: 3 additions & 1 deletion climanet/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import numpy as np
import xarray as xr
import torch
import time

from torch.utils.tensorboard import SummaryWriter

Expand Down Expand Up @@ -222,7 +223,8 @@ def set_seed(seed: int = 42):
def setup_logging(log_dir: str) -> SummaryWriter:
"""Set up TensorBoard logging directory and writer."""
Path(log_dir).mkdir(parents=True, exist_ok=True)
return SummaryWriter(log_dir)
timestamp_utc = time.strftime("%Y%m%dT%H%M%S", time.gmtime())
return SummaryWriter(log_dir, filename_suffix=f'_UTC{timestamp_utc}')


def compute_masked_loss(
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dependencies = [
"matplotlib>=3.10.8",
"netcdf4>=1.7.4",
"scipy>=1.17.1",
"tbparse>=0.0.9",
"tensorboard",
"torch>=2.10.0",
"xarray>=2025.12.0",
Expand Down
21 changes: 19 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
def test_dummy():
assert True
from climanet.utils import setup_logging
from tbparse import SummaryReader


def test_setup_logging(tmp_path):
writer = setup_logging(tmp_path)
log_text = "This is a test log entry."
writer.add_scalar("Test Scalar", 42)
writer.add_text("Test Text", log_text)
writer.close()

# Test that there is one event file
# The file should have "UTC" keyword in timestamp suffix
assert len(list(tmp_path.glob("events*UTC*"))) == 1

# Load the events file with SummaryReader
reader = SummaryReader(tmp_path)
assert reader.text["value"].iloc[0] == log_text # check text
assert reader.scalars["value"].iloc[0] == 42 # check scalar