Skip to content

Commit

Permalink
fixed _frequency_from_approx_interval
Browse files Browse the repository at this point in the history
  • Loading branch information
siligam committed Nov 13, 2024
1 parent a2115e3 commit ddc85fc
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions src/pymorize/timeaverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@

import pandas as pd
import xarray as xr

import numpy as np
import functools
from .logging import logger


Expand Down Expand Up @@ -135,23 +136,19 @@ def _frequency_from_approx_interval(interval: str):
("year", lambda x: f"{x}YE", 365),
("month", lambda x: f"{x}ME", 30),
("day", lambda x: f"{x}D", 1),
("hour", lambda x: f"{x}H", 24),
("minute", lambda x: f"{x}min", 24 * 60),
("second", lambda x: f"{x}s", 24 * 60 * 60),
("millisecond", lambda x: f"{x}ms", 24 * 60 * 60 * 1000),
("hour", lambda x: f"{x}H", 1 / 24),
("minute", lambda x: f"{x}min", 1.0 / (24 * 60)),
("second", lambda x: f"{x}s", 1.0 / (24 * 60 * 60)),
("millisecond", lambda x: f"{x}ms", 1.0 / (24 * 60 * 60 * 1000)),
]
try:
interval = float(interval)
except ValueError:
return interval
to_divide = {"decade", "year", "month", "day"}
isclose = functools.partial(np.isclose, rtol=1e-3)
for name, func, val in notation:
if name in to_divide:
value = interval // val
else:
value = interval * val
if value >= 1:
value = round(value)
if (interval >= val) or isclose(interval, val):
value = round(interval / val)
value = "" if value == 1 else value
return func(value)

Expand Down Expand Up @@ -313,7 +310,5 @@ def compute_average(da: xr.DataArray, rule):
time: mean
time: mean grid_longitude: mean
time: point
""".strip().split(
"\n"
)
""".strip().split("\n")
"""list: cell_methods to ignore when calculating time averages"""

0 comments on commit ddc85fc

Please sign in to comment.