Community Engagement Improves UW Tools #602
maddenp-cu
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
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
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
uwtoolsin solving recurring NWP workflow problems.We've already received some excellent suggestions from users that have led to our implementing valuable new
uwtoolsfeatures. Here are a few.Accepting
uw config realizeupdate values onstdinLike most tools in the Unix tradition,
uwaccepts input piped in viastdinas an alternative to disk files. Early on,uw config realizesupported providing its input config viastdin, but required that update values come from a file. So the following has long worked: Givenupdate.yamlwe can update the Fortran namelist config provided on
stdinwith 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-formatflag. Givenconfig.nmlwe can update the Fortran namelist in
config.nmlwith values supplied onstdin:The
uw config realize--totalflagThe default behavior of
uw config realizeis 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.yamlIf we already know that GFS analysis will be used, we might want to partially realize the config with that information:
partial.yamlLater,
partial.yamlcould 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
uwtoolsuser 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--totalflag to provide this mechanism.For example:
Here,
--totalcausesuwto exit with error status (which could be used to terminate e.g. a Bash script callinguw) after advising us to use the--values-neededflag to report unrendered Jinja2 expressions. The--values-neededoutput makes the typo (hinstead ofhh) easy to spot.Support for Jinja2 macros in
uw template renderJinja2 provides support for macros, which can be accessed in a template via its
importdirective. 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.jinja2and a template file referencing it:
template.jinja2we can render the template into a script for downloading some GFS forecast files:
The
macros.jinja2file could be reused byimporting it into other templates, keeping knowledge about the upstream location of these files DRY.(Note that
template.jinja2could findmacros.jinja2because they were located in the same directory. The optional--search-pathoption 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,
uwtoolssupport means thatuw config realizeoruw template render.For example, we might need to use cycle and leadtime information in various ways like in:
config.yamlWe can symlink an analysis file by using the
linkaction and selecting theanlblock:And we can copy a forecast file by using the
copyaction and selecting thefcstblock:The result:
In a near-future release, we will be renaming the
filemodefs("filesystem") and adding amakedirsaction that can be used to create directory structures.🦾
We'd like to thank our users who have already given us valuable feedback leading to
uwtoolsimprovements 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 makeuwtoolseven better!Beta Was this translation helpful? Give feedback.
All reactions