Community Engagement Improves UW Tools #602
maddenp-noaa
started this conversation in
Blog
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
It's no accident that the Unified Workflow Tools repo lives in the ufs-community GitHub organization, or that we publish our conda packages to a ufs-community channel: We are building tools to address community needs, and community engagement -- via discussions, feature requests, and, yes, even bug reports -- is crucial to growing the utility of
uwtools
in solving recurring NWP workflow problems.We've already received some excellent suggestions from users that have led to our implementing valuable new
uwtools
features. Here are a few.Accepting
uw config realize
update values onstdin
Like most tools in the Unix tradition,
uw
accepts input piped in viastdin
as an alternative to disk files. Early on,uw config realize
supported providing its input config viastdin
, but required that update values come from a file. So the following has long worked: Givenupdate.yaml
we can update the Fortran namelist config provided on
stdin
with the values from the YAML file:However, an important (and probably even more common) use case involves an input config file, updated with values read from
stdin
. Based on user feedback, we added support for this touwtools
, activated on the CLI by use of the--update-format
flag. Givenconfig.nml
we can update the Fortran namelist in
config.nml
with values supplied onstdin
:The
uw config realize
--total
flagThe default behavior of
uw config realize
is to render as many embedded Jinja2 expressions as possible, leaving others intact, potentially to be rendered by later processing. For example, a config might define the name of an atmospheric analysis file, based on a prefix read from an environment variable:config.yaml
If we already know that GFS analysis will be used, we might want to partially realize the config with that information:
partial.yaml
Later,
partial.yaml
could be fully realized by providing cycle information:The above demonstrates why partial rendering can be useful. However, we often want to fully realize a config immediately:
But what if we've introduced an error that prevents this? A
uwtools
user suggested to us that a way to detect an incompletely realized config and fail early could save time and make troubleshooting easier. We added the--total
flag to provide this mechanism.For example:
Here,
--total
causesuw
to exit with error status (which could be used to terminate e.g. a Bash script callinguw
) after advising us to use the--values-needed
flag to report unrendered Jinja2 expressions. The--values-needed
output makes the typo (h
instead ofhh
) easy to spot.Support for Jinja2 macros in
uw template render
Jinja2 provides support for macros, which can be accessed in a template via its
import
directive. Guided by a bug report filed by a user, we added support for importing macros in templates processed byuw template render
.For example, given a file containing a Jinja2 macro:
macros.jinja2
and a template file referencing it:
template.jinja2
we can render the template into a script for downloading some GFS forecast files:
The
macros.jinja2
file could be reused byimport
ing it into other templates, keeping knowledge about the upstream location of these files DRY.(Note that
template.jinja2
could findmacros.jinja2
because they were located in the same directory. The optional--search-path
option can be used to provide a colon-delimited list of directories to search for Jinja2 macro files.)File copy/link tool
A common need in NWP workflows involves copying or linking standard sets of files into run directories. Based on a feature request from a user, we added this functionality to
uwtools
.While a one-off implementation isn't difficult to achieve in, say, Bash,
uwtools
support means thatuw config realize
oruw template render
.For example, we might need to use cycle and leadtime information in various ways like in:
config.yaml
We can symlink an analysis file by using the
link
action and selecting theanl
block:And we can copy a forecast file by using the
copy
action and selecting thefcst
block:The result:
In a near-future release, we will be renaming the
file
modefs
("filesystem") and adding amakedirs
action that can be used to create directory structures.🦾
We'd like to thank our users who have already given us valuable feedback leading to
uwtools
improvements that we hope will benefit our entire community. If you are reading this, you, too, are part of our community, and we'd love to hear from you in our Discussions or, yes, even in our Issues. Not every potential feature will be a good fit foruwtools
, but we have been able to implement those shown here, and several others, so far. Help us makeuwtools
even better!Beta Was this translation helpful? Give feedback.
All reactions