Beispiel #1
0
    def CreateSurface(self, firedata, saveloc):
        # Opens file, or expected df to be passed, and returns a sursafe of expected fire based on FRP
        # Saves a raster of surface
        # constants
        lat = 'LATITUDE'
        long = 'LONGITUDE'
        conf = 'FRP'
        min_points = 4

        # set size of arrays
        points = np.array(firedata[[lat, long]])
        delx = abs(self.top_left[1] - self.bot_right[1]) / self.xres
        dely = abs(self.top_left[0] - self.bot_right[0]) / self.yres

        # create evenly spaced array given number of boxes
        x = np.arange(min(self.top_left[1], self.bot_right[1]), max(self.top_left[1], self.bot_right[1]), delx)
        y = np.arange(max(self.top_left[0], self.bot_right[0]), min(self.top_left[0], self.bot_right[0]), -dely)

        grid_x, grid_y = np.meshgrid(x, y)

        pointy = points[:, 0]
        pointx = points[:, 1]

        # create surface
        # Check if there are enough points to make surface
        if len(firedata.index) >= min_points:
            z = griddata((pointx, pointy), firedata[conf], (grid_x, grid_y), method='linear')
            # Convert surface to raster file
            rc.Convert2tif(z, saveloc, self.top_left, self.bot_right, self.xres, self.yres, False)
        else:
            print('Not enough points at ' + self.saveloc)
        return 0
Beispiel #2
0
    def Elevation(self):
        print('Calculating Elevations')
        #coordinates
        left = self.top_left[1]
        right = self.bot_right[1]
        top = self.top_left[0]
        bott = self.bot_right[0]

        eledata = rs.open(self.fileloc)

        #index of coordinates
        row1, col1 = eledata.index(left, top)
        row2, col2 = eledata.index(right, bott)
        elearray = eledata.read(1)

        # make matrix of coords
        elemat = elearray[row1:(row2 + 1), col1:(col2 + 1)]

        output = self.InturpEle(elemat)
        delh = np.max(output) - np.min(output)

        # Output Elevation as Raster
        print('Saving Elevations')
        rc.Convert2tif(output, self.save, self.top_left, self.bot_right,
                       self.xres, self.yres, False)
        #Output elevation results
        np.savetxt(self.save + '.csv', output, delimiter=',')
        return output, delh
Beispiel #3
0
    def Extract_Data(self):
        #x and y delta as angles
        delx = abs(self.top_left[1] - self.bot_right[1]) / self.xres
        dely = abs(self.top_left[0] - self.bot_right[0]) / self.yres

        #distance of each box in KM
        xdelta, ydelta = llt.Coord2Dist(delx, dely, self.top_left[0])

        #size of boxes in m
        print(str(xdelta * 1000) + 'm - xbox')
        print(str(ydelta * 1000) + 'm - ybox')

        #make matrix of coords
        elemat = np.zeros((self.yres, self.xres))
        eledata = rs.open(self.loc)

        #Search each box location for water
        for i in range(self.yres):
            for j in range(self.xres):
                coord = (self.xCoord(j), self.yCoord(i))
                for val in eledata.sample([coord]):
                    if val[0] > self.season:
                        #if there is water we remove it
                        elemat[i, j] = 0
                    else:
                        elemat[i, j] = 1

        savespot = self.saveloc + '\\' + 'WaterData'
        #Produce raster or return array
        if self.saveloc != '':
            rc.Convert2tif(elemat, savespot, self.top_left, self.bot_right, self.xres, self.yres, False)
        else:
            return elemat

        return 0
Beispiel #4
0
    def WeatherData(self, delh):
        ######    Modified wind data #########
        if d.wth:
            wethloc = p.weatherfolder + '\\' + p.weatherfile

            reppday = 1
            dim = len(p.datesin) * len(p.times)
            uwind = np.empty((dim, self.cols, self.rows))
            vwind = np.empty((dim, self.cols, self.rows))
            i = 0

            print('Extracting Wind Data')
            for date in p.datesin:
                for time in p.times:
                    tim = datetime.strptime(date + ' ' + time,
                                            '%Y-%m-%d %H:%M')
                    sol = Wind_Data.WindData(wethloc, self.saveloc, tim,
                                             p.startcoords, self.coord[0],
                                             self.coord[1], self.rows,
                                             self.cols, False).Extract_Data()

                    uwind[i, :, :] = sol[0]
                    vwind[i, :, :] = sol[1]
                    i += 1

            #wind slope interaction
            xslope = np.genfromtxt(p.saveloc + "\\" + "xslope.csv",
                                   delimiter=",")
            yslope = np.genfromtxt(p.saveloc + "\\" + "yslope.csv",
                                   delimiter=",")

            print("Modifying Wind Data")
            for ell in range(dim):
                uwind[ell, :, :] = Wind_Slope.WindTopography(
                    xslope, uwind[ell, :, :], delh, 1000 * self.xres,
                    True).Data_Extract()
                vwind[ell, :, :] = Wind_Slope.WindTopography(
                    yslope, vwind[ell, :, :], delh, 1000 * self.yres,
                    False).Data_Extract()

                windloc = p.saveloc + "\\" + "WindData" + str(ell)
                rc.Convert2tif(uwind[ell, :, :], windloc + "-u", self.coord[0],
                               self.coord[1], self.rows, self.cols, False)
                rc.Convert2tif(vwind[ell, :, :], windloc + "-v", self.coord[0],
                               self.coord[1], self.rows, self.cols, False)

            return 0
