def _pixels_of_interest_to_array(self, point_tif): # =========== Jul 8, 2017 # print 'point tif', point_tif point_arr = convert_raster_to_array(point_tif) try: if os.path.isfile(paths.mask): point_arr = apply_mask(paths.mask, point_arr) except TypeError: pass point_arr = apply_mask_pixel_tracker(paths.point_shape, point_arr) # print 'new point arr', point_arr # print 'new point arr shape', point_arr.shape return point_arr
def _pixels_of_interest_to_array(self, point_tif): # =========== Jul 8, 2017 # print 'point tif', point_tif point_arr = convert_raster_to_array(point_tif) try: if os.path.isfile(paths.mask): point_arr = apply_mask(paths.mask, point_arr) except TypeError: pass point_arr = apply_mask_pixel_tracker(paths.point_shape, point_arr) # print 'new point arr', point_arr # print 'new point arr shape', point_arr.shape return point_arr
def get_kcb(in_path, date_object): """ Find NDVI image and convert to Kcb. :param in_path: NDVI input data path. :type in_path: str :param date_object: Datetime object of date. :return: numpy array object """ # print date_object doy = date_object.timetuple().tm_yday year = date_object.year # print('date object', date_object) if year == 2000: band = 1 raster = '{}_{}.tif'.format(year, doy) elif year == 2001: for num in NUMS: diff = doy - num if 0 <= diff <= 15: start = num if num == 353: nd = num + 12 else: nd = num + 15 band = diff + 1 raster = '{}_{}_{}.tif'.format(year, start, nd) print('raster', raster) break else: for i, num in enumerate(NUMS): diff = doy - num if 0 <= diff <= 15: band = diff + 1 raster = '{}_{}.tif'.format(year, i + 1) break ndvi = convert_raster_to_array(in_path, raster, band=band) return ndvi
# =================================IMPORTS======================================= from osgeo import gdal from numpy import array, where, count_nonzero, ones, zeros import os from recharge.raster_tools import convert_raster_to_array from recharge.raster_tools import get_raster_geo_attributes as get_geo input_path = 'E:\\' sand_tif = 'combo_pct_sand.tif' clay_tif = 'combo_pct_clay.tif' out_name = 'rew_22SEPT16.tif' geo = get_geo(input_path) sand = convert_raster_to_array(input_path, sand_tif) clay = convert_raster_to_array(input_path, clay_tif) #From ASCE pg 195, equations from Ritchie et al., 1989 rew = 8 + 0.08 * clay rew = where(sand > 80.0, 20.0 - 0.15 * sand, rew) rew = where(clay > 50, 11 - 0.06 * clay, rew) driver = gdal.GetDriverByName('GTiff') out_data_set = driver.Create(os.path.join(input_path, out_name), geo['cols'], geo['rows'], geo['bands'], geo['data_type']) out_data_set.SetGeoTransform(geo['geotransform']) out_data_set.SetProjection(geo['projection']) output_band = out_data_set.GetRasterBand(1) output_band.WriteArray(rew, 0, 0)
# you may not use this file except in compliance # with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # =============================================================================== # =================================IMPORTS======================================= from osgeo import gdal from numpy import array, where, count_nonzero, ones, zeros import os from recharge.raster_tools import convert_raster_to_array from recharge.raster_tools import get_raster_geo_attributes as get_geo input_path = 'C:\Users\David\Documents\Recharge\Thesis\Figures\maps' sand_tif = 'total_precip_2000_2013_11OCT16.tif' geo = get_geo(input_path) ppt = convert_raster_to_array(input_path, sand_tif) print 'mean precip = {}'.format(ppt.mean()) # ========================== EOF ==============================================
EXu 13 SEP 2017 """ from recharge.raster_tools import convert_raster_to_array import numpy as np #Locations for Walnut Gulch input_path = 'G:\\Walnut\\WalnutSoilProperties\\' sand_tif = 'Merged_percSand.tif' clay_tif = 'Merged_percClay.tif' silt_tif = 'Merged_percSilt.tif' BD_w_tif = 'Merged_gcmBD3rdbar.tif' Ksat_tif = 'Merged_umsKsat.tif' OM_tif = 'Merged_OrgMatter.tif' WC_tif = 'Merged_WC3rdbar.tif' sand = convert_raster_to_array(input_path, sand_tif) clay = convert_raster_to_array(input_path, clay_tif) silt_e = convert_raster_to_array(input_path, silt_tif) #elev = convert_raster_to_array(input_path, elev_tif) BD_w = convert_raster_to_array(input_path, BD_w_tif) #wet bulk density Ksat = convert_raster_to_array(input_path, Ksat_tif) #extracted OM = convert_raster_to_array(input_path, OM_tif) WC = convert_raster_to_array(input_path, WC_tif) sand_1d = sand.flatten() clay_1d = clay.flatten() silt_e_1d = silt_e.flatten() silt_s_1d = np.subtract(100, clay_1d + sand_1d) #elev_1d = elev.flatten() BD_w_1d = BD_w.flatten() Ksat_1d = Ksat.flatten()
""" from recharge.raster_tools import convert_raster_to_array import numpy as np #Locations for Walnut Gulch input_path = 'G:\\Walnut\\WalnutSoilProperties\\' sand_tif = 'Merged_percSand.tif' clay_tif = 'Merged_percClay.tif' silt_tif = 'Merged_percSilt.tif' BD_w_tif = 'Merged_gcmBD3rdbar.tif' Ksat_tif = 'Merged_umsKsat.tif' OM_tif = 'Merged_OrgMatter.tif' WC_tif = 'Merged_WC3rdbar.tif' sand = convert_raster_to_array(input_path, sand_tif) clay = convert_raster_to_array(input_path, clay_tif) silt_e = convert_raster_to_array(input_path, silt_tif) #elev = convert_raster_to_array(input_path, elev_tif) BD_w = convert_raster_to_array(input_path, BD_w_tif)#wet bulk density Ksat = convert_raster_to_array(input_path, Ksat_tif)#extracted OM = convert_raster_to_array(input_path, OM_tif) WC = convert_raster_to_array(input_path, WC_tif) sand_1d = sand.flatten() clay_1d = clay.flatten() silt_e_1d = silt_e.flatten() silt_s_1d = np.subtract(100,clay_1d+sand_1d) #elev_1d = elev.flatten() BD_w_1d = BD_w.flatten() Ksat_1d = Ksat.flatten()
from recharge.raster_tools import get_raster_geo_attributes input_folder = 'G:\\ETRM_inputs_Walnut\\NDVI\\NDVI_Real\\' files = os.listdir(input_folder) root = "G:\\ETRM_inputs_Walnut\\PM_RAD\\PM2000\\" for it in files: in_folder = input_folder+it+"\\" os.chdir(in_folder) for raster in find_format(in_folder, '*.tif'): FOLDER,r_name = os.path.split(raster) tiff = r_name temp = "temp.tif" cut = 'gdalwarp -overwrite -s_srs EPSG:{a} -t_srs EPSG:{a} -te {b} {c} {d} {e} -ts {f} {g}\n' \ ' -r {h} -multi {j} {k}'.format(a=projection, b=x_min_n, c=y_min_n, d=x_max, e=y_max, f=cols_n, g=rows_n, h=resample_method, j=tiff, k=temp) call(cut) ndvi = convert_raster_to_array(in_folder, temp) arr = ndvi*0.0001 geo = get_raster_geo_attributes(root) output_path = in_folder+tiff convert_array_to_raster(output_path, arr, geo, output_band=1) ###========================= #Prism #============================================= #Walnut import os, fnmatch from subprocess import call
# =================================IMPORTS======================================= from osgeo import gdal from numpy import array, where, count_nonzero, ones, zeros import os from recharge.raster_tools import convert_raster_to_array from recharge.raster_tools import get_raster_geo_attributes as get_geo input_path = 'E:\\' sand_tif = 'combo_pct_sand.tif' clay_tif = 'combo_pct_clay.tif' out_name = 'rew_22SEPT16.tif' geo = get_geo(input_path) sand = convert_raster_to_array(input_path, sand_tif) clay = convert_raster_to_array(input_path, clay_tif) #From ASCE pg 195, equations from Ritchie et al., 1989 rew = 8 + 0.08 * clay rew = where(sand > 80.0, 20.0 - 0.15 * sand, rew) rew = where(clay > 50, 11 - 0.06 * clay, rew) driver = gdal.GetDriverByName('GTiff') out_data_set = driver.Create(os.path.join(input_path, out_name), geo['cols'], geo['rows'], geo['bands'], geo['data_type']) out_data_set.SetGeoTransform(geo['geotransform']) out_data_set.SetProjection(geo['projection']) output_band = out_data_set.GetRasterBand(1) output_band.WriteArray(rew, 0, 0)