Using Python, In this assignment, we will analyze the HURDAT2 dataset for Atlant
ID: 3751583 • Letter: U
Question
Using Python, In this assignment, we will analyze the HURDAT2 dataset for Atlantic hurricane data from 1851 through 2017. This dataset is provided by the National Hurricane Center and is documented here. You will do some analysis of this data to answer some questions about it. I have provided code to organize this data, but you may feel free to improve this rudimentary organization. I have also provided functions that allow you to check your work. Note that you may choose to organize the cells as you wish, but you must properly label each problem’s code and its solution. Use a Markdown cell to add a header denoting your work for a particular problem.
You should start with the provided Jupyter Notebook, http://www.cis.umassd.edu/~dkoop/dsc201-2018fa/a1/a1.ipynb. Download this notebook (right-click to save the link) and upload it to your Jupyter workspace (on the JupyterHub server or your local notebook/lab). Make sure to execute the first two cells in the notebook (Shift+Enter). The second cell will download the data and define a variable records which consists of a list of tuples each with two entries:
a string with information about the hurricane and
a list of strings each of which is a tracking point for the hurricane
To access the fourth hurricane’s third tracking point, you would access records[3][1][2]. Remember indexing is zero-based! Thus [3] accesses the fourth hurricane, [1] accesses the list of tracking point strings, and [2] accesses the third tracking point.
In the provided file, I provided examples of how to check your work. For example, for Problem 1, you would call the check1 function with the number of hurricane names. After executing this function, you will see a message that indicates whether your answer is correct.
1. Number of Unique Hurricane Names (10 pts)
Write code that computes the number of unique hurricane names in the dataset. Note that UNNAMED is not a hurricane name.
Hints:
You will need to extract the name from the string in the first entry in the tuple
The split function for strings will be useful
The strip function will also be useful to trim whitespace
Consider using a set to keep track of all the names
2. Most Frequently Used Name (10 pts)
Write code that computes the most frequently used hurricane name. Again, UNNAMED does not count!
Hints:
collections.Counter() is a good structure to help with counting.
Clean up the strings in the same manner as in Problem 1.
3. Year with Most Hurricanes (10 pts)
Write code that computes the year with the most hurricanes.
Hints:
You can extract the year from the first entry in the tuple. It is the last four characters before the first comma.
4. Most Northerly Hurricane (10 pts)
Write code that computes the hurricane that went furthest north as measured by the greatest latitude. You need to find the name and the year of the hurricane.
Hints:
Check the documentation to find where the latitude is recorded.
You will need to go through the tracking points to check all of the latitude points recorded.
You need to keep track of three things: the maximum latitude seen so far plus the name of the corresponding hurricane and year
The latitude adds the N character to indicate the northern hemisphere. This needs to be removed to do numeric comparisons.
You can convert a string to a float or int by casting it. For example, float("81.5") returns a floating-point value of 81.5.
5. Hurricane with Maximum Sustained Wind (10 pts)
Write code that determines the hurricane with the highest sustained windspeed. You need to find the name, year, and wind speed for this hurricane.
Hints:
Check the documentation to find where the wind speed is recorded.
You will need to go through the tracking points to check all of the wind speeds recorded.
You can convert a string to a float or int by casting it. For example, float("81.5") returns a floating-point value of 81.5.
Explanation / Answer
classifier.py
#!/usr/bin/env python 3.2
__all__ = ['classify', 'test']
def classify(wind):
'''Classifies strom based on wind speed. Winds are in knots.'''
if wind < 34:
cat = 'TD'
elif (34 <= wind and wind <= 63):
cat = 'TS'
elif (64 <= wind and wind <= 82):
cat = 'H1'
elif (83 <= wind and wind <= 95):
cat = 'H2'
elif (96 <= wind and wind <= 113):
cat = 'H3'
elif (114 <= wind and wind <= 135):
cat = 'H4'
elif wind > 135:
cat = 'H5'
return cat
def test():
'''Test function.'''
print('---Module classifier test---')
# Run test if module is run as a program
if __name__ == '__main__':
test()
coordAvg.py
import math
__all__ = ['avgAll', 'avgMid', 'avgFirst', 'avgLast', 'calcScale',
'weightedAvgCoords', 'test']
def __mean(nums):
'''Calculates average of a list.'''
if len(nums):
return float( sum(nums) / len(nums))
else:
return 0.0
def __toCartesian(lat, lon):
lat = math.radians(lat)
lon = math.radians(lon)
x = math.cos(lat) * math.cos(lon)
y = math.cos(lat) * math.sin(lon)
z = math.sin(lat)
cartCoords = [x,y,z]
return cartCoords
def __avgCoords(latList, lonList):
'''Calculates cartesian coordinates from lat lon using geographic midpoint.
Returns lat/lon coords in degrees.'''
xList = []
yList = []
zList = []
for i in range(0, len(lonList)):
coords = __toCartesian(latList[i], lonList[i])
xList.append(coords[0])
yList.append(coords[1])
zList.append(coords[2])
x = __mean(xList)
y = __mean(yList)
z = __mean(zList)
lon = math.atan2(y, x)
hyp = math.sqrt(x * x + y * y)
lat = math.atan2(z, hyp)
lon = math.degrees(lon)
lat = math.degrees(lat)
coords = [lat, lon]
return coords
def __calcDif(aList):
'''Calculates difference between items in a list and returns a list of
differences.'''
difList = []
for item in aList:
if item == aList[0]:
prevItem = item
else:
currentItem = item
difList.append(math.fabs(currentItem - prevItem))
prevItem = currentItem
return difList
def calcScale(latList, lonList):
'''Calculates scale of storm based on number of measurements.'''
deltaLatList = __calcDif(latList)
deltaLonList = __calcDif(lonList)
scale = sum(deltaLatList) * sum(deltaLonList)
return scale
def avgAll(latList, lonList):
'''Averages all poins in list. Method 1.'''
average = __avgCoords(latList, lonList)
return average
def avgMid(latList, lonList, windList, numMeas):
'''Averages numMeas on either side of highest point in windList. Method 2.'''
maxWind = max(windList)
#print('Max Wind:',maxWind)
mid = windList.index(maxWind)
#print('Mid:', mid)
if maxWind == windList[0]:
#print('Special Case')
average = __avgCoords(latList, lonList)
elif mid-numMeas < 0:
#print('Special Case 2')
average = __avgCoords(latList[0:mid+numMeas],lonList[0:mid+numMeas])
else:
#print('Normal')
average = __avgCoords(latList[mid-numMeas:mid+numMeas],lonList[mid-numMeas:mid+numMeas])
return average
def avgFirst(latList, lonList, numMeas):
'''First day (first numMeas measurements) average. Method 3.'''
average = __avgCoords(latList[:numMeas], lonList[:numMeas])
return average
def avgLast(latList, lonList, numMeas):
'''Last day (last numMeas measurements) average. Method 4.'''
average = __avgCoords(latList[-numMeas:], lonList[-numMeas:])
return average
def __calcWeight(scale, scaleMax):
'''Calculates weight of storm givin a list of corresponding scales.'''
weight = scale / scaleMax
return weight
def weightedAvgCoords(latList, lonList, scale, scaleMax):
'''Determines weighted lat and lon by integrating over each
and weighting by the provided weight for i number of storms. Returns a list
of coordinates.'''
weight = __calcWeight(scale, scaleMax)
coords = __avgCoords(latList, lonList)
lat = coords[0] * weight
lon = coords[1] * weight
weightedAvg = [lat, lon]
return weightedAvg
def test():
'''Test function.'''
print('---Module coordAvg test---')
latList = [28.0, 28.0, 28.0, 28.1, 28.2, 28.3, 28.4, 28.6, 29.0, 29.5, 30.0,
30.5, 31.0]
lonList = [94.8, 95.4, 96.0, 96.5, 97.0, 97.6, 98.3, 98.9, 99.4, 99.8, 100.0,
100.1, 100.2]
windList = [80, 80, 80, 80, 70, 60, 60, 50, 50, 40, 40, 40, 40]
numMeas = 4
#
print('--Actual Values--')
print('All :', [28.904683, 97.985048])
print('Mid :', [])
print('First:', [28.026472, 95.674809])
print('Last :', [30.250083, 100.024174])
print('--Test Values--')
print('All :', avgAll(latList, lonList))
print('Mid :', avgMid(latList, lonList, windList, numMeas))
print('First:', avgFirst(latList, lonList, numMeas))
print('Last :', avgLast(latList, lonList, numMeas))
print(' ***__mean Test***')
meanList = [10, 20, 30]
calcMean = __mean(meanList)
if 20 != calcMean:
print('!!!---TEST FAIL---!!!')
print('Actual Mean:', 20)
print('Calc Mean:',calcMean)
else:
print('PASS')
print(' ***__toCartesian Test***')
lat = 28.0
lon = 94.8
cart = __toCartesian(lat, lon)
if [-0.07388315034589424, 0.8798509713754594, 0.4694715627858908] != cart:
print('!!!---TEST FAIL---!!!')
print('Actual Cart:', [-0.07388315034589424, 0.8798509713754594, 0.4694715627858908])
print('Calc Cart :', cart)
else:
print('PASS')
print(' ***weightedAvgCoords Test***')
latList = [25.6,26.8,28.1,29.3,30.2,31.3,32.9,35.1,37]
lonList = [-61.2,-63,-64.6,-65.9,-65.8,-64,-60.9,-57.2,-53.5]
scale = 194.94
scaleMax = 1591.04
test = weightedAvgCoords(latList, lonList, scale, scaleMax)
test = [round(test[0],1),round(test[1],1)]
known = [3.8,-7.6]
if known != test:
print('!!!---TEST FAIL---!!!')
print('Actual:', known)
print('Calc :', test)
else:
print('PASS')
print(' ***__calcDif Test***')
aList = [25.6,26.8,28.1,29.3,30.2,31.3,32.9,35.1,37]
test = __calcDif(aList)
for i in range(0,len(test)):
test[i] = round(test[i],4)
known = [1.2,1.3,1.2,0.9,1.1,1.6,2.2,1.9]
if known != test:
print('!!!---TEST FAIL---!!!')
print('Actual:', known)
print('Calc :', test)
else:
print('PASS')
print(' ***__calcWeight Test***')
scale = 194.94
scaleMax = 1591.04
test = round(__calcWeight(scale,scaleMax),6)
known = 0.122524
if known != test:
print('!!!---TEST FAIL---!!!')
print('Actual:', known)
print('Calc :', test)
else:
print('PASS')
print(' ***calcScale Test***')
latList = [25.6,26.8,28.1,29.3,30.2,31.3,32.9,35.1,37]
lonList = [-61.2,-63,-64.6,-65.9,-65.8,-64,-60.9,-57.2,-53.5]
test = round(calcScale(latList, lonList),2)
known = 194.94
if known != test:
print('!!!---TEST FAIL---!!!')
print('Actual:', known)
print('Calc :', test)
else:
print('PASS')
# Run test if module is run as a program
if __name__ == '__main__':
test()
coordExport.py
import os, fileIO, coordAvg
__all__ = ['exportToTXT', 'getScaleList', 'test']
scaleList = []
def getScaleList():
'''Returns scaleList for use with weighted averaging.'''
return scaleList
def __getID(line):
if line == '':
ID = -999
else:
ID = line[0:6]
return ID
def __getName(line):
name = line[7:17]
return name
def __getYear(line):
year = line[18:22]
return year
def __getMonth(line):
month = line[23:25]
return month
def __getDay(line):
day = line[26:28]
return day
def __getHour(line):
hour = line[29:31]
return hour
def __getLat(line):
lat = float(line[32:37])
return lat
def __getLon(line):
lon = float(line[38:44])
return lon
def __getWind(line):
wind = int(line[45:48])
return wind
def __getPres(line):
pres = int(line[49:53])
return pres
def __getStage(line):
stage = line[54:70]
return stage
def __getCat(line):
cat = line[71:73]
return cat
def __getLandfall(line):
landfall = int(line[74])
return landfall
def __filterData(dataFile, filterTerms, searchType='and'):
'''Filters data based on filterTerms and optional searchType ('and' or 'or').
These filterTerms can include 'stage', 'cat', and 'landfall' and must be in the
dictionary format ({key:value}). For 'stage' and 'cat' multiple entries can be entered
as a list. 'landfall' must be entered as an integer. The searchType can either be 'and' or 'or'.'''
newData = []
dataFile.readline() # Reads headers
for line in dataFile:
addCat = True
addLandfall = True
addStage = True
if 'stage' in filterTerms:
stageList = filterTerms['stage']
if __getStage(line).strip() not in stageList:
addStage = False
if 'cat' in filterTerms:
catList = filterTerms['cat']
if __getCat(line).strip() not in catList:
addCat = False
if 'landfall' in filterTerms:
landfall = filterTerms['landfall']
if __getLandfall(line) != landfall:
addLandfall = False
if searchType == 'and':
if addStage and addCat and addLandfall:
newData.append(line)
else:
if addStage or addCat or addLandfall:
newData.append(line)
return newData
def exportToTXT(hurdatExport, filename, filterTerms={}, numMeas=4):
'''Loops through hurdatExport.txt and saves relevent averages.
Optionally choose number of measurements used (default = 4).
Optionally filter data file. See __filterData() for more info.
Creates file with headers: ID,decade,startYear,startMonth,startDay,
startHour,name,avgAll,avgMid,avgFirst,avgLast.'''
hurdatExport.readline() # Reads headers
txtExport = fileIO.makeTextFile(filename)
txtExport.write('ID dec year mo dy hr name allLat allLon midLat midLon firstLat firstLon lastLat lastLon')
print('Saving file...')
if filterTerms == {}:
lineList = hurdatExport.readlines()
else:
lineList = __filterData(hurdatExport,filterTerms)
lineList.append('')
for i in range(len(lineList)):
nextLine = lineList[i]
if i == 0:
prevID = 'null'
line = nextLine
continue
ID = __getID(line)
nextID = __getID(nextLine)
if ID != prevID:
#print(ID)
latList = []
lonList = []
windList = []
prevID = ID
name = __getName(line)
startYear = __getYear(line)
decade = startYear[0:3] + '0'
startMonth = __getMonth(line)
startDay = __getDay(line)
startHour = __getHour(line)
# landfall =
# store avg lat, lon, and wind
#print('Storing info...')
lat = __getLat(line)
lon = __getLon(line)
wind = __getWind(line)
latList.append(lat)
lonList.append(lon)
windList.append(wind)
if ID != nextID:
#print('Writing...')
txtExport.write(' ')
avgAll = coordAvg.avgAll(latList, lonList)
avgMid = coordAvg.avgMid(latList, lonList, windList, numMeas)
#print('WindList:',windList)
avgFirst = coordAvg.avgFirst(latList, lonList, numMeas)
avgLast = coordAvg.avgLast(latList, lonList, numMeas)
scale = coordAvg.calcScale(latList, lonList)
scaleList.append(scale)
txtExport.write('{0} {1} {2} {3} {4} {5} {6} {7:10.6f} {8:10.6f} {9:10.6f} {10:10.6f} {11:10.6f} {12:10.6f} {13:10.6f} {14:10.6f}'.format(ID,decade,startYear,startMonth,startDay,startHour,name,
avgAll[0],-avgAll[1],avgMid[0],-avgMid[1],avgFirst[0],-avgFirst[1],avgLast[0],-avgLast[1]))
write = False
prevID = ID
line = nextLine
print(txtExport.name, 'saved to', os.getcwd(), ' ')
def test():
'''Test function.'''
print('---Module coordExport test---')
hurdatExport = fileIO.openFile('HURDAT_Export.txt')
hurdatExport.readline() # Reads headers
line = hurdatExport.readline()
print('***__getStage test***')
print('Stage :',__getStage(line))
print('***__getCat test***')
print('Cat :',__getCat(line))
print('***__getLandfall test***')
print('Landfall:',__getLandfall(line))
print('***__filter test***')
filterTerms = {}
#filterTerms = {'cat':['TS','H1','H2','H3','H4','H5']}
filterTerms = {'stage':'Tropical Cyclone'}
searchType = 'and'
filteredData = __filterData(hurdatExport, filterTerms, searchType)
verbose = False
if verbose:
for line in filteredData:
print(line)
print('Number of entires found:',len(filteredData))
# Run test if module is run as a program
if __name__ == '__main__':
test()
fileIO.py
__all__ = ['openFile', 'makeTextFile', 'test']
import os
def openFile(filename, root=''):
'''Opens file for read on Windows, Mac, and Linux.'''
path = os.path.join(root, filename)
hurdatData = open(path,'r')
return hurdatData
def makeTextFile(filename):
'''Opens new file for write.'''
if os.path.isfile(filename):
print(filename, 'already exists.')
prompt = True
while prompt == True:
userInput = input('Overwrite (y/n)? ')
if userInput == ('y' or 'Y'):
f = open(filename,'w')
prompt = False
elif userInput == ('n' or 'N'):
newFilename = input('Enter new filename: ')
if not os.path.isfile(newFilename):
f = open(newFilename,'w')
prompt = False
else:
print(newFilename, 'already exists.')
else:
print("Please enter either 'y' or 'n'.")
else:
f = open(filename,'w')
return f
def test():
'''Test function.'''
print('---Module FileIO test---')
# Run test if module is run as a program
if __name__ == '__main__':
test()
hurdatExport.py
import os, fileIO
import hurdatReader as hr
def exportToCSV(hurdatData, filename):
'''Loops through and saves HURDAT data as a csv file.'''
csvExport = fileIO.makeTextFile(filename)
csvExport.write('ID, name, year, month, day, hour, lat, lon, wind, pressure, stage, category, landfall')
print('Saving file...')
hourList = [0,6,12,18]
for line in hurdatData:
if hr.isHeader(line):
ID = hr.getStormID(line)
name = hr.getName(line).strip()
year = hr.getYear(line)
landfall = hr.madeLandfall(line)
elif hr.isFooter(line):
pass
else:
x = 11
y = 28
for i in range(4):
lon = hr.getLon(line, x, y)
if (hr.getLat(line, x, y) and lon != 0.0):
if lon >= 180.0:
lon = (lon - 360)*-1
else:
lon = lon * -1
csvExport.write(' ')
csvExport.write(str(ID))
csvExport.write(', ' + name)
csvExport.write(', ' + str(year))
csvExport.write(', ' + str(hr.getMonth(line)))
csvExport.write(', ' + str(hr.getDay(line)))
csvExport.write(', ' + str(hourList[i])) # write hour
csvExport.write(', ' + str(hr.getLat(line, x, y)))
csvExport.write(', ' + str(lon))
csvExport.write(', ' + str(hr.getWind(line, x, y)))
csvExport.write(', ' + str(hr.getPressure(line, x, y)))
csvExport.write(', ' + str(hr.getStage(line, x, y)))
csvExport.write(', ' + str(hr.getCategory(line, x, y)))
csvExport.write(', ' + str(landfall))
x = y
y = x + 17
if hr.getMonth(line) == 12 and hr.getDay(line) == 31 and hourList[i] == 18:
year = year + 1
csvExport.close()
print(csvExport.name, 'saved to', os.getcwd(), ' ')
def exportToTXT(hurdatData, filename):
'''Loops through and saves HURDAT data as a txt file.'''
txtExport = fileIO.makeTextFile(filename)
txtExport.write('{0:6} {1:11}{2:4} {3:2} {4:2} {5:2} {6:6} {7:6} {8:2} {9:4} {10:16} {11} {12}'.format(
'ID', 'name', 'year', 'mo', 'da', 'hr', 'lat', 'lon', 'wi', 'pre','stage', 'ct', 'landfall'))
print('Saving file...')
hourList = [0,6,12,18]
for line in hurdatData:
if hr.isHeader(line):
ID = hr.getStormID(line)
name = hr.getName(line)
year = hr.getYear(line)
landfall = hr.madeLandfall(line)
elif hr.isFooter(line):
pass
else:
x = 11
y = 28
for i in range(4):
if (hr.getLat(line, x, y) and hr.getLon(line, x, y)) != 0.0:
txtExport.write(' ')
txtExport.write('{0} {1}{2} {3:2d} {4:2d} {5:2d} {6:5.1f} {7:6.1f} {8:3d} {9:4d} {10:16} {11} {12}'.format(
ID, name, year,
hr.getMonth(line), hr.getDay(line), hourList[i],
hr.getLat(line,x,y), hr.getLon(line,x,y),
hr.getWind(line,x,y), hr.getPressure(line,x,y),
hr.getStage(line,x,y), hr.getCategory(line,x,y),
landfall))
#txtExport.write(' ' + str(hr.madeLandfall(line)))
x = y
y = x + 17
if hr.getMonth(line) == 12 and hr.getDay(line) == 31 and hourList[i] == 18:
year = year + 1
txtExport.close()
print(txtExport.name, 'saved to', os.getcwd(), ' ')
def test():
'''Test function.'''
print('---Module hurdatExport test---')
# Run test if module is run as a program
if __name__ == '__main__':
test()
hurdatReader.py
__all__ = ['isHeader', 'isFooter', 'madeLandfall', 'getName', 'getYear',
'getMonth', 'getDay', 'getStormNum', 'getNumDays', 'getDailyData',
'getStage','getLat', 'getLon', 'getWind', 'getPressure',
'getCategory','test']
import classifier
def isHeader(line):
'''Returns True if line is header, false if not.'''
if line[17:19] == 'M=':
result = True
else:
result = False
return result
def isFooter(line):
'''Returns True if line is footer, false if not.'''
result = False
try:
int(line[6])
except ValueError:
result = True
return result
def madeLandfall(line):
'''Returns if storm made landfall or not.'''
if (isHeader(line) and line[52] == '1'):
result = 1
else:
result = 0
return result
def getName(line):
'''Returns storm name.'''
if isHeader(line):
name = line[35:46]
return name
def getYear(line):
'''Returns storm year.'''
if isHeader(line):
year = line[12:16]
return int(year)
def getMonth(line):
'''Returns storm month.'''
month = line[6:8]
if month[0] == '0':
month = ' ' + month[1]
return int(month)
def getDay(line):
'''Returns storm day.'''
day = line[9:11]
if day[0] == '0':
day = ' ' + day[1]
return int(day)
def getStormID(line):
'''Returns the number of the storm (from total record).'''
if isHeader(line):
stormID = line[22:24].strip().zfill(2)
stormID = str(getYear(line)) + stormID
return int(stormID)
def getNumDays(line):
'''Returns the number of days of data there are.'''
if isHeader(line):
numDays = int(line[19:21])
return numDays
def getStage(line, x, y):
subLine = line[x:y]
stage = subLine[0]
if stage == '*':
stage = 'Tropical Cyclone'
elif stage == 'S':
stage = 'Subtropical'
elif stage == 'E':
stage = 'Extratropical'
elif stage == 'W':
stage = 'Wave'
elif stage == 'L':
stage = 'Remnant Low'
return stage
def getLat(line, x, y):
'''Returns the latitude for specific 6 hour measurement.'''
subLine = line[x:y]
lat = subLine[1:4]
lat = lat[0:2] + '.' + lat[2]
return float(lat)
def getLon(line, x, y):
'''Returns the longitude for specific 6 hour measurement.'''
subLine = line[x:y]
lon = subLine[4:8]
lon = lon[0:3] + '.' + lon[3]
return float(lon)
def getWind(line, x, y):
'''Returns wind spead for specific 6 hour measurement.'''
subLine = line[x:y]
wind = subLine[9:12]
return int(wind)
def getPressure(line, x, y):
'''Returns pressure for specific 6 hour measurement.'''
subLine = line[x:y]
pressure = subLine[13:17]
if pressure == ' 0':
pressure = -999
return int(pressure)
def getCategory(line, x, y):
'''Returns category for specific 6 hour measurement.'''
category = classifier.classify(getWind(line, x, y))
return category
def test():
'''Test function.'''
print('---Module hurdatReader test---')
import os, fileIO
hurdatData = fileIO.openFile('HURDAT_tracks1851to2010_atl_2011rev.txt', '..\data')
hourList = [0,6,12,18]
for line in hurdatData:
if isHeader(line):
ID = getStormID(line)
name = getName(line).strip()
year = getYear(line)
landfall = madeLandfall(line)
elif isFooter(line):
pass
else:
x = 11
y = 28
for i in range(4):
lon = getLon(line, x, y)
if (getLat(line, x, y) and lon != 0.0 and year == 1886):
if lon >= 180.0:
lon = (lon - 360)*-1
else:
lon = lon * -1
print(' ')
print('ID :', str(ID))
print('Name :', name)
print('Year :', str(year))
print('Month:', str(getMonth(line)))
print('Day :', str(getDay(line)))
print('Hour :', str(hourList[i])) # write hour
print('Lat :', str(getLat(line, x, y)))
print('Lon :', str(lon).strip())
print('Wind :', str(getWind(line, x, y)))
print('Press:', str(getPressure(line, x, y)))
print('Stage:', getStage(line, x, y))
print('Cat :', getCategory(line, x, y))
print('Land :', str(landfall))
x = y
y = x + 17
if getMonth(line) == 12 and getDay(line) == 31 and hourList[i] == 18:
year = year + 1
hurdatData.close()
# Run test if module is run as a program
if __name__ == '__main__':
test()
main.py
import hurdatExport, fileIO, coordExport
# Read HURDAT Data
print('-----')
print('Reading HURDAT data...')
print('-----')
hurdatData = fileIO.openFile('HURDAT_tracks1851to2010_atl_2011rev.txt', '..\data')
hurdatExport.exportToCSV(hurdatData, '..\output\HURDAT_Export.csv')
hurdatData.seek(0, 0)
hurdatExport.exportToTXT(hurdatData, '..\output\HURDAT_Export.txt')
hurdatData.close()
# Average coordinates with all observations
print('-----')
print('Saving average coordinates data...')
print('-----')
hurdatExportFile = fileIO.openFile('..\output\HURDAT_Export.txt')
coordExport.exportToTXT(hurdatExportFile, '..\output\Coord_Export.txt')
# Average coordinates using filters
# Only category TS-H5 Storms
hurdatExportFile.seek(0, 0)
filterTerms = {'cat':['TS','H1','H2','H3','H4','H5']}
coordExport.exportToTXT(hurdatExportFile, '..\output\Coord_Export_TS-H5.txt', filterTerms)
# Only storms that made landfall
hurdatExportFile.seek(0, 0)
filterTerms = {'landfall':1}
coordExport.exportToTXT(hurdatExportFile, '..\output\Coord_Export_Landfall.txt', filterTerms)
# Only storms that made landfall and were category H3-H5
hurdatExportFile.seek(0, 0)
filterTerms = {'landfall':1,'cat':['H3','H4','H5']}
coordExport.exportToTXT(hurdatExportFile, '..\output\Coord_Export_Landfall_H3-H5.txt', filterTerms)
hurdatExportFile.close()
print('-----')
print('All files successfully created.')
print('-----')
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.