Skip to content

Commit

Permalink
Add linting via flake to github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
mandli committed May 24, 2024
1 parent ddc6de0 commit 4b91c9f
Show file tree
Hide file tree
Showing 18 changed files with 102 additions and 70 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Storm surge examples testing

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Checkout clawpack
uses: actions/checkout@v4.1.5
with:
repository: clawpack/clawpack
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install gfortran liblapack-pic liblapack-dev libnetcdf-dev libnetcdff-dev
python -m pip install --upgrade pip
pip install flake8 pytest
- name: Setup clawpack super repository
run: |
git submodule init
git submodule update
pip install --user -e .
- name: Lint with flake8
run: |
cd geoclaw
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
# - name: Test with pytest
# run: |
# cd geoclaw
# pytest
9 changes: 1 addition & 8 deletions World_Simulation/setplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,7 @@ def gauge_afteraxes(cd):
axes.set_xticks([0, 1, 2, 3, 4, 5, 6, 7, 8])
axes.set_xticklabels([r"$0$",r"$1$",r"$2$", r"$3$", r"$4$", r"$5$", r"$6$", r"$7$", r"$8$"])
axes.grid(True)


try:
gauge_data=gauges[cd.gaugeno-1]
axes.plot(gauge_data[:,0], gauge_data[:,1], label=data_names[cd.gaugeno-1])
axes.legend()
except:
print('Gauge Data Unavailable')

plotaxes.afteraxes = gauge_afteraxes


Expand Down
2 changes: 1 addition & 1 deletion delta_2020/setrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ def setgeo(rundata):

# Convert ATCF data to GeoClaw format
clawutil.data.get_remote_file("http://ftp.nhc.noaa.gov/atcf/archive/2020/bal262020.dat.gz")
atcf_path = os.path.join(data_dir, "bal262020.dat")
atcf_path = os.path.join(scratch_dir, "bal262020.dat")
# Note that the get_remote_file function does not support gzip files which
# are not also tar files. The following code handles this
with gzip.open(".".join((atcf_path, 'gz')), 'rb') as atcf_file, \
Expand Down
2 changes: 1 addition & 1 deletion dennis_2005/setrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ def setgeo(rundata):
topo_path = os.path.join(scratch_dir, 'gulf_caribbean.tt3')
topo_data.topofiles.append([3, topo_path])

