Skip to content

Commit c8eed11

Browse files
authored
Merge pull request #52 from J-Lentz/tentative-cylc-updates
Support remainder PP chunks
2 parents 0215cea + 4861c7a commit c8eed11

File tree

5 files changed

+161
-201
lines changed

5 files changed

+161
-201
lines changed

Jinja2Filters/form_remap_dep.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def form_remap_dep(grid_type: str,
5656
# Note: history_segment should be specified for primary chunk generation,
5757
# and omitted for secondary chunk generation.
5858
if output_type == "ts":
59-
if history_segment == chunk:
59+
if str(history_segment) == str(chunk):
6060
prereq_task = "rename-split-to-pp"
6161
else:
6262
prereq_task = "make-timeseries"

Jinja2Filters/iter_chunks.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from metomi.isodatetime.parsers import DurationParser, TimePointParser
2+
3+
def iter_chunks(chunk_sizes, history_segment, pp_start, pp_stop):
4+
"""Return an iterator over all PP chunks. For each chunk, a dictionary is
5+
yielded consisting of `chunk_size`, `cycle_point`, `segments`, and `is_partial` keys.
6+
7+
Arguments:
8+
chunk_sizes (list of strings)
9+
history_segment (string)
10+
pp_start (string)
11+
pp_stop (string)
12+
13+
Example:
14+
>>> list(iter_chunks(["P2Y", "P3Y"], "P1Y", "0001", "0003"))
15+
Result:
16+
[
17+
{
18+
'chunk_size': Duration<P2Y>,
19+
'cycle_point': TimePoint<0001-01-01>,
20+
'segments': [TimePoint<0001-01-01>, TimePoint<0002-01-01>],
21+
'is_partial': False
22+
},
23+
{
24+
'chunk_size': Duration<P2Y>,
25+
'cycle_point': TimePoint<0003-01-01>,
26+
'segments': [TimePoint<0003-01-01>],
27+
'is_partial': True
28+
},
29+
{
30+
'chunk_size': Duration<P3Y>,
31+
'cycle_point': TimePoint<0001-01-01>,
32+
'segments': [TimePoint<0001-01-01>, TimePoint<0002-01-01>, TimePoint<0003-01-01>],
33+
'is_partial': False
34+
}
35+
]
36+
"""
37+
duration_parser = DurationParser()
38+
time_point_parser = TimePointParser(default_to_unknown_time_zone=True)
39+
40+
chunk_sizes = (duration_parser.parse(cs) for cs in chunk_sizes)
41+
history_segment = duration_parser.parse(history_segment)
42+
pp_start = time_point_parser.parse(pp_start)
43+
pp_stop = time_point_parser.parse(pp_stop)
44+
45+
def n_segments(interval):
46+
return int(interval.get_seconds() / history_segment.get_seconds())
47+
48+
for cs in chunk_sizes:
49+
n_segments_full_chunk = n_segments(cs)
50+
cycle_point = pp_start
51+
while cycle_point <= pp_stop:
52+
n_segments_remaining = n_segments(pp_stop + history_segment - cycle_point)
53+
n = min(n_segments_full_chunk, n_segments_remaining)
54+
yield {
55+
'chunk_size': cs,
56+
'cycle_point': cycle_point,
57+
'segments': [cycle_point + history_segment*i for i in range(n)],
58+
'is_partial': False if n == n_segments_full_chunk else True
59+
}
60+
cycle_point += cs

app/make-timeavgs/bin/make-timeavgs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ for dir in ${dirs[@]}; do
5656

5757
#now need to pick the right date-time format for the cycle-point
5858
if [[ $file_freq == P1M ]]; then
59-
cyclepoint=$(cylc cycle-point --template CCYY12)
59+
cyclepoint=$(cylc cycle-point --template CCYYMM)
6060
tool_args=month
6161
elif [[ $file_freq == P1Y ]]; then
6262
cyclepoint=$(cylc cycle-point --template CCYY)
@@ -66,7 +66,7 @@ for dir in ${dirs[@]}; do
6666
continue
6767
fi
6868

69-
files=($(ls $dir/$interval/$component.*-$cyclepoint.*.nc))
69+
files=($(ls $dir/$interval/$component.$cyclepoint-*.*.nc))
7070
if [[ ${#files[@]} -lt 1 ]]; then
7171
echo "---WARNING--- no files found in directory $dir!"
7272
echo "moving on to next directory..."

app/make-timeseries/bin/make-timeseries

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ echo " output dir: $outputDir"
126126
echo " begin: $begin"
127127
echo " input chunk: $inputChunk"
128128
echo " output chunk: $outputChunk"
129+
echo " pp stop: $pp_stop"
129130
echo " component: $component"
130131
echo " components allowed to fail: ${fail_ok_components:=}"
131132
echo " use subdirs: ${use_subdirs:=}"
@@ -134,7 +135,18 @@ type cdo
134135
type isodatetime
135136

136137
# Determine how many expected files to concatenate
137-
expectedChunks=$(( $(isodatetime --as-total=H $outputChunk | sed -e 's/\.0$//') / $(isodatetime --as-total=H $inputChunk | sed -e 's/\.0$//') ))
138+
inputChunkHrs=$(isodatetime --as-total=H $inputChunk | sed -e 's/\.0$//')
139+
expectedChunks=$(( $(isodatetime --as-total=H $outputChunk | sed -e 's/\.0$//') / inputChunkHrs ))
140+
availChunks=$(( $(isodatetime --as-total=H $begin $pp_stop --offset2=$inputChunk | sed -e 's/\.0$//') / inputChunkHrs ))
141+
142+
if ((availChunks >= expectedChunks))
143+
then
144+
end=$(isodatetime $begin --offset $outputChunk)
145+
else
146+
expectedChunks=$availChunks
147+
end=$(isodatetime $pp_stop --offset $inputChunk)
148+
fi
149+
138150
if (( expectedChunks > 0 )); then
139151
echo NOTE: Expect to concatenate $expectedChunks subchunks
140152
else
@@ -161,8 +173,6 @@ if [ ! -z "${EPMT_DATA_LINEAGE+x}" ] && [ "$EPMT_DATA_LINEAGE" = "1" ]; then
161173
echo "Set PYTHONPATH and created i/o lists"
162174
fi
163175

164-
# Calculate end date
165-
end=$(isodatetime $begin --offset $outputChunk)
166176
# remove trailing Z to allow string comparison later
167177
begin=${begin%Z}
168178
end=${end%Z}

0 commit comments

Comments
 (0)