Beispiel #5
0
def PrintLatLong(dumploc, coord1, coord2, xres, yres):
    delx = abs(coord1[1] - coord2[1]) / xres
    dely = abs(coord1[0] - coord2[0]) / yres

    lat = np.empty((xres, yres))
    long = np.empty((xres, yres))

    for i in range(xres):
        for j in range(yres):
            lat[j, i] = coord1[0] - dely * j
            long[j, i] = coord1[1] + delx * i

    rc.Convert2tif(lat, dumploc + '\\' + 'lat', coord1, coord2, xres, yres,
                   False)
    rc.Convert2tif(long, dumploc + '\\' + 'lon', coord1, coord2, xres, yres,
                   False)
    return 0
Beispiel #6
0
 def SurfaceWater(self):
     if d.wat:
         print('Extracting Water Data')
         watloc = p.waterfolder + '\\' + p.waterfile
         water = WaterData.SurfaceWater(watloc, self.coord[0],
                                        self.coord[1], self.rows, self.cols,
                                        '').Extract_Data()
         rc.Convert2tif(water, watloc, self.coord[0], self.coord[1],
                        self.rows, self.cols, False)
     else:
         water = 0
     return water
Beispiel #7
0
    def SlopeData(self):
        ######    Slope Data    ##########
        eleloc = p.elefolder + '\\' + p.elefile
        if d.ele:
            print('Extracting Elevation Data')

            delh = ed.Elevation(eleloc, self.coord[0], self.coord[1],
                                self.rows, self.cols, self.saveloc,
                                self.elesave).Extract_Data()
        else:
            arr = rc.readrst(self.saveloc + "\\" + self.elesave)
            delh = np.max(arr) - np.min(arr)
        return delh
Beispiel #8
0
    def CombineBreaks(self):
        water = self.SurfaceWater()
        roads = self.RoadData()
        if d.rod and d.wat:

            breaks = np.multiply(water, roads)
        elif d.rod or d.wat:
            breaks = water if d.wat else roads
        else:
            breaks = 0

            #write tif of barriers
        if d.rod or d.wat:
            print("Donezo")
            rc.Convert2tif(breaks, self.barriersave, self.coord[0],
                           self.coord[1], self.rows, self.cols, False)
        return 0
Beispiel #9
0
def CreateSurface(fileloc, filename, dumploc, coord1, coord2, sizex, sizey,
                  boolian):
    #Opens file, or expected df to be passed, and returns a sursafe of expected fire based on FRP
    #Saves a raster of surface
    #constants
    lat = 'LATITUDE'
    long = 'LONGITUDE'
    conf = 'FRP'

    #checks if file or df is passed
    if boolian:
        firedata = pd.read_csv(fileloc + '\\' + filename)
    else:
        firedata = fileloc

    #set size of arrays
    points = np.array(firedata[[lat, long]])
    delx = abs(coord1[1] - coord2[1]) / sizex
    dely = abs(coord1[0] - coord2[0]) / sizey

    #create evenly spaced array given number of boxes
    x = np.arange(min(coord1[1], coord2[1]), max(coord1[1], coord2[1]), delx)
    y = np.arange(max(coord1[0], coord2[0]), min(coord1[0], coord2[0]), -dely)

    grid_x, grid_y = np.meshgrid(x, y)

    pointy = points[:, 0]
    pointx = points[:, 1]

    #create surface
    #Check if there are enough points to make surface
    if len(firedata.index) >= 4:
        z = griddata((pointx, pointy),
                     firedata[conf], (grid_x, grid_y),
                     method='linear')
        #Convert surface to raster file
        rc.Convert2tif(z, dumploc, coord1, coord2, sizex, sizey, False)
    else:
        print('Not enough points at ' + dumploc)
    return 0
Beispiel #10
0
from FireSpotting import CombinedModel as fs

######### Step 1: Run Data Grab ####################:
print("Step 1: Extracting Data")
cd.RunData().ExtractAll()
res = llt.Coord2Dist((pm.coord2[1] - pm.coord1[1]) / p.n,
                     (pm.coord1[0] - pm.coord2[0]) / p.m, pm.coord1[0])
print("Grid Resolution in km (x, y): " + str(res))

#Wind Data Read in
winnum = len(pm.times) * len(pm.datesin)
windu = np.zeros((winnum, p.m, p.n), dtype=np.float32)
windv = np.zeros((winnum, p.m, p.n), dtype=np.float32)
if p.wthuse:  #check if there is weather data to extract
    for i in range(winnum):
        windu[i, :, :] = rc.readrst(pm.saveloc + "\\" + "WindData" + str(i) +
                                    "-u")
        windv[i, :, :] = -rc.readrst(
            pm.saveloc + "\\" + "WindData" + str(i) + "-v"
        )  #negitive sign as wind direction is reverse of axis direction

#check if there is elevation data
print("Grabbing Slope Data")
if p.eleuse:
    heights = rc.readrst(pm.saveloc + '\\ElevationData')
    heights = heights.astype(dtype=np.float32)
else:
    heights = np.zeros((p.m, p.n), dtype=np.float32)

#check if to use fire break:
print("Grabbing Firebrand Data")
if p.brkuse: