Importing metplus modules to external python scripts #2635
-
Hi, I have come up with a potentially interesting use case for METplus tools, and I was curious to get some feedback from the METplus developers on my implementation, whether that feedback is "that looks fine", "there's a better way to do that", "please don't open that can of worms", or some other reaction. The use case mainly boils down to how we currently use METplus in the context of the UFS SRW Application. Because we want to avoid duplication of information while allowing users as much flexibility as possible, we allow users to use METplus wildcards for filenames; e.g. for reading in forecast files
I realize this is undocumented and likely not an intended use of METplus (directly accessing internal functions like this) but I found that this dramatically decreases the complexity of our scripts, and ensures self-consistency with the handling of filenames in our workflow. Since I can't find any references to other people attempting this sort of thing, I thought it made sense to open a discussion here so developers and others might offer feedback. Let me know if you'd like more information, I could post the full script or even a full example use case if that would be helpful. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
@mkavulich, big picture, I certainly don't have any objection to accessing functionality provided by any of the METplus Python components. We'd like the METplus wrappers to work well out of the box, but providing them as modules that can be loaded facilitates advanced usage like what you're doing. The only potential downside would be if future changes to the METplus string template substitution logic broke the logic in SRW. But you can protect against that using automated testing to figure out as soon as something changes. And I certainly don't expect any changes that'd break the logic. That being said, I want to call your attention to some work that's on @georgemccabe's plate. #2524 is intended to check for the amount of valid input files and only run if a configurable threshold is met. Folks at NOAA had been doing this upstream with shell scripts, and @georgemccabe has been working to replicate that logic directly through METplus wrappers. However @georgemccabe just went on parental leave, so I don't have any guarantee on whether the complete set of changes will make it into the next release. But I just wanted to put it on your radar. So while using string template substitution directly is great, you may find that validating input files can also be done directly by METplus in the future. |
Beta Was this translation helpful? Give feedback.
-
Hi @mkavulich, I agree with @JohnHalleyGotway's response above. It sounds like the solution outlined in issue #2524 would allow you to configure METplus to perform the available input file checks and prevent a timely/costly run if insufficient files were found. However, since this issue is not marked as required for the official release, it is unclear if this enhancement will make it into the next release. It is good to know that this functionality would be useful to your project as well. This helps to prioritize this work. Regarding the import of the metplus python module in your scripts: As you have discovered, it is certainly possible to import metplus into your own python script. You can even install the module into your python environment by running A few comments on the code snippet you shared:
I hope this lengthy response is helpful and answers your questions. Feel free to post your full python script here if you'd like so other users can utilize the same behavior until issue #2524 is completed. |
Beta Was this translation helpful? Give feedback.
Hi @mkavulich,
I agree with @JohnHalleyGotway's response above.
It sounds like the solution outlined in issue #2524 would allow you to configure METplus to perform the available input file checks and prevent a timely/costly run if insufficient files were found. However, since this issue is not marked as required for the official release, it is unclear if this enhancement will make it into the next release. It is good to know that this functionality would be useful to your project as well. This helps to prioritize this work.
Regarding the import of the metplus python module in your scripts:
As you have discovered, it is certainly possible to import metplus into your own python script. You …