clawutil.data.get_remote_file(
clawutil.data.get_remote_file(
"https://www.jumbomail.me/l/en/gallery/6C697261515A333163756E464B3342347436653838673D3D/715049578")
topo_path = os.path.join(scratch_dir, 'gulf_caribbean.tt3')
topo_data.topofiles.append([3, topo_path])
Expand Down
10 changes: 6 additions & 4 deletions florence_2018/setplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"""
import os
import io
import urllib.request

import numpy as np
import matplotlib
Expand Down Expand Up @@ -43,7 +45,7 @@ def setplot(plotdata):

# Load data from output
clawdata = clawpack.clawutil.data.ClawInputData(2)
clawdata.read('claw.data')
clawdata.read(os.path.join(plotdata.outdir,'claw.data'))
physics = clawpack.geoclaw.data.GeoClawData()
physics.read(os.path.join(plotdata.outdir,'geoclaw.data'))
surge_data = clawpack.geoclaw.data.SurgeData()
Expand Down Expand Up @@ -388,8 +390,8 @@ def fetch(product, expected_header, col_idx, col_types):
if verbose:
print('Fetching {} data from NOAA for station {}'.format(
product, station))
full_url = '{}?{}'.format(NOAA_API_URL, urlencode(noaa_params))
with urlopen(full_url) as response:
full_url = '{}?{}'.format(NOAA_API_URL, urllib.request.urlencode(noaa_params))
with urllib.request.urlopen(full_url) as response:
text = response.read().decode('utf-8')
with io.StringIO(text) as data:
# ensure that received header is correct
Expand Down Expand Up @@ -633,7 +635,7 @@ def gauge_afteraxes(cd):
# Set up for axes in this figure:
plotaxes = plotfigure.new_plotaxes()
try:
plotaxes.xlimits = [amrdata.t0,amrdata.tfinal]
plotaxes.xlimits = [clawdata.t0, clawdata.tfinal]
except:
pass
plotaxes.ylimits = surface_limits
Expand Down
8 changes: 4 additions & 4 deletions ike_2008/setplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def read_tide_gauge_data(base_path, skiprows=5, verbose=False):
station_info_file = open(os.path.join(base_path,'Ike_Gauges_web.txt'),'r')

# Skip past header
for i in xrange(skiprows):
for i in range(skiprows):
station_info_file.readline()

# Read in each station
Expand All @@ -88,7 +88,7 @@ def read_tide_gauge_data(base_path, skiprows=5, verbose=False):
else:
stations[data_line[0]]['gauge_no'] = int(data_line[1])
if verbose:
print "Station %s: %s" % (data_line[0],stations[data_line[0]])
print("Station %s: %s" % (data_line[0],stations[data_line[0]]))

# Load and extract real station data
data = scipy.io.loadmat(os.path.join(base_path,'result_%s.mat' % data_line[0]))
Expand Down Expand Up @@ -116,7 +116,7 @@ def read_adcirc_gauge_data(only_gauges=None, base_path="", verbose=False):
data = numpy.loadtxt(gauge_file)
stations[i+1] = data
if verbose:
print "Read in ADCIRC gauge file %s" % gauge_file
print("Read in ADCIRC gauge file %s" % gauge_file)

return stations

Expand Down Expand Up @@ -144,7 +144,7 @@ def read_adcirc_gauge_data(only_gauges=None, base_path="", verbose=False):
adcirc_path = "./gauge_data"
ADCIRC_gauges = read_adcirc_gauge_data(base_path=os.path.join(adcirc_path,'new_data'))
except:
print "Could not load external gauge files, ignoring."
print("Could not load external gauge files, ignoring.")
pass


Expand Down
7 changes: 4 additions & 3 deletions ike_2008/setrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
"""

from __future__ import print_function

import os
import datetime

import numpy as np

import clawpack.clawutil.data
import clawpack.geoclaw.topotools as topotools

# Need to adjust the date a bit due to weirdness with leap year (I think)
ike_landfall = datetime.datetime(2008,9,13 - 1,7) - datetime.datetime(2008,1,1,0)

Expand Down Expand Up @@ -579,7 +580,7 @@ def get_topo(plot=False):
os.path.join(base_url, "NOAA_Galveston_Houston.tt3.tar.bz2"),
os.path.join(base_url, "galveston_tx.asc.tar.bz2")]
for url in urls:
data.get_remote_file(url, verbose=True)
clawpack.clawutil.data.get_remote_file(url, verbose=True)

# Plot if requested
if plot:
Expand Down
12 changes: 6 additions & 6 deletions irene_2011/setplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,12 @@ def gauge_afteraxes(cd):
axes.grid(True)


try:
gauge_data=gauges[cd.gaugeno-1]
axes.plot(gauge_data[:,0], gauge_data[:,1], label=data_names[cd.gaugeno-1])
axes.legend()
except:
print('Gauge Data Unavailable')
# try:
# gauge_data=gauges[cd.gaugeno-1]
# axes.plot(gauge_data[:,0], gauge_data[:,1], label=data_names[cd.gaugeno-1])
# axes.legend()
# except:
# print('Gauge Data Unavailable')
plotaxes.afteraxes = gauge_afteraxes


Expand Down
2 changes: 1 addition & 1 deletion karen_2013/setrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def setgeo(rundata):
try:
geo_data = rundata.geo_data
except:
print "*** Error, this rundata has no geo_data attribute"
print("*** Error, this rundata has no geo_data attribute")
raise AttributeError("Missing geo_data attribute")

# == Physics ==
Expand Down
12 changes: 6 additions & 6 deletions maria_2017/setplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,12 @@ def gauge_afteraxes(cd):

