From 1dcf6165c1ca90691e53e9762bbe219dcce64b6d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 28 Jun 2024 11:02:52 -0600 Subject: [PATCH] Update develop-ref after dtcenter/MET#2921 (#2627) * Feature #1974 Documentation: update coding standards section (#2260) * Feature #2253 conftest fixture to set pytest tmpdir (#2261) * Feature #2151 Documentation: Add quick search keywords METplotpy/calcpy use cases (#2259) * Feature #2138 CI enhance MET Docker tag override (#2258) * Updating development instructions. * fixed typo * fixed another typo * Feature #2207 Documentation - Updates to Contributor's Guide (#2263) Co-authored-by: Dan Adriaansen * Feature develop update install files (#2266) * Updating installation files * Removing run_commands.sh * Updated the file to add a MINICONDA_PATH * Adding files for jet * Adding orion file * Removing beta references * Corrected met version * Adding files for WCOSS2 machines * Removing rc1 from acorn file * Removing beta1 * Bugfix #1853 develop - PointStat don't require mask variables to be set (#2262) * update version of certifi to match auto-generated dependabot PR #2267 * feature #2253 more tests for diff_util.py (#2264) * update versions of METplus components for the next official release * updated release notes for 5.1.0 release * removed duplicate entries in release notes * Added EC2 instance recipee with S3 mounting ability (#2269) * Updating the Subsetting Tests by Marker section (#2272) * update release date for 5.1.0 release (#2276) * update version for development towards 6.0.0-beta1 release * added new use case that was missing * Bugfix #2279 develop - buoy station file from 2022 (#2280) * Feature 2253 series analysis tests (#2277) * Fix typo in pull_request_template.md * Make code coverage report available (#2287) * Use updated dtcenter/metplus-action-data-update tag that fixes bug that causes GHA disk to exceed capacity when too many data volumes are created. Use specific commit of coveralls python action to ensure it will not change * removed climatology keyword from use cases that aren't relevant that were accidentally added with PR #1984 * update readme with current information * Feature #2282 coord_release_docs (#2288) Co-authored-by: George McCabe <23407799+georgemccabe@users.noreply.github.com> * continue workflow if coveralls step fails -- this typically happens on a pull request from a fork because the authentication fails * Feature 2253 system util tests (#2297) * Feature #2294 LSR use case (#2295) * Feature 2253 run util tests (#2307) * Release Guide - remove beta/rc tags/releases (#2309) * Add 'component: repository maintenance' label. Already ran the script to push this change and the NOAA OAR reporting label to all the METplus repos. * Hotfix for labels, adding a new one for 'component: input data' and also fixing the get_lablels.sh to search for up to 200 existing labels. Also work on the log messages. * Fix typo in comment * Feature #2283 time looping consolidation (#2311) Co-authored-by: John Halley Gotway * New issue template: Update Truth (#2332) Co-authored-by: John Halley Gotway * feature #2253 tests for run_util, 'Usage' bugfix (#2313) * Feature #2338 Debian 12 Conda environments (#2341) Co-authored-by: John Halley Gotway * Feature 1488 usecase satwinds (#2324) Co-authored-by: George McCabe <23407799+georgemccabe@users.noreply.github.com> * Feature #2283 include times (#2345) Co-authored-by: John Halley Gotway * feature #2253 tests for config_validate, mock logger in conftest (#2320) * Feature #2299 / #2310 Remove deprecated MET config env vars and TCMPRPlotter (#2347) Co-authored-by: John Halley Gotway * remove MODEL and OBTYPE to use defaults from MET config * Feature #2348 v6.0.0-beta1 release (#2351) * update version for development towards 6.0.0-beta2 release * copy libGL and libEGL files into docker image to prevent errors with geovista python package * run use that uses geovista to test * Feature #2156 release_acceptance_testing (#2352) * feature #2253 print error logs from conftest (#2358) * feature #2253 met_db_load tests (#2355) * Rename 5.1.0.lua_wcoss2 to 6.0.0.lua_wcoss2 * Update and rename 5.1.0_acorn to 6.0.0_acorn * Update 6.0.0_acorn * feature #2253 add tests for gfdl_tracker (#2354) Co-authored-by: George McCabe <23407799+georgemccabe@users.noreply.github.com> * Create 6.0.0_gaea * Update and rename 5.1.0_hera to 6.0.0_hera * Feature #2156 release_acceptance_testing take2 (#2361) Co-authored-by: lisagoodrich <33230218+lisagoodrich@users.noreply.github.com> * Feature #2329 Docker info in Installation Chapter (#2366) * feature_2253_extract_tiles_tests (#2368) * Feature 2253 tc pairs tests (#2369) * Feature 2253 tc csv writer (#2373) * update requirements for building docs to get around build failure where python packages required to build RTD have disappeared from the automatically generated commands from RTD * fix ReadTheDocs requirements to include pillow which is a dependency of sphinx-gallery: see https://blog.readthedocs.com/defaulting-latest-build-tools/ for more info on why this was necessary * Feature #2340 TCDiag one_time_per_file_flag (#2374) * Update and rename 5.1.0_jet to 6.0.0_jet * Added libssh * prune docker files before running use cases to prevent running out of disk space when running use cases, ci-run-all-diff * Feature 2253 command builder tests (#2378) * Feature 2253 series analysis test (#2380) * Feature 2253 py embed test (#2379) * ignore cyclone plotter from code coverage report because it will be replaced with METplotpy logic * Feature 898 headers (#2389) * changing _ to - for header consistency * changing _ to - for header consistency * updating all headers for consistency * updating all headers for consistency and adding spacing The spacing doesn't seem to be required but it is the convention that we follow for headers. * updating all headers for consistency * updating headers for consistency and adding capital letters to headers * Using the overline ### to keep index consistent with other indexes * updating all headers for consistency * update requirements for building docs to get around build failure where python packages required to build RTD have disappeared from the automatically generated commands from RTD * updating all headers and some spacing for consistency * updating headers for consistency * changing to ### for consistency * Per #898, fixed the headers for the Release Guide part, chapters, and sections. * Duplicating changes in develop branch for requirements.txt file * updating headers * Per #2669, updated header formatting to resolve errors * Per #2669, udpating header * Per #2669, udpating headers * Per #2669, udpating header * Per #2669, updated header formatting * Per #2669, update header formatting * updating headers * Per #898, removed space in front of title * Capitalizing Please * changing to just italics to match standard formatting * indenting for consistent formatting * fixing italics again * changing from note to warning for consistency * updating headers, adding some capitalizing to the headers * fixing typo Co-authored-by: George McCabe <23407799+georgemccabe@users.noreply.github.com> * This file was committed but never updated or used Per Minna, ok to delete. * Restructuring table of contents to make it more clear which guides are for users and which are for contributors * fixing formatting for clairity Co-authored-by: Julie Prestopnik --------- Co-authored-by: George McCabe <23407799+georgemccabe@users.noreply.github.com> Co-authored-by: Julie Prestopnik * Feature #2349 upgrade instructions for deprecated MET config files (#2386) * Feature 2123 di doc update (#2392) Co-authored-by: Tracy * change log to list name of config variable , e.g. GRID_STAT_CONFIG_FILE, to easily see which variable should be removed * Major refactor including elimination of unnecessary imports, only computing the index for the season requested instead of all seasons all the time, which also fixes a bug selecting which season the user requested. Results are identical for all seasons for the test data for the use case. * Feature 1667 doc conventions (#2397) * New additions based on the old branch feature_1667_updating_overview * Moving the release-notes reference label * Added label for METplus_glossary for use in Documentation conentions section. * Adding images for the Documentation Conventions section * Modifying wording and testing formatting in Internal Links section * Second take on formatting * Third attempt at formatting * Fourth attempt at formatting * Modified wording, sections, and formatting * Minor modifications * Added period * Changed Pretty Table to PrettyTable * Modify informationg about converting an existing table and adding images * Resolving errors * Reformatting * Moving placement of reference label * Attempting to fix table title * Fixed incorrect alignment * Made changes based on Lisa's suggestions * Made changes based on Lisa's suggestions * Made corrections * Made corrections * Per #1667, fixing typos * Per #1667, corrected text --------- Co-authored-by: Julie Prestopnik * Feature #2377 Log to terminal only (#2398) * Update conda envs to use conda-forge only (#2402) * rearrange MET config env var tables for GridStat so they are in the order that they appear in the wrapped MET config file * use mamba instead of conda and update version of netcdf python package used to 1.6.2 * skip s2s_mid_lat WeatherRegime use case that produces different results often * updated version of xesmf because <0.7.1 does not work with mamba * per #2412, fix bug in GenVxMask to put quotes around argument so a grid specification string with spaces will be an accepted value * downgrade version of esmf package to fix bug described in https://github.com/pangeo-data/xESMF/issues/246 * Feature #2219 SeriesAnalysis multiple input files (#2408) * Adding 3 new requestors to the list of common_labels.txt for NOAA/NHC, CSU/CIRA, and Australian BOM ci-skip-all * Feature 2405 match tables2wrapper (#2416) Co-authored-by: George McCabe <23407799+georgemccabe@users.noreply.github.com> * per #2423, follow symbolic links when traversing directories to find files within a time window, ci-run-all-diff * Feature #2252 WaveletStat wrapper (#2427) Co-authored-by: j-opatz <59586397+j-opatz@users.noreply.github.com> * add WaveletStat use case to group and temporarily disable TCDiag use case because changes to the wrapper are needed to fix it after changes to the MET tool were merged * update version number for beta2 release (#2431) * update version for dev towards beta3 * Feature #2371 Embed use case upgrade demo video into upgrade instructions (#2444) * fix failing use case tests -- install python packages dateutil and requests via apk instead of pip because the pip commands began failing -- see PEP668 https://peps.python.org/pep-0668/ -- also changed scripts to create conda environments for use case tests to install all packages in a single call to mamba instead of individual calls * remove commands to install geovista from source because it is now installed from conda * Feature #1989: Add OMI use case (#2457) Co-authored-by: George McCabe <23407799+georgemccabe@users.noreply.github.com> * Feature #2432 TCDiag new config changes (#2453) * move medium range 10 use case into group with 3-5 to speed up runs * Feature #2334 land_mask (and topo_mask) in PointStat (#2456) * added use cases with pygrib * Feature #2430 TCPairs consensus.diag_required and consensus.diag_min_req (#2439) * Quickfix cloud use case desc imgs (#2464) * added pics, updated desc * add last two imgs * Fixing spelling and capitalization * Feature 2454 doc overview conv (#2471) * adding documentation in different sections * adding grid table section * fixing links * grammar updates * Per #2454, updated sections and wording. * Per #2454, added a period to the end of a sentence. * Per #2454, fixing formatting * Per #2454, updating wording * adding a section for line breaks in a table * adding :code: information * trying to fix warning * take 2 * take 3 or 4 * maybe fixed * updating link * fixing web link again * web link saga continues * Changed "ReadTheDocs" to "Read the Docs" * Updated "main_v" references to be "main_v12.0" * Removed references to main_v*, replacing with raw RST It is not maintainable to have links to branches which will become old. Since we can avoid it by adding the raw RST in the documentation, I have removed all references to main_v* in favor of placing the raw RST in the documentation. * Modified the "Code in a Paragraph" section * Reworded for consistency within the document * Added back the link for Sphinx code blocks --------- Co-authored-by: Julie Prestopnik * add argument to workflow dispatch event so that MET DockerHub repo used for tests can be easily overridden to test changes in a MET PR before merging * Feature dtcenter/MET#2796 GHA Node20 deprecation warnings (#2473) * per dtcenter/MET#2796, update versions of actions to prevent deprecated node warnings in GHA runs * change arguments to workflow dispatch so they are no longer required -- these are not needed to be set when triggering by hand through the web interface * Feature dtcenter/MET#2796 develop - Fix error log artifact creation (#2475) * updated version of pillow to fix security vulnerability alerted by dependabot in PR #2477 * remove docker image after runtime image is created from metplus image and conda env image * turn on use case to test image removal * prune images if image tag doesn't exist -- it appears that if the image is built on the fly (when PR is coming from fork) then the tag exists, but if not, the image tag is set to * support commands that must run in the shell to see if || will work in docker image pruning step * try to fix image removal * Feature 2383 use case sat alt (#2480) * new docs, files for use case * new files * updating to run use case * updated python libraries, changed test env * trying new point logic * added to script for nan removal * redid Python script to take adv of new MET ability for nans * Update run status * removed unused settings * run image prune commands separately * changed shell back to false * split up use case groups so the same envs are used by a group to see if that resolves the disk space issues * turn off use cases * feature 2253 fix empty pytest logs (#2485) * added more commands to free up disk space as suggested in https://github.com/apache/flink/blob/master/tools/azure-pipelines/free_disk_space.sh, ci-run-all-cases * Feature 2406 redo usecase rrfs (#2488) * issue #2406 RRFS use case files * issue #2406 added usecase to tests * Issue #2406 added metplotpy and metcalcpy as dependencies * Feature #2460 allow missing input (#2493) * changed template to use datetime format that works on MacOS * update logic to only write a file list file if there are more than 1 files, updated unit tests to match new behavior, added exception handling to series analysis to prevent crash if file does not exist * use getraw instead of getstr to prevent crash if providing a filename template tag to override a config variable on the command line * Add optional argument to subset file function to always write a file list text file even if there is only 1 file found. Use this argument in UserScript wrapper so that the environment variables that contain paths to file list files are consistent in format for use in user scripts * enhanced function to support different output variable types * removed the need for overriding clear function in specific wrappers and added optional argument to skip clearing input file list * clean up formatting * per #2460, start to implement logic to prevent errors when some input files are not found * isolate logic to find input files into find_input_files functions. clean up those functions to return boolean instead of sometimes returning None or a list of files to be consistent * remove python embedding checks because MET is now smart enough to determine if a python script is used with always setting file_type * turn on use cases to test error handling * merge artifacts * run only failed cases * always run merge step * run on a case that will succeed to test error log merge step * only run error log merge step if there were 'Save error logs' jobs that succeeded * run cases that will fail * fix condition to merge error logs * run group that will succeed but have diffs - check error logs doesn't fail * testing - add use case group that will succeed but will cause diffs becaus there is no truth data - to confirm that the error log merge step behaves properly in this case * run 3 jobs, 2 should error, to confirm that error_logs is created properly * repeat diff no error test but with * per dtcenter/MET#2796, fix error log artifact creation by merging error logs if any of the 'Save error logs' steps ran successfully * run test to confirm diff does not cause merge error logs to fail * Revert "run test to confirm diff does not cause merge error logs to fail" This reverts commit ff2d1cac57c431a047ee250e9dae9b0a813a78ba. * run test to confirm error logs are merged properly when 2 use case groups have errors * try checking output variable as string instead of boolean * Revert "run test to confirm error logs are merged properly when 2 use case groups have errors" This reverts commit 8106666a73685e654e0146d4fed56f2382f1bfc7. * run test again * test again * move check for error logs for shell script and use github env vars * Revert "run test again" This reverts commit 7a0a99c6e7031c5dafb1177d4b4ca3f32a999dac. * break 2 use cases to test that error logs are still created properly * checkout repo to get script used to merge error logs * Revert "break 2 use cases to test that error logs are still created properly" This reverts commit cb6d0b46db353b4b4709183be2fe7e5ce64ff5ff. * test merge error log again on no error diff run * fix script * move merge error logic back to workflow * break 2 use cases to test that error logs are still created properly * Revert "break 2 use cases to test that error logs are still created properly" This reverts commit 82aa0e11096aace3ccc2c79cd631533fc6426900. * remove testing use case group * Revert "remove python embedding checks because MET is now smart enough to determine if a python script is used with always setting file_type" This reverts commit de3b4b03a45bb871c71e770ff9e602739d6b63d5. * clean up lines * update logic to check that python embedding is set up properly to only try to set file_type automatically if it is not already set and if the wrapper is a tool that supports multiple input files via python embedding (which require file_type to be set). also changed error if not set properly to warning and use PYTHON_NUMPY as a default * remove run_count increment before run_at_time_once - set closer to find_input_files so run count and missing input count are consistent * return boolean from find_input_files function to be consistent with other functions * per #2460, warn instead of error if missing inputs are allowed, track counters for number of runs and missing inputs * per #2460, added check to report error if allowed missing input threshold is met * run clear before running plot_data_plane * removed test group * report warning instead of error if ALLOW_MISSING_INPUTS is True * cleanup * change function to pytest fixture so it can be used by other test scripts * update ascii2nc test to process more than 1 time to ensure commands are built properly for each run * add unit tests to ensure missing input file logic works properly for ascii2nc and grid_stat * set variable to skip RuntimeFreq logic to find input files to prevent duplicate increment of run_count -- these will be removed when the wrapper has been updated to find files using RuntimeFreq logic * remove unneccesary error checking * cleanup * call function to handle input templates that need to be handled separately for each item in the comma-separated list (for UserScript and GridDiag only) * add time_info to ALL_FILES dictionaries to be consistent with other wrappers * clean up logging for reporting error when missing inputs exceeds threshold * added function to get files for a single run time to be consistent with other functions * skip increment of run_count when FIND_FILES=True and RuntimeFreq input file logic is skipped to prevent duplicate increments * added empty test files * remove redundant variables * view warnings on a failed test run * add more empty test files * added unit tests for missing input logic * remove MANDATORY setting for EnsembleStat and GenEnsProd and instead pass mandatory argument to call to find model files so warnings/errors are properly displayed for other inputs * cleanup * remove allow missing input logic from ExtractTiles wrapper * added functions to parse template/dir variables from config, removed explicit calls to read those variables from GridStat * remove error if more labels than inputs are provided (for UserScript and GridDiag only) -- extra labels will just be ignored * added required boolean for input templates * per #2460, change warning messages to debug when checking a list of DA offsets since it is common that a given offset will not always be found in the files * added tests for missing input logic for many wrappers * cleanup * fix increment of number of runs * skip missing input logic * change how required is handled for input templates * warn instead of error if missing input is allowed * remove increment of missing input counters because it is handled in RuntimeFreq * check status of input files and increment counters in overridden run_once_per_lead. remove increment of missing input counters because it is handled in run_once_per_lead * added unit tests for missing input logic * skip missing input logic * cleanup * cleanup, use fixture for tests, add unit tests for missing input, bypass missing input logic on wrappers that don't need it * removed file that is not needed * added unit tests for pb2nc to test -valid_beg/end arguments and changes to properly support any runtime frequencies * warn instead of error if allowing missing inputs * cleanup * implement changes to properly support all runtime frequencies for pb2nc. previously all files that match a wildcard will be used instead of selecting only files that fall within the specified time range. some functions moved into pb2nc wrapper will eventually be moved up so that they are used by all wrappers to be consistent * added unit tests that will fail until wrapper is updated * replace functions in RuntimeFreq wrapper used to find input files so they can be used by all wrappers, updated ioda2nc wrapper to find input files properly to fix tests * cleanup * removed mtd version of get_input_templates and added logic to RuntimeFreq's version to get the same behavior * added unit tests for MTD missing input checks * per #2491, add release notes for beta3 * Feature #2491 v6.0.0 beta3 (#2495) * update version for beta3 release * fixed typos in release notes * update version to note development towards beta4 release * Per suggestion from @JohnHalleyGotway, create intermediate branch for updating truth data to avoid branch protection rules. I added a step to delete the intermediate branch locally if it exists to prevent conflicts with the update * added quotes to prevent error in echo caused by parenthesis * fix incorrect command * Revert "fix incorrect command" This reverts commit e7dffb6b0b351ab1b4bca5b563c1f5beef7737a9. * Revert "added quotes to prevent error in echo caused by parenthesis" This reverts commit c1cb3c4f0d7851bea720a50fac6011cd381017dc. * Revert "Per suggestion from @JohnHalleyGotway, create intermediate branch for updating truth data to avoid branch protection rules. I added a step to delete the intermediate branch locally if it exists to prevent conflicts with the update" This reverts commit 525809dc3bd73ace969b046062967796035f4d86. * Hotfix: Allow symbolic link to run_metplus.py to run (#2500) * Adding use case tests * Changing test environment * Testing environment changes * Documentation update * Updating Documentation * Updating documentation for disk space failure * Added new use case category * Fixing use case test * Fixing bug in use case file * Testing s2s after data removal * add back use cases that were accidentally removed * fix incorrect use case added * Setting tests to false for merge * Removes extraneous imports. * Switches to function call for the coupling index. * Correct number of args in comment. * Testing for old use cases * Setting tests to false for merge * update tests to update develop data -- modified commands to create new use case category directory if it does not already exist, move step to remove old data to be completed just after new data is copied to vX.Y * Summation has to have a dimension supplied for the gridded data, but for pandas the only dimension is time (but it is un-named). Therefore the numerator for the covariance term had to be split out between the fcst and obs case. * Feature 2463 modify table (#2508) * creating test dropdown menus * fixing warnings * fixing warnings * fixing warnings 3 * fixing warnings 4 * Attempt to fix documentation errors * adding 2 more test dropdowns please note. There is still a message about WARNING: Duplicate explicit target name: "gridstat: cloud fractions with neighborhood and probabilities (pygrib)". John O will fix this. I should not touch it. * fixing spacing * trying to fix link * take 2 * Removing double underscores added earlier * moving dropdown menus * Adding version to dropdown menu title * fixing spacing * dropdowns date util, eofs, h5py * fixing formatting * fixing formatting * Per #2463, adding template for future entries * adding imageio, lxml & matplotlib * dropdown up to nc-time-axis * fixing spacing problems * Fixing broken s2s links and other incorrect links * Fixing spelling and capitalization * Removing the dash in front of 1.4 for nc-time-axis * Modifying formatting * adding dropdowns thru pylab * fixing problems * dropdowns thru scikit-learn * fixing spacing * final dropdowns thru yaml * fixing spacing * fixing loose ends * Per #2463, moving information to an Appendix and adding text and links in an overview * Per #2463, adding to index.rst * Per #2463, reworded language and updated Python 3.8 reference * Per #2463, fixing errors * Per #2463, made updates based on feedback at the METplus Engineering meeting. * removing tables, changing most METplus wrappers, version numbers. * trying to fix met_version * Per #2463, adding necessary code for substitutions * Per #2463, fixing syntax error * adding period * removing section 1.5 * Per #2463, replace old label reference with new label reference and updated text to reflect the move to drop down menus * read python version from file to replace in docs * fixed typo in variable name * adding python_version to the overview. --------- Co-authored-by: Julie Prestopnik Co-authored-by: George McCabe <23407799+georgemccabe@users.noreply.github.com> * per #2509, automate MET version used in documentation to be X+6.Y.0 of METplus version * Bugfix #2520 ASCII2NC file window issue and redundant wrapper initialization (#2522) * per PyCharm documentation, only ignore workspace.xml idea file and commit the rest of the .idea files to version control * per #2520, create function to get METplus wrapper class without initializing it and use that function to read list of deprecated env vars to prevent redundant initialization of wrappers that can cause unintended side effects * handle file_window variables consistently by using CommandBuilder function * comment out optional config variables that previously caused a failure when unset * Update update_truth.md Fix typo in the update_truth issue template in the develop branch. * Update update_truth.md Update wording in the update_truth issue template. * Feature #2530 dev timeline (#2532) * Per #2530, add a development timeline to the METplus Release Information section of the User's Guide. Also update the Release Guide instructions. * Per #2530, tweak the wording. * Update docs/Release_Guide/release_steps/update_release_notes_development.rst Co-authored-by: Julie Prestopnik --------- Co-authored-by: Julie Prestopnik * Adds static station lookup file for use with Python embedding for FLUXNET observations. * Major overhaul to forecast Python embedding script for the TCI use case. * Major overhaul to observation Python embedding script for the TCI use case, to compute TCI from raw observations rather than read pre-computed TCI. * Updates documentation file for TCI use case. * Adds METcalcpy version number. * Refactors wording and fixes typo. * Fixes RST formatting. * Finally fixed RST error. * Adds support to remove leap days if requested. * Updates command line args for Python embedding scripts. * Feature #2537 develop sonarqube_gha (#2541) * Per #2537, add SonarQube workflow for METplus * Per #2537, update nightly build email list. * Per #2537, fix cut/paste error configure_sonarqube.sh * Per #2537, exclude test code from code coverage statistics. * Updated conf file for use case. * Removes new TCI function because it is in METcalcpy now. * Removes old code, somsome reorganization and clarification and setting of params, and also switches the fluxnet metadata file to a command line argument instead of an environment variable. * Update the 6.0.0 Coordinated Release development timeline in release-notes.rst * Support for environment variables or default options for filtering and filename patterns, DEBUG mode added and set to False by default, adjustment of print statements for logging, and refactoring filtering of stations to ensure we don't process a file that we shouldn't by better coupling of filenames and stations. * Makes DEBUG an env var for config via metplus wrappers. * Reorganization of config file, adds environment variables, and updates comments for use case changes. * Updates to documentation. * Fixes tables. * Adds table of contents to the top for users to click on. * Updates use case documentation file. * Updated config file with obs and fcst subirectories in the path. * Added optional key/value to use_case_groups.json to prevent a use case group from running to easily disable it temporarily. Disable short_range:14 use case until it can be fixed with #2551 * update pillow version based on recommendation from dependabot: https://github.com/dtcenter/METplus/security/dependabot/5 * Switches to using metplotpy_env to get metcalcpy dependency. * Adds filtering based on missing data values. * Finishing touches to debug statements for testing. * Fixing a few minor code smells from last week. * update link to METplus Components Python Requirements table in PR template * Update docs/use_cases/model_applications/land_surface/PointStat_fcstCESM_obsFLUXNET2015_TCI.py Co-authored-by: George McCabe <23407799+georgemccabe@users.noreply.github.com> * Feature #2555 v6.0.0 beta4 (#2556) * update version for beta4 release * added release notes for beta4 release * update version for development towards beta5 release * update location of METviewer docker-compose.yml file that moved from PR dtcenter/METviewer#525 * Feature #2537 develop single_sq_project (#2558) * Update the beta4 release date wording * Feature #2433 Ugrid config variables in GridStat/PointStat (#2517) * update version for release * added new use case that was missing * Bugfix #2279 main_v5.1 - buoy station file from 2022 (#2281) * Fix typo in pull_request_template.md * added notes to make it clear that upgrade instructions are not needed if upgrading from 5.0 to 5.1 * New issue template: Update Truth (#2332) Co-authored-by: John Halley Gotway (cherry picked from commit 44335f33ab152a0b254041961a41895dde614ae0) * add GitHub Actions workflow that is used to create Docker images that hold the conda environment used for the automated tests -- adding this to the default main_v5.1 branch so that it will become available to run for other branches as a workflow_dispatch workflow * Per #2433, added support for setting the ugrid MET config variables for GridStat and PointStat wrappers. Also moved the seeps variable up so that it matches the order of the default config files in the MET repo * add argument to workflow dispatch event so that MET DockerHub repo used for tests can be easily overridden to test changes in a MET PR before merging * Feature dtcenter/MET#2796 main_v5.1 GHA Node20 deprecation warnings (#2474) * per dtcenter/MET#2796, update versions of actions to prevent deprecated node warnings in GHA runs - main_v5.1 * fix ReadTheDocs requirements to include pillow which is a dependency of sphinx-gallery: see https://blog.readthedocs.com/defaulting-latest-build-tools/ for more info on why this was necessary * install python packages via apk instead of pip to prevent GHA failures that were fixed in develop but not in main_v5.1 * per dtcenter/MET#2796, fix error log merging for main_v5.1 same as develop * Bump pillow from 10.0.1 to 10.2.0 in /docs (#2477) Bumps [pillow](https://github.com/python-pillow/Pillow) from 10.0.1 to 10.2.0. - [Release notes](https://github.com/python-pillow/Pillow/releases) - [Changelog](https://github.com/python-pillow/Pillow/blob/main/CHANGES.rst) - [Commits](https://github.com/python-pillow/Pillow/compare/10.0.1...10.2.0) --- updated-dependencies: - dependency-name: pillow dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Create 5.1.0_casper * per #2433, add support for setting the optional -config argument for a ugrid config file for PointStat and GridStat. Also moved the optional arguments to be added to the command after all of the required arguments so the command is easier to read * per #2433 and discussion on meeting 3/21/2024, change command line argument from -config to -ugrid_config * update unit tests to check for new command line argument name -ugrid_config * Updates information about GDAS surface winds having a QC value that is above the default settings in the PB2NC config file. --------- Signed-off-by: dependabot[bot] Co-authored-by: John Halley Gotway Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Julie Prestopnik Co-authored-by: Daniel Adriaansen * SonarQube add python code coverage report (#2565) * run code coverage before SonarQube scan * generate xml report and configure SQ to read coverage.xml * exclude more files from code coverage report * exclude more files that should not be included in the code coverage report * more changes to code coverage exclude list * removed bad characters accidentally added * exclude cyclone plotter wrapper because it is excluded from code coverage report * ignore SonarQube lint files generated by PyCharm * Updating MTD conv radius/thresh description (#2566) * Updating MTD conv radius/thresh description * Update glossary.rst * Update docs/Users_Guide/glossary.rst Co-authored-by: George McCabe <23407799+georgemccabe@users.noreply.github.com> * Update docs/Users_Guide/glossary.rst Co-authored-by: George McCabe <23407799+georgemccabe@users.noreply.github.com> --------- Co-authored-by: George McCabe <23407799+georgemccabe@users.noreply.github.com> * Feature update modulefiles (#2564) * Adding 6.0.0 file for derecho and removing 5.1.0 file for cheyenne * Updating modulefiles * Updating orion file * Adding file for hercules * Adding file for casper * Update internal/scripts/installation/modulefiles/6.0.0_casper Co-authored-by: George McCabe <23407799+georgemccabe@users.noreply.github.com> --------- Co-authored-by: George McCabe <23407799+georgemccabe@users.noreply.github.com> * Feature #1989: Add OMI to Verification Datasets Guide (#2585) Refs: #1989 * Feature #2479 time_offset_warning (#2587) * Per #2479, add support for setting time_offset_warning in all wrapped MET config files * Per #2479, add documentation and examples to basic use case param files for time_offset_warning * Feature 2346 develop update templates (#2589) * Per #2346, modifying issue templates * Per #2346, modifying pull request template * Per #2346, modifying entries based on suggestions by @georgemccabe * Bugfix #2567 PointStat multiple point observation files (#2582) * per #2567, properly pass multiple point observation files to point_stat using the -point_obs argument * per #2567, fix bug that caused file window logic to fail * Revert "per #2567, fix bug that caused file window logic to fail" This reverts commit 27fe8226c58e9a028a7979664bbf224296fdd6ea. * per #2567, fix bug that caused file window logic to fail * Feature #1514 MADIS2NC wrapper (#2591) * Per #1514, implement MADIS2NC wrapper and added example use case. Also updated the function to handle the time_summary dictionary in MET config files to support names that exactly match the name found in the dictionary, e.g. ASCII2NC_TIME_SUMMARY_OBS_VAR sets time_summary.obs_var (previously only ASCII2NC_TIME_SUMMARY_VAR_NAMES was supported and is still supported) * remove execute permissions from image files * Per #1514, add image for basic use case * removed large image files that are no longer being used in documentation * add support for time_offset_warning for MADIS2NC wrapper after the PR to add that support for other wrappers has been merged into develop * report error if output template is not defined * update contributor's guide with more up-to-date info on how to create a new wrapper and basic components of wrappers * fix warnings in documentation * fix formatting issues * Per #1514, add new basic use case to automated test suite * add step to comment out version number in wrapped MET config file * turn off use case to prepare for PR * added a pytest fixture to handle comparison of use case commands and environment variable values to remove a lot of redundant logic in each wrapper test. Added fake madis data * removed commented code * properly substitute template tags in all command line arguments * properly handle unset rec_beg and rec_end to prevent missing value from being added to command lien arg * added new madis2nc use case to existing met_tool_wrapper and temporarily disabled land_surface:0 until we can resolve the differences * Feature 2346 develop update templates (#2594) * Per #2346, modifying issue templates * Per #2346, modifying pull request template * Per #2346, modifying entries based on suggestions by @georgemccabe * Per 2346, making updates based on feedback at last MET Eng. Meeting * Enhance update truth data workflow to create a uniquely named branch to update *-ref branches and commit/append to a log file that tracks the reasons for updating the truth data. This is done to ensure that the *-ref branch testing workflow run that actually updates the truth data is always run even if there are no other changes to the METplus branch since the last update, e.g. when a change to another component like MET warrants the truth data update * git add change log file in case it doesn't already exist * changed logic to no longer push changes to develop/main_vX.Y, but instead merge changes from -ref into the update branch * retain update truth history file from *-ref * dtcenter/MET#2899 fixes a bug reading point observations using Python Embedding in PointStat and EnsembleStat, which should fix the PBL use case -- dtcenter/METplus#2246 -- so turned on diff test for PBL use case to ensure that results are consistent going forward * Feature #2429 MvMODE multivar intensity (#2603) * Feature #2547 ASCII2NC -valid_beg and -valid_end arguments (#2606) * prevent divide by zero if run_count is 0 * Per #2547, add support for setting -valid_beg and -valid_end command line arguments. Added changes to make ASCII2NC wrapper able to run for all runtime frequencies * Refactored system_util preprocess_file function to reduce cognitive complexity and add quotation marks around 'filenames' that contain spaces (typically python embedding commands) so explicit handling of these cases don't need to be done downstream. Added unit tests to test more python embedding cases * remove logic to add quotes around input file since it is handled already in preprocess_file * changed find_input_files function to return None or a time_info dictionary to be consistent across wrappers * added ReformatPointWrapper to use as parent class for ASCII2NC, MADIS2NC, PB2NC, and Point2Grid wrappers to consistently handle tools that reformat point observation data. Moved verbosity to the end of commands * clean up pb2nc wrapper to be more consistent with other ReformatPoint wrappers * per #2547, added glossary entries for new config variables to set -valid_beg/end and added commented example to basic use case config file * added glossary entries for *_RUNTIME_FREQ variables * Per #2513, remove TC_RMW_MAX_RANGE_KM * Feature 2494 update fv3 data (#2610) * Updated for new data * Updated to match new data * Updates due to new data/updates to data * Updates due to new data/data variables * Changes due to changes to data variables, date * Updates due to changes to data * Update the date to reflect the new data (with updates to variables) * fixed error with formatting * Remove redundant instructions. * For testing * Update use_case_groups.json * Revert to original location of input data to use the same data for all three FV3 Physics Tendency use cases. * Revert to original location of data from tarball * Remove typo in file directory name * Update use_case_groups.json Returned 10-12 to follow 11 * Update use_case_groups.json revert to false for testing the short range use cases for FV3 physics tendency * Update use_case_groups.json fix alignment of opening curly brace * Update use_case_groups.json revert to original formatting * removed config variable that should be set by the user because it is specific to the user's environment --------- Co-authored-by: George McCabe <23407799+georgemccabe@users.noreply.github.com> * Feature #2578 PCPCombine -input_thresh for missing inputs (#2609) * refactoring to reduce duplicate/redundant code, reduce cognitive complexity to satisfy SonarQube, etc * change wording of error log to satisfy test * set -input_thresh argument if set for add, derive, and sum methods. refactor setting of method arguments, e.g. -add, -sum, etc., cleanup * refactor how level is handled in find_data function so that if the level has already been set, it will use that value, otherwise try to get it from {data_type}_level, e.g. fcst_level, otherwise set it to 0 to prevent errors * refactor duplicate code into function to satisfy SonarQube * removed unused variable * use find_data function to find input files to be consistent with other wrappers, only allow multiple input files to be found for a given call to find_data if using the -derive method * fix typo in key * suppress warnings when files aren't found because it is expected * formatting to be consistent in doc string * per #2578, add MISSING before file path that is not found if input_thresh is set and less than 1.0, added unit test to ensure correct behavior occurs * add documentation blocks for new functions, ci-run-all-diff * use pytest fixture instead of local function * add support for setting -vld_thresh argument * per #2578, added documentation and tests for setting -input_thresh and -vld_thresh * moved verbosity argument to end of command to more easily change it when debugging * refactor to reduce cognitive complexity to satisfy SonarQube * update usage statement to include METplus version number * Add copy button for code blocks to easily copy/paste commands (#2611) * add copy button for code blocks to easily copy/paste commands * turn off copy button always visible but leave code block so it can be turned on easily if desired * Update release-notes.rst Update METplus-6.0.0 development schedule. * Fix numbering. * fix broken link * added entry to update truth change log: develop dtcenter/MET#2921 --------- Signed-off-by: dependabot[bot] Co-authored-by: George McCabe <23407799+georgemccabe@users.noreply.github.com> Co-authored-by: John Sharples <41682323+John-Sharples@users.noreply.github.com> Co-authored-by: lisagoodrich <33230218+lisagoodrich@users.noreply.github.com> Co-authored-by: Dan Adriaansen Co-authored-by: jprestop Co-authored-by: Hank Fisher Co-authored-by: metplus-bot <97135045+metplus-bot@users.noreply.github.com> Co-authored-by: John Halley Gotway Co-authored-by: j-opatz <59586397+j-opatz@users.noreply.github.com> Co-authored-by: reza-armuei <144857501+reza-armuei@users.noreply.github.com> Co-authored-by: Tracy Hertneky <39317287+hertneky@users.noreply.github.com> Co-authored-by: Tracy Co-authored-by: Mallory Row Co-authored-by: j-opatz Co-authored-by: bikegeek <3753118+bikegeek@users.noreply.github.com> Co-authored-by: Christina Kalb Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/ISSUE_TEMPLATE/update_truth.md | 2 +- .github/update_truth_change_log.txt | 1 + docs/Users_Guide/glossary.rst | 26 + docs/Users_Guide/release-notes.rst | 5 +- docs/Users_Guide/wrappers.rst | 4 + docs/_static/theme_override.css | 7 + docs/conf.py | 12 +- docs/requirements.txt | 1 + internal/tests/pytests/conftest.py | 8 +- .../pcp_combine/test_pcp_combine_wrapper.py | 201 ++++--- metplus/util/system_util.py | 43 +- metplus/util/time_util.py | 2 +- metplus/wrappers/command_builder.py | 221 ++++---- metplus/wrappers/pcp_combine_wrapper.py | 522 +++++++++--------- metplus/wrappers/reformat_gridded_wrapper.py | 34 +- metplus/wrappers/regrid_data_plane_wrapper.py | 120 ++-- .../PCPCombine/PCPCombine_add.conf | 3 + .../PCPCombine/PCPCombine_bucket.conf | 3 + .../PCPCombine/PCPCombine_derive.conf | 3 + .../PCPCombine/PCPCombine_loop_custom.conf | 3 + .../PCPCombine_python_embedding.conf | 3 + .../PCPCombine/PCPCombine_subtract.conf | 2 + .../PCPCombine/PCPCombine_sum.conf | 3 + ush/run_metplus.py | 21 +- 24 files changed, 666 insertions(+), 584 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/update_truth.md b/.github/ISSUE_TEMPLATE/update_truth.md index 23c22a3553..1838e4b0b4 100644 --- a/.github/ISSUE_TEMPLATE/update_truth.md +++ b/.github/ISSUE_TEMPLATE/update_truth.md @@ -57,6 +57,6 @@ assignees: '' be updated. - [ ] Update the truth data. This should be handled by a METplus wrappers engineer. - See the [instructions to update the truth data](https://metplus.readthedocs.io/en/develop/Contributors_Guide/continuous_integration.html#update-truth-data-update-truth-data-yml) + See the [instructions to update the truth data](https://metplus.readthedocs.io/en/develop/Contributors_Guide/continuous_integration.html#update-truth-data-update-truth-yml) for more info. - [ ] Close this issue. diff --git a/.github/update_truth_change_log.txt b/.github/update_truth_change_log.txt index f070692b02..5ee4d97c2b 100644 --- a/.github/update_truth_change_log.txt +++ b/.github/update_truth_change_log.txt @@ -1,2 +1,3 @@ [20240523_17:36:49 develop] No PR - Testing that the truth data will update even if there are no changes to the METplus repository since the last update [20240612_13:45:41 develop] #2610 - #2610 changed the input data for 3 short range use cases (10-12). +[20240627_18:08:16 develop] dtcenter/MET#2921 - Re-defines azimuths definitions and corrects the logic for deriving radial and tangential winds. diff --git a/docs/Users_Guide/glossary.rst b/docs/Users_Guide/glossary.rst index 29890ccfcf..f351df3f53 100644 --- a/docs/Users_Guide/glossary.rst +++ b/docs/Users_Guide/glossary.rst @@ -11979,3 +11979,29 @@ METplus Configuration Glossary There is no default, so a value must be specified. All runtime frequencies are supported. | *Used by:* UserScript + + FCST_PCP_COMBINE_INPUT_THRESH + Specify the value for the command line argument '-input_thresh' for the + forecast run of PCPCombine, e.g. :term:`FCST_PCP_COMBINE_RUN` is True. + Not used when :term:`FCST_PCP_COMBINE_METHOD` is SUBTRACT or USER_DEFINED. + + | *Used by:* PCPCombine + + OBS_PCP_COMBINE_INPUT_THRESH + Specify the value for the command line argument '-input_thresh' for the + observation run of PCPCombine, e.g. :term:`OBS_PCP_COMBINE_RUN` is True. + Not used when :term:`OBS_PCP_COMBINE_METHOD` is SUBTRACT or USER_DEFINED. + + | *Used by:* PCPCombine + + FCST_PCP_COMBINE_VLD_THRESH + Specify the value for the command line argument '-vld_thresh' for the + forecast run of PCPCombine, e.g. :term:`FCST_PCP_COMBINE_RUN` is True. + + | *Used by:* PCPCombine + + OBS_PCP_COMBINE_VLD_THRESH + Specify the value for the command line argument '-vld_thresh' for the + observation run of PCPCombine, e.g. :term:`OBS_PCP_COMBINE_RUN` is True. + + | *Used by:* PCPCombine diff --git a/docs/Users_Guide/release-notes.rst b/docs/Users_Guide/release-notes.rst index 57f28f6a0e..7719979e6b 100644 --- a/docs/Users_Guide/release-notes.rst +++ b/docs/Users_Guide/release-notes.rst @@ -19,8 +19,9 @@ is broken down into the following development cycles for each component: 3. **Beta3** releases for the METplus components occurred around 2024-02-08. 4. **Beta4** releases for the METplus components occurred around 2024-04-17. 5. **Beta5** releases are tentatively scheduled for 2024-06-26. -6. **Release Candidate 1** releases have not yet been scheduled. -7. **Official Release** releases have not yet been scheduled. +6. **Beta6** releases are tentatively scheduled for 2024-09-04. +7. **Release Candidate 1** releases are tentatively scheduled for 2024-11-13. +8. **Official Release** releases have not yet been scheduled. .. _components-release-notes: diff --git a/docs/Users_Guide/wrappers.rst b/docs/Users_Guide/wrappers.rst index cb24c991dd..870ccf672d 100644 --- a/docs/Users_Guide/wrappers.rst +++ b/docs/Users_Guide/wrappers.rst @@ -6027,6 +6027,10 @@ METplus Configuration | :term:`PCP_COMBINE_INC_VALID_TIMES` | :term:`PCP_COMBINE_SKIP_INIT_TIMES` | :term:`PCP_COMBINE_INC_INIT_TIMES` +| :term:`FCST_PCP_COMBINE_INPUT_THRESH` +| :term:`FCST_PCP_COMBINE_VLD_THRESH` +| :term:`OBS_PCP_COMBINE_INPUT_THRESH` +| :term:`OBS_PCP_COMBINE_VLD_THRESH` | .. warning:: **DEPRECATED:** diff --git a/docs/_static/theme_override.css b/docs/_static/theme_override.css index 859922a900..43dd595e4b 100644 --- a/docs/_static/theme_override.css +++ b/docs/_static/theme_override.css @@ -29,3 +29,10 @@ padding: 12px 12px; padding: 0; } */ + +/* copy button for code blocks is always visible */ +/* +button.copybtn { + opacity: 1; +} +*/ diff --git a/docs/conf.py b/docs/conf.py index f067b51cc4..08b09b1b4f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -115,11 +115,13 @@ # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. -extensions = ['sphinx.ext.autodoc', - 'sphinx.ext.intersphinx', - 'sphinx_gallery.gen_gallery', - 'sphinx_design', - ] +extensions = [ + 'sphinx.ext.autodoc', + 'sphinx.ext.intersphinx', + 'sphinx_gallery.gen_gallery', + 'sphinx_design', + 'sphinx_copybutton', +] # settings for ReadTheDocs PDF creation latex_engine = 'pdflatex' diff --git a/docs/requirements.txt b/docs/requirements.txt index 0628125f64..4095fb6d3d 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -3,3 +3,4 @@ pillow==10.3.0 sphinx-gallery==0.14.0 sphinx-rtd-theme==1.3.0 sphinx-design==0.3.0 +sphinx-copybutton==0.5.2 diff --git a/internal/tests/pytests/conftest.py b/internal/tests/pytests/conftest.py index de6a6f4efa..9cbcfa1701 100644 --- a/internal/tests/pytests/conftest.py +++ b/internal/tests/pytests/conftest.py @@ -199,11 +199,13 @@ def make_nc(tmp_path, lon, lat, z, data, variable='Temp', file_name='fake.nc'): def get_test_data_dir(): """!Get path to directory containing test data. """ - def get_test_data_path(subdir): + def get_test_data_path(subdir=None): internal_tests_dir = os.path.abspath( - os.path.join(os.path.dirname(__file__), os.pardir) + os.path.join(os.path.dirname(__file__), os.pardir, 'data') ) - return os.path.join(internal_tests_dir, 'data', subdir) + if subdir: + internal_tests_dir = os.path.join(internal_tests_dir, subdir) + return internal_tests_dir return get_test_data_path diff --git a/internal/tests/pytests/wrappers/pcp_combine/test_pcp_combine_wrapper.py b/internal/tests/pytests/wrappers/pcp_combine/test_pcp_combine_wrapper.py index 5b4ed11317..a0291936ac 100644 --- a/internal/tests/pytests/wrappers/pcp_combine/test_pcp_combine_wrapper.py +++ b/internal/tests/pytests/wrappers/pcp_combine/test_pcp_combine_wrapper.py @@ -9,20 +9,7 @@ from metplus.util import ti_calculate -def get_test_data_dir(config, subdir=None): - top_dir = os.path.join(config.getdir('METPLUS_BASE'), - 'internal', 'tests', 'data') - if subdir: - top_dir = os.path.join(top_dir, subdir) - return top_dir - - -def pcp_combine_wrapper(metplus_config, d_type): - """! Returns a default PCPCombineWrapper with /path/to entries in the - metplus_system.conf and metplus_runtime.conf configuration - files. Subsequent tests can customize the final METplus configuration - to over-ride these /path/to values.""" - config = metplus_config +def set_minimum_config_settings(config, d_type): config.set('config', 'FCST_PCP_COMBINE_INPUT_ACCUMS', '6') config.set('config', 'FCST_PCP_COMBINE_INPUT_NAMES', 'P06M_NONE') config.set('config', 'FCST_PCP_COMBINE_INPUT_LEVELS', '"(*,*)"') @@ -56,14 +43,21 @@ def pcp_combine_wrapper(metplus_config, d_type): elif d_type == "OBS": config.set('config', 'OBS_PCP_COMBINE_RUN', True) +def pcp_combine_wrapper(metplus_config, d_type): + """! Returns a default PCPCombineWrapper with /path/to entries in the + metplus_system.conf and metplus_runtime.conf configuration + files. Subsequent tests can customize the final METplus configuration + to over-ride these /path/to values.""" + config = metplus_config + set_minimum_config_settings(config, d_type) return PCPCombineWrapper(config) @pytest.mark.wrapper -def test_get_accumulation_1_to_6(metplus_config): +def test_get_accumulation_1_to_6(metplus_config, get_test_data_dir): data_src = "OBS" pcw = pcp_combine_wrapper(metplus_config, data_src) - input_dir = get_test_data_dir(pcw.config, subdir='accum') + input_dir = get_test_data_dir('accum') task_info = {} task_info['valid'] = datetime.strptime("2016090418", '%Y%m%d%H') time_info = ti_calculate(task_info) @@ -85,10 +79,10 @@ def test_get_accumulation_1_to_6(metplus_config): @pytest.mark.wrapper -def test_get_accumulation_6_to_6(metplus_config): +def test_get_accumulation_6_to_6(metplus_config, get_test_data_dir): data_src = "FCST" pcw = pcp_combine_wrapper(metplus_config, data_src) - input_dir = get_test_data_dir(pcw.config, subdir='accum') + input_dir = get_test_data_dir('accum') task_info = {} task_info['valid'] = datetime.strptime("2016090418", '%Y%m%d%H') time_info = ti_calculate(task_info) @@ -107,10 +101,10 @@ def test_get_accumulation_6_to_6(metplus_config): @pytest.mark.wrapper -def test_get_lowest_forecast_file_dated_subdir(metplus_config): +def test_get_lowest_forecast_file_dated_subdir(metplus_config, get_test_data_dir): data_src = "FCST" pcw = pcp_combine_wrapper(metplus_config, data_src) - input_dir = get_test_data_dir(pcw.config, subdir='fcst') + input_dir = get_test_data_dir('fcst') valid_time = datetime.strptime("201802012100", '%Y%m%d%H%M') pcw.c_dict[f'{data_src}_INPUT_DIR'] = input_dir pcw._build_input_accum_list(data_src, {'valid': valid_time}) @@ -120,11 +114,11 @@ def test_get_lowest_forecast_file_dated_subdir(metplus_config): @pytest.mark.wrapper -def test_forecast_constant_init(metplus_config): +def test_forecast_constant_init(metplus_config, get_test_data_dir): data_src = "FCST" pcw = pcp_combine_wrapper(metplus_config, data_src) pcw.c_dict['FCST_CONSTANT_INIT'] = True - input_dir = get_test_data_dir(pcw.config, subdir='fcst') + input_dir = get_test_data_dir('fcst') init_time = datetime.strptime("2018020112", '%Y%m%d%H') valid_time = datetime.strptime("2018020121", '%Y%m%d%H') pcw.c_dict[f'{data_src}_INPUT_DIR'] = input_dir @@ -134,11 +128,11 @@ def test_forecast_constant_init(metplus_config): @pytest.mark.wrapper -def test_forecast_not_constant_init(metplus_config): +def test_forecast_not_constant_init(metplus_config, get_test_data_dir): data_src = "FCST" pcw = pcp_combine_wrapper(metplus_config, data_src) pcw.c_dict['FCST_CONSTANT_INIT'] = False - input_dir = get_test_data_dir(pcw.config, subdir='fcst') + input_dir = get_test_data_dir('fcst') init_time = datetime.strptime("2018020112", '%Y%m%d%H') valid_time = datetime.strptime("2018020121", '%Y%m%d%H') pcw.c_dict[f'{data_src}_INPUT_DIR'] = input_dir @@ -149,10 +143,10 @@ def test_forecast_not_constant_init(metplus_config): @pytest.mark.wrapper -def test_get_lowest_forecast_file_no_subdir(metplus_config): +def test_get_lowest_forecast_file_no_subdir(metplus_config, get_test_data_dir): data_src = "FCST" pcw = pcp_combine_wrapper(metplus_config, data_src) - input_dir = get_test_data_dir(pcw.config, subdir='fcst') + input_dir = get_test_data_dir('fcst') valid_time = datetime.strptime("201802012100", '%Y%m%d%H%M') template = "file.{init?fmt=%Y%m%d%H}f{lead?fmt=%HHH}.nc" pcw.c_dict[f'{data_src}_INPUT_TEMPLATE'] = template @@ -163,10 +157,10 @@ def test_get_lowest_forecast_file_no_subdir(metplus_config): @pytest.mark.wrapper -def test_get_lowest_forecast_file_yesterday(metplus_config): +def test_get_lowest_forecast_file_yesterday(metplus_config, get_test_data_dir): data_src = "FCST" pcw = pcp_combine_wrapper(metplus_config, data_src) - input_dir = get_test_data_dir(pcw.config, subdir='fcst') + input_dir = get_test_data_dir('fcst') valid_time = datetime.strptime("201802010600", '%Y%m%d%H%M') template = "file.{init?fmt=%Y%m%d%H}f{lead?fmt=%HHH}.nc" pcw.c_dict[f'{data_src}_INPUT_TEMPLATE'] = template @@ -177,14 +171,14 @@ def test_get_lowest_forecast_file_yesterday(metplus_config): @pytest.mark.wrapper -def test_setup_add_method(metplus_config): +def test_setup_add_method(metplus_config, get_test_data_dir): data_src = "OBS" pcw = pcp_combine_wrapper(metplus_config, data_src) task_info = {} task_info['valid'] = datetime.strptime("2016090418", '%Y%m%d%H') time_info = ti_calculate(task_info) - input_dir = get_test_data_dir(pcw.config, subdir='accum') + input_dir = get_test_data_dir('accum') lookback = 6 * 3600 files_found = pcw.setup_add_method(time_info, lookback, data_src) assert files_found @@ -239,14 +233,14 @@ def test_setup_subtract_method(metplus_config, custom): @pytest.mark.wrapper -def test_pcp_combine_add_subhourly(metplus_config): +def test_pcp_combine_add_subhourly(metplus_config, get_test_data_dir): fcst_name = 'A000500' fcst_level = 'Surface' fcst_output_name = 'A001500' fcst_fmt = f'\'name="{fcst_name}"; level="{fcst_level}";\'' config = metplus_config - test_data_dir = get_test_data_dir(config) + test_data_dir = get_test_data_dir() fcst_input_dir = os.path.join(test_data_dir, 'pcp_in', 'add') @@ -285,16 +279,12 @@ def test_pcp_combine_add_subhourly(metplus_config): app_path = os.path.join(config.getdir('MET_BIN_DIR'), wrapper.app_name) verbosity = f"-v {wrapper.c_dict['VERBOSITY']}" out_dir = wrapper.c_dict.get('FCST_OUTPUT_DIR') - expected_cmds = [(f"{app_path} {verbosity} " - "-add " - f"{fcst_input_dir}/20190802_i1800_m0_f1815.nc " - f"{fcst_fmt} " - f"{fcst_input_dir}/20190802_i1800_m0_f1810.nc " - f"{fcst_fmt} " - f"{fcst_input_dir}/20190802_i1800_m0_f1805.nc " - f"{fcst_fmt} " + expected_cmds = [(f"{app_path} -add " + f"{fcst_input_dir}/20190802_i1800_m0_f1815.nc {fcst_fmt} " + f"{fcst_input_dir}/20190802_i1800_m0_f1810.nc {fcst_fmt} " + f"{fcst_input_dir}/20190802_i1800_m0_f1805.nc {fcst_fmt} " f'-name "{fcst_output_name}" ' - f"{out_dir}/5min_mem00_lag00.nc"), + f"{out_dir}/5min_mem00_lag00.nc {verbosity}"), ] all_cmds = wrapper.run_all_times() @@ -307,11 +297,11 @@ def test_pcp_combine_add_subhourly(metplus_config): @pytest.mark.wrapper -def test_pcp_combine_bucket(metplus_config): +def test_pcp_combine_bucket(metplus_config, get_test_data_dir): fcst_output_name = 'APCP' config = metplus_config - test_data_dir = get_test_data_dir(config) + test_data_dir = get_test_data_dir() fcst_input_dir = os.path.join(test_data_dir, 'pcp_in', 'bucket') @@ -349,8 +339,7 @@ def test_pcp_combine_bucket(metplus_config): app_path = os.path.join(config.getdir('MET_BIN_DIR'), wrapper.app_name) verbosity = f"-v {wrapper.c_dict['VERBOSITY']}" out_dir = wrapper.c_dict.get('FCST_OUTPUT_DIR') - expected_cmds = [(f"{app_path} {verbosity} " - "-add " + expected_cmds = [(f"{app_path} -add " f"{fcst_input_dir}/2012040900_F015.grib " "'name=\"APCP\"; level=\"A03\";' " f"{fcst_input_dir}/2012040900_F012.grib " @@ -358,7 +347,7 @@ def test_pcp_combine_bucket(metplus_config): f"{fcst_input_dir}/2012040900_F006.grib " "'name=\"APCP\"; level=\"A06\";' " f'-name "{fcst_output_name}" ' - f"{out_dir}/2012040915_A015.nc"), + f"{out_dir}/2012040915_A015.nc {verbosity}"), ] all_cmds = wrapper.run_all_times() @@ -384,14 +373,14 @@ def test_pcp_combine_bucket(metplus_config): ] ) @pytest.mark.wrapper -def test_pcp_combine_derive(metplus_config, config_overrides, extra_fields): +def test_pcp_combine_derive(metplus_config, get_test_data_dir, config_overrides, extra_fields): stat_list = 'sum,min,max,range,mean,stdev,vld_count' fcst_name = 'APCP' fcst_level = 'A03' fcst_fmt = f'-field \'name="{fcst_name}"; level="{fcst_level}";\'' config = metplus_config - test_data_dir = get_test_data_dir(config) + test_data_dir = get_test_data_dir() fcst_input_dir = os.path.join(test_data_dir, 'pcp_in', 'derive') @@ -437,8 +426,7 @@ def test_pcp_combine_derive(metplus_config, config_overrides, extra_fields): app_path = os.path.join(config.getdir('MET_BIN_DIR'), wrapper.app_name) verbosity = f"-v {wrapper.c_dict['VERBOSITY']}" out_dir = wrapper.c_dict.get('FCST_OUTPUT_DIR') - expected_cmds = [(f"{app_path} {verbosity} " - f"-derive {stat_list} " + expected_cmds = [(f"{app_path} -derive {stat_list} " f"{fcst_input_dir}/2005080700/24.tm00_G212 " f"{fcst_input_dir}/2005080700/21.tm00_G212 " f"{fcst_input_dir}/2005080700/18.tm00_G212 " @@ -446,7 +434,7 @@ def test_pcp_combine_derive(metplus_config, config_overrides, extra_fields): f"{fcst_input_dir}/2005080700/12.tm00_G212 " f"{fcst_input_dir}/2005080700/09.tm00_G212 " f"{fcst_fmt} {extra_fields}" - f"{out_dir}/2005080700_f24_A18.nc"), + f"{out_dir}/2005080700_f24_A18.nc {verbosity}"), ] all_cmds = wrapper.run_all_times() @@ -459,12 +447,12 @@ def test_pcp_combine_derive(metplus_config, config_overrides, extra_fields): @pytest.mark.wrapper -def test_pcp_combine_loop_custom(metplus_config): +def test_pcp_combine_loop_custom(metplus_config, get_test_data_dir): fcst_name = 'APCP' ens_list = ['ens1', 'ens2', 'ens3', 'ens4', 'ens5', 'ens6'] config = metplus_config - test_data_dir = get_test_data_dir(config) + test_data_dir = get_test_data_dir() fcst_input_dir = os.path.join(test_data_dir, 'pcp_in', 'loop_custom') @@ -505,12 +493,11 @@ def test_pcp_combine_loop_custom(metplus_config): out_dir = wrapper.c_dict.get('FCST_OUTPUT_DIR') expected_cmds = [] for ens in ens_list: - cmd = (f"{app_path} {verbosity} " - f"-add " + cmd = (f"{app_path} -add " f"{fcst_input_dir}/{ens}/2009123112_02400.grib " "'name=\"APCP\"; level=\"A24\";' " f'-name "{fcst_name}" ' - f"{out_dir}/{ens}/2009123112_02400.nc") + f"{out_dir}/{ens}/2009123112_02400.nc {verbosity}") expected_cmds.append(cmd) all_cmds = wrapper.run_all_times() @@ -523,10 +510,10 @@ def test_pcp_combine_loop_custom(metplus_config): @pytest.mark.wrapper -def test_pcp_combine_subtract(metplus_config): +def test_pcp_combine_subtract(metplus_config, get_test_data_dir): config = metplus_config - test_data_dir = get_test_data_dir(config) + test_data_dir = get_test_data_dir() fcst_input_dir = os.path.join(test_data_dir, 'pcp_in', 'derive') @@ -562,14 +549,13 @@ def test_pcp_combine_subtract(metplus_config): app_path = os.path.join(config.getdir('MET_BIN_DIR'), wrapper.app_name) verbosity = f"-v {wrapper.c_dict['VERBOSITY']}" out_dir = wrapper.c_dict.get('FCST_OUTPUT_DIR') - expected_cmds = [(f"{app_path} {verbosity} " - f"-subtract " + expected_cmds = [(f"{app_path} -subtract " f"{fcst_input_dir}/2005080700/18.tm00_G212 " "'name=\"APCP\"; level=\"A18\";' " f"{fcst_input_dir}/2005080700/15.tm00_G212 " "'name=\"APCP\"; level=\"A15\";' " '-name "APCP" ' - f"{out_dir}/2005080718_A003.nc"), + f"{out_dir}/2005080718_A003.nc {verbosity}"), ] all_cmds = wrapper.run_all_times() @@ -582,14 +568,14 @@ def test_pcp_combine_subtract(metplus_config): @pytest.mark.wrapper -def test_pcp_combine_sum_subhourly(metplus_config): +def test_pcp_combine_sum_subhourly(metplus_config, get_test_data_dir): fcst_name = 'A000500' fcst_level = 'Surface' fcst_output_name = 'A001500' fcst_fmt = f'-field \'name="{fcst_name}"; level="{fcst_level}";\'' config = metplus_config - test_data_dir = get_test_data_dir(config) + test_data_dir = get_test_data_dir() fcst_input_dir = os.path.join(test_data_dir, 'pcp_in', 'add') @@ -628,15 +614,14 @@ def test_pcp_combine_sum_subhourly(metplus_config): app_path = os.path.join(config.getdir('MET_BIN_DIR'), wrapper.app_name) verbosity = f"-v {wrapper.c_dict['VERBOSITY']}" out_dir = wrapper.c_dict.get('FCST_OUTPUT_DIR') - expected_cmds = [(f"{app_path} {verbosity} " - "-sum " + expected_cmds = [(f"{app_path} -sum " "20190802_180000 000500 " "20190802_181500 001500 " f"-pcpdir {fcst_input_dir} " f"-pcprx 20190802_i1800_m0_f* " f"{fcst_fmt} " f"-name \"{fcst_output_name}\" " - f"{out_dir}/5min_mem00_lag00.nc"), + f"{out_dir}/5min_mem00_lag00.nc {verbosity}"), ] all_cmds = wrapper.run_all_times() @@ -712,7 +697,7 @@ def test_get_extra_fields(metplus_config, names, levels, expected_args): wrapper = PCPCombineWrapper(config) - wrapper._handle_extra_field_arguments(data_src) + wrapper.set_command_line_arguments(data_src) wrapper._handle_name_argument('', data_src) for index, expected_arg in enumerate(expected_args): assert wrapper.args[index] == expected_arg @@ -720,7 +705,6 @@ def test_get_extra_fields(metplus_config, names, levels, expected_args): @pytest.mark.wrapper def test_add_method_single_file(metplus_config): - data_src = 'FCST' config = metplus_config config.set('config', 'DO_NOT_RUN_EXE', True) config.set('config', 'INPUT_MUST_EXIST', False) @@ -761,21 +745,21 @@ def test_add_method_single_file(metplus_config): in_file = (f"{wrapper.c_dict.get('FCST_INPUT_DIR')}/" "20191002_prec_1hracc_75hrfcst_e00.nc") expected_cmds = [ - (f"{app_path} {verbosity} -add " + (f"{app_path} -add " f"{in_file} 'name=\"rf\"; level=\"(20191003_00,*,*)\";' " f"{in_file} 'name=\"rf\"; level=\"(20191002_23,*,*)\";' " f"{in_file} 'name=\"rf\"; level=\"(20191002_22,*,*)\";' " - f"{out_dir}/2019100300_prec_03hracc_e00.nc"), - (f"{app_path} {verbosity} -add " + f"{out_dir}/2019100300_prec_03hracc_e00.nc {verbosity}"), + (f"{app_path} -add " f"{in_file} 'name=\"rf\"; level=\"(20191003_03,*,*)\";' " f"{in_file} 'name=\"rf\"; level=\"(20191003_02,*,*)\";' " f"{in_file} 'name=\"rf\"; level=\"(20191003_01,*,*)\";' " - f"{out_dir}/2019100303_prec_03hracc_e00.nc"), - (f"{app_path} {verbosity} -add " + f"{out_dir}/2019100303_prec_03hracc_e00.nc {verbosity}"), + (f"{app_path} -add " f"{in_file} 'name=\"rf\"; level=\"(20191003_06,*,*)\";' " f"{in_file} 'name=\"rf\"; level=\"(20191003_05,*,*)\";' " f"{in_file} 'name=\"rf\"; level=\"(20191003_04,*,*)\";' " - f"{out_dir}/2019100306_prec_03hracc_e00.nc"), + f"{out_dir}/2019100306_prec_03hracc_e00.nc {verbosity}"), ] assert len(all_cmds) == len(expected_cmds) @@ -817,7 +801,6 @@ def test_subtract_method_zero_accum(metplus_config): config.set('config', 'FCST_PCP_COMBINE_OUTPUT_ACCUM', '1H') config.set('config', 'FCST_PCP_COMBINE_OUTPUT_NAME', input_name) - # NETCDF example should use zero accum, GRIB example should not (use -add) expected_cmds_dict = {} expected_cmds_dict['NETCDF'] = [ @@ -855,10 +838,76 @@ def test_subtract_method_zero_accum(metplus_config): app_path = os.path.join(config.getdir('MET_BIN_DIR'), wrapper.app_name) verbosity = f"-v {wrapper.c_dict['VERBOSITY']}" - expected_cmds = [f"{app_path} {verbosity} {item}" + expected_cmds = [f"{app_path} {item} {verbosity}" for item in expected_cmds_dict[data_type]] assert len(all_cmds) == len(expected_cmds) for (cmd, env_vars), expected_cmd in zip(all_cmds, expected_cmds): # ensure commands are generated as expected assert cmd == expected_cmd + + +@pytest.mark.parametrize( + 'input_thresh, vld_thresh, success', [ + (None, None, False), + (0.6, None, True), + (1.0, None, False), + (None, 0.2, False), + (0.6, 0.2, True), + (1.0, 0.2, False), + ] +) +@pytest.mark.wrapper +def test_add_method_missing_input(metplus_config, get_test_data_dir, input_thresh, vld_thresh, success): + data_src = "OBS" + input_dir = get_test_data_dir('accum') + + config = metplus_config + set_minimum_config_settings(config, data_src) + config.set('config', 'LOOP_BY', "VALID") + config.set('config', 'VALID_TIME_FMT', "%Y%m%d%H") + config.set('config', 'VALID_BEG', "2016090415") + config.set('config', 'VALID_END', "2016090415") + config.set('config', 'VALID_INCREMENT', "1d") + config.set('config', f'{data_src}_PCP_COMBINE_INPUT_DIR', input_dir) + config.set('config', f'{data_src}_PCP_COMBINE_OUTPUT_ACCUM', '6H') + config.set('config', f'{data_src}_PCP_COMBINE_INPUT_ACCUMS', '1H') + if input_thresh is not None: + config.set('config', f'{data_src}_PCP_COMBINE_INPUT_THRESH', input_thresh) + if vld_thresh is not None: + config.set('config', f'{data_src}_PCP_COMBINE_VLD_THRESH', vld_thresh) + wrapper = PCPCombineWrapper(config) + + assert wrapper.isOK + + all_cmds = wrapper.run_all_times() + if not success: + assert len(all_cmds) == 0 + return + + field_name = wrapper.config.get('config', f'{data_src}_PCP_COMBINE_INPUT_NAMES') + field_info = f"'name=\"{field_name}\";'" + + app_path = os.path.join(config.getdir('MET_BIN_DIR'), wrapper.app_name) + verbosity = f"-v {wrapper.c_dict['VERBOSITY']}" + out_dir = wrapper.c_dict.get(f'{data_src}_OUTPUT_DIR') + extra_args = '' + if input_thresh: + extra_args += f' -input_thresh {input_thresh}' + if vld_thresh: + extra_args += f' -vld_thresh {vld_thresh}' + expected_cmds = [ + f"{app_path} -add" + f" {input_dir}/20160904/file.2016090415.01h {field_info}" + f" {input_dir}/20160904/file.2016090414.01h {field_info}" + f" {input_dir}/20160904/file.2016090413.01h {field_info}" + f" {input_dir}/20160904/file.2016090412.01h {field_info}" + f" MISSING{input_dir}/20160904/file.2016090411.01h {field_info}" + f" MISSING{input_dir}/20160904/file.2016090410.01h {field_info}" + f"{extra_args} {out_dir}/20160904/outfile.2016090415_A06h {verbosity}" + ] + assert len(all_cmds) == len(expected_cmds) + + for (cmd, env_vars), expected_cmd in zip(all_cmds, expected_cmds): + # ensure commands are generated as expected + assert cmd == expected_cmd diff --git a/metplus/util/system_util.py b/metplus/util/system_util.py index 29f4e8bc19..55f2f964ae 100644 --- a/metplus/util/system_util.py +++ b/metplus/util/system_util.py @@ -121,26 +121,19 @@ def prune_empty(output_dir, logger): """ # Check for empty files. - for root, dirs, files in os.walk(output_dir): - # Create a full file path by joining the path - # and filename. - for a_file in files: - a_file = os.path.join(root, a_file) - if os.stat(a_file).st_size == 0: - logger.debug("Empty file: " + a_file + - "...removing") - os.remove(a_file) + for a_file in traverse_dir(output_dir): + if os.stat(a_file).st_size == 0: + logger.debug("Empty file: " + a_file + + "...removing") + os.remove(a_file) # Now check for any empty directories, some # may have been created when removing # empty files. - for root, dirs, files in os.walk(output_dir): - for direc in dirs: - full_dir = os.path.join(root, direc) - if not os.listdir(full_dir): - logger.debug("Empty directory: " + full_dir + - "...removing") - os.rmdir(full_dir) + for full_dir in traverse_dir(output_dir, get_dirs=True): + if not os.listdir(full_dir): + logger.debug("Empty directory: " + full_dir + "...removing") + os.rmdir(full_dir) def get_files(filedir, filename_regex): @@ -353,3 +346,21 @@ def preprocess_file(filename, data_type, config, allow_dir=False): return filename return None + + +def traverse_dir(data_dir, get_dirs=False): + """!Generator used to navigate through and yield full path to all files or + directories under data_dir. + + @param data_dir directory to traverse + @param get_dirs If True, get all directories under data_dir. If False, get + all files under data_dir. Defaults to False (files). + """ + for dir_path, dirs, all_files in os.walk(data_dir, followlinks=True): + if get_dirs: + items = sorted(dirs) + else: + items = sorted(all_files) + + for dir_name in items: + yield os.path.join(dir_path, dir_name) diff --git a/metplus/util/time_util.py b/metplus/util/time_util.py index 6dc305b4b6..88c7646e41 100755 --- a/metplus/util/time_util.py +++ b/metplus/util/time_util.py @@ -13,7 +13,7 @@ from dateutil.relativedelta import relativedelta import re -from .string_manip import split_level, format_thresh +from .string_manip import format_thresh '''!@namespace TimeInfo @brief Utility to handle timing in METplus wrappers diff --git a/metplus/wrappers/command_builder.py b/metplus/wrappers/command_builder.py index cc5d6aedc9..5a18ff9be4 100755 --- a/metplus/wrappers/command_builder.py +++ b/metplus/wrappers/command_builder.py @@ -29,7 +29,7 @@ from ..util import get_wrapper_name, is_python_script from ..util.met_config import add_met_config_dict, handle_climo_dict from ..util import mkdir_p, get_skip_times -from ..util import get_log_path, RunArgs, run_cmd +from ..util import get_log_path, RunArgs, run_cmd, traverse_dir # pylint:disable=pointless-string-statement @@ -449,7 +449,7 @@ def find_obs_offset(self, time_info, mandatory=True, return_list=False): # errors when searching through offset list is_mandatory = mandatory if offsets == [0] else False - self.c_dict['SUPRESS_WARNINGS'] = True + self.c_dict['SUPPRESS_WARNINGS'] = True for offset in offsets: time_info['offset_hours'] = offset time_info = ti_calculate(time_info) @@ -458,10 +458,10 @@ def find_obs_offset(self, time_info, mandatory=True, return_list=False): return_list=return_list) if obs_path is not None: - self.c_dict['SUPRESS_WARNINGS'] = False + self.c_dict['SUPPRESS_WARNINGS'] = False return obs_path, time_info - self.c_dict['SUPRESS_WARNINGS'] = False + self.c_dict['SUPPRESS_WARNINGS'] = False # if no files are found return None # if offsets are specified, log error with list offsets used @@ -496,22 +496,6 @@ def find_data(self, time_info, data_type='', mandatory=True, if data_type and not data_type.endswith('_'): data_type_fmt += '_' - # set generic 'level' to level that corresponds to data_type if set - level = time_info.get(f'{data_type_fmt.lower()}level', '0') - - # strip off prefix letter if it exists - level = split_level(level)[1] - - # set level to 0 character if it is not a number, e.g. NetCDF level - if not level.isdigit(): - level = '0' - - # if level is a range, use the first value, i.e. if 250-500 use 250 - level = level.split('-')[0] - - # if level is in hours, convert to seconds - level = get_seconds_from_string(level, 'H') - # arguments for find helper functions arg_dict = {'data_type': data_type_fmt, 'mandatory': mandatory, @@ -522,13 +506,12 @@ def find_data(self, time_info, data_type='', mandatory=True, if (self.c_dict.get(data_type_fmt + 'FILE_WINDOW_BEGIN', 0) == 0 and self.c_dict.get(data_type_fmt + 'FILE_WINDOW_END', 0) == 0): - return self._find_exact_file(**arg_dict, allow_dir=allow_dir, - level=level) + return self._find_exact_file(**arg_dict, allow_dir=allow_dir) # if looking for a file within a time window: return self._find_file_in_window(**arg_dict) - def _find_exact_file(self, level, data_type, time_info, mandatory=True, + def _find_exact_file(self, data_type, time_info, mandatory=True, return_list=False, allow_dir=False): input_template = self.c_dict.get(f'{data_type}INPUT_TEMPLATE', '') data_dir = self.c_dict.get(f'{data_type}INPUT_DIR', '') @@ -550,19 +533,37 @@ def _find_exact_file(self, level, data_type, time_info, mandatory=True, "does not allow multiple files to be provided.") return None - # pop level from time_info to avoid conflict with explicit level - # then add it back after the string sub call - saved_level = time_info.pop('level', None) + # If level is not already set in time_info, set it and remove it later. + # Check if {data_type}level is set, e.g. fcst_level, + # otherwise use 0 to prevent error when level is requested in template. + has_level = True if time_info.get('level') else False + if not has_level: + # set generic 'level' to level that corresponds to data_type if set + level = time_info.get(f'{data_type.lower()}level', '0') + + # strip off prefix letter if it exists + level = split_level(level)[1] + + # set level to 0 character if it is not a number, e.g. NetCDF level + if not level.isdigit(): + level = '0' + + # if level is a range, use the first value, i.e. if 250-500 use 250 + level = level.split('-')[0] + + # if level is in hours, convert to seconds + level = get_seconds_from_string(level, 'H') + time_info['level'] = level input_must_exist = self._get_input_must_exist(template_list, data_dir) - check_file_list = self._get_files_to_check(template_list, level, + check_file_list = self._get_files_to_check(template_list, time_info, data_dir, data_type) - # if it was set, add level back to time_info - if saved_level is not None: - time_info['level'] = saved_level + # if it was not set, remove it from time_info + if not has_level: + time_info.pop('level', None) # if multiple files are not supported by the wrapper and multiple # files are found, error and exit @@ -578,17 +579,7 @@ def _find_exact_file(self, level, data_type, time_info, mandatory=True, # return None if no files were found if not check_file_list: msg = f"Could not find any {data_type}INPUT files" - # warn instead of error if it is not mandatory to find files - if (not mandatory - or not self.c_dict.get('MANDATORY', True) - or self.c_dict.get('ALLOW_MISSING_INPUTS', False)): - if self.c_dict.get('SUPRESS_WARNINGS', False): - self.logger.debug(msg) - else: - self.logger.warning(msg) - else: - self.log_error(msg) - + self._log_message_dynamic_level(msg, mandatory) return None found_files = self._check_that_files_exist(check_file_list, data_type, @@ -603,6 +594,28 @@ def _find_exact_file(self, level, data_type, time_info, mandatory=True, return found_files + def _is_optional_input(self, mandatory): + return (not self.c_dict.get('MANDATORY', True) + or self.c_dict.get('ALLOW_MISSING_INPUTS', False) + or not mandatory) + + def _log_message_dynamic_level(self, msg, mandatory): + """!Log message based on rules. If mandatory input and missing inputs + are not allowed, log an error. Otherwise, log a warning unless warnings + are suppressed, in which case log debug. + + @param msg message to be logged + @param mandatory boolean indicating if input data is mandatory + """ + # warn instead of error if it is not mandatory to find files + if self._is_optional_input(mandatory): + if self.c_dict.get('SUPPRESS_WARNINGS', False): + self.logger.debug(msg) + else: + self.logger.warning(msg) + else: + self.log_error(msg) + def _get_input_must_exist(self, template_list, data_dir): """!Check if input must exist. The config dict setting INPUT_MUST_EXIST can force a False result to skip checks for files existing. Also, if @@ -629,7 +642,7 @@ def _get_input_must_exist(self, template_list, data_dir): return False return True - def _get_files_to_check(self, template_list, level, time_info, data_dir, + def _get_files_to_check(self, template_list, time_info, data_dir, data_type): """!Get list of files to check if they exist. @returns list of tuples containing file path and template used to build @@ -641,7 +654,7 @@ def _get_files_to_check(self, template_list, level, time_info, data_dir, full_template = os.path.join(data_dir, template) # perform string substitution on full path - full_path = do_string_sub(full_template, **time_info, level=level) + full_path = do_string_sub(full_template, **time_info) if os.path.sep not in full_path: self.logger.debug(f"{full_path} is not a file path. " @@ -686,20 +699,11 @@ def _check_that_files_exist(self, check_file_list, data_type, allow_dir, if not processed_path: msg = (f"Could not find {data_type}INPUT file {file_path} " f"using template {template}") - if (not mandatory - or not self.c_dict.get('MANDATORY', True) - or self.c_dict.get('ALLOW_MISSING_INPUTS', False)): - - if self.c_dict.get('SUPRESS_WARNINGS', False): - self.logger.debug(msg) - else: - self.logger.warning(msg) - - if self.c_dict.get(f'{data_type}FILL_MISSING'): - found_file_list.append(f'MISSING{file_path}') - continue - else: - self.log_error(msg) + self._log_message_dynamic_level(msg, mandatory) + if (self._is_optional_input(mandatory) and + self.c_dict.get(f'{data_type}FILL_MISSING')): + found_file_list.append(f'MISSING{file_path}') + continue return None @@ -737,18 +741,7 @@ def _find_file_in_window(self, data_type, time_info, mandatory=True, if not closest_files: msg = (f"Could not find {data_type}INPUT files under {data_dir} within range " f"[{valid_range_lower},{valid_range_upper}] using template {template}") - if (not mandatory - or not self.c_dict.get('MANDATORY', True) - or self.c_dict.get('ALLOW_MISSING_INPUTS', False)): - - if self.c_dict.get('SUPRESS_WARNINGS', False): - self.logger.debug(msg) - else: - self.logger.warning(msg) - - else: - self.log_error(msg) - + self._log_message_dynamic_level(msg, mandatory) return None # remove any files that are the same as another but zipped @@ -796,41 +789,38 @@ def _get_closest_files(self, data_dir, template, valid_time, "%Y%m%d%H%M%S").strftime("%s")) # step through all files under input directory in sorted order - for dirpath, _, all_files in os.walk(data_dir, followlinks=True): - for filename in sorted(all_files): - fullpath = os.path.join(dirpath, filename) - - # remove input data directory to get relative path - rel_path = fullpath.replace(f'{data_dir}/', "") - # extract time information from relative path using template - file_time_info = get_time_from_file(rel_path, template, - self.logger) - if file_time_info is None: - continue + for fullpath in traverse_dir(data_dir): + # remove input data directory to get relative path + rel_path = fullpath.replace(f'{data_dir}/', "") + # extract time information from relative path using template + file_time_info = get_time_from_file(rel_path, template, + self.logger) + if file_time_info is None: + continue - # get valid time and check if it is within the time range - file_valid_time = file_time_info['valid'].strftime("%Y%m%d%H%M%S") - # skip if could not extract valid time - if not file_valid_time: - continue - file_valid_dt = datetime.strptime(file_valid_time, "%Y%m%d%H%M%S") - file_valid_seconds = int(file_valid_dt.strftime("%s")) - # skip if outside time range - if file_valid_seconds < lower_limit or file_valid_seconds > upper_limit: - continue + # get valid time and check if it is within the time range + file_valid_time = file_time_info['valid'].strftime("%Y%m%d%H%M%S") + # skip if could not extract valid time + if not file_valid_time: + continue + file_valid_dt = datetime.strptime(file_valid_time, "%Y%m%d%H%M%S") + file_valid_seconds = int(file_valid_dt.strftime("%s")) + # skip if outside time range + if file_valid_seconds < lower_limit or file_valid_seconds > upper_limit: + continue - # if multiple files are allowed, get all files within range - if self.c_dict.get('ALLOW_MULTIPLE_FILES', False): - closest_files.append(fullpath) - continue + # if multiple files are allowed, get all files within range + if self.c_dict.get('ALLOW_MULTIPLE_FILES', False): + closest_files.append(fullpath) + continue - # if only 1 file is allowed, check if file is - # closer to desired valid time than previous match - diff = abs(valid_seconds - file_valid_seconds) - if diff < closest_time: - closest_time = diff - del closest_files[:] - closest_files.append(fullpath) + # if only 1 file is allowed, check if file is + # closer to desired valid time than previous match + diff = abs(valid_seconds - file_valid_seconds) + if diff < closest_time: + closest_time = diff + del closest_files[:] + closest_files.append(fullpath) return closest_files @@ -874,11 +864,7 @@ def find_input_files_ensemble(self, time_info, fill_missing=True): input_files = self.find_model(time_info, return_list=True, mandatory=False) if not input_files: msg = "Could not find any input files" - if (not self.c_dict.get('MANDATORY', True) - or self.c_dict.get('ALLOW_MISSING_INPUTS', False)): - self.logger.warning(msg) - else: - self.log_error(msg) + self._log_message_dynamic_level(msg, True) return False # if control file is requested, remove it from input list @@ -1029,15 +1015,7 @@ def find_and_check_output_file(self, time_info=None, # get directory that the output file will exist if is_directory: parent_dir = output_path - valid = '*' - lead = '*' - if time_info: - if time_info['valid'] != '*': - valid = time_info['valid'].strftime('%Y%m%d_%H%M%S') - if time_info['lead'] != '*': - lead = seconds_to_met_time(time_info['lead_seconds'], - force_hms=True) - + valid, lead = self._get_valid_and_lead_from_time_info(time_info) prefix = self.get_output_prefix(time_info, set_env_vars=False) prefix = f'{self.app_name}_{prefix}' if prefix else self.app_name search_string = f'{prefix}_{lead}L_{valid}V*' @@ -1077,6 +1055,19 @@ def find_and_check_output_file(self, time_info=None, 'to process') return False + @staticmethod + def _get_valid_and_lead_from_time_info(time_info): + valid = '*' + lead = '*' + if not time_info: + return valid, lead + + if time_info['valid'] != '*': + valid = time_info['valid'].strftime('%Y%m%d_%H%M%S') + if time_info['lead'] != '*': + lead = seconds_to_met_time(time_info['lead_seconds'], force_hms=True) + return valid, lead + def check_for_externals(self): self.check_for_gempak() diff --git a/metplus/wrappers/pcp_combine_wrapper.py b/metplus/wrappers/pcp_combine_wrapper.py index d4617e3053..e00b3153cf 100755 --- a/metplus/wrappers/pcp_combine_wrapper.py +++ b/metplus/wrappers/pcp_combine_wrapper.py @@ -7,12 +7,12 @@ import os from datetime import timedelta -from ..util import do_string_sub, getlist, preprocess_file +from ..util import do_string_sub, getlist from ..util import get_seconds_from_string, ti_get_lead_string, ti_calculate from ..util import get_relativedelta, ti_get_seconds_from_relativedelta from ..util import time_string_to_met_time, seconds_to_met_time from ..util import parse_var_list, template_to_regex, split_level -from ..util import add_field_info_to_time_info, sub_var_list +from ..util import add_field_info_to_time_info, sub_var_list, MISSING_DATA_VALUE from . import ReformatGriddedWrapper '''!@namespace PCPCombineWrapper @@ -29,7 +29,7 @@ class PCPCombineWrapper(ReformatGriddedWrapper): RUNTIME_FREQ_SUPPORTED = ['RUN_ONCE_FOR_EACH'] # valid values for [FCST/OBS]_PCP_COMBINE_METHOD - valid_run_methods = ['ADD', 'SUM', 'SUBTRACT', 'DERIVE', 'USER_DEFINED'] + VALID_RUN_METHODS = ['ADD', 'SUM', 'SUBTRACT', 'DERIVE', 'USER_DEFINED'] def __init__(self, config, instance=None): self.app_name = 'pcp_combine' @@ -49,154 +49,169 @@ def create_c_dict(self): c_dict['VERBOSITY'] = self.config.getstr('config', 'LOG_PCP_COMBINE_VERBOSITY', c_dict['VERBOSITY']) - c_dict['ALLOW_MULTIPLE_FILES'] = True - fcst_run = self.config.getbool('config', 'FCST_PCP_COMBINE_RUN', False) - obs_run = self.config.getbool('config', 'OBS_PCP_COMBINE_RUN', False) - if not fcst_run and not obs_run: - self.log_error("Must set either FCST_PCP_COMBINE_RUN or " - "OBS_PCP_COMBINE_RUN") - return c_dict + if c_dict['FCST_RUN']: + c_dict = self._set_fcst_or_obs_dict_items('FCST', c_dict) - if fcst_run: - c_dict = self.set_fcst_or_obs_dict_items('FCST', c_dict) - c_dict['VAR_LIST_FCST'] = parse_var_list( - self.config, - data_type='FCST', - met_tool=self.app_name - ) - if obs_run: - c_dict = self.set_fcst_or_obs_dict_items('OBS', c_dict) - c_dict['VAR_LIST_OBS'] = parse_var_list( - self.config, - data_type='OBS', - met_tool=self.app_name - ) + if c_dict['OBS_RUN']: + c_dict = self._set_fcst_or_obs_dict_items('OBS', c_dict) return c_dict - def set_fcst_or_obs_dict_items(self, d_type, c_dict): + def _set_fcst_or_obs_dict_items(self, d_type, c_dict): """! Set c_dict values specific to either forecast (FCST) or observation (OBS) data. - @param d_type data type, either FCST or OBS + @param d_type data type, either 'FCST' or 'OBS' @param c_dict config dictionary to populate @returns c_dict with values for given data type set """ # handle run method - run_method = self.config.getstr( - 'config', - f'{d_type}_PCP_COMBINE_METHOD', '' + run_method = self.config.getraw( + 'config', f'{d_type}_PCP_COMBINE_METHOD' ).upper() # change CUSTOM (deprecated) to USER_DEFINED - if run_method == 'CUSTOM': - run_method = 'USER_DEFINED' + run_method = 'USER_DEFINED' if run_method == 'CUSTOM' else run_method - if run_method not in self.valid_run_methods: + if run_method not in self.VALID_RUN_METHODS: self.log_error(f"Invalid value for {d_type}_PCP_COMBINE_METHOD: " f"{run_method}. Valid options are " - f"{','.join(self.valid_run_methods)}.") + f"{','.join(self.VALID_RUN_METHODS)}.") return c_dict c_dict[f'{d_type}_RUN_METHOD'] = run_method + # if derive method, allow multiple files and read stat list + if c_dict[f'{d_type}_RUN_METHOD'] == "DERIVE": + c_dict[f'{d_type}_STAT_LIST'] = getlist( + self.config.getraw('config', f'{d_type}_PCP_COMBINE_STAT_LIST') + ) + c_dict['ALLOW_MULTIPLE_FILES'] = True + + # handle I/O directories and templates + c_dict[f'{d_type}_INPUT_DIR'] = self.config.getdir( + f'{d_type}_PCP_COMBINE_INPUT_DIR', '' + ) + c_dict[f'{d_type}_INPUT_TEMPLATE'] = self.config.getraw( + 'config', f'{d_type}_PCP_COMBINE_INPUT_TEMPLATE' + ) + + c_dict[f'{d_type}_OUTPUT_DIR'] = self.config.getdir( + f'{d_type}_PCP_COMBINE_OUTPUT_DIR', '' + ) + c_dict[f'{d_type}_OUTPUT_TEMPLATE'] = self.config.getraw( + 'config', f'{d_type}_PCP_COMBINE_OUTPUT_TEMPLATE' + ) + # get lookback from _LOOKBACK or _OUTPUT_ACCUM or _DERIVE_LOOKBACK c_dict[f'{d_type}_LOOKBACK'] = self._handle_lookback(c_dict, d_type) c_dict[f'{d_type}_MIN_FORECAST'] = self.config.getstr( - 'config', - f'{d_type}_PCP_COMBINE_MIN_FORECAST', '0' + 'config', f'{d_type}_PCP_COMBINE_MIN_FORECAST', '0' ) c_dict[f'{d_type}_MAX_FORECAST'] = self.config.getstr( - 'config', - f'{d_type}_PCP_COMBINE_MAX_FORECAST', '256H' + 'config', f'{d_type}_PCP_COMBINE_MAX_FORECAST', '256H' ) c_dict[f'{d_type}_INPUT_DATATYPE'] = self.config.getstr( - 'config', - f'{d_type}_PCP_COMBINE_INPUT_DATATYPE', '' + 'config', f'{d_type}_PCP_COMBINE_INPUT_DATATYPE', '' ) c_dict[f'{d_type}_ACCUMS'] = getlist( - self.config.getraw('config', - f'{d_type}_PCP_COMBINE_INPUT_ACCUMS', '') + self.config.getraw('config', f'{d_type}_PCP_COMBINE_INPUT_ACCUMS') ) c_dict[f'{d_type}_NAMES'] = getlist( - self.config.getraw('config', - f'{d_type}_PCP_COMBINE_INPUT_NAMES', '') + self.config.getraw('config', f'{d_type}_PCP_COMBINE_INPUT_NAMES') ) c_dict[f'{d_type}_LEVELS'] = getlist( - self.config.getraw('config', - f'{d_type}_PCP_COMBINE_INPUT_LEVELS', '') + self.config.getraw('config', f'{d_type}_PCP_COMBINE_INPUT_LEVELS') ) c_dict[f'{d_type}_OPTIONS'] = getlist( - self.config.getraw('config', - f'{d_type}_PCP_COMBINE_INPUT_OPTIONS', '') + self.config.getraw('config', f'{d_type}_PCP_COMBINE_INPUT_OPTIONS') ) c_dict[f'{d_type}_OUTPUT_NAME'] = self.config.getstr( - 'config', - f'{d_type}_PCP_COMBINE_OUTPUT_NAME', '' - ) - c_dict[f'{d_type}_INPUT_DIR'] = self.config.getdir( - f'{d_type}_PCP_COMBINE_INPUT_DIR', '' - ) - c_dict[f'{d_type}_INPUT_TEMPLATE'] = self.config.getraw( - 'config', - f'{d_type}_PCP_COMBINE_INPUT_TEMPLATE' - ) - - c_dict[f'{d_type}_OUTPUT_DIR'] = self.config.getdir( - f'{d_type}_PCP_COMBINE_OUTPUT_DIR', '' - ) - c_dict[f'{d_type}_OUTPUT_TEMPLATE'] = self.config.getraw( - 'config', - f'{d_type}_PCP_COMBINE_OUTPUT_TEMPLATE' - ) - - c_dict[f'{d_type}_STAT_LIST'] = getlist( - self.config.getstr('config', - f'{d_type}_PCP_COMBINE_STAT_LIST', '') + 'config', f'{d_type}_PCP_COMBINE_OUTPUT_NAME', '' ) c_dict[f'{d_type}_BUCKET_INTERVAL'] = self.config.getseconds( - 'config', - f'{d_type}_PCP_COMBINE_BUCKET_INTERVAL', 0 + 'config', f'{d_type}_PCP_COMBINE_BUCKET_INTERVAL', 0 ) c_dict[f'{d_type}_CONSTANT_INIT'] = self.config.getbool( - 'config', - f'{d_type}_PCP_COMBINE_CONSTANT_INIT', False + 'config', f'{d_type}_PCP_COMBINE_CONSTANT_INIT', False ) # read any additional names/levels to add to command c_dict[f'{d_type}_EXTRA_NAMES'] = getlist( - self.config.getraw('config', - f'{d_type}_PCP_COMBINE_EXTRA_NAMES', '') + self.config.getraw('config', f'{d_type}_PCP_COMBINE_EXTRA_NAMES') ) c_dict[f'{d_type}_EXTRA_LEVELS'] = getlist( - self.config.getraw('config', - f'{d_type}_PCP_COMBINE_EXTRA_LEVELS', '') + self.config.getraw('config', f'{d_type}_PCP_COMBINE_EXTRA_LEVELS') ) # fill in missing extra level values with None fill_num = (len(c_dict[f'{d_type}_EXTRA_NAMES']) - len(c_dict[f'{d_type}_EXTRA_LEVELS'])) - if fill_num > 0: - for _ in range(fill_num): - c_dict[f'{d_type}_EXTRA_LEVELS'].append(None) + for _ in range(fill_num): + c_dict[f'{d_type}_EXTRA_LEVELS'].append(None) c_dict[f'{d_type}_EXTRA_OUTPUT_NAMES'] = getlist( - self.config.getraw('config', - f'{d_type}_PCP_COMBINE_EXTRA_OUTPUT_NAMES', '') + self.config.getraw('config', f'{d_type}_PCP_COMBINE_EXTRA_OUTPUT_NAMES') ) c_dict[f'{d_type}_USE_ZERO_ACCUM'] = self.config.getbool( - 'config', - f'{d_type}_PCP_COMBINE_USE_ZERO_ACCUM', False + 'config', f'{d_type}_PCP_COMBINE_USE_ZERO_ACCUM', False + ) + + c_dict[f'VAR_LIST_{d_type}'] = parse_var_list( + self.config, + data_type=d_type, + met_tool=self.app_name ) + self._set_thresholds(c_dict, d_type) + self._error_check_config(c_dict, d_type) + + # skip RuntimeFreq input file logic - remove once integrated + c_dict['FIND_FILES'] = False + return c_dict + + def _set_thresholds(self, c_dict, d_type): + """!Read input_thresh value from METplusConfig and set c_dict. Report + an error if value is not between 0 and 1. Set {d_type}_FILL_MISSING to + True if input_thresh is less than 1, meaning missing input is allowed. + + @param c_dict dictionary to set values + @param d_type data type, either 'FCST' or 'OBS' + """ + for t_type in ('VLD_THRESH', 'INPUT_THRESH'): + thresh = ( + self.config.getfloat('config', f'{d_type}_PCP_COMBINE_{t_type}') + ) + if thresh == float(MISSING_DATA_VALUE): + continue + + if thresh < 0 or thresh > 1: + self.log_error(f'{d_type}_PCP_COMBINE_{t_type} must be 0-1') + continue + + c_dict[f'{d_type}_{t_type}'] = thresh + + # if missing input is allowed, add MISSING to path if file is not found + # subtract method does not support missing inputs + if (c_dict.get(f'{d_type}_INPUT_THRESH', 1) < 1 and + c_dict[f'{d_type}_RUN_METHOD'] != "SUBTRACT"): + c_dict[f'{d_type}_FILL_MISSING'] = True + + def _error_check_config(self, c_dict, d_type): + """!Check c_dict values and log errors if anything is not set properly. + + @param c_dict dictionary containing values read from config + @param d_type type of input, either 'FCST' or 'OBS' + """ + run_method = c_dict[f'{d_type}_RUN_METHOD'] if run_method == 'DERIVE' and not c_dict[f'{d_type}_STAT_LIST']: self.log_error('Statistic list is empty. Must set ' f'{d_type}_PCP_COMBINE_STAT_LIST if running ' @@ -228,16 +243,12 @@ def set_fcst_or_obs_dict_items(self, d_type, c_dict): self.log_error(f'{d_type}_PCP_COMBINE_INPUT_LEVELS list ' 'should be either empty or the same length as ' f'{d_type}_PCP_COMBINE_INPUT_ACCUMS list.') - # skip RuntimeFreq input file logic - remove once integrated - c_dict['FIND_FILES'] = False - return c_dict def run_at_time_once(self, time_info): var_list = sub_var_list(self.c_dict['VAR_LIST'], time_info) data_src = self.c_dict['DATA_SRC'] - if not var_list: - var_list = [None] + var_list = [None] if not var_list else var_list for var_info in var_list: self.run_at_time_one_field(time_info, var_info, data_src) @@ -263,24 +274,23 @@ def run_at_time_one_field(self, time_info, var_info, data_src): time_info['level'] = lookback_seconds add_field_info_to_time_info(time_info, var_info) - # if method is not USER_DEFINED or DERIVE, - # check that field information is set + can_run = False if method == "USER_DEFINED": can_run = self.setup_user_method(time_info, data_src) - elif method == "DERIVE": - can_run = self.setup_derive_method(time_info, lookback_seconds, - data_src) - elif method == "ADD": - can_run = self.setup_add_method(time_info, lookback_seconds, - data_src) - elif method == "SUM": - can_run = self.setup_sum_method(time_info, lookback_seconds, - data_src) - elif method == "SUBTRACT": - can_run = self.setup_subtract_method(time_info, lookback_seconds, - data_src) else: - can_run = None + self.args.append(f'-{method.lower()}') + if method == "DERIVE": + can_run = self.setup_derive_method(time_info, lookback_seconds, + data_src) + elif method == "ADD": + can_run = self.setup_add_method(time_info, lookback_seconds, + data_src) + elif method == "SUM": + can_run = self.setup_sum_method(time_info, lookback_seconds, + data_src) + elif method == "SUBTRACT": + can_run = self.setup_subtract_method(time_info, lookback_seconds, + data_src) if not can_run: self.log_error("pcp_combine could not generate command") @@ -289,7 +299,7 @@ def run_at_time_one_field(self, time_info, var_info, data_src): # set time info level back to lookback seconds time_info['level'] = lookback_seconds - self._handle_extra_field_arguments(data_src, time_info) + self.set_command_line_arguments(data_src, time_info) # add -name argument output_name = self.c_dict.get(f'{data_src}_OUTPUT_NAME') @@ -316,15 +326,12 @@ def setup_user_method(self, time_info, data_src): """! Setup pcp_combine to call user defined command @param time_info dictionary containing timing information - @params data_src data type (FCST or OBS) - @rtype string - @return path to output file + @param data_src data type, either 'FCST' or 'OBS' + @rtype bool + @return True always """ - command_template = self.config.getraw( - 'config', - f'{data_src}_PCP_COMBINE_COMMAND' - ) - user_command = do_string_sub(command_template, **time_info) + temp = self.config.getraw('config', f'{data_src}_PCP_COMBINE_COMMAND') + user_command = do_string_sub(temp, **time_info) self.args.extend(user_command.split()) return True @@ -334,12 +341,10 @@ def setup_subtract_method(self, time_info, accum, data_src): @param time_info object containing timing information @param accum accumulation amount to compute in seconds - @params data_src data type (FCST or OBS) + @param data_src data type, either 'FCST' or 'OBS' @rtype string @return path to output file """ - self.args.append('-subtract') - lead = time_info['lead_seconds'] lead2 = lead - accum @@ -351,18 +356,8 @@ def setup_subtract_method(self, time_info, accum, data_src): files_found = [] - full_template = os.path.join(self.c_dict[f'{data_src}_INPUT_DIR'], - self.c_dict[f'{data_src}_INPUT_TEMPLATE']) - - # get first file - filepath1 = do_string_sub(full_template, **time_info) - file1 = preprocess_file(filepath1, - self.c_dict[data_src+'_INPUT_DATATYPE'], - self.config) - - if file1 is None: - self.log_error(f'Could not find {data_src} file {filepath1} ' - f'using template {full_template}') + file1 = self.find_data(time_info, data_type=data_src) + if not file1: return None # handle field information @@ -376,6 +371,12 @@ def setup_subtract_method(self, time_info, accum, data_src): if self.c_dict.get(f"{data_src}_OPTIONS"): field_args['extra'] = self.c_dict[f"{data_src}_OPTIONS"][0] + field_info1 = self.get_field_string( + time_info=time_info, + search_accum=seconds_to_met_time(lead), + **field_args + ) + # if data is GRIB and second lead is 0, then # run PCPCombine in -add mode with just the first file if lead2 == 0 and not self.c_dict[f'{data_src}_USE_ZERO_ACCUM']: @@ -385,14 +386,9 @@ def setup_subtract_method(self, time_info, accum, data_src): f"{data_src}_PCP_COMBINE_USE_ZERO_ACCUM = True") self.args.clear() self.args.append('-add') - field_info = self.get_field_string( - time_info=time_info, - search_accum=seconds_to_met_time(lead), - **field_args - ) self.args.append(file1) - self.args.append(field_info) - files_found.append((file1, field_info)) + self.args.append(field_info1) + files_found.append((file1, field_info1)) return files_found # else continue building -subtract command @@ -404,21 +400,10 @@ def setup_subtract_method(self, time_info, accum, data_src): time_info2['level'] = accum time_info2['custom'] = time_info.get('custom', '') - filepath2 = do_string_sub(full_template, **time_info2) - file2 = preprocess_file(filepath2, - self.c_dict[data_src+'_INPUT_DATATYPE'], - self.config) - - if file2 is None: - self.log_error(f'Could not find {data_src} file {filepath2} ' - f'using template {full_template}') + file2 = self.find_data(time_info2, data_type=data_src) + if not file2: return None - field_info1 = self.get_field_string( - time_info=time_info, - search_accum=seconds_to_met_time(lead), - **field_args - ) field_info2 = self.get_field_string( time_info=time_info2, search_accum=seconds_to_met_time(lead2), @@ -441,16 +426,13 @@ def setup_sum_method(self, time_info, lookback, data_src): @param time_info object containing timing information @param lookback accumulation amount to compute in seconds - @params data_src data type (FCST or OBS) - @rtype string - @return path to output file + @param data_src data type, either 'FCST' or 'OBS' + @rtype bool + @return True always """ - self.args.append('-sum') - + in_accum = 0 if self.c_dict[f"{data_src}_ACCUMS"]: in_accum = self.c_dict[data_src+'_ACCUMS'][0] - else: - in_accum = 0 in_accum = time_string_to_met_time(in_accum, 'H') out_accum = time_string_to_met_time(lookback, 'S') @@ -480,6 +462,8 @@ def setup_sum_method(self, time_info, lookback, data_src): # set -field name and level if set in config self._handle_field_argument(data_src, time_info) + self._handle_input_thresh_argument(data_src) + return True def setup_add_method(self, time_info, lookback, data_src): @@ -491,8 +475,6 @@ def setup_add_method(self, time_info, lookback, data_src): @rtype string @return path to output file """ - self.args.append('-add') - # create list of tuples for input levels and optional field names self._build_input_accum_list(data_src, time_info) @@ -510,6 +492,8 @@ def setup_add_method(self, time_info, lookback, data_src): self.log_error(msg) return False + self._handle_input_thresh_argument(data_src) + return files_found def setup_derive_method(self, time_info, lookback, data_src): @@ -521,8 +505,6 @@ def setup_derive_method(self, time_info, lookback, data_src): @rtype string @return path to output file """ - self.args.append('-derive') - # add list of statistics self.args.append(','.join(self.c_dict[f"{data_src}_STAT_LIST"])) @@ -541,8 +523,7 @@ def setup_derive_method(self, time_info, lookback, data_src): level=accum_dict['level'], extra=accum_dict['extra']) self.run_count += 1 - input_files = self.find_data(time_info, - data_type=data_src, + input_files = self.find_data(time_info, data_type=data_src, return_list=True) if not input_files: self.missing_input_count += 1 @@ -575,6 +556,8 @@ def setup_derive_method(self, time_info, lookback, data_src): # set -field name and level from first file field info self.args.append(f'-field {files_found[0][1]}') + self._handle_input_thresh_argument(data_src) + return files_found def _handle_lookback(self, c_dict, d_type): @@ -652,9 +635,11 @@ def get_accumulation(self, time_info, accum, data_src, @param time_info dictionary containing time information @param accum desired accumulation to build in seconds - @param data_src type of data (FCST or OBS) - @rtype bool - @return True if full set of files to build accumulation is found + @param data_src type of data, either 'FCST' or 'OBS' + @param field_info_after_file if True, add field information after each + file in the arguments (defaults to True) + @rtype list + @return list of files to build accumulation or None """ search_time = time_info['valid'] custom = time_info.get('custom', '') @@ -679,18 +664,7 @@ def get_accumulation(self, time_info, accum, data_src, time_info['valid']) # log the input and output accumulation information - search_accum_list = [] - for lev in self.c_dict['ACCUM_DICT_LIST']: - if lev['template'] is not None: - search_accum_list.append(lev['template']) - else: - search_accum_list.append(ti_get_lead_string(lev['amount'], - plural=False)) - - self.logger.debug("Trying to build a " - f"{ti_get_lead_string(total_accum, plural=False)} " - "accumulation using " - f"{' or '.join(search_accum_list)} input data") + self._log_search_accum_list(total_accum) files_found = [] @@ -703,50 +677,17 @@ def get_accumulation(self, time_info, accum, data_src, # look for biggest accum that fits search for accum_dict in self.c_dict['ACCUM_DICT_LIST']: - if (accum_dict['amount'] > total_accum and - accum_dict['template'] is None): - continue - - search_file, lead = self.find_input_file(time_info['init'], - search_time, - accum_dict['amount'], - data_src, - custom) - - if not search_file: + search_file, field_info, accum_amount = ( + self._find_file_for_accum(accum_dict, total_accum, + time_info, search_time, + data_src, custom) + ) + if search_file is None: continue - # if found a file, add it to input list with info - # if template is used in accum, find value and - # apply bucket interval is set - if accum_dict['template'] is not None: - accum_amount = self.get_template_accum(accum_dict, - search_time, - lead, - data_src, - custom) - if accum_amount > total_accum: - self.logger.debug("Accumulation amount is bigger " - "than remaining accumulation.") - continue - else: - accum_amount = accum_dict['amount'] - - search_time_info = { - 'valid': search_time, - 'lead': lead, - } - field_info = self.get_field_string( - time_info=search_time_info, - search_accum=time_string_to_met_time(accum_amount), - name=accum_dict['name'], - level=accum_dict['level'], - extra=accum_dict['extra'] - ) # add file to input list and step back to find more data - self.args.append(search_file) - if field_info_after_file: - self.args.append(field_info) + self._add_file_and_field_info_to_args(search_file, field_info, + field_info_after_file) files_found.append((search_file, field_info)) self.logger.debug(f"Adding input file: {search_file} " @@ -771,6 +712,84 @@ def get_accumulation(self, time_info, accum, data_src, return files_found + def _log_search_accum_list(self, total_accum): + """!Format and log information about the desired accumulation to build + and the configurations that define the search accumulations. + + @param total_accum desired accumulation to build + """ + search_accum_list = [] + for lev in self.c_dict['ACCUM_DICT_LIST']: + if lev['template'] is not None: + search_accum_list.append(lev['template']) + else: + search_accum_list.append(ti_get_lead_string(lev['amount'], + plural=False)) + + self.logger.debug("Trying to build a " + f"{ti_get_lead_string(total_accum, plural=False)} " + "accumulation using " + f"{' or '.join(search_accum_list)} input data") + + def _add_file_and_field_info_to_args(self, search_file, field_info, + field_info_after_file): + """!Helper function to add arguments to reduce cognitive complexity + of get_accumulation function. Adds to self.args list. + + @param search_file file path + @param field_info formatted field information associate with file path + @param field_info_after_file boolean if True add field info after file + """ + self.args.append(search_file) + if field_info_after_file: + self.args.append(field_info) + + def _find_file_for_accum(self, accum_dict, total_accum, time_info, + search_time, data_src, custom): + if (accum_dict['amount'] > total_accum and + accum_dict['template'] is None): + return None, None, None + + self.c_dict['SUPPRESS_WARNINGS'] = True + search_file, lead = self.find_input_file(time_info['init'], + search_time, + accum_dict['amount'], + data_src, + custom) + self.c_dict['SUPPRESS_WARNINGS'] = False + if not search_file: + return None, None, None + + # if found a file, add it to input list with info + # if template is used in accum, find value and + # apply bucket interval is set + if accum_dict['template'] is not None: + accum_amount = self.get_template_accum(accum_dict, + search_time, + lead, + data_src, + custom) + if accum_amount > total_accum: + self.logger.debug("Accumulation amount is bigger " + "than remaining accumulation.") + return None, None, None + else: + accum_amount = accum_dict['amount'] + + search_time_info = { + 'valid': search_time, + 'lead': lead, + } + field_info = self.get_field_string( + time_info=search_time_info, + search_accum=time_string_to_met_time(accum_amount), + name=accum_dict['name'], + level=accum_dict['level'], + extra=accum_dict['extra'] + ) + + return search_file, field_info, accum_amount + def get_lowest_fcst_file(self, valid_time, data_src, custom): """! Find the lowest forecast hour that corresponds to the valid time @@ -813,18 +832,10 @@ def get_lowest_fcst_file(self, valid_time, data_src, custom): } time_info = ti_calculate(input_dict) time_info['custom'] = custom - search_file = os.path.join(self.c_dict[f'{data_src}_INPUT_DIR'], - self.c_dict[data_src+'_INPUT_TEMPLATE']) - search_file = do_string_sub(search_file, **time_info) - self.logger.debug(f"Looking for {search_file}") - - search_file = preprocess_file( - search_file, - self.c_dict[data_src+'_INPUT_DATATYPE'], - self.config) - - if search_file is not None: - return search_file, forecast_lead + search_file = self.find_data(time_info, data_type=data_src, + return_list=True, mandatory=False) + if search_file: + return search_file[0], forecast_lead forecast_lead += smallest_input_accum return None, 0 @@ -850,7 +861,6 @@ def get_field_string(self, time_info=None, search_accum=0, name=None, def find_input_file(self, init_time, valid_time, search_accum, data_src, custom): lead = 0 - in_template = self.c_dict[data_src+'_INPUT_TEMPLATE'] if ('{lead?' in in_template or @@ -871,13 +881,12 @@ def find_input_file(self, init_time, valid_time, search_accum, data_src, time_info = ti_calculate(input_dict) time_info['custom'] = custom time_info['level'] = int(search_accum) - input_path = os.path.join(self.c_dict[f'{data_src}_INPUT_DIR'], - in_template) - input_path = do_string_sub(input_path, **time_info) + input_path = self.find_data(time_info, data_type=data_src, + return_list=True, mandatory=False) + if input_path: + input_path = input_path[0] - return preprocess_file(input_path, - self.c_dict[f'{data_src}_INPUT_DATATYPE'], - self.config), lead + return input_path, lead def get_template_accum(self, accum_dict, search_time, lead, data_src, custom): @@ -908,22 +917,30 @@ def get_template_accum(self, accum_dict, search_time, lead, data_src, def get_command(self): - cmd = (f"{self.app_path} -v {self.c_dict['VERBOSITY']} " - f"{' '.join(self.args)} {self.get_output_path()}") + cmd = (f"{self.app_path} {' '.join(self.args)}" + f" {self.get_output_path()} -v {self.c_dict['VERBOSITY']}") return cmd - def _handle_extra_field_arguments(self, data_src, time_info=None): - extra_names = self.c_dict.get(data_src + '_EXTRA_NAMES') - if not extra_names: - return + def set_command_line_arguments(self, data_src, time_info=None): + """!Handle extra field arguments and vld_thresh argument. - extra_levels = self.c_dict.get(data_src + '_EXTRA_LEVELS') - for name, level in zip(extra_names, extra_levels): - field_string = self.get_field_string(time_info=time_info, - name=name, - level=level) - field_format = f"-field {field_string}" - self.args.append(field_format) + @param data_src type of data, either 'FCST' or 'OBS' + @param time_info dictionary containing time information or None + (defaults to None) + """ + extra_names = self.c_dict.get(data_src + '_EXTRA_NAMES') + if extra_names: + extra_levels = self.c_dict.get(data_src + '_EXTRA_LEVELS') + for name, level in zip(extra_names, extra_levels): + field_string = self.get_field_string(time_info=time_info, + name=name, + level=level) + field_format = f"-field {field_string}" + self.args.append(field_format) + + vld_thresh = self.c_dict.get(f'{data_src}_VLD_THRESH') + if vld_thresh: + self.args.append(f'-vld_thresh {vld_thresh}') def _handle_field_argument(self, data_src, time_info): if not self.c_dict[f'{data_src}_NAMES']: @@ -958,6 +975,13 @@ def _handle_name_argument(self, output_name, data_src): name_format = f'-name "{name_format}"' self.args.append(name_format) + def _handle_input_thresh_argument(self, data_src): + input_thresh = self.c_dict.get(f'{data_src}_INPUT_THRESH') + if not input_thresh: + return + + self.args.append(f'-input_thresh {input_thresh}') + def _build_input_accum_list(self, data_src, time_info): accum_list = self.c_dict[data_src + '_ACCUMS'] level_list = self.c_dict[data_src + '_LEVELS'] diff --git a/metplus/wrappers/reformat_gridded_wrapper.py b/metplus/wrappers/reformat_gridded_wrapper.py index 92aa3ce162..13522a2327 100755 --- a/metplus/wrappers/reformat_gridded_wrapper.py +++ b/metplus/wrappers/reformat_gridded_wrapper.py @@ -10,10 +10,6 @@ Condition codes: 0 for success, 1 for failure ''' -import os - -from ..util import get_lead_sequence -from ..util import time_util, skip_time from . import LoopTimesWrapper # pylint:disable=pointless-string-statement @@ -34,6 +30,22 @@ class ReformatGriddedWrapper(LoopTimesWrapper): def __init__(self, config, instance=None): super().__init__(config, instance=instance) + def create_c_dict(self): + c_dict = super().create_c_dict() + + # check if FCST or OBS should be run + app = self.app_name.upper() + for fcst_or_obs in ('FCST', 'OBS'): + c_dict[f'{fcst_or_obs}_RUN'] = ( + self.config.getbool('config', f'{fcst_or_obs}_{app}_RUN', False) + ) + + if not c_dict['FCST_RUN'] and not c_dict['OBS_RUN']: + self.log_error(f'Must set either FCST_{app}_RUN or OBS_{app}_RUN') + return c_dict + + return c_dict + def run_at_time(self, input_dict): """! Runs the MET application for a given run time. Processing forecast or observation data is determined by conf variables. @@ -42,22 +54,12 @@ def run_at_time(self, input_dict): @param input_dict dictionary containing init or valid time info """ - app_name_caps = self.app_name.upper() run_list = [] - if self.config.getbool('config', 'FCST_'+app_name_caps+'_RUN', False): + if self.c_dict['FCST_RUN']: run_list.append("FCST") - if self.config.getbool('config', 'OBS_'+app_name_caps+'_RUN', False): + if self.c_dict['OBS_RUN']: run_list.append("OBS") - if not run_list: - class_name = self.__class__.__name__[0: -7] - self.log_error(f"{class_name} specified in process_list, but " - f"FCST_{app_name_caps}_RUN and " - f"OBS_{app_name_caps}_RUN are both False. " - f"Set one or both to true or remove {class_name} " - "from the process_list") - return - for to_run in run_list: self.logger.info("Processing {} data".format(to_run)) self.c_dict['VAR_LIST'] = self.c_dict.get(f'VAR_LIST_{to_run}') diff --git a/metplus/wrappers/regrid_data_plane_wrapper.py b/metplus/wrappers/regrid_data_plane_wrapper.py index 940743800e..ace6a6aeb8 100755 --- a/metplus/wrappers/regrid_data_plane_wrapper.py +++ b/metplus/wrappers/regrid_data_plane_wrapper.py @@ -47,95 +47,39 @@ def create_c_dict(self): f'{app}_ONCE_PER_FIELD', True) - c_dict['FCST_INPUT_TEMPLATE'] = \ - self.config.getraw('filename_templates', - f'FCST_{app}_INPUT_TEMPLATE', - '') - - if not c_dict['FCST_INPUT_TEMPLATE']: - c_dict['FCST_INPUT_TEMPLATE'] = \ - self.config.getraw('filename_templates', - f'FCST_{app}_TEMPLATE', - '') - - c_dict['OBS_INPUT_TEMPLATE'] = \ - self.config.getraw('filename_templates', - 'OBS_REGRID_DATA_PLANE_INPUT_TEMPLATE', - '') - - if not c_dict['OBS_INPUT_TEMPLATE']: - c_dict['OBS_INPUT_TEMPLATE'] = \ - self.config.getraw('filename_templates', - 'OBS_REGRID_DATA_PLANE_TEMPLATE', - '') - - c_dict['FCST_OUTPUT_TEMPLATE'] = \ - self.config.getraw('filename_templates', - 'FCST_REGRID_DATA_PLANE_OUTPUT_TEMPLATE', - '') - - if not c_dict['FCST_OUTPUT_TEMPLATE']: - c_dict['FCST_OUTPUT_TEMPLATE'] = \ - self.config.getraw('filename_templates', - 'FCST_REGRID_DATA_PLANE_TEMPLATE', - '') - - c_dict['OBS_OUTPUT_TEMPLATE'] = \ - self.config.getraw('filename_templates', - 'OBS_REGRID_DATA_PLANE_OUTPUT_TEMPLATE', - '') - - if not c_dict['OBS_OUTPUT_TEMPLATE']: - c_dict['OBS_OUTPUT_TEMPLATE'] = \ - self.config.getraw('filename_templates', - 'OBS_REGRID_DATA_PLANE_TEMPLATE', - '') - window_types = [] - if self.config.getbool('config', 'FCST_REGRID_DATA_PLANE_RUN', False): - window_types.append('FCST') - c_dict['FCST_INPUT_DIR'] = \ - self.config.getdir('FCST_REGRID_DATA_PLANE_INPUT_DIR', '') - - c_dict['FCST_OUTPUT_DIR'] = \ - self.config.getdir('FCST_REGRID_DATA_PLANE_OUTPUT_DIR', '') - - if not c_dict['FCST_INPUT_TEMPLATE']: - self.log_error("FCST_REGRID_DATA_PLANE_INPUT_TEMPLATE must be set if " - "FCST_REGRID_DATA_PLANE_RUN is True") - - - if not c_dict['FCST_OUTPUT_TEMPLATE']: - self.log_error("FCST_REGRID_DATA_PLANE_OUTPUT_TEMPLATE must be set if " - "FCST_REGRID_DATA_PLANE_RUN is True") - - c_dict['VAR_LIST_FCST'] = parse_var_list( - self.config, - data_type='FCST', - met_tool=self.app_name - ) - - if self.config.getbool('config', 'OBS_REGRID_DATA_PLANE_RUN', False): - window_types.append('OBS') - c_dict['OBS_INPUT_DIR'] = \ - self.config.getdir('OBS_REGRID_DATA_PLANE_INPUT_DIR', '') - - c_dict['OBS_OUTPUT_DIR'] = \ - self.config.getdir('OBS_REGRID_DATA_PLANE_OUTPUT_DIR', '') - - if not c_dict['OBS_INPUT_TEMPLATE']: - self.log_error("OBS_REGRID_DATA_PLANE_INPUT_TEMPLATE must be set if " - "OBS_REGRID_DATA_PLANE_RUN is True") - - if not c_dict['OBS_OUTPUT_TEMPLATE']: - self.log_error("OBS_REGRID_DATA_PLANE_OUTPUT_TEMPLATE must be set if " - "OBS_REGRID_DATA_PLANE_RUN is True") - - c_dict['VAR_LIST_OBS'] = parse_var_list( - self.config, - data_type='OBS', - met_tool=self.app_name - ) + for fcst_or_obs in ('FCST', 'OBS'): + if not c_dict[f'{fcst_or_obs}_RUN']: + continue + + window_types.append(fcst_or_obs) + + for in_or_out in ('INPUT', 'OUTPUT'): + # read FCST/OBS_INPUT/OUTPUT_DIR + c_dict[f'{fcst_or_obs}_{in_or_out}_DIR'] = ( + self.config.getdir(f'{fcst_or_obs}_{app}_{in_or_out}_DIR') + ) + + # read FCST/OBS_INPUT/OUTPUT_TEMPLATE + name = self.config.get_mp_config_name( + [f'{fcst_or_obs}_{app}_{in_or_out}_TEMPLATE', + f'{fcst_or_obs}_{app}_TEMPLATE'] + ) + if not name: + self.log_error(f"{fcst_or_obs}_{app}_{in_or_out}_TEMPLATE " + f"must be set if {fcst_or_obs}_{app}_RUN") + continue + + c_dict[f'{fcst_or_obs}_{in_or_out}_TEMPLATE'] = ( + self.config.getraw('config', name) + ) + + # set list of variables (fields) + c_dict[f'VAR_LIST_{fcst_or_obs}'] = parse_var_list( + self.config, + data_type=fcst_or_obs, + met_tool=self.app_name + ) self.handle_file_window_variables(c_dict, data_types=window_types) diff --git a/parm/use_cases/met_tool_wrapper/PCPCombine/PCPCombine_add.conf b/parm/use_cases/met_tool_wrapper/PCPCombine/PCPCombine_add.conf index 529e6999ca..5c41b22184 100644 --- a/parm/use_cases/met_tool_wrapper/PCPCombine/PCPCombine_add.conf +++ b/parm/use_cases/met_tool_wrapper/PCPCombine/PCPCombine_add.conf @@ -70,3 +70,6 @@ FCST_PCP_COMBINE_INPUT_LEVELS = Surface FCST_PCP_COMBINE_OUTPUT_ACCUM = 15M FCST_PCP_COMBINE_OUTPUT_NAME = A001500 + +#FCST_PCP_COMBINE_INPUT_THRESH = +#FCST_PCP_COMBINE_VLD_THRESH = diff --git a/parm/use_cases/met_tool_wrapper/PCPCombine/PCPCombine_bucket.conf b/parm/use_cases/met_tool_wrapper/PCPCombine/PCPCombine_bucket.conf index bd8ca11286..6325df895b 100644 --- a/parm/use_cases/met_tool_wrapper/PCPCombine/PCPCombine_bucket.conf +++ b/parm/use_cases/met_tool_wrapper/PCPCombine/PCPCombine_bucket.conf @@ -66,3 +66,6 @@ FCST_PCP_COMBINE_INPUT_ACCUMS = {lead} FCST_PCP_COMBINE_OUTPUT_ACCUM = 15H FCST_PCP_COMBINE_OUTPUT_NAME = APCP + +#FCST_PCP_COMBINE_INPUT_THRESH = +#FCST_PCP_COMBINE_VLD_THRESH = diff --git a/parm/use_cases/met_tool_wrapper/PCPCombine/PCPCombine_derive.conf b/parm/use_cases/met_tool_wrapper/PCPCombine/PCPCombine_derive.conf index b2f8d6f637..831f636ba7 100644 --- a/parm/use_cases/met_tool_wrapper/PCPCombine/PCPCombine_derive.conf +++ b/parm/use_cases/met_tool_wrapper/PCPCombine/PCPCombine_derive.conf @@ -79,3 +79,6 @@ FCST_PCP_COMBINE_OUTPUT_NAME = #FCST_PCP_COMBINE_EXTRA_NAMES = #FCST_PCP_COMBINE_EXTRA_LEVELS = #FCST_PCP_COMBINE_EXTRA_OUTPUT_NAMES = + +#FCST_PCP_COMBINE_INPUT_THRESH = +#FCST_PCP_COMBINE_VLD_THRESH = diff --git a/parm/use_cases/met_tool_wrapper/PCPCombine/PCPCombine_loop_custom.conf b/parm/use_cases/met_tool_wrapper/PCPCombine/PCPCombine_loop_custom.conf index 64d449d8ba..720d6ccb43 100644 --- a/parm/use_cases/met_tool_wrapper/PCPCombine/PCPCombine_loop_custom.conf +++ b/parm/use_cases/met_tool_wrapper/PCPCombine/PCPCombine_loop_custom.conf @@ -70,3 +70,6 @@ FCST_PCP_COMBINE_INPUT_ACCUMS = 24H FCST_PCP_COMBINE_OUTPUT_ACCUM = 24H FCST_PCP_COMBINE_OUTPUT_NAME = APCP + +#FCST_PCP_COMBINE_INPUT_THRESH = +#FCST_PCP_COMBINE_VLD_THRESH = diff --git a/parm/use_cases/met_tool_wrapper/PCPCombine/PCPCombine_python_embedding.conf b/parm/use_cases/met_tool_wrapper/PCPCombine/PCPCombine_python_embedding.conf index d9cd56f96e..ebb7a0127e 100644 --- a/parm/use_cases/met_tool_wrapper/PCPCombine/PCPCombine_python_embedding.conf +++ b/parm/use_cases/met_tool_wrapper/PCPCombine/PCPCombine_python_embedding.conf @@ -64,6 +64,9 @@ OBS_PCP_COMBINE_INPUT_DATATYPE = PYTHON_NUMPY OBS_PCP_COMBINE_INPUT_ACCUMS = 6 OBS_PCP_COMBINE_INPUT_NAMES = {PARM_BASE}/use_cases/met_tool_wrapper/PCPCombine/sum_IMERG_V06_HDF5.py {OBS_PCP_COMBINE_INPUT_DIR} IRprecipitation {valid?fmt=%Y%m%d%H} 02 +#OBS_PCP_COMBINE_INPUT_THRESH = +#OBS_PCP_COMBINE_VLD_THRESH = + [user_env_vars] # uncomment and change this to the path of a version of python that has the h5py package installed #MET_PYTHON_EXE = /path/to/python/with/h5-py/and/numpy/packages/bin/python diff --git a/parm/use_cases/met_tool_wrapper/PCPCombine/PCPCombine_subtract.conf b/parm/use_cases/met_tool_wrapper/PCPCombine/PCPCombine_subtract.conf index caf0890409..59174513d1 100644 --- a/parm/use_cases/met_tool_wrapper/PCPCombine/PCPCombine_subtract.conf +++ b/parm/use_cases/met_tool_wrapper/PCPCombine/PCPCombine_subtract.conf @@ -69,3 +69,5 @@ FCST_PCP_COMBINE_OUTPUT_ACCUM = 3H FCST_PCP_COMBINE_OUTPUT_NAME = APCP_03 FCST_PCP_COMBINE_USE_ZERO_ACCUM = False + +#FCST_PCP_COMBINE_VLD_THRESH = diff --git a/parm/use_cases/met_tool_wrapper/PCPCombine/PCPCombine_sum.conf b/parm/use_cases/met_tool_wrapper/PCPCombine/PCPCombine_sum.conf index bdfa337ebd..9012e7fb3b 100644 --- a/parm/use_cases/met_tool_wrapper/PCPCombine/PCPCombine_sum.conf +++ b/parm/use_cases/met_tool_wrapper/PCPCombine/PCPCombine_sum.conf @@ -66,3 +66,6 @@ FCST_PCP_COMBINE_INPUT_LEVELS = Surface FCST_PCP_COMBINE_OUTPUT_ACCUM = 15M FCST_PCP_COMBINE_OUTPUT_NAME = A001500 + +#FCST_PCP_COMBINE_INPUT_THRESH = +#FCST_PCP_COMBINE_VLD_THRESH = diff --git a/ush/run_metplus.py b/ush/run_metplus.py index 9886e1119b..eb374b4427 100755 --- a/ush/run_metplus.py +++ b/ush/run_metplus.py @@ -28,6 +28,7 @@ import produtil.setup from metplus.util import pre_run_setup, run_metplus, post_run_cleanup +from metplus import __version__ as metplus_version '''!@namespace run_metplus Main script the processes all the tasks in the PROCESS_LIST @@ -57,15 +58,12 @@ def main(): def usage(): """!How to call this script.""" - print (''' -Usage: %s arg1 arg2 arg3 - -h|--help Display this usage statement - -Arguments: -/path/to/parmfile.conf -- Specify custom configuration file to use -section.option=value -- override conf options on the command line - -'''%(basename(__file__))) + print(f"Running METplus v{metplus_version}\n" + f"Usage: {basename(__file__)} arg1 arg2 arg3\n" + " -h|--help Display this usage statement\n\n" + "Arguments:\n" + "/path/to/parmfile.conf -- Specify custom configuration file to use\n" + "section.option=value -- override conf options on the command line") sys.exit(2) @@ -83,9 +81,8 @@ def get_config_inputs_from_command_line(): # print usage statement and exit if help arg is found help_args = ('-h', '--help', '-help') - for help_arg in help_args: - if help_arg in sys.argv: - usage() + if any(arg in sys.argv for arg in help_args): + usage() # pull out command line arguments config_inputs = []