Skip to content

Commit

Permalink
Feature 339 tcdiag skewt (#365)
Browse files Browse the repository at this point in the history
* Issu #337 initial version of skew T, hard-coded, proof-of-concept version

* initial commit of config file

* Addes some logic to retrieve units for each field.  Still need to get the units for the levels (z).

* Added a few more settings for setting sounding hours of interest.

* Issue #337 added support to get the YYMMDDhh and basin-storm id from the input file

* Issue #337 added logging support

* Issue #337 added settings for logging, decimation, turning on/off plotting features.

* Issue #337 updated logging

* instructions and environment yaml file

* Remove hard-coded paths

* reinstated resampling/decimating wind barbs

* fix comment for labels along the y2-axis

* Close figure after saving to prevent warning from Matplotlib about too many figures opened at once

* allow user to specify subdir for log and output dirs

* Added a note to the README about which line options are supported, as per the error message I recieved when I used an unsupported value (I didn't see the explanation in the config file at first)  -- if not all of these values are actually appropriate, adjust this message as needed.

* updated year for copyright, reformatted file, fixed typos

* tests for partially and completely missing data

* partial and completely missing data to use for testing

* config file for testing

* checking for missing data

* Add check for empty file

* Update requirements.txt

update scipy from 1.9.3 to 1.10.0 to address dependabot/vulnerability

* clean up code following sonarlint check

* resolve conflict

* fixed indentation of 'return'- previously got indented too far and only processes the first sounding time

* new data to test behavior when there is an empty file

* Clean up tests, add test for empty input data file

---------

Co-authored-by: Jonathan Vigh <[email protected]>
  • Loading branch information
bikegeek and jvigh authored Jul 11, 2023
1 parent 38ecf69 commit 6280c79
Show file tree
Hide file tree
Showing 6 changed files with 539 additions and 53 deletions.

Large diffs are not rendered by default.

20 changes: 16 additions & 4 deletions metplotpy/plots/skew_t/skew_t.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import re
import logging
import warnings
import shutil

import pandas
import pandas as pd
Expand Down Expand Up @@ -441,7 +442,7 @@ def retrieve_height(sounding_data: pd.DataFrame, hour_of_interest: str,
return hgt_by_hour


def check_for_all_na(input_file, soundings_df: pandas.DataFrame) -> bool:
def check_for_all_na(soundings_df: pandas.DataFrame) -> bool:
''' Checks if the file consists entirely of the fill/missing data value of 9999.
Args:
Expand Down Expand Up @@ -502,12 +503,22 @@ def create_skew_t(input_file: str, config: dict) -> None:
Return:
None, generate plots as png files in the specified output file directory.
'''


file_only = os.path.basename(input_file)
logger.info(f" Creating skew T plots for input file {file_only} ")

# Check for zero-sized file and log empty file and return to continue to the next
# file in the input directory.
if os.stat(input_file).st_size == 0:
logger.warning(f"EMPTY FILE, NO CONTENT in {file_only}. NO PLOT "
f"GENERATED.")
return

sounding_df, plevs = extract_sounding_data(input_file)

# Check if sounding data consists entirely of na-values.
all_na = check_for_all_na(input_file, sounding_df)
all_na = check_for_all_na(sounding_df)
if all_na:
logger.warning(f"NO DATA to plot for {file_only}. NO PLOT GENERATED.")
return
Expand Down Expand Up @@ -567,7 +578,7 @@ def create_skew_t(input_file: str, config: dict) -> None:
continue

v_winds_all_nan = check_list_for_all_nan(v_winds)
if u_winds_all_nan:
if v_winds_all_nan:
logger.warning(f"No data for the v-winds for {cur_time} hour and "
f"{file_only}")
continue
Expand Down Expand Up @@ -667,6 +678,8 @@ def create_skew_t(input_file: str, config: dict) -> None:
plt.close('all')
logger.info(f"Finished generating plots for {cur_time} hr in {file_only}")

return


def main(config_filename=None):
'''
Expand Down Expand Up @@ -728,7 +741,6 @@ def main(config_filename=None):
for file_of_interest in files_of_interest:
create_skew_t(file_of_interest, config)

# create_skew_t(input_file, config)
except yaml.YAMLError as exc:
logger.error(f"YAMLError: {exc}")

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plotly==5.13.0
pytest>=7.2.1
pyyaml==6.0
scikit-image==0.19.3
scipy==1.10.0
scipy==1.10.0
xarray==2023.1.0
eofs==1.4.0
#cartopy==0.21.1
Expand Down
Loading

0 comments on commit 6280c79

Please sign in to comment.