#may or may not keep this? see irene example
#credit for below code to author of Irene example
try:
gauge_data=gaugea[cd.gaugeno-1]
axes.plot(gauge_data[:,0], gauge_data[:,1], label=data_names[cd.gaugeno-1])
axes.legend()
except:
print('Gauge Data Unavailable')
# try:
# gauge_data=gaugea[cd.gaugeno-1]
# axes.plot(gauge_data[:,0], gauge_data[:,1], label=data_names[cd.gaugeno-1])
# axes.legend()
# except:
# print('Gauge Data Unavailable')
#irene code ends here
plotaxes.afteraxes = gauge_afteraxes #originally line 209 - KEEP!!

Expand Down
10 changes: 5 additions & 5 deletions mumbai/extract_track_data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

from __future__ import print_function


import sys
import os
Expand Down Expand Up @@ -50,7 +50,7 @@ def create_storm_file(storm, output_path="mumbai.storm"):
# "(8x i4 i2i2i26x a4 2x,i3,1x,i4,a1,2x,i4,a1,2x,i3,2x,i4,47x,i3,2x,i3)"
# "(8x i4 i2i2i26x a4 2xi3 xi4 a i4 a i3 2x,i4,47x,i3,2x,i3)"
# "( YYYYMMDDHH BEST FOR lat_D long_D max cpre rrp rad"
for n in xrange(len(storm['track'][0])):
for n in range(len(storm['track'][0])):
# AL, 00, HHHHMMDDHH, , BEST, 0, LATN, LONW, XX, CPRE, TS, , 0, 0, 0, 0,
date = "%s%s%s%s" % ( storm['time'][n].year,
str(storm['time'][n].month).zfill(2),
Expand Down Expand Up @@ -94,7 +94,7 @@ def plot_tracks(storms, plot_cat=True):
# print(storm['track'])
# print(longitude, latitude)
# import pdb; pdb.set_trace()
for i in xrange(len(longitude)):
for i in range(len(longitude)):
if plot_cat:
color = category_color[storm['category'][i]]
else:
Expand Down Expand Up @@ -146,7 +146,7 @@ def extract_data(path, mask_dist=numpy.infty, mask_category=0):

# Convert into storms and truncate zeros
storms = []
for n in xrange(lon.shape[0]):
for n in range(lon.shape[0]):
m = len(lon[n].nonzero()[0])

distance = numpy.sqrt( (lon[n, :m] - mumbai[0])**2
Expand All @@ -156,7 +156,7 @@ def extract_data(path, mask_dist=numpy.infty, mask_category=0):
'time': [datetime.datetime(year[0, n],
month[n, i],
day[n, i],
hour[n, i]) for i in xrange(m)],
hour[n, i]) for i in range(m)],
'max_winds': max_winds[n, :m],
'radius_max_winds': radius_max_winds[n, :m],
'central_pressure': central_pressure[n, :m],
Expand Down
6 changes: 3 additions & 3 deletions mumbai/setplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

# Gauge name translation
gauge_landfall = []
for i in xrange(3):
for i in range(3):
if storm_num == 1:
# Storm 1
gauge_landfall.append(datetime.datetime(1997, 11, 15, 3) - datetime.datetime(1997, 1, 1, 0))
Expand Down Expand Up @@ -163,7 +163,7 @@ def add_custom_colorbar_ticks_to_axes(axes, item_name, ticks, tick_labels=None):
full_xlimits = regions['Full Domain (Grids)'][0]
full_ylimits = regions['Full Domain (Grids)'][1]

for (name, region_data) in regions.iteritems():
for (name, region_data) in regions.items():

#
# Surface
Expand Down Expand Up @@ -251,7 +251,7 @@ def friction_after_axes(cd):
# ==========================
grids = [[0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1]]
label = ["(No Grids)", "(Grids)"]
for i in xrange(2):
for i in range(2):
# Pressure field
plotfigure = plotdata.new_plotfigure(name='Pressure %s' % label[i],
figno=fig_num_counter.get_counter())
Expand Down
2 changes: 1 addition & 1 deletion mumbai/setrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ def setgeo(rundata):
try:
geo_data = rundata.geo_data
except:
print "*** Error, this rundata has no geo_data attribute"
print("*** Error, this rundata has no geo_data attribute")
raise AttributeError("Missing geo_data attribute")

