def writeToCSVPG(csvFile, varData, date, lats, lons, miss = False): #Compress to one dimension slats, slons, grid = ncu.compressGrid(lats, lons, varData, miss) #Write to file (must put longitude first) for dataPoint in zip([str(date)] * len(grid), slons, slats, grid): csvFile.write(dataPoint[0] + ',POINT(' + str(dataPoint[1]) + ' ' + str(dataPoint[2]) + '),' + str(dataPoint[3]) + '\n')
def writeToJSON_Mongo(jsonFile, varData, date, lats, lons, miss = False): #Compress to one dimension slats, slons, grid = ncu.compressGrid(lats, lons, varData, miss) #Write to file as a mongo document with an inner geojson for the location for dataPoint in zip(slons, slats, [str(date)] * len(grid), grid): jsonFile.write('{"location": {"type": "Point", "coordinates": [' + str(dataPoint[0]) + ',' + str(dataPoint[1]) + \ ']}, "date": "' + dataPoint[2] + '", "' + VAR_NAME + '": ' + str(dataPoint[3]) + '}\n')
def writeToCSV(csvFile, varData, timeData, timeUnits, lats, lons, miss = False): for i, grid in enumerate(varData): #Compress to one dimension slats, slons, grid = ncu.compressGrid(lats, lons, grid, miss) dat = str(num2date(timeData[i], timeUnits)) #Write to file for dataPoint in zip(slats, slons, [dat] * len(grid), grid): #csvFile.write(str(slats[j]) + ',' + str(slons[j]) + ',' + dat + ',' + str(dataPoint) + '\n') csvFile.write(','.join([str(e) for e in dataPoint]) + '\n')
def writeToJSON(jsonFile, varData, date, lats, lons, miss = False): #Compress to one dimension slats, slons, grid = ncu.compressGrid(lats, lons, varData, miss) #Write to file #GeoJSON accepts location in lon,lat format... for i, dataPoint in enumerate(zip(slons, slats, [str(date)] * len(grid), grid)): jsonData = '{"type": "Feature", "geometry": {"type": "Point", "coordinates": [' + str(dataPoint[0]) + ',' + str(dataPoint[1]) + \ ']}, "properties": {"date": "' + dataPoint[2] + '", "' + VAR_NAME + '": ' + str(dataPoint[3]) + '}}' if i < len(grid) - 1: jsonData = jsonData + ',' jsonFile.write(jsonData) #Finally, write the next line for the next file jsonFile.write('\n')