-
Notifications
You must be signed in to change notification settings - Fork 3
Scripts - HRRR - Check that all requested variables are in the grib file #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
brentwilder
wants to merge
3
commits into
iSnobal:main
Choose a base branch
from
brentwilder:check-vars
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -107,6 +107,11 @@ check_file_existence(){ | |
| # Pass EXIT_ON_SUCCESS to exit the job when found. | ||
| # return 3 on failure and signal alt pathway | ||
| if [[ -s "${FILE_NAME}" ]]; then | ||
| # If data is missing vars we remove it from disk | ||
| if ! check_file_is_valid_and_index "${FILE_NAME}"; then | ||
| rm -f "${FILE_NAME}" | ||
| return 3 | ||
| fi | ||
|
jomey marked this conversation as resolved.
|
||
| if [[ "${1}" == "${EXIT_ON_SUCCESS}" ]]; then | ||
| printf " exists \n" | ||
| exit 0 | ||
|
|
@@ -117,6 +122,39 @@ check_file_existence(){ | |
| } | ||
| export -f check_file_existence | ||
|
|
||
|
|
||
| check_file_is_valid_and_index() { | ||
| # Checks file has all required HRRR Variables | ||
| # If this check passes, we write the index file | ||
| local file=$1 | ||
| local metadata | ||
| local var | ||
| local file_idx_data | ||
|
|
||
| # Check to make sure index exists, if not create it | ||
| if [[ -f "${file}.idx" ]]; then | ||
| metadata=$(cut -d: -f4,5 "${file}.idx") | ||
| else | ||
| file_idx_data=$(wgrib2 "${file}" -s 2>/dev/null) | ||
| metadata=$(echo "${file_idx_data}" | cut -d: -f4,5) | ||
| fi | ||
|
|
||
| # Look through to ensure hrrr vars are present | ||
| IFS='|' read -ra vars <<< "${HRRR_VARS}" | ||
| for var in "${vars[@]}"; do | ||
| if ! echo "${metadata}" | grep -E -q "^${var}(:| )?"; then | ||
| return 1 | ||
| fi | ||
| done | ||
|
|
||
| # Write index if it does not exist yet | ||
| if [[ -n "${file_idx_data}" ]]; then | ||
| echo "${file_idx_data}" > "${file}.idx" | ||
| fi | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about doing this on line #136 and then using that as the basis for "grepping". If we have a miss, we will delete it again on line #146 I know that creating this index is quick and this way we would still only do it once |
||
| return 0 | ||
| } | ||
| export -f check_file_is_valid_and_index | ||
|
|
||
| get_grib_range(){ | ||
| INDEX_FILE=$(curl -s "${ARCHIVE_URL}.idx") | ||
| RANGE_GREP="grep -A 1 -B 1 " | ||
|
|
@@ -204,9 +242,10 @@ download_hrrr() { | |
|
|
||
| rm "$TMP_FILE" | ||
|
|
||
| # If download produced zero size file, retry with alternate archives | ||
| if [[ ! -s "$FILE_NAME" ]]; then | ||
| >&2 printf " File is zero size, checking alternate archives...\n" | ||
| # If download produced zero size file (or missing vars), retry with alternate archives | ||
| check_file_existence | ||
| if [[ $? -eq 3 ]]; then | ||
| >&2 printf " File is zero size or has missing variables, checking alternate archives...\n" | ||
|
|
||
| # Loop through archives until file is no longer zero size | ||
| # or all archives have been checked. | ||
|
|
@@ -220,22 +259,23 @@ download_hrrr() { | |
| wgrib2 - -v0 ${GRIB_THREADS} -match "${HRRR_VARS}" -grib "$FILE_NAME" >&1 | ||
| find . -type f -name "${FILE_NAME}.missing" -size 0 -delete | ||
| rm "$TMP_FILE" | ||
| # break loop once file successfully downloaded and nonzero | ||
| [[ -s "$FILE_NAME" ]] && break | ||
| # Break loop once file successfully downloaded and has valid data | ||
| check_file_existence | ||
| if [[ $? -eq 0 ]]; then | ||
| break | ||
| fi | ||
| # Otherwise keep going | ||
| >&2 printf " Still zero size from %s\n" "$ALT_ARCHIVE" | ||
| fi | ||
| done | ||
| fi | ||
|
|
||
| if [[ -s "$FILE_NAME" ]]; then | ||
| # Create index file | ||
| wgrib2 -s "${FILE_NAME}" > "${FILE_NAME}.idx" | ||
| if [[ -f "${FILE_NAME}.idx" ]]; then | ||
| printf " created \n" | ||
| fi | ||
|
|
||
| # If the previous hour forecast successfully downloaded, replace missing file with it | ||
| if [[ -n "$MISSING_FILE" ]] && [[ -s "$FILE_NAME" ]]; then | ||
| if [[ -n "$MISSING_FILE" ]] && [[ -f "${FILE_NAME}.idx" ]]; then | ||
| "$COPY_SCRIPT" "$FILE_NAME" "$MISSING_FILE" | ||
| fi | ||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.