# == Physics ==
Expand Down
1 change: 1 addition & 0 deletions sandy_2012/setplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import clawpack.amrclaw.data as amrclaw
import clawpack.geoclaw.data as geodata
import clawpack.geoclaw.surge.plot as surgeplot
import clawpack.geoclaw.topotools as topotools
import csv
from clawpack.geoclaw.util import fetch_noaa_tide_data

Expand Down
20 changes: 10 additions & 10 deletions scripts/gauge_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def read_tide_gauge_data(base_path, skiprows=5, verbose=True):
station_info_file = open(os.path.join(base_path,'Ike_Gauges_web.txt'),'r')

# Skip past header
for i in xrange(skiprows):
for i in range(skiprows):
station_info_file.readline()

# Read in each station
Expand All @@ -66,7 +66,7 @@ def read_tide_gauge_data(base_path, skiprows=5, verbose=True):
else:
stations[data_line[0]]['gauge_no'] = int(data_line[1])
if verbose:
print "Station %s: %s" % (data_line[0],stations[data_line[0]])
print("Station %s: %s" % (data_line[0],stations[data_line[0]]))

# Load and extract real station data
data = scipy.io.loadmat(os.path.join(base_path,'result_%s.mat' % data_line[0]))
Expand Down Expand Up @@ -94,7 +94,7 @@ def read_adcirc_gauge_data(only_gauges=None, base_path="", verbose=True):
data = np.loadtxt(gauge_file)
stations[i+1] = data
if verbose:
print "Read in ADCIRC gauge file %s" % gauge_file
print("Read in ADCIRC gauge file %s" % gauge_file)

return stations

Expand Down Expand Up @@ -129,10 +129,10 @@ def load_geoclaw_gauge_data(only_gauges=None, base_path="_output", verbose=True)
try:
file_path = os.path.join(base_path,'fort.gauge')
if not os.path.exists(file_path):
print '*** Warning: cannot find gauge data file %s'%file_path
print('*** Warning: cannot find gauge data file %s'%file_path)
pass
else:
print "Reading gauge data from %s" % file_path
print("Reading gauge data from %s" % file_path)
raw_data = np.loadtxt(file_path)

gauge_read_string = ""
Expand All @@ -151,11 +151,11 @@ def load_geoclaw_gauge_data(only_gauges=None, base_path="_output", verbose=True)
gauges[n] = gauge

if verbose:
print "Read in GeoClaw gauge [%s]" % gauge_read_string[1:]
print("Read in GeoClaw gauge [%s]" % gauge_read_string[1:])

except Exception as e:
print '*** Error reading gauges in ClawPlotData.getgauge'
print '*** outdir = ', base_path
print('*** Error reading gauges in ClawPlotData.getgauge')
print('*** outdir = ', base_path)
raise e

# for (i,gauge_no) in enumerate(gauge_list):
Expand All @@ -165,7 +165,7 @@ def load_geoclaw_gauge_data(only_gauges=None, base_path="_output", verbose=True)


elapsed = (time.clock() - start)
print "Single gauge reading elapsed time = %s" % elapsed
print("Single gauge reading elapsed time = %s" % elapsed)

start = time.clock()
raw_data = np.loadtxt(os.path.join(base_path,'fort.gauge'))
Expand All @@ -183,7 +183,7 @@ def load_geoclaw_gauge_data(only_gauges=None, base_path="_output", verbose=True)
# self.gaugesoln_dict[(n, outdir)] = gauge

elapsed = (time.clock() - start)
print "All gauges reading elapsed time = %s" % elapsed
print("All gauges reading elapsed time = %s" % elapsed)
return gauges


Expand Down
Loading

0 comments on commit 4b91c9f

Please sign in to comment.