def SimpleSwath(path, file1, axis): # make sure names are in correct format NewPath = LSDOst.AppendSepToDirectoryPath(path) raster_file1 = NewPath + file1 # get some information about the raster NDV, xsize, ysize, GeoT, Projection, DataType = LSDMap_IO.GetGeoInfo( raster_file1) print "NDV is: " print NDV if NDV == None: NDV = -9999 print "No NDV defined" Raster1 = LSDMap_IO.ReadRasterArrayBlocks(raster_file1, raster_band=1) #nan_raster = Raster1[Raster1==NDV]=np.nan #print nan_raster #now mask the nodata masked_Raster1 = np.ma.masked_values(Raster1, NDV) means = np.mean(masked_Raster1, axis) medians = np.median(masked_Raster1, axis) std_deviations = np.std(masked_Raster1, axis) twentyfifth_percentile = np.percentile(masked_Raster1, 25, axis) seventyfifth_percentile = np.percentile(masked_Raster1, 75, axis) # This stuff only works with numpy 1.8 or later, wich we don't have #means = np.nanmean(nan_raster, axis) #medians = np.nanmedian(nan_raster, axis) #std_deviations = np.nanstd(nan_raster, axis) #twentyfifth_percentile = np.nanpercentile(nan_raster, 25, axis) #seventyfifth_percentile = np.nanpercentile(nan_raster, 75, axis) #print means #print medians #print std_deviations #print twentyfifth_percentile #print seventyfifth_percentile return means, medians, std_deviations, twentyfifth_percentile, seventyfifth_percentile
def GetTicksForUTM(FileName, x_max, x_min, y_max, y_min, n_target_tics): CellSize, XMin, XMax, YMin, YMax = LSDMap_IO.GetUTMMaxMin(FileName) NDV, xsize, ysize, GeoT, Projection, DataType = LSDMap_IO.GetGeoInfo( FileName) xmax_UTM = XMax xmin_UTM = XMin ymax_UTM = YMax ymin_UTM = YMin #print "now UTM, xmax: " +str(xmax_UTM)+" x_min: " +str(xmin_UTM)+" y_maxb: " +str(ymax_UTM)+" y_minb: " +str(ymin_UTM) dy_fig = ymax_UTM - ymin_UTM dx_fig = xmax_UTM - xmin_UTM dx_spacing = dx_fig / n_target_tics dy_spacing = dy_fig / n_target_tics if (dx_spacing > dy_spacing): dy_spacing = dx_spacing str_dy = str(dy_spacing) str_dy = str_dy.split('.')[0] n_digits = str_dy.__len__() nd = int(n_digits) first_digit = float(str_dy[0]) #print "str_dy: " +str_dy+ " n_digits: " +str(nd)+" first_digit: " + str(first_digit) dy_spacing_rounded = first_digit * pow(10, (nd - 1)) #print "n_digits: "+str(n_digits)+" dy_spacing: " +str(dy_spacing) + " and rounded: "+str(dy_spacing_rounded) str_xmin = str(xmin_UTM) str_ymin = str(ymin_UTM) #print "before split str_xmin: "+ str_xmin + " str ymin: " + str_ymin str_xmin = str_xmin.split('.')[0] str_ymin = str_ymin.split('.')[0] #print "after split str_xmin: "+ str_xmin + " str ymin: " + str_ymin xmin_UTM = float(str_xmin) ymin_UTM = float(str_ymin) #print "UTM: "+ str(xmin_UTM) + " str ymin: " + str(ymin_UTM) n_digx = str_xmin.__len__() n_digy = str_ymin.__len__() #print "n_dig_x: " + str(n_digx)+ " nd: " + str(nd) if (n_digx - nd + 1) >= 1: front_x = str_xmin[:(n_digx - nd + 1)] else: front_x = str_xmin if (n_digy - nd + 1) >= 1: front_y = str_ymin[:(n_digy - nd + 1)] else: front_y = str_ymin #print "xmin: " + str_xmin + " ymin: " + str_ymin + " n_digx: " + str(n_digx)+ " n_digy: " + str(n_digy) #print "frontx: " +front_x+" and fronty: "+ front_y round_xmin = float(front_x) * pow(10, nd - 1) round_ymin = float(front_y) * pow(10, nd - 1) #print "x_min: " +str(xmin_UTM)+ " round xmin: " +str(round_xmin)+ " y_min: " +str(ymin_UTM)+" round y_min: " + str(round_ymin) # now we need to figure out where the xllocs and ylocs are xUTMlocs = np.zeros(2 * n_target_tics) yUTMlocs = np.zeros(2 * n_target_tics) xlocs = np.zeros(2 * n_target_tics) ylocs = np.zeros(2 * n_target_tics) new_x_labels = [] new_y_labels = [] round_ymax = round_ymin + dy_spacing_rounded * (2 * n_target_tics - 1) #print "n_target_tics: " + str(n_target_tics) + " round_ymax: " +str(round_ymax) for i in range(0, 2 * n_target_tics): xUTMlocs[i] = round_xmin + (i) * dy_spacing_rounded yUTMlocs[i] = round_ymin + (i) * dy_spacing_rounded #xlocs[i] = (xUTMlocs[i]-XMin) xlocs[i] = xUTMlocs[i] # need to account for the rows starting at the upper boundary ylocs[i] = round_ymax - (yUTMlocs[i] - round_ymin) #print "i: " + str(i) +" yUTM: " + str(yUTMlocs[i])+ " rounded, reversed: " +str( ylocs[i]) new_x_labels.append(str(xUTMlocs[i]).split(".")[0]) new_y_labels.append(str(yUTMlocs[i]).split(".")[0]) #print xUTMlocs #print xlocs #print yUTMlocs #print ylocs #print new_x_labels #print new_y_labels new_xlocs = [] new_xUTMlocs = [] x_labels = [] # Now loop through these to get rid of those not in range for index, xloc in enumerate(xlocs): #print xloc if (xloc < XMax and xloc > XMin): new_xlocs.append(xloc) new_xUTMlocs.append(xUTMlocs[index]) x_labels.append(new_x_labels[index]) new_ylocs = [] new_yUTMlocs = [] y_labels = [] # Now loop through these to get rid of those not in range for index, yloc in enumerate(ylocs): #print yloc if (yloc < YMax and yloc > YMin): new_ylocs.append(yloc) new_yUTMlocs.append(yUTMlocs[index]) y_labels.append(new_y_labels[index]) #print "=======================================" #print "I am getting the tick marks now" #print "X extent: " + str(XMin)+ " " +str(XMax) #print "Y extent: " + str(YMin)+ " " +str(YMax) #print "x ticks: " #print new_xlocs #print "y ticks: " #print new_ylocs #return xlocs,ylocs,new_x_labels,new_y_labels return new_xlocs, new_ylocs, x_labels, y_labels