Skip to content

Commit f81020e

Browse files
committed
Update: omit day in date
1 parent b950755 commit f81020e

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

kaleidoscope/main/resolve.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def _add_arguments(parser):
8686
parser.add_argument(
8787
"target_file",
8888
help="the file path pattern of target datasets. Patterns "
89-
"YYYY/MM and YYYYMMDD are replaced with the date associated "
89+
"YYYY/MM and YYYYMM are replaced with the date associated "
9090
"with the time step extracted. The pattern ZZZZ is replaced "
9191
"with the depth level, if applicable.",
9292
type=Path,
@@ -142,7 +142,7 @@ def _add_version(parser):
142142
)
143143

144144

145-
def date(t: DataArray, f: str = "%Y%m%d") -> str:
145+
def date(t: DataArray, f: str = "%Y%m") -> str:
146146
"""
147147
Converts a time stamp into a formatted date.
148148
@@ -237,39 +237,39 @@ def run(self, args: Namespace): # noqa: D102
237237
target: Dataset = source.isel(
238238
{VID_TIM: i, VID_DEP: k}
239239
)
240-
writer: Writing = self._create_writer(args)
241240
target_path: Path = Path(
242241
f"{args.target_file}".replace(
243242
"YYYY/MM", date(t[i], "%Y/%m")
244243
)
245-
.replace("YYYYMMDD", date(t[i]))
244+
.replace("YYYYMM", date(t[i]))
246245
.replace("ZZZZ", index(k))
247246
)
248-
if not target_path.parent.exists():
249-
target_path.parent.mkdir(parents=True)
250-
try:
251-
writer.write(target, target_path)
252-
finally:
253-
target.close()
247+
self._write_target(args, target, target_path)
254248
else:
255249
target: Dataset = source.isel({VID_TIM: i})
256-
writer: Writing = self._create_writer(args)
257250
target_path: Path = Path(
258251
f"{args.target_file}".replace(
259252
"YYYY/MM", date(t[i], "%Y/%m")
260-
).replace("YYYYMMDD", date(t[i]))
253+
).replace("YYYYMM", date(t[i]))
261254
)
262-
if not target_path.parent.exists():
263-
target_path.parent.mkdir(parents=True)
264-
try:
265-
writer.write(target, target_path)
266-
finally:
267-
target.close()
255+
self._write_target(args, target, target_path)
268256
get_logger().info(f"finished writing time step")
269257
finally:
270258
if source is not None:
271259
source.close()
272260

261+
def _write_target(
262+
self, args: Namespace, target: Dataset, target_path: Path
263+
):
264+
"""This method does not belong to public API."""
265+
if not target_path.parent.exists():
266+
target_path.parent.mkdir(parents=True)
267+
writer: Writing = self._create_writer(args)
268+
try:
269+
writer.write(target, target_path)
270+
finally:
271+
target.close()
272+
273273
def get_result( # noqa: D102
274274
self, args: Namespace, *inputs: Dataset
275275
) -> Dataset:

0 commit comments

Comments
 (0)