Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
Merge branch 'feature/insolation_plus_6' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
floriankrb committed Feb 26, 2024
2 parents 347929b + df2df0c commit 73cfa60
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 327 deletions.
69 changes: 0 additions & 69 deletions ecml_tools/create/functions/actions/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,81 +6,12 @@
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.
#
from copy import deepcopy

from climetlab import load_source

from ecml_tools.create.utils import to_datetime_list

DEBUG = True


def to_list(x):
if isinstance(x, (list, tuple)):
return x
return [x]


def get_template_field(request):
"""Create a template request from the initial request, setting the date, time,
levtype and param fields."""
template_request = {
"class": "ea",
"expver": "0001",
"type": "an",
"date": "20200101",
"time": "0000",
"levtype": "sfc",
"param": "2t",
}
for k in ["area", "grid"]: # is class needed?
if k in request:
template_request[k] = request[k]
template = load_source("mars", template_request)
assert len(template) == 1, (len(template), template_request)
return template


def normalise_time_to_hours(r):
r = deepcopy(r)
if "time" not in r:
return r

times = []
for t in to_list(r["time"]):
assert len(t) == 4, r
assert t.endswith("00"), r
times.append(int(t) // 100)
r["time"] = tuple(times)
return r


def constants(context, dates, template, param):
context.trace("✅", f"load_source(constants, {template}, {param}")
return load_source("constants", source_or_dataset=template, date=dates, param=param)


execute = constants

if __name__ == "__main__":
import yaml

config = yaml.safe_load(
"""
class: ea
expver: '0001'
grid: 20.0/20.0
levtype: sfc
# param: [10u, 10v, 2d, 2t, lsm, msl, sdor, skt, slor, sp, tcw, z]
number: [0, 1]
param: [cos_latitude]
"""
)
dates = yaml.safe_load(
"[2022-12-30 18:00, 2022-12-31 00:00, 2022-12-31 06:00, 2022-12-31 12:00]"
)
dates = to_datetime_list(dates)

DEBUG = True
for f in constants(None, dates, **config):
print(f, f.to_numpy().mean())
245 changes: 0 additions & 245 deletions ecml_tools/create/group.py

This file was deleted.

Loading

0 comments on commit 73cfa60

Please sign in to comment.