From b994dfcb7381c1d155a204bef97306bbbdc863b1 Mon Sep 17 00:00:00 2001 From: David John Gagne Date: Thu, 30 Sep 2021 11:24:14 -0600 Subject: [PATCH] Addressing flake8 errors. --- .travis.yml | 15 -- demos/obj_tracking.py | 23 +-- doc/conf.py | 131 +++++++++--------- hagelslag/data/GribModelGrid.py | 4 +- hagelslag/processing/STObject.py | 2 +- hagelslag/processing/TrackProcessing.py | 9 +- hagelslag/util/lsr_calibration_dataset.py | 2 +- .../util/mrms_mesh_calibration_dataset.py | 6 +- hagelslag/util/testing_sector.py | 2 +- requirements.txt | 2 +- 10 files changed, 93 insertions(+), 103 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index ec3da2d..0000000 --- a/.travis.yml +++ /dev/null @@ -1,15 +0,0 @@ -language: python -env: - - PYTHON_VERSION=3.8 IPYTHON_KERNEL=python3 -before_install: - - wget -q https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh - - sh Miniconda3-latest-Linux-x86_64.sh -b -p /home/travis/miniconda - - export PATH=/home/travis/miniconda/bin:$PATH -install: - - conda env create -f environment.yml - - source activate hagelslag - - echo `which python` -script: - - pytest -notifications: - email: true diff --git a/demos/obj_tracking.py b/demos/obj_tracking.py index 3b20a2a..18181ca 100755 --- a/demos/obj_tracking.py +++ b/demos/obj_tracking.py @@ -18,10 +18,12 @@ import numpy as np from scipy.ndimage import gaussian_filter, find_objects -from hagelslag.data import ModelOutput -from hagelslag.processing import STObject +from hagelslag.data.ModelOutput import ModelOutput +from hagelslag.processing.STObject import STObject from hagelslag.processing.EnhancedWatershedSegmenter import EnhancedWatershed from hagelslag.processing.ObjectMatcher import ObjectMatcher, closest_distance +from netCDF4 import Dataset + # In[2]: @@ -49,7 +51,8 @@ # data_increment (int): quantization interval. Use 1 if you don't want to quantize # max_thresh (int): values greater than maxThresh are treated as the maximum threshold # size_threshold_pixels (int): clusters smaller than this threshold are ignored. -# delta (int): maximum number of data increments the cluster is allowed to range over. Larger d results in clusters over larger scales. +# delta (int): maximum number of data increments the cluster is allowed to range over. Larger d results in +# clusters over larger scales. # From ahij's config file. if field == "MAX_UPDRAFT_HELICITY" or field == "UP_HELI_MAX03": @@ -61,11 +64,10 @@ levels = params['min_thresh'] * np.arange(1, 8) levels = np.append(levels, params['min_thresh'] * 15) model_watershed_params = ( -params['min_thresh'], params['step'], params['max_thresh'], params["max_size"], params["delta"]) + params['min_thresh'], params['step'], params['max_thresh'], params["max_size"], params["delta"]) end_date = start_date + timedelta(hours=0) -from netCDF4 import Dataset model_grid = ModelOutput(ensemble_name, member, @@ -149,15 +151,16 @@ def get_forecast_objects(model_grid, ew_params, min_size, gaussian_window): num_slices = len(obj_slices) model_objects.append([]) if num_slices > 0: - fig, ax = plt.subplots() - t = plt.contourf(model_grid.lon, model_grid.lat, hour_labels, np.arange(0, num_slices + 1) + 0.5, + plt.subplots() + plt.contourf(model_grid.lon, model_grid.lat, hour_labels, np.arange(0, num_slices + 1) + 0.5, extend="max", cmap="Set1", latlon=True, title=str(run_date) + " " + field + " " + str(h)) - ret = plt.savefig(odir + "enh_watershed_ex/ew{0:02d}.png".format(h)) + plt.savefig(odir + "enh_watershed_ex/ew{0:02d}.png".format(h)) for s, sl in enumerate(obj_slices): model_objects[-1].append(STObject(model_grid.data[h][sl], # np.where(hour_labels[sl] > 0, 1, 0), # For some objects (especially long, diagonal ones), the rectangular - # slice encompasses part of other objects (i.e. non-zero elements of slice). + # slice encompasses part of other objects + # (i.e. non-zero elements of slice). # We don't want them in our mask. np.where(hour_labels[sl] == s + 1, 1, 0), model_grid.x[sl], @@ -198,7 +201,7 @@ def track_forecast_objects(input_model_objects, model_grid, object_matcher): elif len(past_time_objs) > 0 and len(model_objects[h]) > 0: assignments = object_matcher.match_objects(past_time_objs, model_objects[h], h - 1, h) print("assignments:", assignments) - unpaired = range(len(model_objects[h])) + unpaired = list(range(len(model_objects[h]))) for pair in assignments: past_time_objs[pair[0]].extend(model_objects[h][pair[1]]) unpaired.remove(pair[1]) diff --git a/doc/conf.py b/doc/conf.py index 42c9f08..fca195e 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -12,28 +12,30 @@ # All configuration values have a default; values that are commented out # serve to show the default. -import sys import os -import shlex +import sys + from mock import Mock as MagicMock class Mock(MagicMock): @classmethod def __getattr__(cls, name): - return Mock() + return Mock() -MOCK_MODULES = ['numpy', 'scipy', 'pandas', 'skimage', 'netCDF4', 'basemap', 'matplotlib', "pyproj", "Nio", "scipy.spatial", - "pygrib", "mpl_toolkits", "mpl_toolkits.axes_grid1", "mpl_toolkits.basemap", "mpl_toolkits.basemap.pyproj", +MOCK_MODULES = ['numpy', 'scipy', 'pandas', 'skimage', 'netCDF4', 'basemap', 'matplotlib', "pyproj", "Nio", + "scipy.spatial", + "pygrib", "mpl_toolkits", "mpl_toolkits.axes_grid1", "mpl_toolkits.basemap", + "mpl_toolkits.basemap.pyproj", "sklearn", 'skimage.morphology', "scipy.ndimage", "matplotlib.pyplot", "scipy.stats", "scipy.signal", - "skimage.measure", "skimage.segmentation", "scipy.interpolate", "skimage.draw", - "mpl_toolkits.axes_grid1.inset_locator", "glue", "sklearn.linear_model", "glue.viewers", "glue.viewers.custom", + "skimage.measure", "skimage.segmentation", "scipy.interpolate", "skimage.draw", + "mpl_toolkits.axes_grid1.inset_locator", "glue", "sklearn.linear_model", "glue.viewers", + "glue.viewers.custom", "glue.viewers.custom.qt", "glue.core", "shapefile", "ncepgrib2", "glue.config", "sklearn.decomposition", "sklearn.model_selection", "arrow"] sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES) - # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. @@ -42,7 +44,7 @@ def __getattr__(cls, name): # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. -#needs_sphinx = '1.0' +# needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom @@ -64,14 +66,14 @@ def __getattr__(cls, name): source_suffix = '.rst' # The encoding of source files. -#source_encoding = 'utf-8-sig' +# source_encoding = 'utf-8-sig' # The master toctree document. master_doc = 'index' # General information about the project. project = u'hagelslag' -copyright = u'2017, David John Gagne II' +copyright = u'2017-2021, David John Gagne II' author = u'David John Gagne II' # The version info for the project you're documenting, acts as replacement for @@ -92,9 +94,9 @@ def __getattr__(cls, name): # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: -#today = '' +# today = '' # Else, today_fmt is used as the format for a strftime call. -#today_fmt = '%B %d, %Y' +# today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. @@ -102,32 +104,31 @@ def __getattr__(cls, name): # The reST default role (used for this markup: `text`) to use for all # documents. -#default_role = None +# default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. -#add_function_parentheses = True +# add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). -#add_module_names = True +# add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. -#show_authors = False +# show_authors = False # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' # A list of ignored prefixes for module index sorting. -#modindex_common_prefix = [] +# modindex_common_prefix = [] # If true, keep warnings as "system message" paragraphs in the built documents. -#keep_warnings = False +# keep_warnings = False # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = False - # -- Options for HTML output ---------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for @@ -140,23 +141,23 @@ def __getattr__(cls, name): html_theme_options = {'sidebarwidth': 375} # Add any paths that contain custom themes here, relative to this directory. -#html_theme_path = [] +# html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". -#html_title = None +# html_title = None # A shorter title for the navigation bar. Default is the same as html_title. -#html_short_title = None +# html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. -#html_logo = None +# html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. -#html_favicon = None +# html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, @@ -166,62 +167,62 @@ def __getattr__(cls, name): # Add any extra paths that contain custom files (such as robots.txt or # .htaccess) here, relative to this directory. These files are copied # directly to the root of the documentation. -#html_extra_path = [] +# html_extra_path = [] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. -#html_last_updated_fmt = '%b %d, %Y' +# html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. -#html_use_smartypants = True +# html_use_smartypants = True # Custom sidebar templates, maps document names to template names. -#html_sidebars = {} +# html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. -#html_additional_pages = {} +# html_additional_pages = {} # If false, no module index is generated. -#html_domain_indices = True +# html_domain_indices = True # If false, no index is generated. -#html_use_index = True +# html_use_index = True # If true, the index is split into individual pages for each letter. -#html_split_index = False +# html_split_index = False # If true, links to the reST sources are added to the pages. -#html_show_sourcelink = True +# html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -#html_show_sphinx = True +# html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. -#html_show_copyright = True +# html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. -#html_use_opensearch = '' +# html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). -#html_file_suffix = None +# html_file_suffix = None # Language to be used for generating the HTML full-text search index. # Sphinx supports the following languages: # 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja' # 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr' -#html_search_language = 'en' +# html_search_language = 'en' # A dictionary with options for the search language support, empty by default. # Now only 'ja' uses this config value -#html_search_options = {'type': 'default'} +# html_search_options = {'type': 'default'} # The name of a javascript file (relative to the configuration directory) that # implements a search results scorer. If empty, the default will be used. -#html_search_scorer = 'scorer.js' +# html_search_scorer = 'scorer.js' # Output file base name for HTML help builder. htmlhelp_basename = 'hagelslagdoc' @@ -229,46 +230,46 @@ def __getattr__(cls, name): # -- Options for LaTeX output --------------------------------------------- latex_elements = { -# The paper size ('letterpaper' or 'a4paper'). -#'papersize': 'letterpaper', + # The paper size ('letterpaper' or 'a4paper'). + # 'papersize': 'letterpaper', -# The font size ('10pt', '11pt' or '12pt'). -#'pointsize': '10pt', + # The font size ('10pt', '11pt' or '12pt'). + # 'pointsize': '10pt', -# Additional stuff for the LaTeX preamble. -#'preamble': '', + # Additional stuff for the LaTeX preamble. + # 'preamble': '', -# Latex figure (float) alignment -#'figure_align': 'htbp', + # Latex figure (float) alignment + # 'figure_align': 'htbp', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, 'hagelslag.tex', u'hagelslag Documentation', - u'David John Gagne II', 'manual'), + (master_doc, 'hagelslag.tex', u'hagelslag Documentation', + u'David John Gagne II', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of # the title page. -#latex_logo = None +# latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. -#latex_use_parts = False +# latex_use_parts = False # If true, show page references after internal links. -#latex_show_pagerefs = False +# latex_show_pagerefs = False # If true, show URL addresses after external links. -#latex_show_urls = False +# latex_show_urls = False # Documents to append as an appendix to all manuals. -#latex_appendices = [] +# latex_appendices = [] # If false, no module index is generated. -#latex_domain_indices = True +# latex_domain_indices = True # -- Options for manual page output --------------------------------------- @@ -281,7 +282,7 @@ def __getattr__(cls, name): ] # If true, show URL addresses after external links. -#man_show_urls = False +# man_show_urls = False # -- Options for Texinfo output ------------------------------------------- @@ -290,19 +291,19 @@ def __getattr__(cls, name): # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'hagelslag', u'hagelslag Documentation', - author, 'hagelslag', 'One line description of project.', - 'Miscellaneous'), + (master_doc, 'hagelslag', u'hagelslag Documentation', + author, 'hagelslag', 'One line description of project.', + 'Miscellaneous'), ] # Documents to append as an appendix to all manuals. -#texinfo_appendices = [] +# texinfo_appendices = [] # If false, no module index is generated. -#texinfo_domain_indices = True +# texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. -#texinfo_show_urls = 'footnote' +# texinfo_show_urls = 'footnote' # If true, do not generate a @detailmenu in the "Top" node's menu. -#texinfo_no_detailmenu = False +# texinfo_no_detailmenu = False diff --git a/hagelslag/data/GribModelGrid.py b/hagelslag/data/GribModelGrid.py index 7fe78e6..ee6af35 100644 --- a/hagelslag/data/GribModelGrid.py +++ b/hagelslag/data/GribModelGrid.py @@ -59,7 +59,7 @@ def __enter__(self): def format_grib_name(self, selected_variable): """ Assigns name to grib2 message number with name 'unknown'. Names based on NOAA grib2 abbreviations. - + Names: 197: RETOP: Echo Top 198: MAXREF: Hourly Maximum of Simulated Reflectivity at 1 km AGL @@ -71,7 +71,7 @@ def format_grib_name(self, selected_variable): 221: MAXDVV: Hourly Maximum of Downward Vertical Velocity in the lowest 400hPa 222: MAXUW: U Component of Hourly Maximum 10m Wind Speed 223: MAXVW: V Component of Hourly Maximum 10m Wind Speed - + Args: selected_variable(str): Name of selected variable for loading Returns: diff --git a/hagelslag/processing/STObject.py b/hagelslag/processing/STObject.py index f846d54..aa7f2fe 100644 --- a/hagelslag/processing/STObject.py +++ b/hagelslag/processing/STObject.py @@ -154,7 +154,7 @@ def trajectory(self): def get_corner(self, time): """ - Gets the corner array indices of the STObject at a given time that corresponds + Gets the corner array indices of the STObject at a given time that corresponds to the upper left corner of the bounding box for the STObject. Args: diff --git a/hagelslag/processing/TrackProcessing.py b/hagelslag/processing/TrackProcessing.py index 489d6e0..7fa4ed4 100644 --- a/hagelslag/processing/TrackProcessing.py +++ b/hagelslag/processing/TrackProcessing.py @@ -547,12 +547,13 @@ def match_single_track_dist(model_track, obs_track): def match_hail_size_step_distributions(self, model_tracks, obs_tracks, track_pairings): """ - Given a matching set of observed tracks for each model track, + Given a matching set of observed tracks for each model track, combine the hail size values and create + an observed hail size distribution. Args: - model_tracks: - obs_tracks: - track_pairings: + model_tracks: List of STObjects + obs_tracks: List of STObjects + track_pairings: Returns: diff --git a/hagelslag/util/lsr_calibration_dataset.py b/hagelslag/util/lsr_calibration_dataset.py index 9872482..b627c63 100644 --- a/hagelslag/util/lsr_calibration_dataset.py +++ b/hagelslag/util/lsr_calibration_dataset.py @@ -5,7 +5,7 @@ import pyproj from netCDF4 import Dataset -from make_proj_grids import * +from make_proj_grids import read_ncar_map_file, make_proj_grids def main(): diff --git a/hagelslag/util/mrms_mesh_calibration_dataset.py b/hagelslag/util/mrms_mesh_calibration_dataset.py index bb30a19..bbf133a 100644 --- a/hagelslag/util/mrms_mesh_calibration_dataset.py +++ b/hagelslag/util/mrms_mesh_calibration_dataset.py @@ -19,9 +19,9 @@ def main(): parser.add_argument("-a", "--mask_file", required=True, help="Path to the ensemble mask file") args = parser.parse_args() if args.end_date: - run_dates = pd.DatetimeIndex(start=args.start_date, end=args.end_date, freq='1D').strftime("%y%m%d") + run_dates = pd.date_range(start=args.start_date, end=args.end_date, freq='1D').strftime("%y%m%d") else: - run_dates = pd.DatetimeIndex(start=args.start_date, end=args.start_date, freq='1D').strftime("%y%m%d") + run_dates = pd.date_range(start=args.start_date, end=args.start_date, freq='1D').strftime("%y%m%d") data_path = args.data_path out_path = args.out_path mapfile = args.map_file @@ -31,7 +31,7 @@ def main(): return -def MESH_verification_data(data_path, maskfile, mapfile, run_dates, out_path, hours=[17, 19, 21]): +def MESH_verification_data(data_path, maskfile, mapfile, run_dates, out_path, hours=(17, 19, 21)): """ Calculate 40 km halos around MESH values greater than a threshold value """ diff --git a/hagelslag/util/testing_sector.py b/hagelslag/util/testing_sector.py index 45c5e46..61247d7 100644 --- a/hagelslag/util/testing_sector.py +++ b/hagelslag/util/testing_sector.py @@ -3,7 +3,7 @@ import numpy as np import pandas as pd -from create_sector_grid_data import * +from create_sector_grid_data import SectorProcessor from hagelslag.processing.ObjectMatcher import centroid_distance, time_distance from hagelslag.processing.ObjectMatcher import shifted_centroid_distance diff --git a/requirements.txt b/requirements.txt index e63baa4..2aecb80 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,4 +15,4 @@ s3fs xarray sphinx pytest - +mock