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('\n') 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(), '\n')
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) elif hr.isFooter(line): pass else: # x = 11 # y = 28 x = 0 y = 0 # 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('\n') 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(hr.getHour(line))) # 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(hr.madeLandfall(line))) # x = y # y = x + 17 if hr.getMonth(line) == 12 and hr.getDay( line) == 31 and hr.getHour(line) == 18: year = year + 1 csvExport.close() print(csvExport.name, 'saved to', os.getcwd(), '\n')
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('\n') 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(), '\n')
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) elif hr.isFooter(line): pass else: # x = 11 # y = 28 x = 0 y = 0 # for i in range(4): if (hr.getLat(line, x, y) and hr.getLon(line, x, y)) != 0.0: txtExport.write('\n') 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), hr.getHour(line), 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), hr.madeLandfall(line))) #txtExport.write(' ' + str(hr.madeLandfall(line))) # x = y # y = x + 17 if hr.getMonth(line) == 12 and hr.getDay( line) == 31 and hr.getHour(line) == 18: year = year + 1 txtExport.close() print(txtExport.name, 'saved to', os.getcwd(), '\n')
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('\n') 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(), '\n')