def makeTempDBF(AggLevel): '''Calculates weighted average monthly temperature at AggLevel = "Woreda" or "Kebele"''' #Set the working directory workingDir = os.getcwd() #Download the monthly temperature data from NOAA GHCN CAMS DataFile = downloadTempData(workingDir) #Intersect the GHCN grid with the Woreda or Kebele shapefile and convert the .dbf to a .csv intersectCSV, GridCSV = intersectGrid(AggLevel, workingDir, "Temp") #Read in raw monthly temperature data at every GHCN grid cell and store it in the matrix 'allData' #dimensions are a x b x c where a = # of gridcells, b = 5 (lat, long, yr, mo, temp), #and c = # of months allData, gridCells = readTempData(DataFile, GridCSV) #Read in weights of each data point to each woreda or kebele WeightMatrix, ID = findTempWeightMatrix(AggLevel, intersectCSV, gridCells) Year = allData[0,2,:] Month = allData[0,3,:] #Calculate area-weighted average temperature data in each woreda or kebele Temp = np.dot(np.transpose(WeightMatrix),allData[:,4,:]) #Write the data to 'WoredaTempDBF.csv' or 'KebeleTempDBF.csv' writeFiles(AggLevel, Temp, ID, Year, Month) return None
def makeTempDBF(AggLevel): '''Calculates weighted average monthly temperature at AggLevel = "Woreda" or "Kebele"''' #Set the working directory workingDir = os.getcwd() #Download the monthly temperature data from NOAA GHCN CAMS DataFile = downloadTempData(workingDir) #Intersect the GHCN grid with the Woreda or Kebele shapefile and convert the .dbf to a .csv intersectCSV, GridCSV = intersectGrid(AggLevel, workingDir, "Temp") #Read in raw monthly temperature data at every GHCN grid cell and store it in the matrix 'allData' #dimensions are a x b x c where a = # of gridcells, b = 5 (lat, long, yr, mo, temp), #and c = # of months allData, gridCells = readTempData(DataFile, GridCSV) #Read in weights of each data point to each woreda or kebele WeightMatrix, ID = findTempWeightMatrix(AggLevel, intersectCSV, gridCells) Year = allData[0, 2, :] Month = allData[0, 3, :] #Calculate area-weighted average temperature data in each woreda or kebele Temp = np.dot(np.transpose(WeightMatrix), allData[:, 4, :]) #Write the data to 'WoredaTempDBF.csv' or 'KebeleTempDBF.csv' writeFiles(AggLevel, Temp, ID, Year, Month) return None
def makeRainDBF(AggLevel=first_arg): '''Makes a .csv database file with average daily rainfall at AggLevel = "Woreda" or "Kebele"''' #Set the working directory workingDir = os.getcwd() #Intersect the NOAA grid with the Woreda or Kebele shapefile and convert the .dbf to a .csv intersectCSV, GridCSV = intersectGrid(AggLevel, workingDir, "Rain") #Read in raw monthly temperature data at every GHCN grid cell and store it in the matrix 'allData' #dimensions are a x b x c where a = # of gridcells, b = 5 (lat, long, yr, mo, temp), #and c = # of months allData, gridCells = readRainData(workingDir,GridCSV) #Calculate and read in weights of each data point to each woreda or kebele WeightMatrix, ID = findRainWeightMatrix(AggLevel, intersectCSV, gridCells) Year = allData[0,3,:] Month = allData[0,4,:] Day = allData[0,5,:] #Calculate area-averaged rainfall data in each woreda or kebele Rain = np.dot(np.transpose(WeightMatrix),allData[:,2,:]) #Write the data to WoredaRainDBF.csv or KebeleRainDBF.csv writeFiles(AggLevel, Rain, ID, Year, Month, Day) return None
def makeRainDBF(AggLevel=first_arg): '''Makes a .csv database file with average daily rainfall at AggLevel = "Woreda" or "Kebele"''' #Set the working directory workingDir = os.getcwd() #Intersect the NOAA grid with the Woreda or Kebele shapefile and convert the .dbf to a .csv intersectCSV, GridCSV = intersectGrid(AggLevel, workingDir, "Rain") #Read in raw monthly temperature data at every GHCN grid cell and store it in the matrix 'allData' #dimensions are a x b x c where a = # of gridcells, b = 5 (lat, long, yr, mo, temp), #and c = # of months allData, gridCells = readRainData(workingDir, GridCSV) #Calculate and read in weights of each data point to each woreda or kebele WeightMatrix, ID = findRainWeightMatrix(AggLevel, intersectCSV, gridCells) Year = allData[0, 3, :] Month = allData[0, 4, :] Day = allData[0, 5, :] #Calculate area-averaged rainfall data in each woreda or kebele Rain = np.dot(np.transpose(WeightMatrix), allData[:, 2, :]) #Write the data to WoredaRainDBF.csv or KebeleRainDBF.csv writeFiles(AggLevel, Rain, ID, Year, Month, Day) return None