From 5bbaa9741665dae412df64b83103baab619aac09 Mon Sep 17 00:00:00 2001 From: Sweet L T Date: Tue, 11 May 2021 10:36:09 -0400 Subject: [PATCH 01/35] adding new file --- NATURF/config.py | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 NATURF/config.py diff --git a/NATURF/config.py b/NATURF/config.py new file mode 100644 index 00000000000..9f73b7b2954 --- /dev/null +++ b/NATURF/config.py @@ -0,0 +1,2 @@ +path = r'C:\ORNL Spring\Census Tracts\Tracts 51-60\005803-005877\005855\005855.shp' +name = "LV_005855" From ed55e0889689df3e96e8ebbd69fca95e2b27fc61 Mon Sep 17 00:00:00 2001 From: lg6 Date: Tue, 11 May 2021 16:20:36 -0400 Subject: [PATCH 02/35] Deleted old scripts and replaced them with new ones. --- NATURF/Building_IDs_Generator.py | 152 ++++++++++ NATURF/Buildings_Raster_Generator.py | 152 ++++++++++ NATURF/Extractor.py | 188 ++++++++++++ NATURF/Final_Outputs.py | 428 +++++++++++++++++++++++++++ NATURF/Master_Script.py | 12 + NATURF/Parameter_Calculations.py | 229 ++++++++++++++ NATURF/WRF_Calculations.py | 79 +++++ 7 files changed, 1240 insertions(+) create mode 100644 NATURF/Building_IDs_Generator.py create mode 100644 NATURF/Buildings_Raster_Generator.py create mode 100644 NATURF/Extractor.py create mode 100644 NATURF/Final_Outputs.py create mode 100644 NATURF/Master_Script.py create mode 100644 NATURF/Parameter_Calculations.py create mode 100644 NATURF/WRF_Calculations.py diff --git a/NATURF/Building_IDs_Generator.py b/NATURF/Building_IDs_Generator.py new file mode 100644 index 00000000000..4e877f66c05 --- /dev/null +++ b/NATURF/Building_IDs_Generator.py @@ -0,0 +1,152 @@ +from config import * +from sys import exit +from time import time +from math import sqrt +from math import ceil +from numpy import array, arange, transpose, set_printoptions, zeros, uint8, uint16, uint32, indices, where, empty, float64, \ + column_stack, savetxt, save +from skimage.draw import polygon +import osr +from PIL import Image +from scipy import ndimage +import csv +from tempfile import TemporaryFile + +try: + from osgeo import gdal, ogr + from osgeo.gdalconst import * +except ImportError: + import gdal + import ogr + from gdalconst import * + +start_time = time() + + +#path = r'C:\ORNL Spring\Census Tracts\Tracts 51-60\005803-005877\005844\005844.shp' + +# get the shapefile driver +driver = ogr.GetDriverByName('ESRI Shapefile') + +datasource2 = driver.Open(path, 0) +if datasource2 is None: + print('Could not open shapefile') + exit(1) + +# register all of the GDAL drivers +gdal.AllRegister() + +layer2 = datasource2.GetLayer() + +extent2 = layer2.GetExtent() + +xOrigin = extent2[0] +yOrigin = extent2[3] + +PIXEL_SIZE = 0.5 + +IMAGE_SIZE_X = (2 * ceil(extent2[3]-extent2[2])) + 100 +IMAGE_SIZE_Y = (2 * ceil(extent2[1]-extent2[0])) + 100 + +pixelWidth = PIXEL_SIZE +pixelHeight = -PIXEL_SIZE + +start_x = int(xOrigin) +start_y = ceil(yOrigin) + +start_x_p = int((start_x - xOrigin) / pixelWidth) +start_y_p = int((start_y - yOrigin) / pixelHeight) + +driver_out = gdal.GetDriverByName('GTiff') +imgOut = driver_out.Create(r'Building_IDs.tif', + IMAGE_SIZE_Y, IMAGE_SIZE_X, 1, gdal.GDT_Int32) + +proj = osr.SpatialReference() +proj.SetWellKnownGeogCS("WGS84") +proj.SetUTM(11, False) + +bandOut1 = imgOut.GetRasterBand(1) + +data1 = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint8) +data1.fill(255) + +ids = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint32) +ids.fill(0) + +buils = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint16) +buils.fill(255) + +tempxyz = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) + +distarr = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) +distarr.fill(0) + +ind = indices(data1.shape) + +names = [] +heights = [] +widths = [] +ratios = [] + +cnt = 1 + +# radius = 15 + +# loop through the buildings +feature_buil = layer2.GetNextFeature() + +while feature_buil: + bid = feature_buil.GetFieldAsString('ID') + + geomb = feature_buil.GetGeometryRef() + ring = geomb.GetGeometryRef(0) + numpoints = ring.GetPointCount() + + if numpoints != 0: + nx, ny, nz = ring.GetPoint(0) + + xOffset = int((nx - xOrigin) / pixelWidth) + yOffset = int((ny - yOrigin) / pixelHeight) + + parr = [[xOffset, yOffset]] + parrx = [[xOffset]] + parry = [[yOffset]] + + for bi in range(1, ring.GetPointCount()): + bpt = ring.GetPoint(bi) + + xoff = int((bpt[0] - xOrigin) / pixelWidth) + yoff = int((bpt[1] - yOrigin) / pixelHeight) + + parr.append([xoff, yoff]) + parrx.append([xoff]) + parry.append([yoff]) + + parrx[:] = [x[0] - start_x_p for x in parrx] + parry[:] = [y[0] - start_y_p for y in parry] + + parrx = array(parrx) + parry = array(parry) + rr, cc = polygon(parrx, parry, [IMAGE_SIZE_Y, IMAGE_SIZE_X]) + + buils[cc, rr] = 127 + + bid = float(bid) + bid = int(bid) + + ids[cc, rr] = where(ids[cc, rr] != 0, ids[cc, rr], cnt) + + # print cnt + + cnt += 1 + feature_buil.Destroy() + feature_buil = layer2.GetNextFeature() + +data1 = where(buils != 127, data1, 127) + +bandOut1.WriteArray(ids, 0, 0) + +imgOut.SetGeoTransform((start_x, pixelWidth, 0, start_y, 0, pixelHeight)) +imgOut.SetProjection(proj.ExportToWkt()) + +print("Script 2 took", str(time() - start_time), "seconds to run") diff --git a/NATURF/Buildings_Raster_Generator.py b/NATURF/Buildings_Raster_Generator.py new file mode 100644 index 00000000000..78a80850725 --- /dev/null +++ b/NATURF/Buildings_Raster_Generator.py @@ -0,0 +1,152 @@ +from config import * +from sys import exit +from time import time +from math import sqrt +from math import ceil +from numpy import array, arange, transpose, set_printoptions, zeros, uint8, uint16, indices, where, empty, float64, \ + column_stack, savetxt +from skimage.draw import polygon +import osr +from PIL import Image +from scipy import ndimage + +try: + from osgeo import gdal, ogr + from osgeo.gdalconst import * +except ImportError: + import gdal + import ogr + from gdalconst import * + +start_time = time() + +#path = r'C:\ORNL Spring\Census Tracts\Tracts 51-60\005803-005877\005844\005844.shp' + +# get the shapefile driver +driver = ogr.GetDriverByName('ESRI Shapefile') + +datasource2 = driver.Open(path, 0) +if datasource2 is None: + print('Could not open shapefile') + exit(1) + +# register all of the GDAL drivers +gdal.AllRegister() + +layer2 = datasource2.GetLayer() + +extent2 = layer2.GetExtent() + +xOrigin = extent2[0] +yOrigin = extent2[3] + +PIXEL_SIZE = 0.5 + +IMAGE_SIZE_X = (2 * ceil(extent2[3]-extent2[2])) + 100 +IMAGE_SIZE_Y = (2 * ceil(extent2[1]-extent2[0])) + 100 + +pixelWidth = PIXEL_SIZE +pixelHeight = -PIXEL_SIZE + +start_x = int(xOrigin) +start_y = ceil(yOrigin) + +start_x_p = int((start_x - xOrigin) / pixelWidth) +start_y_p = int((start_y - yOrigin) / pixelHeight) + +driver_out = gdal.GetDriverByName('GTiff') +imgOut = driver_out.Create(r'Buildings_Raster.tif', + IMAGE_SIZE_Y, IMAGE_SIZE_X, 1, 1) + +proj = osr.SpatialReference() +proj.SetWellKnownGeogCS("WGS84") +proj.SetUTM(11, False) + +bandOut1 = imgOut.GetRasterBand(1) + +data1 = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint8) +data1.fill(255) + +ids = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint16) +ids.fill(255) + +buils = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint16) +buils.fill(255) + +tempxyz = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) + +distarr = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) +distarr.fill(0) + +ind = indices(data1.shape) + +ys = 0 +yl = 0 +xs = 0 +xl = 0 + +# radius = 15 + +# loop through the buildings +feature_buil = layer2.GetNextFeature() + +while feature_buil: + geomb = feature_buil.GetGeometryRef() + ring = geomb.GetGeometryRef(0) + numpoints = ring.GetPointCount() + + if numpoints != 0: + nx, ny, _ = ring.GetPoint(0) + + # print(nx, ny) + # print(xOrigin, yOrigin) + + xOffset = int((nx - xOrigin) / pixelWidth) + yOffset = int((ny - yOrigin) / pixelHeight) + + # print(xOffset, yOffset) + + parr = [[xOffset, yOffset]] + parrx = [[xOffset]] + parry = [[yOffset]] + + # print(parrx) + # print(parry) + # print(ring.GetPointCount()) + + for i in range(1, numpoints): + bpt = ring.GetPoint(i) + + xoff = int((bpt[0] - xOrigin) / pixelWidth) + yoff = int((bpt[1] - yOrigin) / pixelHeight) + + parrx.append([xoff]) + parry.append([yoff]) + + # print(parrx) + # print(parry) + + parrx[:] = [x[0] - start_x_p for x in parrx] + parry[:] = [y[0] - start_y_p for y in parry] + + # print(parrx) + # print(parry) + + parrx = array(parrx) + parry = array(parry) + rr, cc = polygon(parrx, parry, [IMAGE_SIZE_Y, IMAGE_SIZE_X]) + # print(rr, cc) + buils[cc, rr] = 127 + + feature_buil.Destroy() + feature_buil = layer2.GetNextFeature() + + +data1 = where(buils != 127, data1, 127) + +bandOut1.WriteArray(data1, 0, 0) + +imgOut.SetGeoTransform((start_x, pixelWidth, 0, start_y, 0, pixelHeight)) +imgOut.SetProjection(proj.ExportToWkt()) + +print("Script 1 took", str(time() - start_time), "seconds to run") diff --git a/NATURF/Extractor.py b/NATURF/Extractor.py new file mode 100644 index 00000000000..e2582741f1d --- /dev/null +++ b/NATURF/Extractor.py @@ -0,0 +1,188 @@ +import os + +import pandas as pd +import geopandas as gpd + +from shapely.geometry import Polygon + + +def polygon_from_bounds(gdf): + """Create a polygon from the bounds of all geometries in a geodataframe. + :param gdf: Geopandas dataframe of polygons. + :return: Shapely Polygon Object + """ + + # get the bounds of all geometries + minx, miny, maxx, maxy = gdf.geometry.total_bounds + + # construct a bounding box + boundary = [(minx, miny), + (maxx, miny), + (maxx, maxy), + (minx, maxy), + (minx, miny)] + + # convert to a polygon object + return Polygon(boundary) + + +def clip_method(buildings_gdf, target_gdf): + """Clip buildings to the target geometries. This method subsets the buildings data first based on the bounding + box around the target geometries to speed things up a bit. Still a slower method. + :param buildings_gdf: The input buildings polygon geodataframe. + :type buildings_gdf: GeoDataFrame + :param target_gdf: Input target polygon features geodataframe. + :type target_gdf: GeoDataFrame + :return: A clipped geodataframe with the target buildings geometries + """ + + # create a polygon for the bounds of the target data + target_poly = polygon_from_bounds(target_gdf) + + # create a valid field where 1 is in the bonding box and 0 is not + buildings_gdf['valid'] = buildings_gdf.geometry.apply(lambda x: 1 if x.intersects(target_poly) else 0) + + # create a subset of buildings polygons that can be used to speed up the clip functionality + buildings_subset_gdf = buildings_gdf.loc[buildings_gdf['valid'] == 1] + + # clip buildings by the target geometries + return gpd.clip(buildings_subset_gdf, target_gdf) + + +def sjoin_method(buildings_gdf, target_gdf, join_type='left', topology='intersects'): + """Spatially join (left) the intersecting geometries of the buildings data for the target features. + :param buildings_gdf: The input buildings polygon geodataframe. + :type buildings_gdf: GeoDataFrame + :param target_gdf: Input target polygon features geodataframe. + :type target_gdf: GeoDataFrame + :param join_type: The type of join: + ‘left’: use keys from left_df; retain only left_df geometry + column + ‘right’: use keys from right_df; retain only right_df geometry + column + ‘inner’: use intersection of keys from both dfs; retain only + left_df geometry column + :type join_type: str + :param topology: Binary predicate, one of {‘intersects’, ‘contains’, ‘within’}. + See http://shapely.readthedocs.io/en/latest/manual.html#binary-predicates. + :type topology: str + :return: A geodataframe with the target buildings geometries + """ + + return gpd.sjoin(left_df=target_gdf, right_df=buildings_gdf, how=join_type, op=topology) + + +def workflow(buildings_shp_file, target_shp_file, existing_shp_file, output_directory=None, x_offset=0, y_offset=0, + write_outputs=True, geometry_field_name='geometry', subset_method='sjoin'): + """The following is a workflow to conduct the following: + [0] Clip input buildings to the polygons in the target shapefile + [1] Offset the geometries in the clipped data by the x, y offset provided by the user + [2] Merge the output of the clipped (or offset) operations with an input shapefile + :param buildings_shp_file: The input buildings polygon shapefile path. + :type buildings_shp_file: str + :param target_shp_file: Input target polygon features shapefile path. + :type target_shp_file: str + :param existing_shp_file: An existing shapefile with the same field names as what will + the same was what is in the clipped output. + :type existing_shp_file: str + :param output_directory: Full path to an output directory to save outputs to. + :type output_directory: str + :param x_offset: Number of map units on the X axis to offset the polygon centroid + by. This should be in the units of the input file geometry. + :type x_offset: int; float + :param y_offset: Number of map units on the Y axis to offset the polygon centroid + by. This should be in the units of the input file geometry. + :type y_offset: int; float + :param write_outputs: Choose to write outputs to shapefiles. + :type write_outputs: bool + :param geometry_field_name: Field name for geometry. Default: `geometry`. + :type geometry_field_name: str + :param subset_method: A method to subset the buildings data using the target data as + as follows: + `sjoin`: Default. Spatially join (left) the intersecting + geometries of the buildings data for the target + features. + `clip`: Clip buildings to the target geometries. This method + subsets the buildings data first based on the bounding + box around the target geometries to speed things up a + bit. Still a slower method. + :param subset_method: str + :return: A geopandas dataframe of the merged output + USAGE: + buildings_shp_file = '' + target_shp_file = '' + existing_shp_file = '' + output_directory = '' + x_offset = 1000 + y_offset = 1000 + write_outputs = True + # which method to use for extracting the buildings data + subset_method = 'sjoin' + result_gdf = workflow(buildings_shp_file=buildings_shp_file, + target_shp_file=target_shp_file, + existing_shp_file=existing_shp_file, + output_directory=output_directory, + x_offset=x_offset, + y_offset=y_offset, + write_outputs=write_outputs, + subset_method=subset_method) + """ + + # import shapefiles to geopandas dataframes + buildings_gdf = gpd.read_file(buildings_shp_file) + target_gdf = gpd.read_file(target_shp_file) + existing_gdf = gpd.read_file(existing_shp_file) + + # ensure coordinate systems match for the inputs + if not (buildings_gdf.crs == target_gdf.crs == existing_gdf.crs): + msg = f"Coordinate systems do not match for the input files." + raise AttributeError(msg) + + # create a spatial subset of the buildings data from features in the target data with a user-preferred method + if subset_method == 'sjoin': + subset_gdf = sjoin_method(buildings_gdf, target_gdf) + elif subset_method == 'clip': + subset_gdf = clip_method(buildings_gdf, target_gdf) + else: + msg = f"`subset_method` '{subset_method}' not in available options: `sjoin`, `clip`" + raise ValueError(msg) + + # offset the clipped geometries by the user specified amount + if x_offset > 0 or y_offset > 0: + subset_gdf[geometry_field_name] = subset_gdf.translate(xoff=x_offset, yoff=y_offset) + + # merge the result into an existing dataset + merged_gdf = pd.concat([existing_gdf, subset_gdf]).pipe(gpd.GeoDataFrame) + + # write outputs if desired + if write_outputs: + subset_gdf.to_file(os.path.join(output_directory, 'subset_data.shp')) + merged_gdf.to_file(os.path.join(output_directory, 'merged_data.shp')) + + return merged_gdf + +# input files +buildings_shp_file = 'C:\ORNL Spring\Shapefiles\ClarkCounty_Project.shp' +target_shp_file = 'C:\ORNL Spring\Shapefiles\Sample_Data_Project.shp' +existing_shp_file = 'C:\ORNL Spring\Shapefiles\ClarkCounty_Project.shp' +output_directory = 'C:\ORNL Spring\Shapefiles' + +# offset in map units +x_offset = 1000 +y_offset = 1000 + +# choose to write outputs +write_outputs = True + +# which method to use for extracting the buildings data +subset_method = 'sjoin' + +# run it and return a geopandas dataframe +result_gdf = workflow(buildings_shp_file=buildings_shp_file, + target_shp_file=target_shp_file, + existing_shp_file=existing_shp_file, + output_directory=output_directory, + x_offset=x_offset, + y_offset=y_offset, + write_outputs=write_outputs, + subset_method=subset_method) \ No newline at end of file diff --git a/NATURF/Final_Outputs.py b/NATURF/Final_Outputs.py new file mode 100644 index 00000000000..8bb33fb844b --- /dev/null +++ b/NATURF/Final_Outputs.py @@ -0,0 +1,428 @@ +from config import * +from WRF_Calculations import * +from sys import exit +from time import time +from math import sqrt +from math import ceil +from numpy import array, arange, transpose, set_printoptions, zeros, uint8, uint16, indices, where, empty, float64, \ + column_stack, savetxt, isnan, mean, shape, ones, int32, save, float32, double, diff +from skimage.draw import polygon +import osr +from PIL import Image +from scipy import ndimage, misc +import pickle +import sklearn.preprocessing +import struct +import csv + +try: + from osgeo import gdal, ogr + from osgeo.gdalconst import * +except ImportError: + import gdal + import ogr + from gdalconst import * + +start_time = time() + +filename = "%s.npy" % name + +#path = r'C:\ORNL Spring\Census Tracts\Tracts 51-60\005803-005877\005844\005844.shp' + +# get the shapefile driver +driver = ogr.GetDriverByName('ESRI Shapefile') + +datasource2 = driver.Open(path, 0) +if datasource2 is None: + print('Could not open shapefile') + exit(1) + +# register all of the GDAL drivers +gdal.AllRegister() + +layer2 = datasource2.GetLayer() +extent2 = layer2.GetExtent() + +xOrigin = extent2[0] +yOrigin = extent2[3] + +FACTOR = 100/0.5 + +PIXEL_SIZE = 0.5 * FACTOR + +IMAGE_SIZE_X = tiley +IMAGE_SIZE_Y = tilex + +pixelWidth = PIXEL_SIZE +pixelHeight = -PIXEL_SIZE + +start_x = int(xOrigin) +start_y = ceil(yOrigin) + +start_x_p = int((start_x - xOrigin) / pixelWidth) +start_y_p = int((start_y - yOrigin) / pixelHeight) + +driver_out = gdal.GetDriverByName('GTiff') + +proj = osr.SpatialReference() +proj.SetWellKnownGeogCS("WGS84") +proj.SetUTM(11, False) + +data1 = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint8) +data1.fill(255) +ids = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint16) +ids.fill(255) + +tempxyz = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) + +distarr = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) +distarr.fill(0) + +ind = indices(data1.shape) + +cnt = 0 + +# radius = 15 + +afile = open(r'names2.pkl', 'rb') +names2 = pickle.load(afile) +afile.close() + +afile = open(r'fad_out2.pkl', 'rb') +fad_out2 = pickle.load(afile) +afile.close() + +afile = open(r'builfrac_out2.pkl', 'rb') +builfrac_out2 = pickle.load(afile) +afile.close() + +afile = open(r'paf_out2.pkl', 'rb') +paf_out2 = pickle.load(afile) +afile.close() + +afile = open(r'fai_out2.pkl', 'rb') +fai_out2 = pickle.load(afile) +afile.close() + +afile = open(r'rdh_out2.pkl', 'rb') +rdh_out2 = pickle.load(afile) +afile.close() + +afile = open(r'rrl_out2.pkl', 'rb') +rrl_out2 = pickle.load(afile) +afile.close() + +afile = open(r'mdh_out2.pkl', 'rb') +mdh_out2 = pickle.load(afile) +afile.close() + +afile = open(r'mrl_out2.pkl', 'rb') +mrl_out2 = pickle.load(afile) +afile.close() + +afile = open(r'bs2par_out2.pkl', 'rb') +bs2par_out2 = pickle.load(afile) +afile.close() + +afile = open(r'zo_out2.pkl', 'rb') +zo_out2 = pickle.load(afile) +afile.close() + +afile = open(r'zd_out2.pkl', 'rb') +zd_out2 = pickle.load(afile) +afile.close() + +afile = open(r'mean_ht_out2.pkl', 'rb') +mean_ht_out2 = pickle.load(afile) +afile.close() + +afile = open(r'std_ht_out2.pkl', 'rb') +std_ht_out2 = pickle.load(afile) +afile.close() + +afile = open(r'awmh_out2.pkl', 'rb') +awmh_out2 = pickle.load(afile) +afile.close() + +afile = open(r'h2w_out2.pkl', 'rb') +h2w_out2 = pickle.load(afile) +afile.close() + +afile = open(r'car_out2.pkl', 'rb') +car_out2 = pickle.load(afile) +afile.close() + +bldgs = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=double) + +# loop through the buildings +feature_buil = layer2.GetNextFeature() + +while feature_buil: + bid = feature_buil.GetFieldAsString('ID') + + if bid in names2: + + geomb = feature_buil.GetGeometryRef() + ring = geomb.GetGeometryRef(0) + numpoints = ring.GetPointCount() + + if numpoints != 0: + nx, ny, nz = ring.GetPoint(0) + + xOffset = int((nx - xOrigin) / pixelWidth) + yOffset = int((ny - yOrigin) / pixelHeight) + + parr = [[xOffset, yOffset]] + parrx = [[xOffset]] + parry = [[yOffset]] + + for i in range(1, numpoints): + bpt = ring.GetPoint(i) + + xoff = int((bpt[0] - xOrigin) / pixelWidth) + yoff = int((bpt[1] - yOrigin) / pixelHeight) + + parrx.append([xoff]) + parry.append([yoff]) + + parrx[:] = [x[0] - start_x_p for x in parrx] + parry[:] = [y[0] - start_y_p for y in parry] + + parrx = array(parrx) + parry = array(parry) + rr, cc = polygon(parrx, parry, [IMAGE_SIZE_Y, IMAGE_SIZE_X]) + + bldgs[cc, rr] = bid + + cnt += 1 + + feature_buil.Destroy() + feature_buil = layer2.GetNextFeature() + +bldgsh = zeros((15, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=double) + +layer2.ResetReading() +feature_buil = layer2.GetNextFeature() + +while feature_buil: + bid = feature_buil.GetFieldAsString('ID') + ht = feature_buil.GetFieldAsString('Height') + + if bid in names2: + if ht != '': + ht = float(ht) + cnt = 0 + + for asdf in range(0, 75, 5): + if ((ht - asdf) >= 5) or (0 < (ht - asdf) < 5): + + geomb = feature_buil.GetGeometryRef() + ring = geomb.GetGeometryRef(0) + numpoints = ring.GetPointCount() + + if numpoints != 0: + nx, ny, nz = ring.GetPoint(0) + + xOffset = int((nx - xOrigin) / pixelWidth) + yOffset = int((ny - yOrigin) / pixelHeight) + + parr = [[xOffset, yOffset]] + parrx = [[xOffset]] + parry = [[yOffset]] + + for i in range(1, numpoints): + bpt = ring.GetPoint(i) + + xoff = int((bpt[0] - xOrigin) / pixelWidth) + yoff = int((bpt[1] - yOrigin) / pixelHeight) + + parrx.append([xoff]) + parry.append([yoff]) + + parrx[:] = [x[0] - start_x_p for x in parrx] + parry[:] = [y[0] - start_y_p for y in parry] + + parrx = array(parrx) + parry = array(parry) + rr, cc = polygon(parrx, parry, [IMAGE_SIZE_Y, IMAGE_SIZE_X]) + + bldgsh[cnt, cc, rr] = bid + + cnt += 1 + + feature_buil.Destroy() + feature_buil = layer2.GetNextFeature() + +fadn = zeros((15, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) +fadw = zeros((15, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) +fads = zeros((15, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) +fade = zeros((15, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) + +pad = zeros((15, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) +rad = zeros((15, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) + +fai = zeros((4, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) +rrl = zeros((4, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) +rdh = zeros((4, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) +mrl = zeros((4, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) + +for i in range(len(fad_out2)): + for j in range(len(fad_out2[i]['n'])): + fadn[j][bldgs == double(names2[i])] = fad_out2[i]['n'][j] + fadw[j][bldgs == double(names2[i])] = fad_out2[i]['w'][j] + fads[j][bldgs == double(names2[i])] = fad_out2[i]['s'][j] + fade[j][bldgs == double(names2[i])] = fad_out2[i]['e'][j] + + pad[j][bldgs == double(names2[i])] = builfrac_out2[i][j] + rad[j][bldgs == double(names2[i])] = builfrac_out2[i][j] + + fai[0][bldgs == double(names2[i])] = fai_out2[i]['n'] + fai[1][bldgs == double(names2[i])] = fai_out2[i]['w'] + fai[2][bldgs == double(names2[i])] = fai_out2[i]['s'] + fai[3][bldgs == double(names2[i])] = fai_out2[i]['e'] + + rrl[0][bldgs == double(names2[i])] = rrl_out2[i]['n'] + rrl[1][bldgs == double(names2[i])] = rrl_out2[i]['w'] + rrl[2][bldgs == double(names2[i])] = rrl_out2[i]['s'] + rrl[3][bldgs == double(names2[i])] = rrl_out2[i]['e'] + + rdh[0][bldgs == double(names2[i])] = rdh_out2[i]['n'] + rdh[1][bldgs == double(names2[i])] = rdh_out2[i]['w'] + rdh[2][bldgs == double(names2[i])] = rdh_out2[i]['s'] + rdh[3][bldgs == double(names2[i])] = rdh_out2[i]['e'] + + mrl[0][bldgs == double(names2[i])] = mrl_out2[i]['n'] + mrl[1][bldgs == double(names2[i])] = mrl_out2[i]['w'] + mrl[2][bldgs == double(names2[i])] = mrl_out2[i]['s'] + mrl[3][bldgs == double(names2[i])] = mrl_out2[i]['e'] + +paf = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) +mea = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) +std = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) +awm = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) +b2p = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) +h2w = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) +grl = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) +gdh = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) +mdh = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) +car = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) + +for i in range(len(h2w_out2)): + h2w[bldgs == double(names2[i])] = h2w_out2[i] + paf[bldgs == double(names2[i])] = paf_out2[i] + mea[bldgs == double(names2[i])] = mean_ht_out2[i] + std[bldgs == double(names2[i])] = std_ht_out2[i] + awm[bldgs == double(names2[i])] = awmh_out2[i] + b2p[bldgs == double(names2[i])] = bs2par_out2[i] + grl[bldgs == double(names2[i])] = zo_out2[i] + gdh[bldgs == double(names2[i])] = zd_out2[i] + mdh[bldgs == double(names2[i])] = mdh_out2[i] + car[bldgs == double(names2[i])] = car_out2[i] + +dbh = zeros((15, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) + +for i in range(len(fad_out2)): + for j in range(len(bldgsh)): + dbh[j][bldgsh[j] == double(names2[i])] += float(1) / float(len(fad_out2)) + +master = zeros((132, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) + +master[0:15] = fadn[0:15] +master[15:30] = fadw[0:15] +master[30:45] = fads[0:15] +master[45:60] = fade[0:15] +master[60:75] = pad[0:15] +master[75:90] = rad[0:15] + +master[90] = paf +master[91] = mea +master[92] = std +master[93] = awm +master[94] = b2p + +master[95:99] = fai[0:4] + +master[99] = car + +master[100] = h2w + +master[101] = ones((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) * 0.99 + +master[102] = grl +master[103] = gdh + +master[104] = rrl[0] +master[105] = rdh[0] +master[106] = rrl[1] +master[107] = rdh[1] +master[108] = rrl[2] +master[109] = rdh[2] +master[110] = rrl[3] +master[111] = rdh[3] + +master[112:116] = mrl[0:4] +master[116] = mdh + +master[117:132] = dbh[0:15] + +for i in range(len(master)): + master[i][isnan(master[i])] = 0 + +# print master[0] + +for i in range(len(master)): + + s = 'tile_' + str(i+1) + '.tif' + + imgOut = driver_out.Create(s, IMAGE_SIZE_Y, IMAGE_SIZE_X, 1, gdal.GDT_Float64) + bandOut1 = imgOut.GetRasterBand(1) + bandOut1.WriteArray(master[i], 0, 0) + imgOut.SetGeoTransform((start_x, pixelWidth, 0, start_y, 0, pixelHeight)) + imgOut.SetProjection(proj.ExportToWkt()) + + svis = 'tile_' + str(i+1) + '_visual.tif' + + master[i] *= 10000 + + imgOut = driver_out.Create(svis, IMAGE_SIZE_Y, IMAGE_SIZE_X, 1, 1) + bandOut1 = imgOut.GetRasterBand(1) + bandOut1.WriteArray(master[i], 0, 0) + imgOut.SetGeoTransform((start_x, pixelWidth, 0, start_y, 0, pixelHeight)) + imgOut.SetProjection(proj.ExportToWkt()) + +master = array(master) +master = master.astype(float32) + +b = master[0][::5][::5] + +master0 = master[0][master[0] != 0] + +master_out = [] + +mast = zeros((132, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float32) + +for i in range(len(master)): + master_outi = bytes() + for j in range(len(master[i])): + for k in range(len(master[i][j])): + master_outi += struct.pack('>i', int(master[i][len(master[i]) - j - 1][k])) + + # print('Progress (inner loop): ', k, '/', len(master[i][j])) + # print('Progress (middle loop): ', j, '/', len(master[i])) + master_out.append(master_outi) + print('Progress (outer loop): ', i, '/', len(master)) + +master_out_final = bytes() + +for i in range(len(master_out)): + master_out_final += master_out[i] + +afile = save('temp', master_out_final) + +with open('temp.npy', 'rb') as tile, open(filename, 'wb') as tile2: + tile2.write(tile.read()[20*4:]) + +print("WRF Index:", min(gridleft,gridright), "-", max(gridleft,gridright), ".", min(gridbottom,gridtop), "-", max(gridbottom,gridtop)) +print("Tile Size:", tilex, "X", tiley) + +print("Script 4 took", str(time() - start_time), "seconds to run") diff --git a/NATURF/Master_Script.py b/NATURF/Master_Script.py new file mode 100644 index 00000000000..00b42697f88 --- /dev/null +++ b/NATURF/Master_Script.py @@ -0,0 +1,12 @@ +from time import time +start_time = time() +import winsound + + +from Buildings_Raster_Generator import * +from Building_IDs_Generator import * +from Parameter_Calculations import * +from Final_Outputs import * + +print("Master script took", str(time() - start_time), "seconds to run") +winsound.Beep(1000,1000) \ No newline at end of file diff --git a/NATURF/Parameter_Calculations.py b/NATURF/Parameter_Calculations.py new file mode 100644 index 00000000000..0e8a179b59b --- /dev/null +++ b/NATURF/Parameter_Calculations.py @@ -0,0 +1,229 @@ +# GRID and BINS (WRF Pre-Processing) + +from config import * +from Function_Definitions import * +from sys import exit +from time import time +import math +from numpy import array, arange, transpose, set_printoptions, zeros, uint8, uint16, indices, where, empty, float64, \ + column_stack, savetxt, save, sum, unique, mean, std, isnan, NaN +from skimage.draw import polygon +import osr +from PIL import Image +from scipy import ndimage +import csv +from tempfile import TemporaryFile +import cv2 +import itertools +import warnings +import pickle +import winsound + +try: + from osgeo import gdal, ogr + from osgeo.gdalconst import * +except ImportError: + import gdal + import ogr + from gdalconst import * + +start_time = time() + +filename = "%s.csv" % name + +wi = math.hypot((extent2[0] - extent2[1]), (extent2[2] - extent2[2])) + +he = math.hypot((extent2[0] - extent2[0]), (extent2[3] - extent2[2])) + +car = wi / he + +cents, hts, areas = get_cents_hts() + +cents_ns, cents_ew, avgsa, nbarea, mean_ht_out, std_ht_out, awmh_out = avg_building_dist(hts, areas, cents) + +fad_out, builfrac_out, fai_out, rdh_out, rrl_out, mdh_out, mrl_out, bs2par_out,\ + zo_out, zd_out, car_out = parameters1('south', 0, nbarea, cents_ns, cents_ew, avgsa) + +# print car_out + +# print fad_out, builfrac_out, fai_out + +h2wratios, names = h2w() + +paras_out = [['Name', 'Frontal Area Density', 'Plan Area Density', 'Roof Area Density', + 'Plan Area Fraction', 'Mean Building Height', 'Standard Deviation of Building Heights', + 'Area Weighted Mean of Building Heights', 'Building Surface to Plan Area Ratio', + 'Frontal Area Index', 'Grimmond and Oke (GO) Roughness Length', 'GO Displacement Height', + 'Raupach Roughness Length', 'Raupach Displacement Height', 'MacDonald et al. Roughness Length', + 'MacDonald et al. Displacement Height', 'Height to Width Ratio', 'Complete Aspect Ratio']] + +# #$%#$%#$%#$%#$%#$%#$%#$%#$%#$%#$%#$%#$%#$% + +names2, fad_out2, builfrac_out2, paf_out2, fai_out2, rdh_out2, rrl_out2, mdh_out2, mrl_out2, bs2par_out2, zo_out2,\ + zd_out2, mean_ht_out2, std_ht_out2, awmh_out2, h2w_out2, car_out2 = [], [], [], [], [], [], [], [], [], [], [],\ + [], [], [], [], [], [] + +# #$%#$%#$%#$%#$%#$%#$%#$%#$%#$%#$%#$%#$%#$% + +with warnings.catch_warnings(): + warnings.simplefilter("ignore", category=RuntimeWarning) + + for i in range(len(names)): + + n1 = names[i] + + # print n1 + + if len(fad_out[i]) != 0: + + for qw in range(len(builfrac_out[i])): + builfrac_out[i][qw] = mean(builfrac_out[i][qw]) + + bui1 = builfrac_out[i] # 15 + + bs21 = mean(bs2par_out[i]) # 1 + + for qw in range(15): + + fad_out[i]['n'][qw] = mean(fad_out[i]['n'][qw]) + fad_out[i]['w'][qw] = mean(fad_out[i]['w'][qw]) + fad_out[i]['s'][qw] = mean(fad_out[i]['s'][qw]) + fad_out[i]['e'][qw] = mean(fad_out[i]['e'][qw]) + + fad1 = fad_out[i] # 15 * 4 + + fai_out[i]['n'] = mean(fai_out[i]['n']) + fai_out[i]['w'] = mean(fai_out[i]['w']) + fai_out[i]['s'] = mean(fai_out[i]['s']) + fai_out[i]['e'] = mean(fai_out[i]['e']) + + rrl_out[i]['n'] = mean(rrl_out[i]['n']) + rrl_out[i]['w'] = mean(rrl_out[i]['w']) + rrl_out[i]['s'] = mean(rrl_out[i]['s']) + rrl_out[i]['e'] = mean(rrl_out[i]['e']) + + rdh_out[i]['n'] = mean(rdh_out[i]['n']) + rdh_out[i]['w'] = mean(rdh_out[i]['w']) + rdh_out[i]['s'] = mean(rdh_out[i]['s']) + rdh_out[i]['e'] = mean(rdh_out[i]['e']) + + mrl_out[i]['n'] = mean(mrl_out[i]['n']) + mrl_out[i]['w'] = mean(mrl_out[i]['w']) + mrl_out[i]['s'] = mean(mrl_out[i]['s']) + mrl_out[i]['e'] = mean(mrl_out[i]['e']) + + fai1 = fai_out[i] # 4 + rrl1 = rrl_out[i] # 4 + rdh1 = rdh_out[i] # 4 + mrl1 = mrl_out[i] # 4 + + paf = mean(builfrac_out[i]) + + mdh1 = mean(mdh_out[i]) # 1? + + mea1 = mean_ht_out[i] # 1 mbh + std1 = std_ht_out[i] # 1 stdev + awm1 = awmh_out[i] # 1 awm + zo1 = mean(zo_out[i]) # 1 grl + zd1 = mean(zd_out[i]) # 1 gdh + h2w1 = h2wratios[i] # 1 h2w + car1 = car_out[i] + + # print n1, fad1, bui1, paf, mea1, std1, awm1, bs21, fai1, zo1, zd1, rrl1, rdh1, mrl1, mdh1, h2w1, car1 + + names2.append(n1) + fad_out2.append(fad1) + builfrac_out2.append(bui1) + paf_out2.append(paf) + fai_out2.append(fai1) + rdh_out2.append(rdh1) + rrl_out2.append(rrl1) + mdh_out2.append(mdh1) + mrl_out2.append(mrl1) + bs2par_out2.append(bs21) + zo_out2.append(zo1) + zd_out2.append(zd1) + mean_ht_out2.append(mea1) + std_ht_out2.append(std1) + awmh_out2.append(awm1) + h2w_out2.append(h2w1) + car_out2.append(car1) + + paras_out.append([n1, fad1, bui1, bui1, paf, mea1, std1, awm1, bs21, fai1, zo1, zd1, rrl1, rdh1, + mrl1, mdh1, h2w1, car1]) + +c = open(filename, 'w') +wr = csv.writer(c) +wr.writerows(paras_out) +c.close() + +afile = open(r'names2.pkl', 'wb') +pickle.dump(names2, afile) +afile.close() + +afile = open(r'fad_out2.pkl', 'wb') +pickle.dump(fad_out2, afile) +afile.close() + +afile = open(r'builfrac_out2.pkl', 'wb') +pickle.dump(builfrac_out2, afile) +afile.close() + +afile = open(r'paf_out2.pkl', 'wb') +pickle.dump(paf_out2, afile) +afile.close() + +afile = open(r'fai_out2.pkl', 'wb') +pickle.dump(fai_out2, afile) +afile.close() + +afile = open(r'rdh_out2.pkl', 'wb') +pickle.dump(rdh_out2, afile) +afile.close() + +afile = open(r'rrl_out2.pkl', 'wb') +pickle.dump(rrl_out2, afile) +afile.close() + +afile = open(r'mdh_out2.pkl', 'wb') +pickle.dump(mdh_out2, afile) +afile.close() + +afile = open(r'mrl_out2.pkl', 'wb') +pickle.dump(mrl_out2, afile) +afile.close() + +afile = open(r'bs2par_out2.pkl', 'wb') +pickle.dump(bs2par_out2, afile) +afile.close() + +afile = open(r'zo_out2.pkl', 'wb') +pickle.dump(zo_out2, afile) +afile.close() + +afile = open(r'zd_out2.pkl', 'wb') +pickle.dump(zd_out2, afile) +afile.close() + +afile = open(r'mean_ht_out2.pkl', 'wb') +pickle.dump(mean_ht_out2, afile) +afile.close() + +afile = open(r'std_ht_out2.pkl', 'wb') +pickle.dump(std_ht_out2, afile) +afile.close() + +afile = open(r'awmh_out2.pkl', 'wb') +pickle.dump(awmh_out2, afile) +afile.close() + +afile = open(r'h2w_out2.pkl', 'wb') +pickle.dump(h2w_out2, afile) +afile.close() + +afile = open(r'car_out2.pkl', 'wb') +pickle.dump(car_out2, afile) +afile.close() + +print("Script 3 took", str(time() - start_time), "seconds to run") +winsound.Beep(1000,1000) diff --git a/NATURF/WRF_Calculations.py b/NATURF/WRF_Calculations.py new file mode 100644 index 00000000000..be60e338b5d --- /dev/null +++ b/NATURF/WRF_Calculations.py @@ -0,0 +1,79 @@ +from config import * +import math +import utm +import osr +try: + from osgeo import gdal, ogr + from osgeo.gdalconst import * +except ImportError: + import gdal + import ogr + from gdalconst import * + +#path = r'C:\ORNL Spring\Census Tracts\Tracts 51-60\005803-005877\005844\005844.shp' + +driver = ogr.GetDriverByName('ESRI Shapefile') + +datasource2 = driver.Open(path, 0) +if datasource2 is None: + print('Could not open ' + r'ChicagoLoop_Morph.shp') + exit(1) + +# register all of the GDAL drivers +gdal.AllRegister() + +layer2 = datasource2.GetLayer() +extent2 = layer2.GetExtent() + +# Define the extent in UTM coordinates, the desired spatial resolution in meters, and also the UTM zone of the study area +top = extent2[3] +bottom = extent2[2] +left = extent2[0] +right = extent2[1] +resolution = 100 +zone = 11 + +# Coverts the UTM coordinates to latitude and longitude +northwest = (top,left) +southeast = (bottom,right) +latlontl = utm.to_latlon(northwest[1],northwest[0],zone, northern=True) +latlonbr = utm.to_latlon(southeast[1],southeast[0],zone, northern=True) +#print(latlontl,latlonbr) + +# Assigns variables to the new coordinates +newtop = latlontl[0] +newbottom = latlonbr[0] +newleft = latlontl[1] +newright = latlonbr[1] + +# Calculates the values for the WRF index number +gridtop = math.ceil(newtop * 120) +gridbottom = int(newbottom * 120) +gridleft = int((newleft + 180) * 120) +gridright = math.ceil((newright + 180) * 120) + +# This prints out the WRF index number (with spaces added) +#print("WRF Index:", min(gridleft,gridright), "-", max(gridleft,gridright), ".", min(gridbottom,gridtop), "-", max(gridbottom,gridtop)) + +# Uses the grid numbers to calculate new latitude and longitude coordinates +newlonglatleft = (gridleft/120) - 180 +newlonglatright = (gridright/120) - 180 +newlonglattop = (gridtop/120) +newlonglatbottom = (gridbottom/120) + +# Converts the new latitude and longitude coordinates back to UTM coordinates +topleft = (newlonglattop,newlonglatleft) +bottomright = (newlonglatbottom,newlonglatright) +utmtl = utm.from_latlon(topleft[0],topleft[1],zone) +utmbr = utm.from_latlon(bottomright[0],bottomright[1],zone) +#print(utmtl) +#print(utmbr) + +# Finds the difference between the eastings and the northings +eastings = abs(utmtl[0]-utmbr[0]) +northings = abs(utmtl[1]-utmbr[1]) + +# Calculates the tile size for the script +tilex = round(eastings/resolution) +tiley = round(northings/resolution) +#print("Tile Size:", tilex, "X", tiley) From 477db7f6a868ed9a33d1e73bbe1a205535f4e2a6 Mon Sep 17 00:00:00 2001 From: lg6 Date: Tue, 11 May 2021 16:48:01 -0400 Subject: [PATCH 03/35] Added Las Vegas census tracts From 9ae3dff12186e6b8a7710e7d26be9b89d448ec33 Mon Sep 17 00:00:00 2001 From: lg6 Date: Tue, 22 Jun 2021 17:38:17 -0400 Subject: [PATCH 04/35] added LA census tracts and modified scripts --- NATURF/Building_IDs_Generator.py | 1 + NATURF/Buildings_Raster_Generator.py | 5 +- NATURF/Final_Outputs.py | 80 +++++++++++++++++++++++++++- NATURF/Master_Script.py | 28 ++++++---- 4 files changed, 101 insertions(+), 13 deletions(-) diff --git a/NATURF/Building_IDs_Generator.py b/NATURF/Building_IDs_Generator.py index 4e877f66c05..640195380f6 100644 --- a/NATURF/Building_IDs_Generator.py +++ b/NATURF/Building_IDs_Generator.py @@ -148,5 +148,6 @@ imgOut.SetGeoTransform((start_x, pixelWidth, 0, start_y, 0, pixelHeight)) imgOut.SetProjection(proj.ExportToWkt()) +del imgOut print("Script 2 took", str(time() - start_time), "seconds to run") diff --git a/NATURF/Buildings_Raster_Generator.py b/NATURF/Buildings_Raster_Generator.py index 78a80850725..58c243ce61e 100644 --- a/NATURF/Buildings_Raster_Generator.py +++ b/NATURF/Buildings_Raster_Generator.py @@ -20,8 +20,8 @@ start_time = time() -#path = r'C:\ORNL Spring\Census Tracts\Tracts 51-60\005803-005877\005844\005844.shp' - +#path = path.encode('unicode_escape') +#print(path) # get the shapefile driver driver = ogr.GetDriverByName('ESRI Shapefile') @@ -148,5 +148,6 @@ imgOut.SetGeoTransform((start_x, pixelWidth, 0, start_y, 0, pixelHeight)) imgOut.SetProjection(proj.ExportToWkt()) +del imgOut print("Script 1 took", str(time() - start_time), "seconds to run") diff --git a/NATURF/Final_Outputs.py b/NATURF/Final_Outputs.py index 8bb33fb844b..764cbad4f0e 100644 --- a/NATURF/Final_Outputs.py +++ b/NATURF/Final_Outputs.py @@ -14,6 +14,9 @@ import sklearn.preprocessing import struct import csv +import os +import glob +import shutil try: from osgeo import gdal, ogr @@ -422,7 +425,80 @@ with open('temp.npy', 'rb') as tile, open(filename, 'wb') as tile2: tile2.write(tile.read()[20*4:]) -print("WRF Index:", min(gridleft,gridright), "-", max(gridleft,gridright), ".", min(gridbottom,gridtop), "-", max(gridbottom,gridtop)) -print("Tile Size:", tilex, "X", tiley) +tilex = str(tilex) +tiley = str(tiley) + +txtname = "%s.txt" % name + +with open('index.txt','w') as index: + index.write('type=continuous\n') + index.write(' projection=regular_ll\n') + index.write(' missing_value=-999900.\n') + index.write(' dy=0.08333333333\n') + index.write(' dx=0.08333333333\n') + index.write(' known_x=1\n') + index.write(' known_y=1\n') + index.write(' known_lat=0.0\n') + index.write(' known_lon=-180.0\n') + index.write(' wordsize=4\n') + index.write(' endian=big\n') + index.write(' signed=no\n') + index.write(' tile_x=') + index.write(tilex + '\n') + index.write(' tile_y=') + index.write(tiley + '\n') + index.write(' tile_z=132\n') + index.write(' units="dimensionless"\n') + index.write(' scale_factor=0.0001\n') + index.write(' description="Urban_Parameters"\n') + +with open('index.txt', 'r') as index, open(txtname, 'w') as index2: + index2.write(index.read()) + +minlr = str(min(gridleft,gridright)) +maxlr = str(max(gridleft,gridright)) +mintb = str(min(gridbottom,gridtop)) +maxtb = str(max(gridbottom,gridtop)) + +indexname = minlr + "-" + maxlr +indexext = mintb + "-" + maxtb + +indexfile = "%s.%s" % (indexname,indexext) + +with open(filename, 'rb') as tile, open(indexfile, 'wb') as tile2: + tile2.write(tile.read()) + +#print("WRF Index:", min(gridleft,gridright), "-", max(gridleft,gridright), ".", min(gridbottom,gridtop), "-", max(gridbottom,gridtop)) +#print("Tile Size:", tilex, "X", tiley) + +os.mkdir(wrf) +os.mkdir(txt) +os.mkdir(tif) + +srcfiles = os.listdir(src) +for file_name in srcfiles: + full_file_name = os.path.join(src, file_name) + if os.path.isfile(full_file_name): + shutil.copy(full_file_name, dest) + +binary = os.path.join(dest, indexfile) +shutil.copy2(binary, wrf) +index = os.path.join(dest, 'index.txt') +shutil.copy2(index, wrf) + +txtfiles = glob.iglob(os.path.join(dest, "*.txt")) +for file in txtfiles: + if os.path.isfile(file): + shutil.move(file, txt) + +tiffiles = glob.iglob(os.path.join(dest, "*.tif")) +for file in tiffiles: + if os.path.isfile(file): + shutil.move(file, tif) + +npyfiles = glob.iglob(os.path.join(dest, "*.npy")) +for file in npyfiles: + if os.path.isfile(file): + shutil.move(file, npy) print("Script 4 took", str(time() - start_time), "seconds to run") diff --git a/NATURF/Master_Script.py b/NATURF/Master_Script.py index 00b42697f88..67db961a1a0 100644 --- a/NATURF/Master_Script.py +++ b/NATURF/Master_Script.py @@ -1,12 +1,22 @@ -from time import time -start_time = time() -import winsound +shppath = r'C:/ORNL Spring/Shapefiles' +shpfiles = glob.iglob(os.path.join(shppath, "*.shp")) +for file in shpfiles: + path = file + name = 'LV_' + str(os.path.splitext(os.path.basename(file))[0]) + src = os.getcwd() + dest = os.path.join(shppath, name) + wrf = os.path.join(dest, name) + tif = os.path.join(dest, 'Tifs') + txt = os.path.join(dest, 'Text') + npy = os.path.join(dest, 'Numpys') + config = open("config.py", "w") + config.write('path = ' + repr(path) + '\n' + 'name = ' + repr(name) + '\n' + 'src = ' + repr(src) + '\n' + 'dest = ' + repr(dest) + '\n' + 'dest = ' + repr(dest) + '\n' + 'wrf = ' + repr(wrf) + '\n' + 'tif = ' + repr(tif) + '\n' + 'txt = ' + repr(txt) + '\n' + 'npy = ' + repr(npy) + '\n') + config.close() -from Buildings_Raster_Generator import * -from Building_IDs_Generator import * -from Parameter_Calculations import * -from Final_Outputs import * + from Buildings_Raster_Generator import * + from Building_IDs_Generator import * + from Parameter_Calculations import * + from Final_Outputs import * -print("Master script took", str(time() - start_time), "seconds to run") -winsound.Beep(1000,1000) \ No newline at end of file + print("Master script took", str(time() - start_time), "seconds to run") \ No newline at end of file From c26fef4320fcfec978ee53afa7d2a687d147bd5a Mon Sep 17 00:00:00 2001 From: lg6 Date: Wed, 23 Jun 2021 12:53:38 -0400 Subject: [PATCH 05/35] Adding Los Angeles census tracts From 261c3ee96d11b32be7cf2c2033b3f13c248f0023 Mon Sep 17 00:00:00 2001 From: lg6 Date: Mon, 19 Jul 2021 11:51:48 -0400 Subject: [PATCH 06/35] updated scripts --- NATURF/.gitkeep | 0 NATURF/.vscode/settings.json | 3 + NATURF/1_no_raster_temp_chicago_UTM.py | 788 ------------ .../2_height_to_width_3_buildfrac_chicago.py | 1063 ----------------- NATURF/3_frontal_area_density_8_chicago2.py | 225 ---- ..._no_raster_temp_chicago_UTM_with_paras2.py | 871 -------------- NATURF/Extractor.py | 188 --- NATURF/Master_Script.py | 22 - NATURF/Master_Script.sh | 32 + NATURF/config.py | 2 - README.md | 0 11 files changed, 35 insertions(+), 3159 deletions(-) mode change 100644 => 100755 NATURF/.gitkeep create mode 100644 NATURF/.vscode/settings.json delete mode 100644 NATURF/1_no_raster_temp_chicago_UTM.py delete mode 100644 NATURF/2_height_to_width_3_buildfrac_chicago.py delete mode 100644 NATURF/3_frontal_area_density_8_chicago2.py delete mode 100644 NATURF/4_no_raster_temp_chicago_UTM_with_paras2.py delete mode 100644 NATURF/Extractor.py delete mode 100644 NATURF/Master_Script.py create mode 100755 NATURF/Master_Script.sh delete mode 100644 NATURF/config.py mode change 100644 => 100755 README.md diff --git a/NATURF/.gitkeep b/NATURF/.gitkeep old mode 100644 new mode 100755 diff --git a/NATURF/.vscode/settings.json b/NATURF/.vscode/settings.json new file mode 100644 index 00000000000..3b664107303 --- /dev/null +++ b/NATURF/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "git.ignoreLimitWarning": true +} \ No newline at end of file diff --git a/NATURF/1_no_raster_temp_chicago_UTM.py b/NATURF/1_no_raster_temp_chicago_UTM.py deleted file mode 100644 index e7577068dc0..00000000000 --- a/NATURF/1_no_raster_temp_chicago_UTM.py +++ /dev/null @@ -1,788 +0,0 @@ -from sys import exit -from time import time -from math import sqrt -from numpy import array, arange, transpose, set_printoptions, zeros, uint8, uint16, indices, where, empty, float64, \ - column_stack, savetxt -from skimage.draw import polygon -import osr -from PIL import Image -from scipy import ndimage - -try: - from osgeo import gdal, ogr - from osgeo.gdalconst import * -except ImportError: - import gdal - import ogr - from gdalconst import * - -set_printoptions(threshold='nan') -start_time = time() - - -def get_pixels(x1, y1, x2, y2): - - m = (float(y1) - float(y2)) / (float(x1) - float(x2) + 0.000000000000000000000000000000001) - yint = float(y1) - (m * float(x1)) - - slope_arr = [] - - if abs(x1-x2) > abs(y1-y2) or abs(x1-x2) == abs(y1-y2): - if x1 > x2: - for si in range(x2, x1+1): - sy = m*si+yint - sy = int(round(sy)) - small = [si, sy] - slope_arr.append(small) - if x1 < x2: - for si in range(x1, x2+1): - sy = m*si+yint - sy = int(round(sy)) - small = [si, sy] - slope_arr.append(small) - - if abs(x1-x2) < abs(y1-y2): - if y1 > y2: - for si in range(y2, y1+1): - sx = (si - yint) / m - sx = int(round(sx)) - small = [sx, si] - slope_arr.append(small) - if y1 < y2: - for si in range(y1, y2+1): - sx = (si - yint) / m - sx = int(round(sx)) - small = [sx, si] - slope_arr.append(small) - - return slope_arr - - -def get_pixels_new(x1, y1, x2, y2): - - m = (float(y1) - float(y2)) / (float(x1) - float(x2) + 0.00000000000000000000000000000001) - yint = float(y1) - (m * float(x1)) - - if abs(x1-x2) > abs(y1-y2) or abs(x1-x2) == abs(y1-y2): - if x1 > x2: - arrx = arange(x2, x1+1) - arry = m * arrx + yint - if x1 <= x2: - arrx = arange(x1, x2+1) - arry = m * arrx + yint - - if abs(x1-x2) < abs(y1-y2): - if y1 > y2: - arry = arange(y2, y1+1) - arrx = (arry - yint) / m - if y1 <= y2: - arry = arange(y1, y2+1) - arrx = (arry - yint) / m - - arr1 = array((arrx, arry)) - arr1 = transpose(arr1) - - return arr1 - - -def get_pixels2(arr1, arr2, arr3, x1, y1, x2, y2, w): - mx = (float(y1) - float(y2)) / (float(x1) - float(x2) + 0.0000000000000000000000000000001) - yint = float(y1) - (mx * float(x1)) - - if abs(x1 - x2) > abs(y1 - y2) or abs(x1 - x2) == abs(y1 - y2): - if x1 > x2: - for i in range(x2, x1 + 1): - yp = int(round(mx * i + yint)) - - bx = i - start_x_p - by = yp - start_y_p - - if 0 <= bx < IMAGE_SIZE and 0 <= by < IMAGE_SIZE: - if w == 'b': - arr1[by][bx] = 0 - arr2[by][bx] = 0 - arr3[by][bx] = 255 - if w == 'r': - arr1[by][bx] = 255 - arr2[by][bx] = 0 - arr3[by][bx] = 0 - - if x1 < x2: - for i in range(x1, x2 + 1): - yp = int(round(mx * i + yint)) - - bx = i - start_x_p - by = yp - start_y_p - - if 0 <= bx < IMAGE_SIZE and 0 <= by < IMAGE_SIZE: - if w == 'b': - arr1[by][bx] = 0 - arr2[by][bx] = 0 - arr3[by][bx] = 255 - if w == 'r': - arr1[by][bx] = 255 - arr2[by][bx] = 0 - arr3[by][bx] = 0 - - if abs(x1 - x2) < abs(y1 - y2): - if y1 > y2: - for i in range(y2, y1 + 1): - xp = int(round((i - yint) / mx)) - - bx = xp - start_x_p - by = i - start_y_p - - if 0 <= bx < IMAGE_SIZE and 0 <= by < IMAGE_SIZE: - if w == 'b': - arr1[by][bx] = 0 - arr2[by][bx] = 0 - arr3[by][bx] = 255 - if w == 'r': - arr1[by][bx] = 255 - arr2[by][bx] = 0 - arr3[by][bx] = 0 - - if y1 < y2: - for i in range(y1, y2 + 1): - xp = int(round((i - yint) / mx)) - - bx = xp - start_x_p - by = i - start_y_p - - if 0 <= bx < IMAGE_SIZE and 0 <= by < IMAGE_SIZE: - if w == 'b': - arr1[by][bx] = 0 - arr2[by][bx] = 0 - arr3[by][bx] = 255 - if w == 'r': - arr1[by][bx] = 255 - arr2[by][bx] = 0 - arr3[by][bx] = 0 - - -def get_pixels2_b(arr1, x1, y1, x2, y2, w): - mx = (float(y1) - float(y2)) / (float(x1) - float(x2) + 0.0000000000000000000000000000001) - yint = float(y1) - (mx * float(x1)) - - if abs(x1 - x2) > abs(y1 - y2) or abs(x1 - x2) == abs(y1 - y2): - if x1 > x2: - for i in range(x2, x1 + 1): - yp = int(round(mx * i + yint)) - - bx = i - start_x_p - by = yp - start_y_p - - if 0 <= bx < IMAGE_SIZE and 0 <= by < IMAGE_SIZE: - if w == 'b': - arr1[by][bx] = 1 - if w == 'r': - arr1[by][bx] = 2 - if x1 < x2: - for i in range(x1, x2 + 1): - yp = int(round(mx * i + yint)) - - bx = i - start_x_p - by = yp - start_y_p - - if 0 <= bx < IMAGE_SIZE and 0 <= by < IMAGE_SIZE: - if w == 'b': - arr1[by][bx] = 1 - if w == 'r': - arr1[by][bx] = 2 - - if abs(x1 - x2) < abs(y1 - y2): - if y1 > y2: - for i in range(y2, y1 + 1): - xp = int(round((i - yint) / mx)) - - bx = xp - start_x_p - by = i - start_y_p - - if 0 <= bx < IMAGE_SIZE and 0 <= by < IMAGE_SIZE: - if w == 'b': - arr1[by][bx] = 1 - if w == 'r': - arr1[by][bx] = 2 - if y1 < y2: - for i in range(y1, y2 + 1): - xp = int(round((i - yint) / mx)) - - bx = xp - start_x_p - by = i - start_y_p - - if 0 <= bx < IMAGE_SIZE and 0 <= by < IMAGE_SIZE: - if w == 'b': - arr1[by][bx] = 1 - if w == 'r': - arr1[by][bx] = 2 - - -def get_pixels2_c(x1, y1, x2, y2): - mx = (float(y1) - float(y2)) / (float(x1) - float(x2) + 0.0000000000000000000000000000001) - yint = float(y1) - (mx * float(x1)) - px_func = [] - py_func = [] - - if abs(x1 - x2) > abs(y1 - y2) or abs(x1 - x2) == abs(y1 - y2): - if x1 > x2: - for i in range(x2, x1 + 1): - yp = int(round(mx * i + yint)) - - bx = i - by = yp - - if 0 <= bx < IMAGE_SIZE_Y and 0 <= by < IMAGE_SIZE_X: - px_func.append(i) - py_func.append(yp) - if x1 < x2: - for i in range(x1, x2 + 1): - yp = int(round(mx * i + yint)) - - bx = i - by = yp - - if 0 <= bx < IMAGE_SIZE_Y and 0 <= by < IMAGE_SIZE_X: - px_func.append(i) - py_func.append(yp) - - if abs(x1 - x2) < abs(y1 - y2): - if y1 > y2: - for i in range(y2, y1 + 1): - xp = int(round((i - yint) / mx)) - - bx = xp - by = i - - if 0 <= bx < IMAGE_SIZE_Y and 0 <= by < IMAGE_SIZE_X: - px_func.append(xp) - py_func.append(i) - if y1 < y2: - for i in range(y1, y2 + 1): - xp = int(round((i - yint) / mx)) - - bx = xp - by = i - - if 0 <= bx < IMAGE_SIZE_Y and 0 <= by < IMAGE_SIZE_X: - px_func.append(xp) - py_func.append(i) - - return px_func, py_func - - -def bbox(x1, y1, x2, y2): - minx = min([x1, x2]) - miny = min([y1, y2]) - maxx = max([x1, x2]) - maxy = max([y1, y2]) - - minx2 = minx - start_x_p - miny2 = miny - start_y_p - maxx2 = maxx - start_x_p - maxy2 = maxy - start_y_p - - # dataa = data[miny-wb:maxy+wb+1, minx-wb:maxx+wb+1] - - # print minx2, miny2, maxx2, maxy2 - - return minx, miny, maxx, maxy, minx2, miny2, maxx2, maxy2 - - -def bbox2(x1, y1, x2, y2): - minx = min([x1, x2]) - # miny = min([y1, y2]) - maxx = max([x1, x2]) - # maxy = max([y1, y2]) - - if minx == x1: - miny = y1 - maxy = y2 - else: - miny = y2 - maxy = y1 - - minx2 = minx - start_x_p - miny2 = miny - start_y_p - maxx2 = maxx - start_x_p - maxy2 = maxy - start_y_p - - # print minx2, miny2, maxx2, maxy2 - - return minx, miny, maxx, maxy, minx2, miny2, maxx2, maxy2 - - -def line_eq(x1, y1, x2, y2): - x1 -= start_x_p - y1 -= start_y_p - x2 -= start_x_p - y2 -= start_y_p - - a1 = float(y1 - y2) - b1 = float(x2 - x1) - c1 = float(x1 * y2) - float(x2 * y1) - - tempa = a1 - tempb = b1 - - if a1 == 0: - tempa = 999999999999 - - if b1 == 0: - tempb = 999999999999 - - if tempa < tempb: - mini = tempa - elif tempb <= tempa: - mini = tempb - else: - mini = 1 - - a1 /= mini - b1 /= mini - c1 /= mini - - return a1, b1, c1 - - -def l2p3(a1, b1, c1, indi, xmin, xmax, ymin, ymax): - - # print indi[0, ymin-wb:ymax+wb+1, xmin-wb:xmax+wb+1].shape, xmin, xmax, ymin, ymax - - ind2a = indi[0, ymin:ymax, xmin:xmax] - ind2b = indi[1, ymin:ymax, xmin:xmax] - - ind2 = [ind2a, ind2b] - - da = a1*ind2[1] + b1*ind2[0] + c1 - db = float(sqrt(a1**2 + b1**2)) + 0.0000000000000000000000000000000000001 - - d = da / db - - return d - - -def midpoint(x1, y1, x2, y2): - # print 'x1 x2:', x1, x2, '\ny1 y2:', y1, y2 - mx = (x1 + x2) / 2 - my = (y1 + y2) / 2 - # print 'mx my:', mx, my - - return mx, my - - -def inter3(x1, y1, x2, y2, lrad1, rrad1): - - dx = x1-x2 - dy = y1-y2 - dist = sqrt(dx*dx + dy*dy) - dx /= (dist + 0.00000000000000000000001) - dy /= (dist + 0.00000000000000000000001); - - if y1 > y2: - x1r = x1 - rrad1*dy - y1r = y1 + rrad1*dx - x1l = x1 + lrad1*dy - y1l = y1 - lrad1*dx - - x2r = x2 - rrad1*dy - y2r = y2 + rrad1*dx - x2l = x2 + lrad1*dy - y2l = y2 - lrad1*dx - else: - x1r = x1 + rrad1*dy - y1r = y1 - rrad1*dx - x1l = x1 - lrad1*dy - y1l = y1 + lrad1*dx - - x2r = x2 + rrad1*dy - y2r = y2 - rrad1*dx - x2l = x2 - lrad1*dy - y2l = y2 + lrad1*dx - - return x1r, y1r, x1l, y1l, x2r, y2r, x2l, y2l - - -def trans(data, bbox_d, xmin, xmax, ymin, ymax, wb): - data[ymin-wb:ymax+wb+1, xmin-wb:xmax+wb+1] = bbox_d - - -def roads_func(ti): - tpt = geom.GetPoint(ti) - - xoff = int((tpt[0] - xOrigin) / pixelWidth) - yoff = int((tpt[1] - yOrigin) / pixelHeight) - - parr.append([xoff, yoff]) - - -def builds_func(bi): - bpt = ring.GetPoint(bi) - - xoff = int((bpt[0] - xOrigin) / pixelWidth) - yoff = int((bpt[1] - yOrigin) / pixelHeight) - - parr.append([xoff, yoff]) - parrx.append([xoff]) - parry.append([yoff]) - - -# get the shapefile driver -driver = ogr.GetDriverByName('ESRI Shapefile') - -# open the data source -datasource = driver.Open(r'chicago_roads_utm.shp', 0) -if datasource is None: - print 'Could not open ' + r'chicago_roads_utm.shp' - exit(1) - -datasource2 = driver.Open(r'ChicagoLoop_Morph3_utm.shp', 0) -if datasource2 is None: - print 'Could not open ' + r'ChicagoLoop_Morph.shp' - exit(1) - -# register all of the GDAL drivers -gdal.AllRegister() - -# img = gdal.Open(r'C:\Users\mbq\Documents\1 ORNL\Work\2621_warped_copy.tif', GA_ReadOnly) -# if img is None: -# print 'Could not open 2621.tif' -# exit(1) - -layer = datasource.GetLayer() - -extent = layer.GetExtent() - -dlon = abs(extent[0] - extent[1]) # wide -dlat = abs(extent[2] - extent[3]) # tall - -xOrigin = extent[0] -yOrigin = extent[3] - -x = extent[1] -y = extent[2] - -PIXEL_SIZE = 0.5 - -IMAGE_SIZE_X = 6300 -IMAGE_SIZE_Y = 3000 - -pixelWidth = PIXEL_SIZE -pixelHeight = -PIXEL_SIZE - -p2500x = PIXEL_SIZE * IMAGE_SIZE_X / 2 -p2500y = PIXEL_SIZE * IMAGE_SIZE_Y / 2 - -dlon_div_2 = dlon / 2 -dlat_div_2 = dlat / 2 - -start_x = 446861 -start_y = 4637537 - -end_x = start_x + p2500x + p2500x -end_y = start_y - p2500y - p2500y - -rows_new = int((end_x - start_x) / pixelWidth) -cols_new = int(round((end_y - start_y) / -pixelHeight)) - -start_x_p = int((start_x - xOrigin) / pixelWidth) -start_y_p = int((start_y - yOrigin) / pixelHeight) - -end_x_p = int((end_x - xOrigin) / pixelWidth) -end_y_p = int((end_y - yOrigin) / pixelHeight) - -# print start_x_p, end_x_p, start_y_p, end_y_p - -rows = int((x - xOrigin) / pixelWidth) -cols = int((y - yOrigin) / pixelHeight) - -layer2 = datasource2.GetLayer() - -driver_out = gdal.GetDriverByName('GTiff') -imgOut = driver_out.Create(r'no_raster_temp_chicago_UTM_new.tif', - IMAGE_SIZE_Y, IMAGE_SIZE_X, 1, 1) - -proj = osr.SpatialReference() -proj.SetWellKnownGeogCS("WGS84") -proj.SetUTM(16) - -bandOut1 = imgOut.GetRasterBand(1) - -data1 = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint8) -data1.fill(255) - -ids = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint16) -ids.fill(255) - -buils = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint16) -buils.fill(255) - -tempxyz = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) - -distarr = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -distarr.fill(0) - -ind = indices(data1.shape) - -ys = 0 -yl = 0 -xs = 0 -xl = 0 - -# radius = 15 - -# loop through the buildings -feature_buil = layer2.GetNextFeature() - -while feature_buil: - geomb = feature_buil.GetGeometryRef() - ring = geomb.GetGeometryRef(0) - numpoints = ring.GetPointCount() - - if numpoints != 0: - nx, ny, nz = ring.GetPoint(0) - - xOffset = int((nx - xOrigin) / pixelWidth) - yOffset = int((ny - yOrigin) / pixelHeight) - - parr = [[xOffset, yOffset]] - parrx = [[xOffset]] - parry = [[yOffset]] - - map(builds_func, xrange(1, ring.GetPointCount())) - - parrx[:] = [x[0] - start_x_p for x in parrx] - parry[:] = [y[0] - start_y_p for y in parry] - - parrx = array(parrx) - parry = array(parry) - rr, cc = polygon(parrx, parry, [IMAGE_SIZE_Y, IMAGE_SIZE_X]) - - buils[cc, rr] = 127 - - feature_buil.Destroy() - feature_buil = layer2.GetNextFeature() - -# loop through the roads -feature_road = layer.GetNextFeature() -while feature_road: - road_type = feature_road.GetFieldAsString('type') - rid = feature_road.GetFieldAsString('osm_id') - - if rid == '236806530': - - if road_type == 'motorway': - radius = 20 - elif road_type == 'trunk': - radius = 18 - elif road_type == 'primary': - radius = 16 - elif road_type == 'secondary': - radius = 14 - elif road_type == 'tertiary': - radius = 12 - elif road_type == 'unclassified': - radius = 10 - elif road_type == 'residential': - radius = 8 - elif road_type == 'service': - radius = 6 - else: - radius = 3 - - thres = 0 - - # print radius - - lradius = radius # - thres - rradius = radius # - thres - - geom = feature_road.GetGeometryRef() - nameg = geom.GetGeometryName() - - if nameg == 'MULTILINESTRING': - - for i in range(geom.GetGeometryCount()): - mgeom = geom.GetGeometryRef(i) - x = mgeom.GetX() - y = mgeom.GetY() - - xOffset = int((x - xOrigin) / pixelWidth) - yOffset = int((y - yOrigin) / pixelHeight) - - parr = [[xOffset, yOffset]] - - for j in range(1, mgeom.GetPointCount()): - tpt = mgeom.GetPoint(j) - - xoff = int((tpt[0] - xOrigin) / pixelWidth) - yoff = int((tpt[1] - yOrigin) / pixelHeight) - - parr.append([xoff, yoff]) - - elif nameg == 'LINESTRING': - - x = geom.GetX() - y = geom.GetY() - - xOffset = int((x - xOrigin) / pixelWidth) - yOffset = int((y - yOrigin) / pixelHeight) - - parr = [[xOffset, yOffset]] - - for j in range(1, geom.GetPointCount()): - tpt = geom.GetPoint(j) - - xoff = int((tpt[0] - xOrigin) / pixelWidth) - yoff = int((tpt[1] - yOrigin) / pixelHeight) - - parr.append([xoff, yoff]) - - for i in range(len(parr)-1): - if (start_x_p <= parr[i][0] < end_x_p) or (start_y_p <= parr[i][1] < end_y_p): # and \ - # (parr[i][0] != parr[i+1][0] and parr[i][1] != parr[i+1][1]): - - x1, y1, x2, y2 = parr[i][0] - start_x_p, parr[i][1] - start_y_p, parr[i+1][0] - start_x_p, parr[i+1][1] - start_y_p - - # print x1, y1, x2, y2 - - xmi, ymi, xma, yma, xmi2, ymi2, xma2, yma2 = bbox(parr[i][0], parr[i][1], parr[i+1][0], parr[i+1][1]) - - a, b, c = line_eq(parr[i][0], parr[i][1], parr[i+1][0], parr[i+1][1]) - - if xmi2 - radius < 0: - xmi2 = 0 - else: - xmi2 -= radius - if ymi2 - radius < 0: - ymi2 = 0 - else: - ymi2 -= radius - - if xmi2 >= IMAGE_SIZE_Y: - xmi2 = IMAGE_SIZE_Y - 1 - if ymi2 >= IMAGE_SIZE_X: - ymi2 = IMAGE_SIZE_X - 1 - - if xma2 + radius + 1 < 0: - xma2 = 0 - if yma2 + radius + 1 < 0: - yma2 = 0 - - if xma2 + radius + 1 >= IMAGE_SIZE_Y: - xma2 = IMAGE_SIZE_Y - 1 - else: - xma2 += radius + 1 - if yma2 + radius + 1 >= IMAGE_SIZE_X: - yma2 = IMAGE_SIZE_X - 1 - else: - yma2 += radius + 1 - - # print xmi2, ymi2, xma2, yma2, radius+1 - - if xmi2 <= xma2 and (((xma2 - xmi2) > (radius+1)) and ((yma2 - ymi2) > (radius+1))): - - if ymi2 > yma2: - tempdgj = yma2 - yma2 = ymi2 - ymi2 = tempdgj - - dist = l2p3(a, b, c, ind, xmi2, xma2, ymi2, yma2) - - # savetxt(r'no_raster_dist.txt', dist, '%lf') - - index = column_stack(where(buils[ymi2:yma2, xmi2:xma2] == 127)) - - # print index, '\n' - - # calculates how far the building is from the road - if len(index) != 0: - dist_r_to_b = dist[index[:, 0], index[:, 1]] - index2 = dist_r_to_b[abs(dist_r_to_b) <= radius] - - indexa = index2[index2 >= 0] # positive - indexb = index2[index2 < 0] # negative - - # print indexa, indexb, '\n' - - if len(indexa) != 0 and len(indexb) != 0: - lradius = abs(indexa.min()) - thres - rradius = abs(indexb.max()) - thres - elif len(indexa) != 0 and len(indexb) == 0: - lradius = abs(indexa.min()) - thres - rradius = radius - (abs(indexa.min()) - thres) + radius - elif len(indexa) == 0 and len(indexb) != 0: - rradius = abs(indexb.max()) - thres - lradius = radius - (abs(indexb.max()) - thres) + radius - else: - lradius = float(radius) - rradius = float(radius) - - index3a = dist_r_to_b[abs(dist_r_to_b) <= lradius] # pos - index3b = dist_r_to_b[abs(dist_r_to_b) <= rradius] # neg - - # print index3a, index3b - - ina = index3a[index3a >= 0] - inb = index3b[index3b < 0] - - # print ina, inb - - if len(ina) != 0: - lradius = abs(ina.min()) - thres - - if len(inb) != 0: - rradius = abs(inb.max()) - thres - - # print lradius, rradius, '\n' - - x1r, y1r, x1l, y1l, x2r, y2r, x2l, y2l = inter3(x1, y1, x2, y2, lradius, rradius) - - xf1, yf1 = midpoint(x1r, y1r, x1l, y1l) - xf2, yf2 = midpoint(x2r, y2r, x2l, y2l) - - rad = sqrt((x1r - xf1)**2 + (y1r - yf1)**2) - - # print rad - - # print xf1, yf1, xf2, yf2 - - if rad >= 1 and ((xf1 >= 0 and yf1 >= 0) and - (xf2 >= 0 and yf2 >= 0) and - (xf1 < IMAGE_SIZE_Y and yf1 < IMAGE_SIZE_X) and - (xf2 < IMAGE_SIZE_Y and yf2 < IMAGE_SIZE_X)): - # print 'here' - - xarr, yarr = get_pixels2_c(int(xf1), int(yf1), int(xf2), int(yf2)) - - tempxyz.fill(255) - tempxyz[yarr, xarr] = 0 - - distarr.resize((yma2-ymi2, xma2-xmi2)) - - distarr = ndimage.distance_transform_edt(tempxyz[ymi2:yma2, xmi2:xma2]) - - # print distarr - - distarr[data1[ymi2:yma2, xmi2:xma2] == 1] = 0 - - data1[ymi2:yma2, xmi2:xma2] = where(distarr > rad, tempxyz[ymi2:yma2, xmi2:xma2], 1) - - xs = xmi2 - ys = ymi2 - xl = xma2 - yl = yma2 - - feature_road.Destroy() - feature_road = layer.GetNextFeature() - -data1 = where(buils != 127, data1, 127) - -bandOut1.WriteArray(data1, 0, 0) - -imgOut.SetGeoTransform((start_x, pixelWidth, 0, start_y, 0, pixelHeight)) -imgOut.SetProjection(proj.ExportToWkt()) - -# close the data source -datasource.Destroy() - -print "Script took", str(time() - start_time), "seconds to run" diff --git a/NATURF/2_height_to_width_3_buildfrac_chicago.py b/NATURF/2_height_to_width_3_buildfrac_chicago.py deleted file mode 100644 index e2f3f7d506c..00000000000 --- a/NATURF/2_height_to_width_3_buildfrac_chicago.py +++ /dev/null @@ -1,1063 +0,0 @@ -from sys import exit -from time import time -from math import sqrt -from numpy import array, arange, transpose, set_printoptions, zeros, uint8, uint16, uint32, indices, where, empty, float64, \ - column_stack, savetxt, save -from skimage.draw import polygon -import osr -from PIL import Image -from scipy import ndimage -import csv -from tempfile import TemporaryFile - -try: - from osgeo import gdal, ogr - from osgeo.gdalconst import * -except ImportError: - import gdal - import ogr - from gdalconst import * - -set_printoptions(threshold='nan') -start_time = time() - - -def get_pixels(x1, y1, x2, y2): - - m = (float(y1) - float(y2)) / (float(x1) - float(x2) + 0.000000000000000000000000000000001) - yint = float(y1) - (m * float(x1)) - - slope_arr = [] - - if abs(x1-x2) > abs(y1-y2) or abs(x1-x2) == abs(y1-y2): - if x1 > x2: - for si in range(x2, x1+1): - sy = m*si+yint - sy = int(round(sy)) - small = [si, sy] - slope_arr.append(small) - if x1 < x2: - for si in range(x1, x2+1): - sy = m*si+yint - sy = int(round(sy)) - small = [si, sy] - slope_arr.append(small) - - if abs(x1-x2) < abs(y1-y2): - if y1 > y2: - for si in range(y2, y1+1): - sx = (si - yint) / m - sx = int(round(sx)) - small = [sx, si] - slope_arr.append(small) - if y1 < y2: - for si in range(y1, y2+1): - sx = (si - yint) / m - sx = int(round(sx)) - small = [sx, si] - slope_arr.append(small) - - return slope_arr - - -def get_pixels_new(x1, y1, x2, y2): - - m = (float(y1) - float(y2)) / (float(x1) - float(x2) + 0.00000000000000000000000000000001) - yint = float(y1) - (m * float(x1)) - - if abs(x1-x2) > abs(y1-y2) or abs(x1-x2) == abs(y1-y2): - if x1 > x2: - arrx = arange(x2, x1+1) - arry = m * arrx + yint - if x1 <= x2: - arrx = arange(x1, x2+1) - arry = m * arrx + yint - - if abs(x1-x2) < abs(y1-y2): - if y1 > y2: - arry = arange(y2, y1+1) - arrx = (arry - yint) / m - if y1 <= y2: - arry = arange(y1, y2+1) - arrx = (arry - yint) / m - - arr1 = array((arrx, arry)) - arr1 = transpose(arr1) - - return arr1 - - -def get_pixels2(arr1, arr2, arr3, x1, y1, x2, y2, w): - mx = (float(y1) - float(y2)) / (float(x1) - float(x2) + 0.0000000000000000000000000000001) - yint = float(y1) - (mx * float(x1)) - - if abs(x1 - x2) > abs(y1 - y2) or abs(x1 - x2) == abs(y1 - y2): - if x1 > x2: - for i in range(x2, x1 + 1): - yp = int(round(mx * i + yint)) - - bx = i - start_x_p - by = yp - start_y_p - - if 0 <= bx < IMAGE_SIZE and 0 <= by < IMAGE_SIZE: - if w == 'b': - arr1[by][bx] = 0 - arr2[by][bx] = 0 - arr3[by][bx] = 255 - if w == 'r': - arr1[by][bx] = 255 - arr2[by][bx] = 0 - arr3[by][bx] = 0 - - if x1 < x2: - for i in range(x1, x2 + 1): - yp = int(round(mx * i + yint)) - - bx = i - start_x_p - by = yp - start_y_p - - if 0 <= bx < IMAGE_SIZE and 0 <= by < IMAGE_SIZE: - if w == 'b': - arr1[by][bx] = 0 - arr2[by][bx] = 0 - arr3[by][bx] = 255 - if w == 'r': - arr1[by][bx] = 255 - arr2[by][bx] = 0 - arr3[by][bx] = 0 - - if abs(x1 - x2) < abs(y1 - y2): - if y1 > y2: - for i in range(y2, y1 + 1): - xp = int(round((i - yint) / mx)) - - bx = xp - start_x_p - by = i - start_y_p - - if 0 <= bx < IMAGE_SIZE and 0 <= by < IMAGE_SIZE: - if w == 'b': - arr1[by][bx] = 0 - arr2[by][bx] = 0 - arr3[by][bx] = 255 - if w == 'r': - arr1[by][bx] = 255 - arr2[by][bx] = 0 - arr3[by][bx] = 0 - - if y1 < y2: - for i in range(y1, y2 + 1): - xp = int(round((i - yint) / mx)) - - bx = xp - start_x_p - by = i - start_y_p - - if 0 <= bx < IMAGE_SIZE and 0 <= by < IMAGE_SIZE: - if w == 'b': - arr1[by][bx] = 0 - arr2[by][bx] = 0 - arr3[by][bx] = 255 - if w == 'r': - arr1[by][bx] = 255 - arr2[by][bx] = 0 - arr3[by][bx] = 0 - - -def get_pixels2_b(arr1, x1, y1, x2, y2, w): - mx = (float(y1) - float(y2)) / (float(x1) - float(x2) + 0.0000000000000000000000000000001) - yint = float(y1) - (mx * float(x1)) - - if abs(x1 - x2) > abs(y1 - y2) or abs(x1 - x2) == abs(y1 - y2): - if x1 > x2: - for i in range(x2, x1 + 1): - yp = int(round(mx * i + yint)) - - bx = i - start_x_p - by = yp - start_y_p - - if 0 <= bx < IMAGE_SIZE and 0 <= by < IMAGE_SIZE: - if w == 'b': - arr1[by][bx] = 1 - if w == 'r': - arr1[by][bx] = 2 - if x1 < x2: - for i in range(x1, x2 + 1): - yp = int(round(mx * i + yint)) - - bx = i - start_x_p - by = yp - start_y_p - - if 0 <= bx < IMAGE_SIZE and 0 <= by < IMAGE_SIZE: - if w == 'b': - arr1[by][bx] = 1 - if w == 'r': - arr1[by][bx] = 2 - - if abs(x1 - x2) < abs(y1 - y2): - if y1 > y2: - for i in range(y2, y1 + 1): - xp = int(round((i - yint) / mx)) - - bx = xp - start_x_p - by = i - start_y_p - - if 0 <= bx < IMAGE_SIZE and 0 <= by < IMAGE_SIZE: - if w == 'b': - arr1[by][bx] = 1 - if w == 'r': - arr1[by][bx] = 2 - if y1 < y2: - for i in range(y1, y2 + 1): - xp = int(round((i - yint) / mx)) - - bx = xp - start_x_p - by = i - start_y_p - - if 0 <= bx < IMAGE_SIZE and 0 <= by < IMAGE_SIZE: - if w == 'b': - arr1[by][bx] = 1 - if w == 'r': - arr1[by][bx] = 2 - - -def get_pixels2_c(x1, y1, x2, y2): - mx = (float(y1) - float(y2)) / (float(x1) - float(x2) + 0.0000000000000000000000000000001) - yint = float(y1) - (mx * float(x1)) - px_func = [] - py_func = [] - - if abs(x1 - x2) > abs(y1 - y2) or abs(x1 - x2) == abs(y1 - y2): - if x1 > x2: - for i in range(x2, x1 + 1): - yp = int(round(mx * i + yint)) - - bx = i - by = yp - - if 0 <= bx < IMAGE_SIZE and 0 <= by < IMAGE_SIZE: - px_func.append(i) - py_func.append(yp) - if x1 < x2: - for i in range(x1, x2 + 1): - yp = int(round(mx * i + yint)) - - bx = i - by = yp - - if 0 <= bx < IMAGE_SIZE and 0 <= by < IMAGE_SIZE: - px_func.append(i) - py_func.append(yp) - - if abs(x1 - x2) < abs(y1 - y2): - if y1 > y2: - for i in range(y2, y1 + 1): - xp = int(round((i - yint) / mx)) - - bx = xp - by = i - - if 0 <= bx < IMAGE_SIZE and 0 <= by < IMAGE_SIZE: - px_func.append(xp) - py_func.append(i) - if y1 < y2: - for i in range(y1, y2 + 1): - xp = int(round((i - yint) / mx)) - - bx = xp - by = i - - if 0 <= bx < IMAGE_SIZE and 0 <= by < IMAGE_SIZE: - px_func.append(xp) - py_func.append(i) - - return px_func, py_func - - -def bbox(x1, y1, x2, y2): - minx = min([x1, x2]) - miny = min([y1, y2]) - maxx = max([x1, x2]) - maxy = max([y1, y2]) - - minx2 = minx - start_x_p - miny2 = miny - start_y_p - maxx2 = maxx - start_x_p - maxy2 = maxy - start_y_p - - # dataa = data[miny-wb:maxy+wb+1, minx-wb:maxx+wb+1] - - # print minx2, miny2, maxx2, maxy2 - - return minx, miny, maxx, maxy, minx2, miny2, maxx2, maxy2 - - -def bbox2(x1, y1, x2, y2): - minx = min([x1, x2]) - # miny = min([y1, y2]) - maxx = max([x1, x2]) - # maxy = max([y1, y2]) - - if minx == x1: - miny = y1 - maxy = y2 - else: - miny = y2 - maxy = y1 - - minx2 = minx - start_x_p - miny2 = miny - start_y_p - maxx2 = maxx - start_x_p - maxy2 = maxy - start_y_p - - # print minx2, miny2, maxx2, maxy2 - - return minx, miny, maxx, maxy, minx2, miny2, maxx2, maxy2 - - -def line_eq(x1, y1, x2, y2): - x1 -= start_x_p - y1 -= start_y_p - x2 -= start_x_p - y2 -= start_y_p - - a1 = float(y1 - y2) - b1 = float(x2 - x1) - c1 = float(x1 * y2) - float(x2 * y1) - - tempa = a1 - tempb = b1 - - if a1 == 0: - tempa = 999999999999 - - if b1 == 0: - tempb = 999999999999 - - if tempa < tempb: - mini = tempa - elif tempb <= tempa: - mini = tempb - else: - mini = 1 - - a1 /= mini - b1 /= mini - c1 /= mini - - return a1, b1, c1 - - -def l2p3(a1, b1, c1, indi, xmin, xmax, ymin, ymax): - - # print indi[0, ymin-wb:ymax+wb+1, xmin-wb:xmax+wb+1].shape, xmin, xmax, ymin, ymax - - ind2a = indi[0, ymin:ymax, xmin:xmax] - ind2b = indi[1, ymin:ymax, xmin:xmax] - - ind2 = [ind2a, ind2b] - - da = a1*ind2[1] + b1*ind2[0] + c1 - db = float(sqrt(a1**2 + b1**2)) + 0.0000000000000000000000000000000000001 - - d = da / db - - return d - - -def midpoint(x1, y1, x2, y2): - # print 'x1 x2:', x1, x2, '\ny1 y2:', y1, y2 - mx = (x1 + x2) / 2 - my = (y1 + y2) / 2 - # print 'mx my:', mx, my - - return mx, my - - -def inter3(x1, y1, x2, y2, lrad1, rrad1): - - dx = x1-x2 - dy = y1-y2 - dist = sqrt(dx*dx + dy*dy) - dx /= (dist + 0.00000000000000000000001) - dy /= (dist + 0.00000000000000000000001) - - if y1 > y2: - x1r = x1 - rrad1*dy - y1r = y1 + rrad1*dx - x1l = x1 + lrad1*dy - y1l = y1 - lrad1*dx - - x2r = x2 - rrad1*dy - y2r = y2 + rrad1*dx - x2l = x2 + lrad1*dy - y2l = y2 - lrad1*dx - else: - x1r = x1 + rrad1*dy - y1r = y1 - rrad1*dx - x1l = x1 - lrad1*dy - y1l = y1 + lrad1*dx - - x2r = x2 + rrad1*dy - y2r = y2 - rrad1*dx - x2l = x2 - lrad1*dy - y2l = y2 + lrad1*dx - - return x1r, y1r, x1l, y1l, x2r, y2r, x2l, y2l - - -def inter4p(x1, y1, x2, y2, rad1): - - dx = x1-x2 - dy = y1-y2 - dist = sqrt(dx*dx + dy*dy) - dx /= (dist + 0.00000000000000000000001) - dy /= (dist + 0.00000000000000000000001) - - if y1 > y2: - x1r = x1 - rad1*dy - y1r = y1 + rad1*dx - else: - x1r = x1 + rad1*dy - y1r = y1 - rad1*dx - - return x1r, y1r - - -def inter4n(x1, y1, x2, y2, rad1): - - dx = x1-x2 - dy = y1-y2 - dist = sqrt(dx*dx + dy*dy) - dx /= (dist + 0.00000000000000000000001) - dy /= (dist + 0.00000000000000000000001) - - if y1 > y2: - x1l = x1 + rad1*dy - y1l = y1 - rad1*dx - else: - x1l = x1 - rad1*dy - y1l = y1 + rad1*dx - - return x1l, y1l - - -def trans(data, bbox_d, xmin, xmax, ymin, ymax, wb): - data[ymin-wb:ymax+wb+1, xmin-wb:xmax+wb+1] = bbox_d - - -def roads_func(ti): - tpt = geom.GetPoint(ti) - - xoff = int((tpt[0] - xOrigin) / pixelWidth) - yoff = int((tpt[1] - yOrigin) / pixelHeight) - - parr.append([xoff, yoff]) - - -# get the shapefile driver -driver = ogr.GetDriverByName('ESRI Shapefile') - -# open the data source -datasource = driver.Open(r'chicago_roads_utm.shp', 0) -if datasource is None: - print 'Could not open roads.shp' - exit(1) - -datasource2 = driver.Open(r'ChicagoLoop_Morph3_utm.shp', 0) -if datasource2 is None: - print 'Could not open buildings.shp' - exit(1) - -# register all of the GDAL drivers -gdal.AllRegister() - -# img = gdal.Open(r'C:\Users\mbq\Documents\1 ORNL\Work\2621_warped_copy.tif', GA_ReadOnly) -# if img is None: -# print 'Could not open 2621.tif' -# exit(1) - -layer = datasource.GetLayer() - -extent = layer.GetExtent() - -dlon = abs(extent[0] - extent[1]) # wide -dlat = abs(extent[2] - extent[3]) # tall - -xOrigin = extent[0] -yOrigin = extent[3] - -x = extent[1] -y = extent[2] - -PIXEL_SIZE = 0.5 - -IMAGE_SIZE_X = 6300 -IMAGE_SIZE_Y = 3000 - -pixelWidth = PIXEL_SIZE -pixelHeight = -PIXEL_SIZE - -p2500x = PIXEL_SIZE * IMAGE_SIZE_X / 2 -p2500y = PIXEL_SIZE * IMAGE_SIZE_Y / 2 - -dlon_div_2 = dlon / 2 -dlat_div_2 = dlat / 2 - -start_x = 446861 -start_y = 4637537 - -end_x = start_x + p2500x + p2500x -end_y = start_y - p2500y - p2500y - -rows_new = int((end_x - start_x) / pixelWidth) -cols_new = int(round((end_y - start_y) / -pixelHeight)) - -start_x_p = int((start_x - xOrigin) / pixelWidth) -start_y_p = int((start_y - yOrigin) / pixelHeight) - -end_x_p = int((end_x - xOrigin) / pixelWidth) -end_y_p = int((end_y - yOrigin) / pixelHeight) - -# print start_x_p, end_x_p, start_y_p, end_y_p - -rows = int((x - xOrigin) / pixelWidth) -cols = int((y - yOrigin) / pixelHeight) - -layer2 = datasource2.GetLayer() - -driver_out = gdal.GetDriverByName('GTiff') -imgOut = driver_out.Create(r'height_to_width_3_buildfrac_chicago_UTM.tif', - IMAGE_SIZE_Y, IMAGE_SIZE_X, 1, gdal.GDT_Int32) - -proj = osr.SpatialReference() -proj.SetWellKnownGeogCS("WGS84") -proj.SetUTM(16) - -bandOut1 = imgOut.GetRasterBand(1) - -data1 = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint8) -data1.fill(255) - -ids = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint32) -ids.fill(0) - -buils = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint16) -buils.fill(255) - -tempxyz = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) - -distarr = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -distarr.fill(0) - -ind = indices(data1.shape) - -names = [] -heights = [] -widths = [] -ratios = [] - -cnt = 1 - -# radius = 15 - -# loop through the buildings -feature_buil = layer2.GetNextFeature() - -while feature_buil: - bid = feature_buil.GetFieldAsString('BLDGID') - - geomb = feature_buil.GetGeometryRef() - ring = geomb.GetGeometryRef(0) - numpoints = ring.GetPointCount() - - if numpoints != 0: - nx, ny, nz = ring.GetPoint(0) - - xOffset = int((nx - xOrigin) / pixelWidth) - yOffset = int((ny - yOrigin) / pixelHeight) - - parr = [[xOffset, yOffset]] - parrx = [[xOffset]] - parry = [[yOffset]] - - for bi in xrange(1, ring.GetPointCount()): - bpt = ring.GetPoint(bi) - - xoff = int((bpt[0] - xOrigin) / pixelWidth) - yoff = int((bpt[1] - yOrigin) / pixelHeight) - - parr.append([xoff, yoff]) - parrx.append([xoff]) - parry.append([yoff]) - - parrx[:] = [x[0] - start_x_p for x in parrx] - parry[:] = [y[0] - start_y_p for y in parry] - - parrx = array(parrx) - parry = array(parry) - rr, cc = polygon(parrx, parry, [IMAGE_SIZE_Y, IMAGE_SIZE_X]) - - buils[cc, rr] = 127 - - bid = float(bid) - bid = int(bid) - - ids[cc, rr] = where(ids[cc, rr] != 0, ids[cc, rr], cnt) - - # print cnt - - cnt += 1 - feature_buil.Destroy() - feature_buil = layer2.GetNextFeature() - -'''layer2.ResetReading() -feature_buil = layer2.GetNextFeature() - -while feature_buil: - name = feature_buil.GetFieldAsString('BLDG') - ht = feature_buil.GetFieldAsString('avg_ht_m') - - if ht != '': - # print name, '=', float(ht) - - # if name == '4500N': # or name == '4500S': - cntr2 = 0 - summ2 = 0 - aveg2 = 0 - aveg1 = 0 - - geomb = feature_buil.GetGeometryRef() - ring = geomb.GetGeometryRef(0) - numpoints = ring.GetPointCount() - - if numpoints != 0: - cntr1 = 0 - summ1 = 0 - - nx, ny, nz = ring.GetPoint(0) - - # print nx, ny - - xOffset = int((nx - xOrigin) / pixelWidth) - yOffset = int((ny - yOrigin) / pixelHeight) - - parr = [[xOffset, yOffset]] - parrx = [[xOffset]] - parry = [[yOffset]] - - parrxc = [[nx]] - parryc = [[ny]] - - for bi in xrange(1, ring.GetPointCount()): - bpt = ring.GetPoint(bi) - - # print bpt[0], bpt[1] - - xoff = int((bpt[0] - xOrigin) / pixelWidth) - yoff = int((bpt[1] - yOrigin) / pixelHeight) - - parr.append([xoff, yoff]) - parrx.append([xoff]) - parry.append([yoff]) - - parrxc.append([bpt[0]]) - parryc.append([bpt[1]]) - - parrx[:] = [x[0] - start_x_p for x in parrx] - parry[:] = [y[0] - start_y_p for y in parry] - - parrx = array(parrx) - parry = array(parry) - - parrxc = array(parrxc) - parryc = array(parryc) - - for na in xrange(0, len(parrx)-1): - p1x = parrx[na] - p1y = parry[na] - - p2x = parrx[na+1] - p2y = parry[na+1] - - dist = sqrt((p2x - p1x)**2 + (p2y - p1y)**2) - - # print dist, distc - - f = int(dist) / 20 - - xarr, yarr = get_pixels2_c(int(p1x), int(p1y), int(p2x), int(p2y)) - - # print xarr, yarr - - if ((len(xarr)/20)-1) > 0: - - for nb in xrange(0, (len(xarr)/20)-1): - # print xarr[(nb*20)+1], yarr[(nb*20)+1] - - tempa = 0 - x1 = xarr[(nb*20)+1] - y1 = yarr[(nb*20)+1] - - x2 = xarr[((nb+1)*20)+1] - y2 = yarr[((nb+1)*20)+1] - - for tg in xrange(1, 200): - perp1x, perp1y = inter4p(x1, y1, x2, y2, tg) - - if perp1x < 0: - perp1x = 0 - if perp1y < 0: - perp1y = 0 - - if perp1x >= IMAGE_SIZE: - perp1x = IMAGE_SIZE - 1 - if perp1y >= IMAGE_SIZE: - perp1y = IMAGE_SIZE - 1 - - if buils[perp1y, perp1x] == 127: - tempa = tg - if tempa > 4: - # print 'p' - break - else: - tempa = tg - - if tempa == 5: - for tg in xrange(1, 200): - perp1x, perp1y = inter4n(p1x, p1y, p2x, p2y, tg) - - if perp1x < 0: - perp1x = 0 - if perp1y < 0: - perp1y = 0 - - if perp1x >= IMAGE_SIZE: - perp1x = IMAGE_SIZE - 1 - if perp1y >= IMAGE_SIZE: - perp1y = IMAGE_SIZE - 1 - - if buils[perp1y, perp1x] == 127: - tempa = tg - if tempa > 4: - # print 'n' - break - else: - tempa = tg - - # print tempa - - if tempa != 5 and tempa != 199: - cntr1 += 1 - summ1 += tempa - # print tempa - - if cntr1 != 0: - aveg1 = summ1 / cntr1 - # print aveg1 - else: - aveg1 = 0 - elif len(xarr) != 0: - tempa = 0 - x1 = xarr[1] - y1 = yarr[1] - - x2 = xarr[1] - y2 = yarr[1] - - for tg in xrange(1, 200): - perp1x, perp1y = inter4p(x1, y1, x2, y2, tg) - - if perp1x < 0: - perp1x = 0 - if perp1y < 0: - perp1y = 0 - - if perp1x >= IMAGE_SIZE: - perp1x = IMAGE_SIZE - 1 - if perp1y >= IMAGE_SIZE: - perp1y = IMAGE_SIZE - 1 - - if buils[perp1y, perp1x] == 127: - tempa = tg - if tempa > 4: - # print 'p' - break - else: - tempa = tg - - if tempa == 5: - for tg in xrange(1, 200): - perp1x, perp1y = inter4n(p1x, p1y, p2x, p2y, tg) - - if perp1x < 0: - perp1x = 0 - if perp1y < 0: - perp1y = 0 - - if perp1x >= IMAGE_SIZE: - perp1x = IMAGE_SIZE - 1 - if perp1y >= IMAGE_SIZE: - perp1y = IMAGE_SIZE - 1 - - if buils[perp1y, perp1x] == 127: - tempa = tg - if tempa > 4: - # print 'n' - break - else: - tempa = tg - - # print tempa - - if tempa != 5 and tempa != 199: - cntr1 += 1 - summ1 += tempa - # print tempa - - if cntr1 != 0: - aveg1 = summ1 / cntr1 - # print aveg1 - else: - aveg1 = 0 - - cntr2 += 1 - summ2 += aveg1 - - if cntr2 != 0 and summ2 != 0: - aveg2 = summ2 / cntr2 - # print name, '=', aveg2*PIXEL_SIZE*100000 # , '\n' - - if aveg2*PIXEL_SIZE*100000 != 0: - names.append(name) - heights.append(float(ht)) - widths.append(aveg2*PIXEL_SIZE*100000) - - feature_buil.Destroy() - feature_buil = layer2.GetNextFeature()''' - -# ratios.append(['Name', 'Height (meters)', 'Width (meters)', 'Ratio (H/W)']) -# -# for i in xrange(0, len(names)): -# n1 = names[i] -# h1 = heights[i] -# w1 = widths[i] -# -# ratio = h1 / w1 -# -# ratios.append([n1, h1, w1, ratio]) -# -# c = open('ratios1.csv', 'wb') -# wr = csv.writer(c) -# wr.writerows(ratios) -# -# c.close() - -# c = open('ids.csv', 'wb') -# wr = csv.writer(c) -# wr.writerows(ids) -# -# c.close() - -# loop through the roads -'''feature_road = layer.GetNextFeature() -while feature_road: - lanes = feature_road.GetFieldAsString('LANES') - name = feature_road.GetFieldAsString('NAME') - shoulder = feature_road.GetFieldAsString('SHOULDER') - oid = feature_road.GetFieldAsString('OBJECTID') - - # if "PARKING" not in name: - - # if name == 'ORNL VISITORS CENTER DR': - - # if oid == '551': - - if shoulder == 'N': - sho = 0 - else: - sho = 1 - - radius = 5 * int(lanes) # + 5/2 * sho - thres = 0 - - # print radius - - lradius = radius # - thres - rradius = radius # - thres - - geom = feature_road.GetGeometryRef() - nameg = geom.GetGeometryName() - - if nameg == 'MULTILINESTRING': - - for i in range(geom.GetGeometryCount()): - mgeom = geom.GetGeometryRef(i) - x = mgeom.GetX() - y = mgeom.GetY() - - xOffset = int((x - xOrigin) / pixelWidth) - yOffset = int((y - yOrigin) / pixelHeight) - - parr = [[xOffset, yOffset]] - - for j in range(1, mgeom.GetPointCount()): - tpt = mgeom.GetPoint(j) - - xoff = int((tpt[0] - xOrigin) / pixelWidth) - yoff = int((tpt[1] - yOrigin) / pixelHeight) - - parr.append([xoff, yoff]) - - elif nameg == 'LINESTRING': - - x = geom.GetX() - y = geom.GetY() - - xOffset = int((x - xOrigin) / pixelWidth) - yOffset = int((y - yOrigin) / pixelHeight) - - parr = [[xOffset, yOffset]] - - for j in range(1, geom.GetPointCount()): - tpt = geom.GetPoint(j) - - xoff = int((tpt[0] - xOrigin) / pixelWidth) - yoff = int((tpt[1] - yOrigin) / pixelHeight) - - parr.append([xoff, yoff]) - - for i in range(len(parr)-1): - if (start_x_p <= parr[i][0] < end_x_p) or (start_y_p <= parr[i][1] < end_y_p): # and \ - # (parr[i][0] != parr[i+1][0] and parr[i][1] != parr[i+1][1]): - - x1, y1, x2, y2 = parr[i][0] - start_x_p, parr[i][1] - start_y_p, parr[i+1][0] - start_x_p, parr[i+1][1] - start_y_p - - # print x1, y1, x2, y2 - - xmi, ymi, xma, yma, xmi2, ymi2, xma2, yma2 = bbox(parr[i][0], parr[i][1], parr[i+1][0], parr[i+1][1]) - - a, b, c = line_eq(parr[i][0], parr[i][1], parr[i+1][0], parr[i+1][1]) - - if xmi2 - radius < 0: - xmi2 = 0 - else: - xmi2 -= radius - if ymi2 - radius < 0: - ymi2 = 0 - else: - ymi2 -= radius - - if xmi2 >= IMAGE_SIZE: - xmi2 = IMAGE_SIZE - 1 - if ymi2 >= IMAGE_SIZE: - ymi2 = IMAGE_SIZE - 1 - - if xma2 + radius + 1 < 0: - xma2 = 0 - if yma2 + radius + 1 < 0: - yma2 = 0 - - if xma2 + radius + 1 >= IMAGE_SIZE: - xma2 = IMAGE_SIZE - 1 - else: - xma2 += radius + 1 - if yma2 + radius + 1 >= IMAGE_SIZE: - yma2 = IMAGE_SIZE - 1 - else: - yma2 += radius + 1 - - # print xmi2, ymi2, xma2, yma2, radius+1 - - if xmi2 <= xma2 and (((xma2 - xmi2) > (radius+1)) and ((yma2 - ymi2) > (radius+1))): - - if ymi2 > yma2: - tempdgj = yma2 - yma2 = ymi2 - ymi2 = tempdgj - - dist = l2p3(a, b, c, ind, xmi2, xma2, ymi2, yma2) - - index = column_stack(where(buils[ymi2:yma2, xmi2:xma2] == 127)) - - # print index, '\n' - - # calculates how far the building is from the road - if len(index) != 0: - dist_r_to_b = dist[index[:, 0], index[:, 1]] - index2 = dist_r_to_b[abs(dist_r_to_b) <= radius] - - indexa = index2[index2 >= 0] - indexb = index2[index2 < 0] - - if len(indexa) != 0 and len(indexb) != 0: - lradius = abs(indexa.min()) - thres - rradius = abs(indexb.max()) - thres - elif len(indexa) != 0 and len(indexb) == 0: - lradius = abs(indexa.min()) - thres - rradius = radius - (abs(indexa.min()) - thres) + radius - elif len(indexa) == 0 and len(indexb) != 0: - rradius = abs(indexb.max()) - thres - lradius = radius - (abs(indexb.max()) - thres) + radius - else: - lradius = float(radius) - rradius = float(radius) - - index3a = dist_r_to_b[abs(dist_r_to_b) <= lradius] # pos - index3b = dist_r_to_b[abs(dist_r_to_b) <= rradius] # neg - - ina = index3a[index3a >= 0] - inb = index3b[index3b < 0] - - if len(ina) != 0: - lradius = abs(ina.min()) - thres - - if len(inb) != 0: - rradius = abs(inb.max()) - thres - - # print lradius, rradius - - x1r, y1r, x1l, y1l, x2r, y2r, x2l, y2l = inter3(x1, y1, x2, y2, lradius, rradius) - - xf1, yf1 = midpoint(x1r, y1r, x1l, y1l) - xf2, yf2 = midpoint(x2r, y2r, x2l, y2l) - - rad = sqrt((x1r - xf1)**2 + (y1r - yf1)**2) - - # print rad - - # print xf1, yf1, xf2, yf2 - - if rad >= 1 and ((xf1 >= 0 and yf1 >= 0) and - (xf2 >= 0 and yf2 >= 0) and - (xf1 < IMAGE_SIZE and yf1 < IMAGE_SIZE) and - (xf2 < IMAGE_SIZE and yf2 < IMAGE_SIZE)): - # print 'here' - - xarr, yarr = get_pixels2_c(int(xf1), int(yf1), int(xf2), int(yf2)) - - tempxyz.fill(255) - tempxyz[yarr, xarr] = 0 - - distarr.resize((yma2-ymi2, xma2-xmi2)) - - distarr = ndimage.distance_transform_edt(tempxyz[ymi2:yma2, xmi2:xma2]) - - # print distarr - - distarr[data1[ymi2:yma2, xmi2:xma2] == 1] = 0 - - data1[ymi2:yma2, xmi2:xma2] = where(distarr > rad, tempxyz[ymi2:yma2, xmi2:xma2], 1) - - feature_road.Destroy() - feature_road = layer.GetNextFeature()''' - -data1 = where(buils != 127, data1, 127) - -bandOut1.WriteArray(ids, 0, 0) - -imgOut.SetGeoTransform((start_x, pixelWidth, 0, start_y, 0, pixelHeight)) -imgOut.SetProjection(proj.ExportToWkt()) - -# close the data source -datasource.Destroy() - -print "Script took", str(time() - start_time), "seconds to run" diff --git a/NATURF/3_frontal_area_density_8_chicago2.py b/NATURF/3_frontal_area_density_8_chicago2.py deleted file mode 100644 index 8433bdc5903..00000000000 --- a/NATURF/3_frontal_area_density_8_chicago2.py +++ /dev/null @@ -1,225 +0,0 @@ -# GRID and BINS (WRF Pre-Processing) - -from frontal_area_density_8_chicago_functions2 import * -from sys import exit -from time import time -import math -from numpy import array, arange, transpose, set_printoptions, zeros, uint8, uint16, indices, where, empty, float64, \ - column_stack, savetxt, save, sum, unique, mean, std, isnan, NaN -from skimage.draw import polygon -import osr -from PIL import Image -from scipy import ndimage -import csv -from tempfile import TemporaryFile -import cv2 -import itertools -import warnings -import pickle - -try: - from osgeo import gdal, ogr - from osgeo.gdalconst import * -except ImportError: - import gdal - import ogr - from gdalconst import * - -set_printoptions(threshold='nan') -start_time = time() - -wi = math.hypot((extent2[0] - extent2[1]), (extent2[2] - extent2[2])) - -he = math.hypot((extent2[0] - extent2[0]), (extent2[3] - extent2[2])) - -car = wi / he - -cents, hts, areas = get_cents_hts() - -cents_ns, cents_ew, avgsa, nbarea, mean_ht_out, std_ht_out, awmh_out = avg_building_dist(hts, areas, cents) - -fad_out, builfrac_out, fai_out, rdh_out, rrl_out, mdh_out, mrl_out, bs2par_out,\ - zo_out, zd_out, car_out = parameters1('south', 0, nbarea, cents_ns, cents_ew, avgsa) - -# print car_out - -# print fad_out, builfrac_out, fai_out - -h2wratios, names = h2w() - -paras_out = [['Name', 'Frontal Area Density', 'Plan Area Density', 'Roof Area Density', - 'Plan Area Fraction', 'Mean Building Height', 'Standard Deviation of Building Heights', - 'Area Weighted Mean of Building Heights', 'Building Surface to Plan Area Ratio', - 'Frontal Area Index', 'Grimmond and Oke (GO) Roughness Length', 'GO Displacement Height', - 'Raupach Roughness Length', 'Raupach Displacement Height', 'MacDonald et al. Roughness Length', - 'MacDonald et al. Displacement Height', 'Height to Width Ratio', 'Complete Aspect Ratio']] - -# #$%#$%#$%#$%#$%#$%#$%#$%#$%#$%#$%#$%#$%#$% - -names2, fad_out2, builfrac_out2, paf_out2, fai_out2, rdh_out2, rrl_out2, mdh_out2, mrl_out2, bs2par_out2, zo_out2,\ - zd_out2, mean_ht_out2, std_ht_out2, awmh_out2, h2w_out2, car_out2 = [], [], [], [], [], [], [], [], [], [], [],\ - [], [], [], [], [], [] - -# #$%#$%#$%#$%#$%#$%#$%#$%#$%#$%#$%#$%#$%#$% - -with warnings.catch_warnings(): - warnings.simplefilter("ignore", category=RuntimeWarning) - - for i in xrange(len(names)): - - n1 = names[i] - - # print n1 - - if len(fad_out[i]) != 0: - - for qw in xrange(len(builfrac_out[i])): - builfrac_out[i][qw] = mean(builfrac_out[i][qw]) - - bui1 = builfrac_out[i] # 15 - - bs21 = mean(bs2par_out[i]) # 1 - - for qw in xrange(15): - - fad_out[i]['n'][qw] = mean(fad_out[i]['n'][qw]) - fad_out[i]['w'][qw] = mean(fad_out[i]['w'][qw]) - fad_out[i]['s'][qw] = mean(fad_out[i]['s'][qw]) - fad_out[i]['e'][qw] = mean(fad_out[i]['e'][qw]) - - fad1 = fad_out[i] # 15 * 4 - - fai_out[i]['n'] = mean(fai_out[i]['n']) - fai_out[i]['w'] = mean(fai_out[i]['w']) - fai_out[i]['s'] = mean(fai_out[i]['s']) - fai_out[i]['e'] = mean(fai_out[i]['e']) - - rrl_out[i]['n'] = mean(rrl_out[i]['n']) - rrl_out[i]['w'] = mean(rrl_out[i]['w']) - rrl_out[i]['s'] = mean(rrl_out[i]['s']) - rrl_out[i]['e'] = mean(rrl_out[i]['e']) - - rdh_out[i]['n'] = mean(rdh_out[i]['n']) - rdh_out[i]['w'] = mean(rdh_out[i]['w']) - rdh_out[i]['s'] = mean(rdh_out[i]['s']) - rdh_out[i]['e'] = mean(rdh_out[i]['e']) - - mrl_out[i]['n'] = mean(mrl_out[i]['n']) - mrl_out[i]['w'] = mean(mrl_out[i]['w']) - mrl_out[i]['s'] = mean(mrl_out[i]['s']) - mrl_out[i]['e'] = mean(mrl_out[i]['e']) - - fai1 = fai_out[i] # 4 - rrl1 = rrl_out[i] # 4 - rdh1 = rdh_out[i] # 4 - mrl1 = mrl_out[i] # 4 - - paf = mean(builfrac_out[i]) - - mdh1 = mean(mdh_out[i]) # 1? - - mea1 = mean_ht_out[i] # 1 mbh - std1 = std_ht_out[i] # 1 stdev - awm1 = awmh_out[i] # 1 awm - zo1 = mean(zo_out[i]) # 1 grl - zd1 = mean(zd_out[i]) # 1 gdh - h2w1 = h2wratios[i] # 1 h2w - car1 = car_out[i] - - # print n1, fad1, bui1, paf, mea1, std1, awm1, bs21, fai1, zo1, zd1, rrl1, rdh1, mrl1, mdh1, h2w1, car1 - - names2.append(n1) - fad_out2.append(fad1) - builfrac_out2.append(bui1) - paf_out2.append(paf) - fai_out2.append(fai1) - rdh_out2.append(rdh1) - rrl_out2.append(rrl1) - mdh_out2.append(mdh1) - mrl_out2.append(mrl1) - bs2par_out2.append(bs21) - zo_out2.append(zo1) - zd_out2.append(zd1) - mean_ht_out2.append(mea1) - std_ht_out2.append(std1) - awmh_out2.append(awm1) - h2w_out2.append(h2w1) - car_out2.append(car1) - - paras_out.append([n1, fad1, bui1, bui1, paf, mea1, std1, awm1, bs21, fai1, zo1, zd1, rrl1, rdh1, - mrl1, mdh1, h2w1, car1]) - -# c = open('NUDAPT_Parameters_ORNL_out8.csv', 'wb') -# wr = csv.writer(c) -# wr.writerows(paras_out) -# c.close() - -afile = open(r'names2_chicago.pkl', 'wb') -pickle.dump(names2, afile) -afile.close() - -afile = open(r'fad_out2_chicago.pkl', 'wb') -pickle.dump(fad_out2, afile) -afile.close() - -afile = open(r'builfrac_out2_chicago.pkl', 'wb') -pickle.dump(builfrac_out2, afile) -afile.close() - -afile = open(r'paf_out2_chicago.pkl', 'wb') -pickle.dump(paf_out2, afile) -afile.close() - -afile = open(r'fai_out2_chicago.pkl', 'wb') -pickle.dump(fai_out2, afile) -afile.close() - -afile = open(r'rdh_out2_chicago.pkl', 'wb') -pickle.dump(rdh_out2, afile) -afile.close() - -afile = open(r'rrl_out2_chicago.pkl', 'wb') -pickle.dump(rrl_out2, afile) -afile.close() - -afile = open(r'mdh_out2_chicago.pkl', 'wb') -pickle.dump(mdh_out2, afile) -afile.close() - -afile = open(r'mrl_out2_chicago.pkl', 'wb') -pickle.dump(mrl_out2, afile) -afile.close() - -afile = open(r'bs2par_out2_chicago.pkl', 'wb') -pickle.dump(bs2par_out2, afile) -afile.close() - -afile = open(r'zo_out2_chicago.pkl', 'wb') -pickle.dump(zo_out2, afile) -afile.close() - -afile = open(r'zd_out2_chicago.pkl', 'wb') -pickle.dump(zd_out2, afile) -afile.close() - -afile = open(r'mean_ht_out2_chicago.pkl', 'wb') -pickle.dump(mean_ht_out2, afile) -afile.close() - -afile = open(r'std_ht_out2_chicago.pkl', 'wb') -pickle.dump(std_ht_out2, afile) -afile.close() - -afile = open(r'awmh_out2_chicago.pkl', 'wb') -pickle.dump(awmh_out2, afile) -afile.close() - -afile = open(r'h2w_out2_chicago.pkl', 'wb') -pickle.dump(h2w_out2, afile) -afile.close() - -afile = open(r'car_out2_chicago.pkl', 'wb') -pickle.dump(car_out2, afile) -afile.close() - -print "Script took", str(time() - start_time), "seconds to run" diff --git a/NATURF/4_no_raster_temp_chicago_UTM_with_paras2.py b/NATURF/4_no_raster_temp_chicago_UTM_with_paras2.py deleted file mode 100644 index aa098b3976c..00000000000 --- a/NATURF/4_no_raster_temp_chicago_UTM_with_paras2.py +++ /dev/null @@ -1,871 +0,0 @@ -from sys import exit -from time import time -from math import sqrt -from numpy import array, arange, transpose, set_printoptions, zeros, uint8, uint16, indices, where, empty, float64, \ - column_stack, savetxt, isnan, mean, shape, ones, int32, save, float32, double -from skimage.draw import polygon -import osr -from PIL import Image -from scipy import ndimage, misc -import pickle -import sklearn.preprocessing -import struct - -try: - from osgeo import gdal, ogr - from osgeo.gdalconst import * -except ImportError: - import gdal - import ogr - from gdalconst import * - -set_printoptions(threshold='nan') -start_time = time() - - -def get_pixels(x1, y1, x2, y2): - - m = (float(y1) - float(y2)) / (float(x1) - float(x2) + 0.000000000000000000000000000000001) - yint = float(y1) - (m * float(x1)) - - slope_arr = [] - - if abs(x1-x2) > abs(y1-y2) or abs(x1-x2) == abs(y1-y2): - if x1 > x2: - for si in range(x2, x1+1): - sy = m*si+yint - sy = int(round(sy)) - small = [si, sy] - slope_arr.append(small) - if x1 < x2: - for si in range(x1, x2+1): - sy = m*si+yint - sy = int(round(sy)) - small = [si, sy] - slope_arr.append(small) - - if abs(x1-x2) < abs(y1-y2): - if y1 > y2: - for si in range(y2, y1+1): - sx = (si - yint) / m - sx = int(round(sx)) - small = [sx, si] - slope_arr.append(small) - if y1 < y2: - for si in range(y1, y2+1): - sx = (si - yint) / m - sx = int(round(sx)) - small = [sx, si] - slope_arr.append(small) - - return slope_arr - - -def get_pixels_new(x1, y1, x2, y2): - - m = (float(y1) - float(y2)) / (float(x1) - float(x2) + 0.00000000000000000000000000000001) - yint = float(y1) - (m * float(x1)) - - if abs(x1-x2) > abs(y1-y2) or abs(x1-x2) == abs(y1-y2): - if x1 > x2: - arrx = arange(x2, x1+1) - arry = m * arrx + yint - if x1 <= x2: - arrx = arange(x1, x2+1) - arry = m * arrx + yint - - if abs(x1-x2) < abs(y1-y2): - if y1 > y2: - arry = arange(y2, y1+1) - arrx = (arry - yint) / m - if y1 <= y2: - arry = arange(y1, y2+1) - arrx = (arry - yint) / m - - arr1 = array((arrx, arry)) - arr1 = transpose(arr1) - - return arr1 - - -def get_pixels2(arr1, arr2, arr3, x1, y1, x2, y2, w): - mx = (float(y1) - float(y2)) / (float(x1) - float(x2) + 0.0000000000000000000000000000001) - yint = float(y1) - (mx * float(x1)) - - if abs(x1 - x2) > abs(y1 - y2) or abs(x1 - x2) == abs(y1 - y2): - if x1 > x2: - for i in range(x2, x1 + 1): - yp = int(round(mx * i + yint)) - - bx = i - start_x_p - by = yp - start_y_p - - if 0 <= bx < IMAGE_SIZE and 0 <= by < IMAGE_SIZE: - if w == 'b': - arr1[by][bx] = 0 - arr2[by][bx] = 0 - arr3[by][bx] = 255 - if w == 'r': - arr1[by][bx] = 255 - arr2[by][bx] = 0 - arr3[by][bx] = 0 - - if x1 < x2: - for i in range(x1, x2 + 1): - yp = int(round(mx * i + yint)) - - bx = i - start_x_p - by = yp - start_y_p - - if 0 <= bx < IMAGE_SIZE and 0 <= by < IMAGE_SIZE: - if w == 'b': - arr1[by][bx] = 0 - arr2[by][bx] = 0 - arr3[by][bx] = 255 - if w == 'r': - arr1[by][bx] = 255 - arr2[by][bx] = 0 - arr3[by][bx] = 0 - - if abs(x1 - x2) < abs(y1 - y2): - if y1 > y2: - for i in range(y2, y1 + 1): - xp = int(round((i - yint) / mx)) - - bx = xp - start_x_p - by = i - start_y_p - - if 0 <= bx < IMAGE_SIZE and 0 <= by < IMAGE_SIZE: - if w == 'b': - arr1[by][bx] = 0 - arr2[by][bx] = 0 - arr3[by][bx] = 255 - if w == 'r': - arr1[by][bx] = 255 - arr2[by][bx] = 0 - arr3[by][bx] = 0 - - if y1 < y2: - for i in range(y1, y2 + 1): - xp = int(round((i - yint) / mx)) - - bx = xp - start_x_p - by = i - start_y_p - - if 0 <= bx < IMAGE_SIZE and 0 <= by < IMAGE_SIZE: - if w == 'b': - arr1[by][bx] = 0 - arr2[by][bx] = 0 - arr3[by][bx] = 255 - if w == 'r': - arr1[by][bx] = 255 - arr2[by][bx] = 0 - arr3[by][bx] = 0 - - -def get_pixels2_b(arr1, x1, y1, x2, y2, w): - mx = (float(y1) - float(y2)) / (float(x1) - float(x2) + 0.0000000000000000000000000000001) - yint = float(y1) - (mx * float(x1)) - - if abs(x1 - x2) > abs(y1 - y2) or abs(x1 - x2) == abs(y1 - y2): - if x1 > x2: - for i in range(x2, x1 + 1): - yp = int(round(mx * i + yint)) - - bx = i - start_x_p - by = yp - start_y_p - - if 0 <= bx < IMAGE_SIZE and 0 <= by < IMAGE_SIZE: - if w == 'b': - arr1[by][bx] = 1 - if w == 'r': - arr1[by][bx] = 2 - if x1 < x2: - for i in range(x1, x2 + 1): - yp = int(round(mx * i + yint)) - - bx = i - start_x_p - by = yp - start_y_p - - if 0 <= bx < IMAGE_SIZE and 0 <= by < IMAGE_SIZE: - if w == 'b': - arr1[by][bx] = 1 - if w == 'r': - arr1[by][bx] = 2 - - if abs(x1 - x2) < abs(y1 - y2): - if y1 > y2: - for i in range(y2, y1 + 1): - xp = int(round((i - yint) / mx)) - - bx = xp - start_x_p - by = i - start_y_p - - if 0 <= bx < IMAGE_SIZE and 0 <= by < IMAGE_SIZE: - if w == 'b': - arr1[by][bx] = 1 - if w == 'r': - arr1[by][bx] = 2 - if y1 < y2: - for i in range(y1, y2 + 1): - xp = int(round((i - yint) / mx)) - - bx = xp - start_x_p - by = i - start_y_p - - if 0 <= bx < IMAGE_SIZE and 0 <= by < IMAGE_SIZE: - if w == 'b': - arr1[by][bx] = 1 - if w == 'r': - arr1[by][bx] = 2 - - -def get_pixels2_c(x1, y1, x2, y2): - mx = (float(y1) - float(y2)) / (float(x1) - float(x2) + 0.0000000000000000000000000000001) - yint = float(y1) - (mx * float(x1)) - px_func = [] - py_func = [] - - if abs(x1 - x2) > abs(y1 - y2) or abs(x1 - x2) == abs(y1 - y2): - if x1 > x2: - for i in range(x2, x1 + 1): - yp = int(round(mx * i + yint)) - - bx = i - by = yp - - if 0 <= bx < IMAGE_SIZE_Y and 0 <= by < IMAGE_SIZE_X: - px_func.append(i) - py_func.append(yp) - if x1 < x2: - for i in range(x1, x2 + 1): - yp = int(round(mx * i + yint)) - - bx = i - by = yp - - if 0 <= bx < IMAGE_SIZE_Y and 0 <= by < IMAGE_SIZE_X: - px_func.append(i) - py_func.append(yp) - - if abs(x1 - x2) < abs(y1 - y2): - if y1 > y2: - for i in range(y2, y1 + 1): - xp = int(round((i - yint) / mx)) - - bx = xp - by = i - - if 0 <= bx < IMAGE_SIZE_Y and 0 <= by < IMAGE_SIZE_X: - px_func.append(xp) - py_func.append(i) - if y1 < y2: - for i in range(y1, y2 + 1): - xp = int(round((i - yint) / mx)) - - bx = xp - by = i - - if 0 <= bx < IMAGE_SIZE_Y and 0 <= by < IMAGE_SIZE_X: - px_func.append(xp) - py_func.append(i) - - return px_func, py_func - - -def bbox(x1, y1, x2, y2): - minx = min([x1, x2]) - miny = min([y1, y2]) - maxx = max([x1, x2]) - maxy = max([y1, y2]) - - minx2 = minx - start_x_p - miny2 = miny - start_y_p - maxx2 = maxx - start_x_p - maxy2 = maxy - start_y_p - - # dataa = data[miny-wb:maxy+wb+1, minx-wb:maxx+wb+1] - - # print minx2, miny2, maxx2, maxy2 - - return minx, miny, maxx, maxy, minx2, miny2, maxx2, maxy2 - - -def bbox2(x1, y1, x2, y2): - minx = min([x1, x2]) - # miny = min([y1, y2]) - maxx = max([x1, x2]) - # maxy = max([y1, y2]) - - if minx == x1: - miny = y1 - maxy = y2 - else: - miny = y2 - maxy = y1 - - minx2 = minx - start_x_p - miny2 = miny - start_y_p - maxx2 = maxx - start_x_p - maxy2 = maxy - start_y_p - - # print minx2, miny2, maxx2, maxy2 - - return minx, miny, maxx, maxy, minx2, miny2, maxx2, maxy2 - - -def line_eq(x1, y1, x2, y2): - x1 -= start_x_p - y1 -= start_y_p - x2 -= start_x_p - y2 -= start_y_p - - a1 = float(y1 - y2) - b1 = float(x2 - x1) - c1 = float(x1 * y2) - float(x2 * y1) - - tempa = a1 - tempb = b1 - - if a1 == 0: - tempa = 999999999999 - - if b1 == 0: - tempb = 999999999999 - - if tempa < tempb: - mini = tempa - elif tempb <= tempa: - mini = tempb - else: - mini = 1 - - a1 /= mini - b1 /= mini - c1 /= mini - - return a1, b1, c1 - - -def l2p3(a1, b1, c1, indi, xmin, xmax, ymin, ymax): - - # print indi[0, ymin-wb:ymax+wb+1, xmin-wb:xmax+wb+1].shape, xmin, xmax, ymin, ymax - - ind2a = indi[0, ymin:ymax, xmin:xmax] - ind2b = indi[1, ymin:ymax, xmin:xmax] - - ind2 = [ind2a, ind2b] - - da = a1*ind2[1] + b1*ind2[0] + c1 - db = float(sqrt(a1**2 + b1**2)) + 0.0000000000000000000000000000000000001 - - d = da / db - - return d - - -def midpoint(x1, y1, x2, y2): - # print 'x1 x2:', x1, x2, '\ny1 y2:', y1, y2 - mx = (x1 + x2) / 2 - my = (y1 + y2) / 2 - # print 'mx my:', mx, my - - return mx, my - - -def inter3(x1, y1, x2, y2, lrad1, rrad1): - - dx = x1-x2 - dy = y1-y2 - dist = sqrt(dx*dx + dy*dy) - dx /= (dist + 0.00000000000000000000001) - dy /= (dist + 0.00000000000000000000001) - - if y1 > y2: - x1r = x1 - rrad1*dy - y1r = y1 + rrad1*dx - x1l = x1 + lrad1*dy - y1l = y1 - lrad1*dx - - x2r = x2 - rrad1*dy - y2r = y2 + rrad1*dx - x2l = x2 + lrad1*dy - y2l = y2 - lrad1*dx - else: - x1r = x1 + rrad1*dy - y1r = y1 - rrad1*dx - x1l = x1 - lrad1*dy - y1l = y1 + lrad1*dx - - x2r = x2 + rrad1*dy - y2r = y2 - rrad1*dx - x2l = x2 - lrad1*dy - y2l = y2 + lrad1*dx - - return x1r, y1r, x1l, y1l, x2r, y2r, x2l, y2l - - -def trans(data, bbox_d, xmin, xmax, ymin, ymax, wb): - data[ymin-wb:ymax+wb+1, xmin-wb:xmax+wb+1] = bbox_d - - -def roads_func(ti): - tpt = geom.GetPoint(ti) - - xoff = int((tpt[0] - xOrigin) / pixelWidth) - yoff = int((tpt[1] - yOrigin) / pixelHeight) - - parr.append([xoff, yoff]) - - -def builds_func(bi): - bpt = ring.GetPoint(bi) - - xoff = int((bpt[0] - xOrigin) / pixelWidth) - yoff = int((bpt[1] - yOrigin) / pixelHeight) - - parr.append([xoff, yoff]) - parrx.append([xoff]) - parry.append([yoff]) - - -# get the shapefile driver -driver = ogr.GetDriverByName('ESRI Shapefile') - -# open the data source -datasource = driver.Open(r'chicago_roads_utm.shp', 0) -if datasource is None: - print 'Could not open' + r'chicago_roads_utm.shp' - exit(1) - -datasource2 = driver.Open(r'ChicagoLoop_Morph3_utm.shp', 0) -if datasource2 is None: - print 'Could not open ' + r'ChicagoLoop_Morph.shp' - exit(1) - -# register all of the GDAL drivers -gdal.AllRegister() - -# img = gdal.Open(r'C:\Users\mbq\Documents\1 ORNL\Work\2621_warped_copy.tif', GA_ReadOnly) -# if img is None: -# print 'Could not open 2621.tif' -# exit(1) - -layer = datasource.GetLayer() - -extent = layer.GetExtent() - -xOrigin = extent[0] -yOrigin = extent[3] - -x = extent[1] -y = extent[2] - -FACTOR = 10 / 0.5 - -PIXEL_SIZE = 0.5 * FACTOR - -IMAGE_SIZE_X = 372 -IMAGE_SIZE_Y = 274 - -pixelWidth = PIXEL_SIZE -pixelHeight = -PIXEL_SIZE - -start_x = 446768 -start_y = 4637947 - -start_x_p = int((start_x - xOrigin) / pixelWidth) -start_y_p = int((start_y - yOrigin) / pixelHeight) - -layer2 = datasource2.GetLayer() - -driver_out = gdal.GetDriverByName('GTiff') - -proj = osr.SpatialReference() -proj.SetWellKnownGeogCS("WGS84") -proj.SetUTM(16) - -data1 = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint8) -data1.fill(255) -ids = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint16) -ids.fill(255) - -tempxyz = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) - -distarr = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -distarr.fill(0) - -ind = indices(data1.shape) - -cnt = 0 - -# radius = 15 - -afile = open(r'names2_chicago.pkl', 'rb') -names2 = pickle.load(afile) -afile.close() - -afile = open(r'fad_out2_chicago.pkl', 'rb') -fad_out2 = pickle.load(afile) -afile.close() - -afile = open(r'builfrac_out2_chicago.pkl', 'rb') -builfrac_out2 = pickle.load(afile) -afile.close() - -afile = open(r'paf_out2_chicago.pkl', 'rb') -paf_out2 = pickle.load(afile) -afile.close() - -afile = open(r'fai_out2_chicago.pkl', 'rb') -fai_out2 = pickle.load(afile) -afile.close() - -afile = open(r'rdh_out2_chicago.pkl', 'rb') -rdh_out2 = pickle.load(afile) -afile.close() - -afile = open(r'rrl_out2_chicago.pkl', 'rb') -rrl_out2 = pickle.load(afile) -afile.close() - -afile = open(r'mdh_out2_chicago.pkl', 'rb') -mdh_out2 = pickle.load(afile) -afile.close() - -afile = open(r'mrl_out2_chicago.pkl', 'rb') -mrl_out2 = pickle.load(afile) -afile.close() - -afile = open(r'bs2par_out2_chicago.pkl', 'rb') -bs2par_out2 = pickle.load(afile) -afile.close() - -afile = open(r'zo_out2_chicago.pkl', 'rb') -zo_out2 = pickle.load(afile) -afile.close() - -afile = open(r'zd_out2_chicago.pkl', 'rb') -zd_out2 = pickle.load(afile) -afile.close() - -afile = open(r'mean_ht_out2_chicago.pkl', 'rb') -mean_ht_out2 = pickle.load(afile) -afile.close() - -afile = open(r'std_ht_out2_chicago.pkl', 'rb') -std_ht_out2 = pickle.load(afile) -afile.close() - -afile = open(r'awmh_out2_chicago.pkl', 'rb') -awmh_out2 = pickle.load(afile) -afile.close() - -afile = open(r'h2w_out2_chicago.pkl', 'rb') -h2w_out2 = pickle.load(afile) -afile.close() - -afile = open(r'car_out2_chicago.pkl', 'rb') -car_out2 = pickle.load(afile) -afile.close() - -bldgs = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=double) - -# loop through the buildings -feature_buil = layer2.GetNextFeature() - -while feature_buil: - bid = feature_buil.GetFieldAsString('BLDGID') - - # print bid, names2[cnt] - - if bid in names2: - # print bid, names2[cnt] - - geomb = feature_buil.GetGeometryRef() - ring = geomb.GetGeometryRef(0) - numpoints = ring.GetPointCount() - - if numpoints != 0: - nx, ny, nz = ring.GetPoint(0) - - xOffset = int((nx - xOrigin) / pixelWidth) - yOffset = int((ny - yOrigin) / pixelHeight) - - parr = [[xOffset, yOffset]] - parrx = [[xOffset]] - parry = [[yOffset]] - - map(builds_func, xrange(1, ring.GetPointCount())) - - parrx[:] = [x[0] - start_x_p for x in parrx] - parry[:] = [y[0] - start_y_p for y in parry] - - parrx = array(parrx) - parry = array(parry) - rr, cc = polygon(parrx, parry, [IMAGE_SIZE_Y, IMAGE_SIZE_X]) - - bldgs[cc, rr] = bid - - # print bid - - cnt += 1 - - feature_buil.Destroy() - feature_buil = layer2.GetNextFeature() - -bldgsh = zeros((15, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=double) - -layer2.ResetReading() -feature_buil = layer2.GetNextFeature() - -while feature_buil: - bid = feature_buil.GetFieldAsString('BLDGID') - ht = feature_buil.GetFieldAsString('MEAN_AVGHT') - - # print ht - - if bid in names2: - if ht != '': - ht = float(ht) - cnt = 0 - - for asdf in xrange(0, 75, 5): - if ((ht - asdf) >= 5) or (0 < (ht - asdf) < 5): - - geomb = feature_buil.GetGeometryRef() - ring = geomb.GetGeometryRef(0) - numpoints = ring.GetPointCount() - - if numpoints != 0: - nx, ny, nz = ring.GetPoint(0) - - xOffset = int((nx - xOrigin) / pixelWidth) - yOffset = int((ny - yOrigin) / pixelHeight) - - parr = [[xOffset, yOffset]] - parrx = [[xOffset]] - parry = [[yOffset]] - - map(builds_func, xrange(1, ring.GetPointCount())) - - parrx[:] = [x[0] - start_x_p for x in parrx] - parry[:] = [y[0] - start_y_p for y in parry] - - parrx = array(parrx) - parry = array(parry) - rr, cc = polygon(parrx, parry, [IMAGE_SIZE_Y, IMAGE_SIZE_X]) - - bldgsh[cnt, cc, rr] = bid - - cnt += 1 - - feature_buil.Destroy() - feature_buil = layer2.GetNextFeature() - -# print bldgs[bldgs != 0] - -# print names2 - -fadn = zeros((15, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -fadw = zeros((15, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -fads = zeros((15, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -fade = zeros((15, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) - -pad = zeros((15, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -rad = zeros((15, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) - -fai = zeros((4, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -rrl = zeros((4, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -rdh = zeros((4, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -mrl = zeros((4, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) - -for i in xrange(len(fad_out2)): - for j in xrange(len(fad_out2[i]['n'])): - fadn[j][bldgs == double(names2[i])] = fad_out2[i]['n'][j] - fadw[j][bldgs == double(names2[i])] = fad_out2[i]['w'][j] - fads[j][bldgs == double(names2[i])] = fad_out2[i]['s'][j] - fade[j][bldgs == double(names2[i])] = fad_out2[i]['e'][j] - - pad[j][bldgs == double(names2[i])] = builfrac_out2[i][j] - rad[j][bldgs == double(names2[i])] = builfrac_out2[i][j] - - fai[0][bldgs == double(names2[i])] = fai_out2[i]['n'] - fai[1][bldgs == double(names2[i])] = fai_out2[i]['w'] - fai[2][bldgs == double(names2[i])] = fai_out2[i]['s'] - fai[3][bldgs == double(names2[i])] = fai_out2[i]['e'] - - rrl[0][bldgs == double(names2[i])] = rrl_out2[i]['n'] - rrl[1][bldgs == double(names2[i])] = rrl_out2[i]['w'] - rrl[2][bldgs == double(names2[i])] = rrl_out2[i]['s'] - rrl[3][bldgs == double(names2[i])] = rrl_out2[i]['e'] - - rdh[0][bldgs == double(names2[i])] = rdh_out2[i]['n'] - rdh[1][bldgs == double(names2[i])] = rdh_out2[i]['w'] - rdh[2][bldgs == double(names2[i])] = rdh_out2[i]['s'] - rdh[3][bldgs == double(names2[i])] = rdh_out2[i]['e'] - - mrl[0][bldgs == double(names2[i])] = mrl_out2[i]['n'] - mrl[1][bldgs == double(names2[i])] = mrl_out2[i]['w'] - mrl[2][bldgs == double(names2[i])] = mrl_out2[i]['s'] - mrl[3][bldgs == double(names2[i])] = mrl_out2[i]['e'] - -paf = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -mea = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -std = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -awm = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -b2p = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -h2w = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -grl = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -gdh = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -mdh = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -car = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) - -for i in xrange(len(h2w_out2)): - h2w[bldgs == double(names2[i])] = h2w_out2[i] - paf[bldgs == double(names2[i])] = paf_out2[i] - mea[bldgs == double(names2[i])] = mean_ht_out2[i] - std[bldgs == double(names2[i])] = std_ht_out2[i] - awm[bldgs == double(names2[i])] = awmh_out2[i] - b2p[bldgs == double(names2[i])] = bs2par_out2[i] - grl[bldgs == double(names2[i])] = zo_out2[i] - gdh[bldgs == double(names2[i])] = zd_out2[i] - mdh[bldgs == double(names2[i])] = mdh_out2[i] - car[bldgs == double(names2[i])] = car_out2[i] - -dbh = zeros((15, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) - -for i in xrange(len(fad_out2)): - for j in xrange(len(bldgsh)): - dbh[j][bldgsh[j] == double(names2[i])] += float(1) / float(len(fad_out2)) - -master = zeros((132, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) - -master[0:15] = fadn[0:15] -master[15:30] = fadw[0:15] -master[30:45] = fads[0:15] -master[45:60] = fade[0:15] -master[60:75] = pad[0:15] -master[75:90] = rad[0:15] - -master[90] = paf -master[91] = mea -master[92] = std -master[93] = awm -master[94] = b2p - -master[95:99] = fai[0:4] - -master[99] = car - -master[100] = h2w - -master[101] = ones((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) * 0.99 - -master[102] = grl -master[103] = gdh - -master[104] = rrl[0] -master[105] = rdh[0] -master[106] = rrl[1] -master[107] = rdh[1] -master[108] = rrl[2] -master[109] = rdh[2] -master[110] = rrl[3] -master[111] = rdh[3] - -master[112:116] = mrl[0:4] -master[116] = mdh - -master[117:132] = dbh[0:15] - -for i in xrange(len(master)): - master[i][isnan(master[i])] = 0 - -# print master[0] - -for i in xrange(len(master)): - - s = 'tile_' + str(i+1) + '.tif' - - imgOut = driver_out.Create(s, IMAGE_SIZE_Y, IMAGE_SIZE_X, 1, gdal.GDT_Float64) - bandOut1 = imgOut.GetRasterBand(1) - bandOut1.WriteArray(master[i], 0, 0) - imgOut.SetGeoTransform((start_x, pixelWidth, 0, start_y, 0, pixelHeight)) - imgOut.SetProjection(proj.ExportToWkt()) - - svis = 'tile_' + str(i+1) + '_visual.tif' - - master[i] *= 10000 - - imgOut = driver_out.Create(svis, IMAGE_SIZE_Y, IMAGE_SIZE_X, 1, 1) - bandOut1 = imgOut.GetRasterBand(1) - bandOut1.WriteArray(master[i], 0, 0) - imgOut.SetGeoTransform((start_x, pixelWidth, 0, start_y, 0, pixelHeight)) - imgOut.SetProjection(proj.ExportToWkt()) - -master = array(master) -master = master.astype(float32) - -b = master[0][::5][::5] - -# print b - -# master[0] += 10 - -# print master[0][master[0] != 0] -master0 = master[0][master[0] != 0] - -# print master0 - -master_out = bytes() - -mast = zeros((132, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float32) - -for i in xrange(len(master)): - for j in xrange(len(master[i])): - for k in xrange(len(master[i][j])): - # print type(master[i][j][k]) - master_out += struct.pack('>i', master[i][len(master[i]) - j - 1][k]) - -# for i in xrange(len(master)): -# for j in xrange(len(master[i])): -# for k in xrange(len(master[i][j])): -# # print type(master[i][j][k]) -# mast[i][j][k] = master[i][len(master[i]) - j - 1][k] -# -# print mast[0][::5][::5] - -# master_out = struct.pack('=%si' % master.size, *master) - -afile = save('master_out_chicago', master_out) - -with open('master_out_chicago.npy', 'rb') as tile, open('master_out2_chicago.npy', 'wb') as tile2: - tile2.write(tile.read()[20*4:]) - -# afile = open(r'master_out.pkl', 'wb') -# pickle.dump(master_out, afile) -# afile.close() - -# imgOut = driver_out.Create('Output\\h2w_out2.tif', -# IMAGE_SIZE_Y, IMAGE_SIZE_X, 1, gdal.GDT_Float64) -# -# bandOut1 = imgOut.GetRasterBand(1) -# bandOut1.WriteArray(h2w, 0, 0) -# imgOut.SetGeoTransform((start_x, pixelWidth, 0, start_y, 0, pixelHeight)) -# imgOut.SetProjection(proj.ExportToWkt()) - -# for i, dic in enumerate(fad_out2): -# print i, double(names2[i]) -# for key in dic: -# for cntr, asdf in enumerate(dic[key]): -# s = double(names2[i]) + '_' + str(key) + '_fad_out2_' + str(cntr+1) -# -# print s -# -# h2w = where(bldgs != double(names2[i]), data1, asdf) - -# close the data source -datasource.Destroy() - -print "Script took", str(time() - start_time), "seconds to run" diff --git a/NATURF/Extractor.py b/NATURF/Extractor.py deleted file mode 100644 index e2582741f1d..00000000000 --- a/NATURF/Extractor.py +++ /dev/null @@ -1,188 +0,0 @@ -import os - -import pandas as pd -import geopandas as gpd - -from shapely.geometry import Polygon - - -def polygon_from_bounds(gdf): - """Create a polygon from the bounds of all geometries in a geodataframe. - :param gdf: Geopandas dataframe of polygons. - :return: Shapely Polygon Object - """ - - # get the bounds of all geometries - minx, miny, maxx, maxy = gdf.geometry.total_bounds - - # construct a bounding box - boundary = [(minx, miny), - (maxx, miny), - (maxx, maxy), - (minx, maxy), - (minx, miny)] - - # convert to a polygon object - return Polygon(boundary) - - -def clip_method(buildings_gdf, target_gdf): - """Clip buildings to the target geometries. This method subsets the buildings data first based on the bounding - box around the target geometries to speed things up a bit. Still a slower method. - :param buildings_gdf: The input buildings polygon geodataframe. - :type buildings_gdf: GeoDataFrame - :param target_gdf: Input target polygon features geodataframe. - :type target_gdf: GeoDataFrame - :return: A clipped geodataframe with the target buildings geometries - """ - - # create a polygon for the bounds of the target data - target_poly = polygon_from_bounds(target_gdf) - - # create a valid field where 1 is in the bonding box and 0 is not - buildings_gdf['valid'] = buildings_gdf.geometry.apply(lambda x: 1 if x.intersects(target_poly) else 0) - - # create a subset of buildings polygons that can be used to speed up the clip functionality - buildings_subset_gdf = buildings_gdf.loc[buildings_gdf['valid'] == 1] - - # clip buildings by the target geometries - return gpd.clip(buildings_subset_gdf, target_gdf) - - -def sjoin_method(buildings_gdf, target_gdf, join_type='left', topology='intersects'): - """Spatially join (left) the intersecting geometries of the buildings data for the target features. - :param buildings_gdf: The input buildings polygon geodataframe. - :type buildings_gdf: GeoDataFrame - :param target_gdf: Input target polygon features geodataframe. - :type target_gdf: GeoDataFrame - :param join_type: The type of join: - ‘left’: use keys from left_df; retain only left_df geometry - column - ‘right’: use keys from right_df; retain only right_df geometry - column - ‘inner’: use intersection of keys from both dfs; retain only - left_df geometry column - :type join_type: str - :param topology: Binary predicate, one of {‘intersects’, ‘contains’, ‘within’}. - See http://shapely.readthedocs.io/en/latest/manual.html#binary-predicates. - :type topology: str - :return: A geodataframe with the target buildings geometries - """ - - return gpd.sjoin(left_df=target_gdf, right_df=buildings_gdf, how=join_type, op=topology) - - -def workflow(buildings_shp_file, target_shp_file, existing_shp_file, output_directory=None, x_offset=0, y_offset=0, - write_outputs=True, geometry_field_name='geometry', subset_method='sjoin'): - """The following is a workflow to conduct the following: - [0] Clip input buildings to the polygons in the target shapefile - [1] Offset the geometries in the clipped data by the x, y offset provided by the user - [2] Merge the output of the clipped (or offset) operations with an input shapefile - :param buildings_shp_file: The input buildings polygon shapefile path. - :type buildings_shp_file: str - :param target_shp_file: Input target polygon features shapefile path. - :type target_shp_file: str - :param existing_shp_file: An existing shapefile with the same field names as what will - the same was what is in the clipped output. - :type existing_shp_file: str - :param output_directory: Full path to an output directory to save outputs to. - :type output_directory: str - :param x_offset: Number of map units on the X axis to offset the polygon centroid - by. This should be in the units of the input file geometry. - :type x_offset: int; float - :param y_offset: Number of map units on the Y axis to offset the polygon centroid - by. This should be in the units of the input file geometry. - :type y_offset: int; float - :param write_outputs: Choose to write outputs to shapefiles. - :type write_outputs: bool - :param geometry_field_name: Field name for geometry. Default: `geometry`. - :type geometry_field_name: str - :param subset_method: A method to subset the buildings data using the target data as - as follows: - `sjoin`: Default. Spatially join (left) the intersecting - geometries of the buildings data for the target - features. - `clip`: Clip buildings to the target geometries. This method - subsets the buildings data first based on the bounding - box around the target geometries to speed things up a - bit. Still a slower method. - :param subset_method: str - :return: A geopandas dataframe of the merged output - USAGE: - buildings_shp_file = '' - target_shp_file = '' - existing_shp_file = '' - output_directory = '' - x_offset = 1000 - y_offset = 1000 - write_outputs = True - # which method to use for extracting the buildings data - subset_method = 'sjoin' - result_gdf = workflow(buildings_shp_file=buildings_shp_file, - target_shp_file=target_shp_file, - existing_shp_file=existing_shp_file, - output_directory=output_directory, - x_offset=x_offset, - y_offset=y_offset, - write_outputs=write_outputs, - subset_method=subset_method) - """ - - # import shapefiles to geopandas dataframes - buildings_gdf = gpd.read_file(buildings_shp_file) - target_gdf = gpd.read_file(target_shp_file) - existing_gdf = gpd.read_file(existing_shp_file) - - # ensure coordinate systems match for the inputs - if not (buildings_gdf.crs == target_gdf.crs == existing_gdf.crs): - msg = f"Coordinate systems do not match for the input files." - raise AttributeError(msg) - - # create a spatial subset of the buildings data from features in the target data with a user-preferred method - if subset_method == 'sjoin': - subset_gdf = sjoin_method(buildings_gdf, target_gdf) - elif subset_method == 'clip': - subset_gdf = clip_method(buildings_gdf, target_gdf) - else: - msg = f"`subset_method` '{subset_method}' not in available options: `sjoin`, `clip`" - raise ValueError(msg) - - # offset the clipped geometries by the user specified amount - if x_offset > 0 or y_offset > 0: - subset_gdf[geometry_field_name] = subset_gdf.translate(xoff=x_offset, yoff=y_offset) - - # merge the result into an existing dataset - merged_gdf = pd.concat([existing_gdf, subset_gdf]).pipe(gpd.GeoDataFrame) - - # write outputs if desired - if write_outputs: - subset_gdf.to_file(os.path.join(output_directory, 'subset_data.shp')) - merged_gdf.to_file(os.path.join(output_directory, 'merged_data.shp')) - - return merged_gdf - -# input files -buildings_shp_file = 'C:\ORNL Spring\Shapefiles\ClarkCounty_Project.shp' -target_shp_file = 'C:\ORNL Spring\Shapefiles\Sample_Data_Project.shp' -existing_shp_file = 'C:\ORNL Spring\Shapefiles\ClarkCounty_Project.shp' -output_directory = 'C:\ORNL Spring\Shapefiles' - -# offset in map units -x_offset = 1000 -y_offset = 1000 - -# choose to write outputs -write_outputs = True - -# which method to use for extracting the buildings data -subset_method = 'sjoin' - -# run it and return a geopandas dataframe -result_gdf = workflow(buildings_shp_file=buildings_shp_file, - target_shp_file=target_shp_file, - existing_shp_file=existing_shp_file, - output_directory=output_directory, - x_offset=x_offset, - y_offset=y_offset, - write_outputs=write_outputs, - subset_method=subset_method) \ No newline at end of file diff --git a/NATURF/Master_Script.py b/NATURF/Master_Script.py deleted file mode 100644 index 67db961a1a0..00000000000 --- a/NATURF/Master_Script.py +++ /dev/null @@ -1,22 +0,0 @@ - -shppath = r'C:/ORNL Spring/Shapefiles' -shpfiles = glob.iglob(os.path.join(shppath, "*.shp")) -for file in shpfiles: - path = file - name = 'LV_' + str(os.path.splitext(os.path.basename(file))[0]) - src = os.getcwd() - dest = os.path.join(shppath, name) - wrf = os.path.join(dest, name) - tif = os.path.join(dest, 'Tifs') - txt = os.path.join(dest, 'Text') - npy = os.path.join(dest, 'Numpys') - config = open("config.py", "w") - config.write('path = ' + repr(path) + '\n' + 'name = ' + repr(name) + '\n' + 'src = ' + repr(src) + '\n' + 'dest = ' + repr(dest) + '\n' + 'dest = ' + repr(dest) + '\n' + 'wrf = ' + repr(wrf) + '\n' + 'tif = ' + repr(tif) + '\n' + 'txt = ' + repr(txt) + '\n' + 'npy = ' + repr(npy) + '\n') - config.close() - - from Buildings_Raster_Generator import * - from Building_IDs_Generator import * - from Parameter_Calculations import * - from Final_Outputs import * - - print("Master script took", str(time() - start_time), "seconds to run") \ No newline at end of file diff --git a/NATURF/Master_Script.sh b/NATURF/Master_Script.sh new file mode 100755 index 00000000000..6d83b5af09e --- /dev/null +++ b/NATURF/Master_Script.sh @@ -0,0 +1,32 @@ +#!/bin/bash +FILES="/mnt/data/UrbanMorphology/im3_ornl/New_Vegas/Vegas_Top_Half/*.shp" +for f in $FILES +do +export path=$f + +python << EOF +import os +path= os.environ['path'] +name = 'LV_' + str(os.path.splitext(os.path.basename(path))[0]) +src = r'/mnt/data/UrbanMorphology/im3_ornl/New_Vegas/Vegas_Top_Half/Scripts' +dest = os.path.join(r'/mnt/data/UrbanMorphology/im3_ornl/New_Vegas/Vegas_Top_Half', name) +wrf = os.path.join(dest, name) +tif = os.path.join(dest, 'Tifs') +txt = os.path.join(dest, 'Text') +npy = os.path.join(dest, 'Numpys') +config = open("config.py", "w") +config.write('path = ' + repr(path) + '\n' + 'name = ' + repr(name) + '\n' + 'src = ' + repr(src) + '\n' + 'dest = ' + repr(dest) + '\n' + 'dest = ' + repr(dest) + '\n' + 'wrf = ' + repr(wrf) + '\n' + 'tif = ' + repr(tif) + '\n' + 'txt = ' + repr(txt) + '\n' + 'npy = ' + repr(npy) + '\n') +config.close() + +EOF + +chmod 777 config.py + +python Buildings_Raster_Generator.py +python Building_IDs_Generator.py +python Parameter_Calculations.py +python Final_Outputs.py + +mv $f /mnt/data/UrbanMorphology/im3_ornl/New_Vegas/LV_Processed_Tracts + +done diff --git a/NATURF/config.py b/NATURF/config.py deleted file mode 100644 index 9f73b7b2954..00000000000 --- a/NATURF/config.py +++ /dev/null @@ -1,2 +0,0 @@ -path = r'C:\ORNL Spring\Census Tracts\Tracts 51-60\005803-005877\005855\005855.shp' -name = "LV_005855" diff --git a/README.md b/README.md old mode 100644 new mode 100755 From 5608da477918ff1cbd681050177c4b87b76ab931 Mon Sep 17 00:00:00 2001 From: lg6 Date: Thu, 22 Jul 2021 10:19:18 -0400 Subject: [PATCH 07/35] Finished new Las Vegas files From 6cdd44f27169e13936c5bf43a80ad1325940da25 Mon Sep 17 00:00:00 2001 From: lg6 Date: Thu, 5 Aug 2021 21:56:49 -0400 Subject: [PATCH 08/35] Finished Los Angeles From b8c28b8784a97ca157a047d9fb968815101ac4c6 Mon Sep 17 00:00:00 2001 From: lg6 Date: Thu, 11 Nov 2021 12:25:21 -0500 Subject: [PATCH 09/35] Added tiles, experiments, etc. --- NATURF/Master_Script.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/NATURF/Master_Script.sh b/NATURF/Master_Script.sh index 6d83b5af09e..599e4eb1fa2 100755 --- a/NATURF/Master_Script.sh +++ b/NATURF/Master_Script.sh @@ -1,5 +1,5 @@ #!/bin/bash -FILES="/mnt/data/UrbanMorphology/im3_ornl/New_Vegas/Vegas_Top_Half/*.shp" +FILES="/mnt/data/UrbanMorphology/im3_ornl/New_Vegas/Vegas_Tiles_Top_Half/*.shp" for f in $FILES do export path=$f @@ -8,8 +8,8 @@ python << EOF import os path= os.environ['path'] name = 'LV_' + str(os.path.splitext(os.path.basename(path))[0]) -src = r'/mnt/data/UrbanMorphology/im3_ornl/New_Vegas/Vegas_Top_Half/Scripts' -dest = os.path.join(r'/mnt/data/UrbanMorphology/im3_ornl/New_Vegas/Vegas_Top_Half', name) +src = r'/mnt/data/UrbanMorphology/im3_ornl/New_Vegas/Vegas_Tiles_Top_Half/Scripts' +dest = os.path.join(r'/mnt/data/UrbanMorphology/im3_ornl/New_Vegas/Vegas_Tiles_Top_Half', name) wrf = os.path.join(dest, name) tif = os.path.join(dest, 'Tifs') txt = os.path.join(dest, 'Text') @@ -27,6 +27,6 @@ python Building_IDs_Generator.py python Parameter_Calculations.py python Final_Outputs.py -mv $f /mnt/data/UrbanMorphology/im3_ornl/New_Vegas/LV_Processed_Tracts +mv $f /mnt/data/UrbanMorphology/im3_ornl/New_Vegas/LV_Processed_Tiles done From 584b89acb4e91e588c9e254de85488ad11519d71 Mon Sep 17 00:00:00 2001 From: "Sweet, Levi" Date: Mon, 7 Mar 2022 22:06:35 +0000 Subject: [PATCH 10/35] Delete WRF_Calculations.py --- NATURF/WRF_Calculations.py | 79 -------------------------------------- 1 file changed, 79 deletions(-) delete mode 100644 NATURF/WRF_Calculations.py diff --git a/NATURF/WRF_Calculations.py b/NATURF/WRF_Calculations.py deleted file mode 100644 index be60e338b5d..00000000000 --- a/NATURF/WRF_Calculations.py +++ /dev/null @@ -1,79 +0,0 @@ -from config import * -import math -import utm -import osr -try: - from osgeo import gdal, ogr - from osgeo.gdalconst import * -except ImportError: - import gdal - import ogr - from gdalconst import * - -#path = r'C:\ORNL Spring\Census Tracts\Tracts 51-60\005803-005877\005844\005844.shp' - -driver = ogr.GetDriverByName('ESRI Shapefile') - -datasource2 = driver.Open(path, 0) -if datasource2 is None: - print('Could not open ' + r'ChicagoLoop_Morph.shp') - exit(1) - -# register all of the GDAL drivers -gdal.AllRegister() - -layer2 = datasource2.GetLayer() -extent2 = layer2.GetExtent() - -# Define the extent in UTM coordinates, the desired spatial resolution in meters, and also the UTM zone of the study area -top = extent2[3] -bottom = extent2[2] -left = extent2[0] -right = extent2[1] -resolution = 100 -zone = 11 - -# Coverts the UTM coordinates to latitude and longitude -northwest = (top,left) -southeast = (bottom,right) -latlontl = utm.to_latlon(northwest[1],northwest[0],zone, northern=True) -latlonbr = utm.to_latlon(southeast[1],southeast[0],zone, northern=True) -#print(latlontl,latlonbr) - -# Assigns variables to the new coordinates -newtop = latlontl[0] -newbottom = latlonbr[0] -newleft = latlontl[1] -newright = latlonbr[1] - -# Calculates the values for the WRF index number -gridtop = math.ceil(newtop * 120) -gridbottom = int(newbottom * 120) -gridleft = int((newleft + 180) * 120) -gridright = math.ceil((newright + 180) * 120) - -# This prints out the WRF index number (with spaces added) -#print("WRF Index:", min(gridleft,gridright), "-", max(gridleft,gridright), ".", min(gridbottom,gridtop), "-", max(gridbottom,gridtop)) - -# Uses the grid numbers to calculate new latitude and longitude coordinates -newlonglatleft = (gridleft/120) - 180 -newlonglatright = (gridright/120) - 180 -newlonglattop = (gridtop/120) -newlonglatbottom = (gridbottom/120) - -# Converts the new latitude and longitude coordinates back to UTM coordinates -topleft = (newlonglattop,newlonglatleft) -bottomright = (newlonglatbottom,newlonglatright) -utmtl = utm.from_latlon(topleft[0],topleft[1],zone) -utmbr = utm.from_latlon(bottomright[0],bottomright[1],zone) -#print(utmtl) -#print(utmbr) - -# Finds the difference between the eastings and the northings -eastings = abs(utmtl[0]-utmbr[0]) -northings = abs(utmtl[1]-utmbr[1]) - -# Calculates the tile size for the script -tilex = round(eastings/resolution) -tiley = round(northings/resolution) -#print("Tile Size:", tilex, "X", tiley) From fa9970cb68fa6ae6572ef34fcc654020338d13d4 Mon Sep 17 00:00:00 2001 From: "Sweet, Levi" Date: Mon, 7 Mar 2022 22:06:48 +0000 Subject: [PATCH 11/35] Delete Parameter_Calculations.py --- NATURF/Parameter_Calculations.py | 229 ------------------------------- 1 file changed, 229 deletions(-) delete mode 100644 NATURF/Parameter_Calculations.py diff --git a/NATURF/Parameter_Calculations.py b/NATURF/Parameter_Calculations.py deleted file mode 100644 index 0e8a179b59b..00000000000 --- a/NATURF/Parameter_Calculations.py +++ /dev/null @@ -1,229 +0,0 @@ -# GRID and BINS (WRF Pre-Processing) - -from config import * -from Function_Definitions import * -from sys import exit -from time import time -import math -from numpy import array, arange, transpose, set_printoptions, zeros, uint8, uint16, indices, where, empty, float64, \ - column_stack, savetxt, save, sum, unique, mean, std, isnan, NaN -from skimage.draw import polygon -import osr -from PIL import Image -from scipy import ndimage -import csv -from tempfile import TemporaryFile -import cv2 -import itertools -import warnings -import pickle -import winsound - -try: - from osgeo import gdal, ogr - from osgeo.gdalconst import * -except ImportError: - import gdal - import ogr - from gdalconst import * - -start_time = time() - -filename = "%s.csv" % name - -wi = math.hypot((extent2[0] - extent2[1]), (extent2[2] - extent2[2])) - -he = math.hypot((extent2[0] - extent2[0]), (extent2[3] - extent2[2])) - -car = wi / he - -cents, hts, areas = get_cents_hts() - -cents_ns, cents_ew, avgsa, nbarea, mean_ht_out, std_ht_out, awmh_out = avg_building_dist(hts, areas, cents) - -fad_out, builfrac_out, fai_out, rdh_out, rrl_out, mdh_out, mrl_out, bs2par_out,\ - zo_out, zd_out, car_out = parameters1('south', 0, nbarea, cents_ns, cents_ew, avgsa) - -# print car_out - -# print fad_out, builfrac_out, fai_out - -h2wratios, names = h2w() - -paras_out = [['Name', 'Frontal Area Density', 'Plan Area Density', 'Roof Area Density', - 'Plan Area Fraction', 'Mean Building Height', 'Standard Deviation of Building Heights', - 'Area Weighted Mean of Building Heights', 'Building Surface to Plan Area Ratio', - 'Frontal Area Index', 'Grimmond and Oke (GO) Roughness Length', 'GO Displacement Height', - 'Raupach Roughness Length', 'Raupach Displacement Height', 'MacDonald et al. Roughness Length', - 'MacDonald et al. Displacement Height', 'Height to Width Ratio', 'Complete Aspect Ratio']] - -# #$%#$%#$%#$%#$%#$%#$%#$%#$%#$%#$%#$%#$%#$% - -names2, fad_out2, builfrac_out2, paf_out2, fai_out2, rdh_out2, rrl_out2, mdh_out2, mrl_out2, bs2par_out2, zo_out2,\ - zd_out2, mean_ht_out2, std_ht_out2, awmh_out2, h2w_out2, car_out2 = [], [], [], [], [], [], [], [], [], [], [],\ - [], [], [], [], [], [] - -# #$%#$%#$%#$%#$%#$%#$%#$%#$%#$%#$%#$%#$%#$% - -with warnings.catch_warnings(): - warnings.simplefilter("ignore", category=RuntimeWarning) - - for i in range(len(names)): - - n1 = names[i] - - # print n1 - - if len(fad_out[i]) != 0: - - for qw in range(len(builfrac_out[i])): - builfrac_out[i][qw] = mean(builfrac_out[i][qw]) - - bui1 = builfrac_out[i] # 15 - - bs21 = mean(bs2par_out[i]) # 1 - - for qw in range(15): - - fad_out[i]['n'][qw] = mean(fad_out[i]['n'][qw]) - fad_out[i]['w'][qw] = mean(fad_out[i]['w'][qw]) - fad_out[i]['s'][qw] = mean(fad_out[i]['s'][qw]) - fad_out[i]['e'][qw] = mean(fad_out[i]['e'][qw]) - - fad1 = fad_out[i] # 15 * 4 - - fai_out[i]['n'] = mean(fai_out[i]['n']) - fai_out[i]['w'] = mean(fai_out[i]['w']) - fai_out[i]['s'] = mean(fai_out[i]['s']) - fai_out[i]['e'] = mean(fai_out[i]['e']) - - rrl_out[i]['n'] = mean(rrl_out[i]['n']) - rrl_out[i]['w'] = mean(rrl_out[i]['w']) - rrl_out[i]['s'] = mean(rrl_out[i]['s']) - rrl_out[i]['e'] = mean(rrl_out[i]['e']) - - rdh_out[i]['n'] = mean(rdh_out[i]['n']) - rdh_out[i]['w'] = mean(rdh_out[i]['w']) - rdh_out[i]['s'] = mean(rdh_out[i]['s']) - rdh_out[i]['e'] = mean(rdh_out[i]['e']) - - mrl_out[i]['n'] = mean(mrl_out[i]['n']) - mrl_out[i]['w'] = mean(mrl_out[i]['w']) - mrl_out[i]['s'] = mean(mrl_out[i]['s']) - mrl_out[i]['e'] = mean(mrl_out[i]['e']) - - fai1 = fai_out[i] # 4 - rrl1 = rrl_out[i] # 4 - rdh1 = rdh_out[i] # 4 - mrl1 = mrl_out[i] # 4 - - paf = mean(builfrac_out[i]) - - mdh1 = mean(mdh_out[i]) # 1? - - mea1 = mean_ht_out[i] # 1 mbh - std1 = std_ht_out[i] # 1 stdev - awm1 = awmh_out[i] # 1 awm - zo1 = mean(zo_out[i]) # 1 grl - zd1 = mean(zd_out[i]) # 1 gdh - h2w1 = h2wratios[i] # 1 h2w - car1 = car_out[i] - - # print n1, fad1, bui1, paf, mea1, std1, awm1, bs21, fai1, zo1, zd1, rrl1, rdh1, mrl1, mdh1, h2w1, car1 - - names2.append(n1) - fad_out2.append(fad1) - builfrac_out2.append(bui1) - paf_out2.append(paf) - fai_out2.append(fai1) - rdh_out2.append(rdh1) - rrl_out2.append(rrl1) - mdh_out2.append(mdh1) - mrl_out2.append(mrl1) - bs2par_out2.append(bs21) - zo_out2.append(zo1) - zd_out2.append(zd1) - mean_ht_out2.append(mea1) - std_ht_out2.append(std1) - awmh_out2.append(awm1) - h2w_out2.append(h2w1) - car_out2.append(car1) - - paras_out.append([n1, fad1, bui1, bui1, paf, mea1, std1, awm1, bs21, fai1, zo1, zd1, rrl1, rdh1, - mrl1, mdh1, h2w1, car1]) - -c = open(filename, 'w') -wr = csv.writer(c) -wr.writerows(paras_out) -c.close() - -afile = open(r'names2.pkl', 'wb') -pickle.dump(names2, afile) -afile.close() - -afile = open(r'fad_out2.pkl', 'wb') -pickle.dump(fad_out2, afile) -afile.close() - -afile = open(r'builfrac_out2.pkl', 'wb') -pickle.dump(builfrac_out2, afile) -afile.close() - -afile = open(r'paf_out2.pkl', 'wb') -pickle.dump(paf_out2, afile) -afile.close() - -afile = open(r'fai_out2.pkl', 'wb') -pickle.dump(fai_out2, afile) -afile.close() - -afile = open(r'rdh_out2.pkl', 'wb') -pickle.dump(rdh_out2, afile) -afile.close() - -afile = open(r'rrl_out2.pkl', 'wb') -pickle.dump(rrl_out2, afile) -afile.close() - -afile = open(r'mdh_out2.pkl', 'wb') -pickle.dump(mdh_out2, afile) -afile.close() - -afile = open(r'mrl_out2.pkl', 'wb') -pickle.dump(mrl_out2, afile) -afile.close() - -afile = open(r'bs2par_out2.pkl', 'wb') -pickle.dump(bs2par_out2, afile) -afile.close() - -afile = open(r'zo_out2.pkl', 'wb') -pickle.dump(zo_out2, afile) -afile.close() - -afile = open(r'zd_out2.pkl', 'wb') -pickle.dump(zd_out2, afile) -afile.close() - -afile = open(r'mean_ht_out2.pkl', 'wb') -pickle.dump(mean_ht_out2, afile) -afile.close() - -afile = open(r'std_ht_out2.pkl', 'wb') -pickle.dump(std_ht_out2, afile) -afile.close() - -afile = open(r'awmh_out2.pkl', 'wb') -pickle.dump(awmh_out2, afile) -afile.close() - -afile = open(r'h2w_out2.pkl', 'wb') -pickle.dump(h2w_out2, afile) -afile.close() - -afile = open(r'car_out2.pkl', 'wb') -pickle.dump(car_out2, afile) -afile.close() - -print("Script 3 took", str(time() - start_time), "seconds to run") -winsound.Beep(1000,1000) From 14682f144f581bffb30ceded4c2ba7a9bf828439 Mon Sep 17 00:00:00 2001 From: "Sweet, Levi" Date: Mon, 7 Mar 2022 22:07:53 +0000 Subject: [PATCH 12/35] Delete Master_Script.sh --- NATURF/Master_Script.sh | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100755 NATURF/Master_Script.sh diff --git a/NATURF/Master_Script.sh b/NATURF/Master_Script.sh deleted file mode 100755 index 599e4eb1fa2..00000000000 --- a/NATURF/Master_Script.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash -FILES="/mnt/data/UrbanMorphology/im3_ornl/New_Vegas/Vegas_Tiles_Top_Half/*.shp" -for f in $FILES -do -export path=$f - -python << EOF -import os -path= os.environ['path'] -name = 'LV_' + str(os.path.splitext(os.path.basename(path))[0]) -src = r'/mnt/data/UrbanMorphology/im3_ornl/New_Vegas/Vegas_Tiles_Top_Half/Scripts' -dest = os.path.join(r'/mnt/data/UrbanMorphology/im3_ornl/New_Vegas/Vegas_Tiles_Top_Half', name) -wrf = os.path.join(dest, name) -tif = os.path.join(dest, 'Tifs') -txt = os.path.join(dest, 'Text') -npy = os.path.join(dest, 'Numpys') -config = open("config.py", "w") -config.write('path = ' + repr(path) + '\n' + 'name = ' + repr(name) + '\n' + 'src = ' + repr(src) + '\n' + 'dest = ' + repr(dest) + '\n' + 'dest = ' + repr(dest) + '\n' + 'wrf = ' + repr(wrf) + '\n' + 'tif = ' + repr(tif) + '\n' + 'txt = ' + repr(txt) + '\n' + 'npy = ' + repr(npy) + '\n') -config.close() - -EOF - -chmod 777 config.py - -python Buildings_Raster_Generator.py -python Building_IDs_Generator.py -python Parameter_Calculations.py -python Final_Outputs.py - -mv $f /mnt/data/UrbanMorphology/im3_ornl/New_Vegas/LV_Processed_Tiles - -done From 182390f996fd73cc0b2a6ac5634d55dce2bb9dc8 Mon Sep 17 00:00:00 2001 From: "Sweet, Levi" Date: Mon, 7 Mar 2022 22:08:14 +0000 Subject: [PATCH 13/35] Delete Final_Outputs.py --- NATURF/Final_Outputs.py | 504 ---------------------------------------- 1 file changed, 504 deletions(-) delete mode 100644 NATURF/Final_Outputs.py diff --git a/NATURF/Final_Outputs.py b/NATURF/Final_Outputs.py deleted file mode 100644 index 764cbad4f0e..00000000000 --- a/NATURF/Final_Outputs.py +++ /dev/null @@ -1,504 +0,0 @@ -from config import * -from WRF_Calculations import * -from sys import exit -from time import time -from math import sqrt -from math import ceil -from numpy import array, arange, transpose, set_printoptions, zeros, uint8, uint16, indices, where, empty, float64, \ - column_stack, savetxt, isnan, mean, shape, ones, int32, save, float32, double, diff -from skimage.draw import polygon -import osr -from PIL import Image -from scipy import ndimage, misc -import pickle -import sklearn.preprocessing -import struct -import csv -import os -import glob -import shutil - -try: - from osgeo import gdal, ogr - from osgeo.gdalconst import * -except ImportError: - import gdal - import ogr - from gdalconst import * - -start_time = time() - -filename = "%s.npy" % name - -#path = r'C:\ORNL Spring\Census Tracts\Tracts 51-60\005803-005877\005844\005844.shp' - -# get the shapefile driver -driver = ogr.GetDriverByName('ESRI Shapefile') - -datasource2 = driver.Open(path, 0) -if datasource2 is None: - print('Could not open shapefile') - exit(1) - -# register all of the GDAL drivers -gdal.AllRegister() - -layer2 = datasource2.GetLayer() -extent2 = layer2.GetExtent() - -xOrigin = extent2[0] -yOrigin = extent2[3] - -FACTOR = 100/0.5 - -PIXEL_SIZE = 0.5 * FACTOR - -IMAGE_SIZE_X = tiley -IMAGE_SIZE_Y = tilex - -pixelWidth = PIXEL_SIZE -pixelHeight = -PIXEL_SIZE - -start_x = int(xOrigin) -start_y = ceil(yOrigin) - -start_x_p = int((start_x - xOrigin) / pixelWidth) -start_y_p = int((start_y - yOrigin) / pixelHeight) - -driver_out = gdal.GetDriverByName('GTiff') - -proj = osr.SpatialReference() -proj.SetWellKnownGeogCS("WGS84") -proj.SetUTM(11, False) - -data1 = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint8) -data1.fill(255) -ids = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint16) -ids.fill(255) - -tempxyz = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) - -distarr = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -distarr.fill(0) - -ind = indices(data1.shape) - -cnt = 0 - -# radius = 15 - -afile = open(r'names2.pkl', 'rb') -names2 = pickle.load(afile) -afile.close() - -afile = open(r'fad_out2.pkl', 'rb') -fad_out2 = pickle.load(afile) -afile.close() - -afile = open(r'builfrac_out2.pkl', 'rb') -builfrac_out2 = pickle.load(afile) -afile.close() - -afile = open(r'paf_out2.pkl', 'rb') -paf_out2 = pickle.load(afile) -afile.close() - -afile = open(r'fai_out2.pkl', 'rb') -fai_out2 = pickle.load(afile) -afile.close() - -afile = open(r'rdh_out2.pkl', 'rb') -rdh_out2 = pickle.load(afile) -afile.close() - -afile = open(r'rrl_out2.pkl', 'rb') -rrl_out2 = pickle.load(afile) -afile.close() - -afile = open(r'mdh_out2.pkl', 'rb') -mdh_out2 = pickle.load(afile) -afile.close() - -afile = open(r'mrl_out2.pkl', 'rb') -mrl_out2 = pickle.load(afile) -afile.close() - -afile = open(r'bs2par_out2.pkl', 'rb') -bs2par_out2 = pickle.load(afile) -afile.close() - -afile = open(r'zo_out2.pkl', 'rb') -zo_out2 = pickle.load(afile) -afile.close() - -afile = open(r'zd_out2.pkl', 'rb') -zd_out2 = pickle.load(afile) -afile.close() - -afile = open(r'mean_ht_out2.pkl', 'rb') -mean_ht_out2 = pickle.load(afile) -afile.close() - -afile = open(r'std_ht_out2.pkl', 'rb') -std_ht_out2 = pickle.load(afile) -afile.close() - -afile = open(r'awmh_out2.pkl', 'rb') -awmh_out2 = pickle.load(afile) -afile.close() - -afile = open(r'h2w_out2.pkl', 'rb') -h2w_out2 = pickle.load(afile) -afile.close() - -afile = open(r'car_out2.pkl', 'rb') -car_out2 = pickle.load(afile) -afile.close() - -bldgs = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=double) - -# loop through the buildings -feature_buil = layer2.GetNextFeature() - -while feature_buil: - bid = feature_buil.GetFieldAsString('ID') - - if bid in names2: - - geomb = feature_buil.GetGeometryRef() - ring = geomb.GetGeometryRef(0) - numpoints = ring.GetPointCount() - - if numpoints != 0: - nx, ny, nz = ring.GetPoint(0) - - xOffset = int((nx - xOrigin) / pixelWidth) - yOffset = int((ny - yOrigin) / pixelHeight) - - parr = [[xOffset, yOffset]] - parrx = [[xOffset]] - parry = [[yOffset]] - - for i in range(1, numpoints): - bpt = ring.GetPoint(i) - - xoff = int((bpt[0] - xOrigin) / pixelWidth) - yoff = int((bpt[1] - yOrigin) / pixelHeight) - - parrx.append([xoff]) - parry.append([yoff]) - - parrx[:] = [x[0] - start_x_p for x in parrx] - parry[:] = [y[0] - start_y_p for y in parry] - - parrx = array(parrx) - parry = array(parry) - rr, cc = polygon(parrx, parry, [IMAGE_SIZE_Y, IMAGE_SIZE_X]) - - bldgs[cc, rr] = bid - - cnt += 1 - - feature_buil.Destroy() - feature_buil = layer2.GetNextFeature() - -bldgsh = zeros((15, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=double) - -layer2.ResetReading() -feature_buil = layer2.GetNextFeature() - -while feature_buil: - bid = feature_buil.GetFieldAsString('ID') - ht = feature_buil.GetFieldAsString('Height') - - if bid in names2: - if ht != '': - ht = float(ht) - cnt = 0 - - for asdf in range(0, 75, 5): - if ((ht - asdf) >= 5) or (0 < (ht - asdf) < 5): - - geomb = feature_buil.GetGeometryRef() - ring = geomb.GetGeometryRef(0) - numpoints = ring.GetPointCount() - - if numpoints != 0: - nx, ny, nz = ring.GetPoint(0) - - xOffset = int((nx - xOrigin) / pixelWidth) - yOffset = int((ny - yOrigin) / pixelHeight) - - parr = [[xOffset, yOffset]] - parrx = [[xOffset]] - parry = [[yOffset]] - - for i in range(1, numpoints): - bpt = ring.GetPoint(i) - - xoff = int((bpt[0] - xOrigin) / pixelWidth) - yoff = int((bpt[1] - yOrigin) / pixelHeight) - - parrx.append([xoff]) - parry.append([yoff]) - - parrx[:] = [x[0] - start_x_p for x in parrx] - parry[:] = [y[0] - start_y_p for y in parry] - - parrx = array(parrx) - parry = array(parry) - rr, cc = polygon(parrx, parry, [IMAGE_SIZE_Y, IMAGE_SIZE_X]) - - bldgsh[cnt, cc, rr] = bid - - cnt += 1 - - feature_buil.Destroy() - feature_buil = layer2.GetNextFeature() - -fadn = zeros((15, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -fadw = zeros((15, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -fads = zeros((15, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -fade = zeros((15, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) - -pad = zeros((15, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -rad = zeros((15, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) - -fai = zeros((4, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -rrl = zeros((4, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -rdh = zeros((4, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -mrl = zeros((4, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) - -for i in range(len(fad_out2)): - for j in range(len(fad_out2[i]['n'])): - fadn[j][bldgs == double(names2[i])] = fad_out2[i]['n'][j] - fadw[j][bldgs == double(names2[i])] = fad_out2[i]['w'][j] - fads[j][bldgs == double(names2[i])] = fad_out2[i]['s'][j] - fade[j][bldgs == double(names2[i])] = fad_out2[i]['e'][j] - - pad[j][bldgs == double(names2[i])] = builfrac_out2[i][j] - rad[j][bldgs == double(names2[i])] = builfrac_out2[i][j] - - fai[0][bldgs == double(names2[i])] = fai_out2[i]['n'] - fai[1][bldgs == double(names2[i])] = fai_out2[i]['w'] - fai[2][bldgs == double(names2[i])] = fai_out2[i]['s'] - fai[3][bldgs == double(names2[i])] = fai_out2[i]['e'] - - rrl[0][bldgs == double(names2[i])] = rrl_out2[i]['n'] - rrl[1][bldgs == double(names2[i])] = rrl_out2[i]['w'] - rrl[2][bldgs == double(names2[i])] = rrl_out2[i]['s'] - rrl[3][bldgs == double(names2[i])] = rrl_out2[i]['e'] - - rdh[0][bldgs == double(names2[i])] = rdh_out2[i]['n'] - rdh[1][bldgs == double(names2[i])] = rdh_out2[i]['w'] - rdh[2][bldgs == double(names2[i])] = rdh_out2[i]['s'] - rdh[3][bldgs == double(names2[i])] = rdh_out2[i]['e'] - - mrl[0][bldgs == double(names2[i])] = mrl_out2[i]['n'] - mrl[1][bldgs == double(names2[i])] = mrl_out2[i]['w'] - mrl[2][bldgs == double(names2[i])] = mrl_out2[i]['s'] - mrl[3][bldgs == double(names2[i])] = mrl_out2[i]['e'] - -paf = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -mea = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -std = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -awm = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -b2p = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -h2w = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -grl = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -gdh = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -mdh = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -car = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) - -for i in range(len(h2w_out2)): - h2w[bldgs == double(names2[i])] = h2w_out2[i] - paf[bldgs == double(names2[i])] = paf_out2[i] - mea[bldgs == double(names2[i])] = mean_ht_out2[i] - std[bldgs == double(names2[i])] = std_ht_out2[i] - awm[bldgs == double(names2[i])] = awmh_out2[i] - b2p[bldgs == double(names2[i])] = bs2par_out2[i] - grl[bldgs == double(names2[i])] = zo_out2[i] - gdh[bldgs == double(names2[i])] = zd_out2[i] - mdh[bldgs == double(names2[i])] = mdh_out2[i] - car[bldgs == double(names2[i])] = car_out2[i] - -dbh = zeros((15, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) - -for i in range(len(fad_out2)): - for j in range(len(bldgsh)): - dbh[j][bldgsh[j] == double(names2[i])] += float(1) / float(len(fad_out2)) - -master = zeros((132, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) - -master[0:15] = fadn[0:15] -master[15:30] = fadw[0:15] -master[30:45] = fads[0:15] -master[45:60] = fade[0:15] -master[60:75] = pad[0:15] -master[75:90] = rad[0:15] - -master[90] = paf -master[91] = mea -master[92] = std -master[93] = awm -master[94] = b2p - -master[95:99] = fai[0:4] - -master[99] = car - -master[100] = h2w - -master[101] = ones((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) * 0.99 - -master[102] = grl -master[103] = gdh - -master[104] = rrl[0] -master[105] = rdh[0] -master[106] = rrl[1] -master[107] = rdh[1] -master[108] = rrl[2] -master[109] = rdh[2] -master[110] = rrl[3] -master[111] = rdh[3] - -master[112:116] = mrl[0:4] -master[116] = mdh - -master[117:132] = dbh[0:15] - -for i in range(len(master)): - master[i][isnan(master[i])] = 0 - -# print master[0] - -for i in range(len(master)): - - s = 'tile_' + str(i+1) + '.tif' - - imgOut = driver_out.Create(s, IMAGE_SIZE_Y, IMAGE_SIZE_X, 1, gdal.GDT_Float64) - bandOut1 = imgOut.GetRasterBand(1) - bandOut1.WriteArray(master[i], 0, 0) - imgOut.SetGeoTransform((start_x, pixelWidth, 0, start_y, 0, pixelHeight)) - imgOut.SetProjection(proj.ExportToWkt()) - - svis = 'tile_' + str(i+1) + '_visual.tif' - - master[i] *= 10000 - - imgOut = driver_out.Create(svis, IMAGE_SIZE_Y, IMAGE_SIZE_X, 1, 1) - bandOut1 = imgOut.GetRasterBand(1) - bandOut1.WriteArray(master[i], 0, 0) - imgOut.SetGeoTransform((start_x, pixelWidth, 0, start_y, 0, pixelHeight)) - imgOut.SetProjection(proj.ExportToWkt()) - -master = array(master) -master = master.astype(float32) - -b = master[0][::5][::5] - -master0 = master[0][master[0] != 0] - -master_out = [] - -mast = zeros((132, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float32) - -for i in range(len(master)): - master_outi = bytes() - for j in range(len(master[i])): - for k in range(len(master[i][j])): - master_outi += struct.pack('>i', int(master[i][len(master[i]) - j - 1][k])) - - # print('Progress (inner loop): ', k, '/', len(master[i][j])) - # print('Progress (middle loop): ', j, '/', len(master[i])) - master_out.append(master_outi) - print('Progress (outer loop): ', i, '/', len(master)) - -master_out_final = bytes() - -for i in range(len(master_out)): - master_out_final += master_out[i] - -afile = save('temp', master_out_final) - -with open('temp.npy', 'rb') as tile, open(filename, 'wb') as tile2: - tile2.write(tile.read()[20*4:]) - -tilex = str(tilex) -tiley = str(tiley) - -txtname = "%s.txt" % name - -with open('index.txt','w') as index: - index.write('type=continuous\n') - index.write(' projection=regular_ll\n') - index.write(' missing_value=-999900.\n') - index.write(' dy=0.08333333333\n') - index.write(' dx=0.08333333333\n') - index.write(' known_x=1\n') - index.write(' known_y=1\n') - index.write(' known_lat=0.0\n') - index.write(' known_lon=-180.0\n') - index.write(' wordsize=4\n') - index.write(' endian=big\n') - index.write(' signed=no\n') - index.write(' tile_x=') - index.write(tilex + '\n') - index.write(' tile_y=') - index.write(tiley + '\n') - index.write(' tile_z=132\n') - index.write(' units="dimensionless"\n') - index.write(' scale_factor=0.0001\n') - index.write(' description="Urban_Parameters"\n') - -with open('index.txt', 'r') as index, open(txtname, 'w') as index2: - index2.write(index.read()) - -minlr = str(min(gridleft,gridright)) -maxlr = str(max(gridleft,gridright)) -mintb = str(min(gridbottom,gridtop)) -maxtb = str(max(gridbottom,gridtop)) - -indexname = minlr + "-" + maxlr -indexext = mintb + "-" + maxtb - -indexfile = "%s.%s" % (indexname,indexext) - -with open(filename, 'rb') as tile, open(indexfile, 'wb') as tile2: - tile2.write(tile.read()) - -#print("WRF Index:", min(gridleft,gridright), "-", max(gridleft,gridright), ".", min(gridbottom,gridtop), "-", max(gridbottom,gridtop)) -#print("Tile Size:", tilex, "X", tiley) - -os.mkdir(wrf) -os.mkdir(txt) -os.mkdir(tif) - -srcfiles = os.listdir(src) -for file_name in srcfiles: - full_file_name = os.path.join(src, file_name) - if os.path.isfile(full_file_name): - shutil.copy(full_file_name, dest) - -binary = os.path.join(dest, indexfile) -shutil.copy2(binary, wrf) -index = os.path.join(dest, 'index.txt') -shutil.copy2(index, wrf) - -txtfiles = glob.iglob(os.path.join(dest, "*.txt")) -for file in txtfiles: - if os.path.isfile(file): - shutil.move(file, txt) - -tiffiles = glob.iglob(os.path.join(dest, "*.tif")) -for file in tiffiles: - if os.path.isfile(file): - shutil.move(file, tif) - -npyfiles = glob.iglob(os.path.join(dest, "*.npy")) -for file in npyfiles: - if os.path.isfile(file): - shutil.move(file, npy) - -print("Script 4 took", str(time() - start_time), "seconds to run") From 56961c832af3c52ea9a360184ed43fbbc65e9691 Mon Sep 17 00:00:00 2001 From: "Sweet, Levi" Date: Mon, 7 Mar 2022 22:08:25 +0000 Subject: [PATCH 14/35] Delete Buildings_Raster_Generator.py --- NATURF/Buildings_Raster_Generator.py | 153 --------------------------- 1 file changed, 153 deletions(-) delete mode 100644 NATURF/Buildings_Raster_Generator.py diff --git a/NATURF/Buildings_Raster_Generator.py b/NATURF/Buildings_Raster_Generator.py deleted file mode 100644 index 58c243ce61e..00000000000 --- a/NATURF/Buildings_Raster_Generator.py +++ /dev/null @@ -1,153 +0,0 @@ -from config import * -from sys import exit -from time import time -from math import sqrt -from math import ceil -from numpy import array, arange, transpose, set_printoptions, zeros, uint8, uint16, indices, where, empty, float64, \ - column_stack, savetxt -from skimage.draw import polygon -import osr -from PIL import Image -from scipy import ndimage - -try: - from osgeo import gdal, ogr - from osgeo.gdalconst import * -except ImportError: - import gdal - import ogr - from gdalconst import * - -start_time = time() - -#path = path.encode('unicode_escape') -#print(path) -# get the shapefile driver -driver = ogr.GetDriverByName('ESRI Shapefile') - -datasource2 = driver.Open(path, 0) -if datasource2 is None: - print('Could not open shapefile') - exit(1) - -# register all of the GDAL drivers -gdal.AllRegister() - -layer2 = datasource2.GetLayer() - -extent2 = layer2.GetExtent() - -xOrigin = extent2[0] -yOrigin = extent2[3] - -PIXEL_SIZE = 0.5 - -IMAGE_SIZE_X = (2 * ceil(extent2[3]-extent2[2])) + 100 -IMAGE_SIZE_Y = (2 * ceil(extent2[1]-extent2[0])) + 100 - -pixelWidth = PIXEL_SIZE -pixelHeight = -PIXEL_SIZE - -start_x = int(xOrigin) -start_y = ceil(yOrigin) - -start_x_p = int((start_x - xOrigin) / pixelWidth) -start_y_p = int((start_y - yOrigin) / pixelHeight) - -driver_out = gdal.GetDriverByName('GTiff') -imgOut = driver_out.Create(r'Buildings_Raster.tif', - IMAGE_SIZE_Y, IMAGE_SIZE_X, 1, 1) - -proj = osr.SpatialReference() -proj.SetWellKnownGeogCS("WGS84") -proj.SetUTM(11, False) - -bandOut1 = imgOut.GetRasterBand(1) - -data1 = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint8) -data1.fill(255) - -ids = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint16) -ids.fill(255) - -buils = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint16) -buils.fill(255) - -tempxyz = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) - -distarr = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -distarr.fill(0) - -ind = indices(data1.shape) - -ys = 0 -yl = 0 -xs = 0 -xl = 0 - -# radius = 15 - -# loop through the buildings -feature_buil = layer2.GetNextFeature() - -while feature_buil: - geomb = feature_buil.GetGeometryRef() - ring = geomb.GetGeometryRef(0) - numpoints = ring.GetPointCount() - - if numpoints != 0: - nx, ny, _ = ring.GetPoint(0) - - # print(nx, ny) - # print(xOrigin, yOrigin) - - xOffset = int((nx - xOrigin) / pixelWidth) - yOffset = int((ny - yOrigin) / pixelHeight) - - # print(xOffset, yOffset) - - parr = [[xOffset, yOffset]] - parrx = [[xOffset]] - parry = [[yOffset]] - - # print(parrx) - # print(parry) - # print(ring.GetPointCount()) - - for i in range(1, numpoints): - bpt = ring.GetPoint(i) - - xoff = int((bpt[0] - xOrigin) / pixelWidth) - yoff = int((bpt[1] - yOrigin) / pixelHeight) - - parrx.append([xoff]) - parry.append([yoff]) - - # print(parrx) - # print(parry) - - parrx[:] = [x[0] - start_x_p for x in parrx] - parry[:] = [y[0] - start_y_p for y in parry] - - # print(parrx) - # print(parry) - - parrx = array(parrx) - parry = array(parry) - rr, cc = polygon(parrx, parry, [IMAGE_SIZE_Y, IMAGE_SIZE_X]) - # print(rr, cc) - buils[cc, rr] = 127 - - feature_buil.Destroy() - feature_buil = layer2.GetNextFeature() - - -data1 = where(buils != 127, data1, 127) - -bandOut1.WriteArray(data1, 0, 0) - -imgOut.SetGeoTransform((start_x, pixelWidth, 0, start_y, 0, pixelHeight)) -imgOut.SetProjection(proj.ExportToWkt()) -del imgOut - -print("Script 1 took", str(time() - start_time), "seconds to run") From 7e66a14995f27deb1c443ddd9090cb22c84e5cfa Mon Sep 17 00:00:00 2001 From: "Sweet, Levi" Date: Mon, 7 Mar 2022 22:08:34 +0000 Subject: [PATCH 15/35] Delete Building_IDs_Generator.py --- NATURF/Building_IDs_Generator.py | 153 ------------------------------- 1 file changed, 153 deletions(-) delete mode 100644 NATURF/Building_IDs_Generator.py diff --git a/NATURF/Building_IDs_Generator.py b/NATURF/Building_IDs_Generator.py deleted file mode 100644 index 640195380f6..00000000000 --- a/NATURF/Building_IDs_Generator.py +++ /dev/null @@ -1,153 +0,0 @@ -from config import * -from sys import exit -from time import time -from math import sqrt -from math import ceil -from numpy import array, arange, transpose, set_printoptions, zeros, uint8, uint16, uint32, indices, where, empty, float64, \ - column_stack, savetxt, save -from skimage.draw import polygon -import osr -from PIL import Image -from scipy import ndimage -import csv -from tempfile import TemporaryFile - -try: - from osgeo import gdal, ogr - from osgeo.gdalconst import * -except ImportError: - import gdal - import ogr - from gdalconst import * - -start_time = time() - - -#path = r'C:\ORNL Spring\Census Tracts\Tracts 51-60\005803-005877\005844\005844.shp' - -# get the shapefile driver -driver = ogr.GetDriverByName('ESRI Shapefile') - -datasource2 = driver.Open(path, 0) -if datasource2 is None: - print('Could not open shapefile') - exit(1) - -# register all of the GDAL drivers -gdal.AllRegister() - -layer2 = datasource2.GetLayer() - -extent2 = layer2.GetExtent() - -xOrigin = extent2[0] -yOrigin = extent2[3] - -PIXEL_SIZE = 0.5 - -IMAGE_SIZE_X = (2 * ceil(extent2[3]-extent2[2])) + 100 -IMAGE_SIZE_Y = (2 * ceil(extent2[1]-extent2[0])) + 100 - -pixelWidth = PIXEL_SIZE -pixelHeight = -PIXEL_SIZE - -start_x = int(xOrigin) -start_y = ceil(yOrigin) - -start_x_p = int((start_x - xOrigin) / pixelWidth) -start_y_p = int((start_y - yOrigin) / pixelHeight) - -driver_out = gdal.GetDriverByName('GTiff') -imgOut = driver_out.Create(r'Building_IDs.tif', - IMAGE_SIZE_Y, IMAGE_SIZE_X, 1, gdal.GDT_Int32) - -proj = osr.SpatialReference() -proj.SetWellKnownGeogCS("WGS84") -proj.SetUTM(11, False) - -bandOut1 = imgOut.GetRasterBand(1) - -data1 = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint8) -data1.fill(255) - -ids = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint32) -ids.fill(0) - -buils = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint16) -buils.fill(255) - -tempxyz = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) - -distarr = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) -distarr.fill(0) - -ind = indices(data1.shape) - -names = [] -heights = [] -widths = [] -ratios = [] - -cnt = 1 - -# radius = 15 - -# loop through the buildings -feature_buil = layer2.GetNextFeature() - -while feature_buil: - bid = feature_buil.GetFieldAsString('ID') - - geomb = feature_buil.GetGeometryRef() - ring = geomb.GetGeometryRef(0) - numpoints = ring.GetPointCount() - - if numpoints != 0: - nx, ny, nz = ring.GetPoint(0) - - xOffset = int((nx - xOrigin) / pixelWidth) - yOffset = int((ny - yOrigin) / pixelHeight) - - parr = [[xOffset, yOffset]] - parrx = [[xOffset]] - parry = [[yOffset]] - - for bi in range(1, ring.GetPointCount()): - bpt = ring.GetPoint(bi) - - xoff = int((bpt[0] - xOrigin) / pixelWidth) - yoff = int((bpt[1] - yOrigin) / pixelHeight) - - parr.append([xoff, yoff]) - parrx.append([xoff]) - parry.append([yoff]) - - parrx[:] = [x[0] - start_x_p for x in parrx] - parry[:] = [y[0] - start_y_p for y in parry] - - parrx = array(parrx) - parry = array(parry) - rr, cc = polygon(parrx, parry, [IMAGE_SIZE_Y, IMAGE_SIZE_X]) - - buils[cc, rr] = 127 - - bid = float(bid) - bid = int(bid) - - ids[cc, rr] = where(ids[cc, rr] != 0, ids[cc, rr], cnt) - - # print cnt - - cnt += 1 - feature_buil.Destroy() - feature_buil = layer2.GetNextFeature() - -data1 = where(buils != 127, data1, 127) - -bandOut1.WriteArray(ids, 0, 0) - -imgOut.SetGeoTransform((start_x, pixelWidth, 0, start_y, 0, pixelHeight)) -imgOut.SetProjection(proj.ExportToWkt()) -del imgOut - -print("Script 2 took", str(time() - start_time), "seconds to run") From c310a12af98e16e0f70da53c658c76fdbd8bbb39 Mon Sep 17 00:00:00 2001 From: "Sweet, Levi" Date: Mon, 7 Mar 2022 22:09:00 +0000 Subject: [PATCH 16/35] Upload New File --- NATURF/Binary.py | 476 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 476 insertions(+) create mode 100644 NATURF/Binary.py diff --git a/NATURF/Binary.py b/NATURF/Binary.py new file mode 100644 index 00000000000..41ff0e93f02 --- /dev/null +++ b/NATURF/Binary.py @@ -0,0 +1,476 @@ +from sys import exit +from math import ceil +from numpy import array, zeros, uint8, uint16, indices,empty, float64, \ + isnan, ones, save, float32, double +from skimage.draw import polygon +import osr +import pickle +import struct + +try: + from osgeo import gdal, ogr + from osgeo.gdalconst import * +except ImportError: + import gdal + import ogr + from gdalconst import * + +def make_binary(name, path, tifDir, cenlat, cenlon, outputDir, id_field, height_field, indexfile): + ''' + Take parameter calculations and format them into a binary file + + Parameters + ---------- + name : str + Name of output csv with no extension. + path : PosixPath or str + Path to study shapefile. + tifDir : PosixPath or str + Path to directory for tif outputs. + cenlat : float + Center latitude of study area + cenlon : float + Center longitude of study area + outputDir : PosixPath or str + Path to directory for non-tif outputs. + id_field : str + Name of ID field in study shapefile. + height_field : str + Name of height field in study shapefile. + indexfile : str + Name of output binary file. + ''' + if type(path) != 'str': + path = str(path) + if type(tifDir) != 'str': + tifDir = str(tifDir) + + filename = "%s.npy" % name + + # get the shapefile driver + driver = ogr.GetDriverByName('ESRI Shapefile') + + datasource2 = driver.Open(path, 0) + if datasource2 is None: + print('Could not open shapefile') + exit(1) + + # register all of the GDAL drivers + gdal.AllRegister() + + layer2 = datasource2.GetLayer() + extent2 = layer2.GetExtent() + + xOrigin = extent2[0] + yOrigin = extent2[3] + + PIXEL_SIZE = 100 + + IMAGE_SIZE_X = 32 + IMAGE_SIZE_Y = 32 + + pixelWidth = PIXEL_SIZE + pixelHeight = -PIXEL_SIZE + + start_x = int(xOrigin) + start_y = ceil(yOrigin) + + start_x_p = int((start_x - xOrigin) / pixelWidth) + start_y_p = int((start_y - yOrigin) / pixelHeight) + + driver_out = gdal.GetDriverByName('GTiff') + + proj = osr.SpatialReference() + proj.SetWellKnownGeogCS("NAD1983") + proj.SetACEA(29.5, 45.5, cenlat, cenlon, 0, 0) + + #proj = osr.SpatialReference() + #proj.SetWellKnownGeogCS("WGS84") + #proj.SetUTM(18, False) + + data1 = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint8) + data1.fill(255) + ids = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint16) + ids.fill(255) + + tempxyz = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) + + distarr = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) + distarr.fill(0) + + ind = indices(data1.shape) + + cnt = 0 + + # radius = 15 + + afile = open(outputDir/'names2.pkl', 'rb') + names2 = pickle.load(afile) + afile.close() + + afile = open(outputDir/'fad_out2.pkl', 'rb') + fad_out2 = pickle.load(afile) + afile.close() + + afile = open(outputDir/'builfrac_out2.pkl', 'rb') + builfrac_out2 = pickle.load(afile) + afile.close() + + afile = open(outputDir/'paf_out2.pkl', 'rb') + paf_out2 = pickle.load(afile) + afile.close() + + afile = open(outputDir/'fai_out2.pkl', 'rb') + fai_out2 = pickle.load(afile) + afile.close() + + afile = open(outputDir/'rdh_out2.pkl', 'rb') + rdh_out2 = pickle.load(afile) + afile.close() + + afile = open(outputDir/'rrl_out2.pkl', 'rb') + rrl_out2 = pickle.load(afile) + afile.close() + + afile = open(outputDir/'mdh_out2.pkl', 'rb') + mdh_out2 = pickle.load(afile) + afile.close() + + afile = open(outputDir/'mrl_out2.pkl', 'rb') + mrl_out2 = pickle.load(afile) + afile.close() + + afile = open(outputDir/'bs2par_out2.pkl', 'rb') + bs2par_out2 = pickle.load(afile) + afile.close() + + afile = open(outputDir/'zo_out2.pkl', 'rb') + zo_out2 = pickle.load(afile) + afile.close() + + afile = open(outputDir/'zd_out2.pkl', 'rb') + zd_out2 = pickle.load(afile) + afile.close() + + afile = open(outputDir/'mean_ht_out2.pkl', 'rb') + mean_ht_out2 = pickle.load(afile) + afile.close() + + afile = open(outputDir/'std_ht_out2.pkl', 'rb') + std_ht_out2 = pickle.load(afile) + afile.close() + + afile = open(outputDir/'awmh_out2.pkl', 'rb') + awmh_out2 = pickle.load(afile) + afile.close() + + afile = open(outputDir/'h2w_out2.pkl', 'rb') + h2w_out2 = pickle.load(afile) + afile.close() + + afile = open(outputDir/'car_out2.pkl', 'rb') + car_out2 = pickle.load(afile) + afile.close() + + bldgs = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=double) + + # loop through the buildings + feature_buil = layer2.GetNextFeature() + + while feature_buil: + bid = feature_buil.GetFieldAsString(id_field) + + if bid in names2: + + geomb = feature_buil.GetGeometryRef() + ring = geomb.GetGeometryRef(0) + numpoints = ring.GetPointCount() + + if numpoints != 0: + nx, ny, nz = ring.GetPoint(0) + + xOffset = int((nx - xOrigin) / pixelWidth) + yOffset = int((ny - yOrigin) / pixelHeight) + + parr = [[xOffset, yOffset]] + parrx = [[xOffset]] + parry = [[yOffset]] + + for i in range(1, numpoints): + bpt = ring.GetPoint(i) + + xoff = int((bpt[0] - xOrigin) / pixelWidth) + yoff = int((bpt[1] - yOrigin) / pixelHeight) + + parrx.append([xoff]) + parry.append([yoff]) + + parrx[:] = [x[0] - start_x_p for x in parrx] + parry[:] = [y[0] - start_y_p for y in parry] + + parrx = array(parrx) + parry = array(parry) + rr, cc = polygon(parrx, parry, [IMAGE_SIZE_Y, IMAGE_SIZE_X]) + + bldgs[cc, rr] = bid + + cnt += 1 + + feature_buil.Destroy() + feature_buil = layer2.GetNextFeature() + + bldgsh = zeros((15, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=double) + + layer2.ResetReading() + feature_buil = layer2.GetNextFeature() + + while feature_buil: + bid = feature_buil.GetFieldAsString(id_field) + ht = feature_buil.GetFieldAsString(height_field) + + if bid in names2: + if ht != '': + ht = float(ht) + cnt = 0 + + for asdf in range(0, 75, 5): + if ((ht - asdf) >= 5) or (0 < (ht - asdf) < 5): + + geomb = feature_buil.GetGeometryRef() + ring = geomb.GetGeometryRef(0) + numpoints = ring.GetPointCount() + + if numpoints != 0: + nx, ny, nz = ring.GetPoint(0) + + xOffset = int((nx - xOrigin) / pixelWidth) + yOffset = int((ny - yOrigin) / pixelHeight) + + parr = [[xOffset, yOffset]] + parrx = [[xOffset]] + parry = [[yOffset]] + + for i in range(1, numpoints): + bpt = ring.GetPoint(i) + + xoff = int((bpt[0] - xOrigin) / pixelWidth) + yoff = int((bpt[1] - yOrigin) / pixelHeight) + + parrx.append([xoff]) + parry.append([yoff]) + + parrx[:] = [x[0] - start_x_p for x in parrx] + parry[:] = [y[0] - start_y_p for y in parry] + + parrx = array(parrx) + parry = array(parry) + rr, cc = polygon(parrx, parry, [IMAGE_SIZE_Y, IMAGE_SIZE_X]) + + bldgsh[cnt, cc, rr] = bid + + cnt += 1 + + feature_buil.Destroy() + feature_buil = layer2.GetNextFeature() + + fadn = zeros((15, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) + fadw = zeros((15, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) + fads = zeros((15, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) + fade = zeros((15, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) + + pad = zeros((15, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) + rad = zeros((15, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) + + fai = zeros((4, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) + rrl = zeros((4, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) + rdh = zeros((4, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) + mrl = zeros((4, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) + + for i in range(len(fad_out2)): + for j in range(len(fad_out2[i]['n'])): + fadn[j][bldgs == double(names2[i])] = fad_out2[i]['n'][j] + fadw[j][bldgs == double(names2[i])] = fad_out2[i]['w'][j] + fads[j][bldgs == double(names2[i])] = fad_out2[i]['s'][j] + fade[j][bldgs == double(names2[i])] = fad_out2[i]['e'][j] + + pad[j][bldgs == double(names2[i])] = builfrac_out2[i][j] + rad[j][bldgs == double(names2[i])] = builfrac_out2[i][j] + + fai[0][bldgs == double(names2[i])] = fai_out2[i]['n'] + fai[1][bldgs == double(names2[i])] = fai_out2[i]['w'] + fai[2][bldgs == double(names2[i])] = fai_out2[i]['s'] + fai[3][bldgs == double(names2[i])] = fai_out2[i]['e'] + + rrl[0][bldgs == double(names2[i])] = rrl_out2[i]['n'] + rrl[1][bldgs == double(names2[i])] = rrl_out2[i]['w'] + rrl[2][bldgs == double(names2[i])] = rrl_out2[i]['s'] + rrl[3][bldgs == double(names2[i])] = rrl_out2[i]['e'] + + rdh[0][bldgs == double(names2[i])] = rdh_out2[i]['n'] + rdh[1][bldgs == double(names2[i])] = rdh_out2[i]['w'] + rdh[2][bldgs == double(names2[i])] = rdh_out2[i]['s'] + rdh[3][bldgs == double(names2[i])] = rdh_out2[i]['e'] + + mrl[0][bldgs == double(names2[i])] = mrl_out2[i]['n'] + mrl[1][bldgs == double(names2[i])] = mrl_out2[i]['w'] + mrl[2][bldgs == double(names2[i])] = mrl_out2[i]['s'] + mrl[3][bldgs == double(names2[i])] = mrl_out2[i]['e'] + + paf = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) + mea = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) + std = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) + awm = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) + b2p = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) + h2w = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) + grl = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) + gdh = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) + mdh = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) + car = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) + + for i in range(len(h2w_out2)): + h2w[bldgs == double(names2[i])] = h2w_out2[i] + paf[bldgs == double(names2[i])] = paf_out2[i] + mea[bldgs == double(names2[i])] = mean_ht_out2[i] + std[bldgs == double(names2[i])] = std_ht_out2[i] + awm[bldgs == double(names2[i])] = awmh_out2[i] + b2p[bldgs == double(names2[i])] = bs2par_out2[i] + grl[bldgs == double(names2[i])] = zo_out2[i] + gdh[bldgs == double(names2[i])] = zd_out2[i] + mdh[bldgs == double(names2[i])] = mdh_out2[i] + car[bldgs == double(names2[i])] = car_out2[i] + + dbh = zeros((15, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) + + for i in range(len(fad_out2)): + for j in range(len(bldgsh)): + dbh[j][bldgsh[j] == double(names2[i])] += float(1) / float(len(fad_out2)) + + master = zeros((132, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) + + master[0:15] = fadn[0:15] + master[15:30] = fadw[0:15] + master[30:45] = fads[0:15] + master[45:60] = fade[0:15] + master[60:75] = pad[0:15] + master[75:90] = rad[0:15] + + master[90] = paf + master[91] = mea + master[92] = std + master[93] = awm + master[94] = b2p + + master[95:99] = fai[0:4] + + master[99] = car + + master[100] = h2w + + master[101] = ones((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) * 0.99 + + master[102] = grl + master[103] = gdh + + master[104] = rrl[0] + master[105] = rdh[0] + master[106] = rrl[1] + master[107] = rdh[1] + master[108] = rrl[2] + master[109] = rdh[2] + master[110] = rrl[3] + master[111] = rdh[3] + + master[112:116] = mrl[0:4] + master[116] = mdh + + master[117:132] = dbh[0:15] + + for i in range(len(master)): + master[i][isnan(master[i])] = 0 + + # print master[0] + + for i in range(len(master)): + + s = 'tile_' + str(i+1) + '.tif' + + imgOut = driver_out.Create(tifDir + '/' + s, IMAGE_SIZE_Y, IMAGE_SIZE_X, 1, gdal.GDT_Float64) + bandOut1 = imgOut.GetRasterBand(1) + bandOut1.WriteArray(master[i], 0, 0) + imgOut.SetGeoTransform((start_x, pixelWidth, 0, start_y, 0, pixelHeight)) + imgOut.SetProjection(proj.ExportToWkt()) + + svis = 'tile_' + str(i+1) + '_visual.tif' + + master[i] *= 10000 + + imgOut = driver_out.Create(tifDir + '/' + svis, IMAGE_SIZE_Y, IMAGE_SIZE_X, 1, 1) + bandOut1 = imgOut.GetRasterBand(1) + bandOut1.WriteArray(master[i], 0, 0) + imgOut.SetGeoTransform((start_x, pixelWidth, 0, start_y, 0, pixelHeight)) + imgOut.SetProjection(proj.ExportToWkt()) + + master = array(master) + master = master.astype(float32) + + b = master[0][::5][::5] + + master0 = master[0][master[0] != 0] + + master_out = [] + + mast = zeros((132, IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float32) + + for i in range(len(master)): + master_outi = bytes() + for j in range(len(master[i])): + for k in range(len(master[i][j])): + master_outi += struct.pack('>i', int(master[i][len(master[i]) - j - 1][k])) + + # print('Progress (inner loop): ', k, '/', len(master[i][j])) + # print('Progress (middle loop): ', j, '/', len(master[i])) + master_out.append(master_outi) + #print('Progress (outer loop): ', i, '/', len(master)) + + master_out_final = bytes() + + for i in range(len(master_out)): + master_out_final += master_out[i] + + afile = save(outputDir/'temp', master_out_final) + + with open(outputDir/'temp.npy', 'rb') as tile, open(outputDir/filename, 'wb') as tile2: + tile2.write(tile.read()[20*4:]) + + tilex = str(IMAGE_SIZE_X) + tiley = str(IMAGE_SIZE_Y) + + with open(outputDir/'index','w') as index: + index.write('type=continuous\n') + index.write(' projection=albers_nad83\n') + index.write(' missing_value=-999900.\n') + index.write(' dy=100.0\n') + index.write(' dx=100.0\n') + index.write(' known_x=1\n') + index.write(' known_y=1\n') + index.write(' known_lat=33.297482\n') + index.write(' known_lon=-119.009446\n') + index.write(' truelat1=45.5\n') + index.write(' truelat2=29.5\n') + index.write(' stdlon=-118.0\n') + index.write(' wordsize=4\n') + index.write(' endian=big\n') + index.write(' signed=no\n') + index.write(' tile_x=') + index.write(tilex + '\n') + index.write(' tile_y=') + index.write(tiley + '\n') + index.write(' tile_z=132\n') + index.write(' units="dimensionless"\n') + index.write(' scale_factor=0.0001\n') + index.write(' description="Urban_Parameters"\n') + + + + with open(outputDir/filename, 'rb') as tile, open(outputDir/indexfile, 'wb') as tile2: + tile2.write(tile.read()) \ No newline at end of file From 60bb5ffb4a84f28467de5b22199d6c9e0d155b23 Mon Sep 17 00:00:00 2001 From: "Sweet, Levi" Date: Mon, 7 Mar 2022 22:09:23 +0000 Subject: [PATCH 17/35] Upload New File --- NATURF/Building_IDs.py | 164 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+) create mode 100644 NATURF/Building_IDs.py diff --git a/NATURF/Building_IDs.py b/NATURF/Building_IDs.py new file mode 100644 index 00000000000..7c68be6535a --- /dev/null +++ b/NATURF/Building_IDs.py @@ -0,0 +1,164 @@ +from sys import exit +from math import ceil +from numpy import array, uint8, uint16, uint32, indices, where, empty, float64 +from skimage.draw import polygon +import osr + +try: + from osgeo import gdal, ogr + from osgeo.gdalconst import * +except ImportError: + import gdal + import ogr + from gdalconst import * + +def make_ids_image(path, tifDir, cenlat, cenlon, id_field): + ''' + Create GeoTiff file containing building ID data. + + Parameters + ---------- + path : PosixPath or str + Path to study shapefile + tifDir : PosixPath or str + Path to directory for tif outputs + cenlat : float + Center latitude of study area + cenlon : float + Center longitude of study area + id_field : str + Name of ID field in study shapefile + ''' + if type(path) != 'str': + path = str(path) + if type(tifDir) != 'str': + tifDir = str(tifDir) + + # get the shapefile driver + driver = ogr.GetDriverByName('ESRI Shapefile') + + datasource2 = driver.Open(path, 0) + if datasource2 is None: + print('Could not open shapefile') + exit(1) + + # register all of the GDAL drivers + gdal.AllRegister() + + layer2 = datasource2.GetLayer() + + extent2 = layer2.GetExtent() + + xOrigin = extent2[0] + yOrigin = extent2[3] + + PIXEL_SIZE = 0.5 + + IMAGE_SIZE_X = (2 * ceil(extent2[3]-extent2[2])) + 100 + IMAGE_SIZE_Y = (2 * ceil(extent2[1]-extent2[0])) + 100 + + pixelWidth = PIXEL_SIZE + pixelHeight = -PIXEL_SIZE + + start_x = int(xOrigin) + start_y = ceil(yOrigin) + + start_x_p = int((start_x - xOrigin) / pixelWidth) + start_y_p = int((start_y - yOrigin) / pixelHeight) + + driver_out = gdal.GetDriverByName('GTiff') + imgOut = driver_out.Create(tifDir + '/Building_IDs.tif', + IMAGE_SIZE_Y, IMAGE_SIZE_X, 1, gdal.GDT_Int32) + + proj = osr.SpatialReference() + proj.SetWellKnownGeogCS("NAD1983") + proj.SetACEA(29.5, 45.5, cenlat, cenlon, 0, 0) + + #proj = osr.SpatialReference() + #proj.SetWellKnownGeogCS("WGS84") + #proj.SetUTM(18, False) + + bandOut1 = imgOut.GetRasterBand(1) + + data1 = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint8) + data1.fill(255) + + ids = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint32) + ids.fill(0) + + buils = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint16) + buils.fill(255) + + tempxyz = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) + + distarr = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) + distarr.fill(0) + + ind = indices(data1.shape) + + names = [] + heights = [] + widths = [] + ratios = [] + + cnt = 1 + + # radius = 15 + + # loop through the buildings + feature_buil = layer2.GetNextFeature() + + while feature_buil: + bid = feature_buil.GetFieldAsString(id_field) + + geomb = feature_buil.GetGeometryRef() + ring = geomb.GetGeometryRef(0) + numpoints = ring.GetPointCount() + + if numpoints != 0: + nx, ny, nz = ring.GetPoint(0) + + xOffset = int((nx - xOrigin) / pixelWidth) + yOffset = int((ny - yOrigin) / pixelHeight) + + parr = [[xOffset, yOffset]] + parrx = [[xOffset]] + parry = [[yOffset]] + + for bi in range(1, ring.GetPointCount()): + bpt = ring.GetPoint(bi) + + xoff = int((bpt[0] - xOrigin) / pixelWidth) + yoff = int((bpt[1] - yOrigin) / pixelHeight) + + parr.append([xoff, yoff]) + parrx.append([xoff]) + parry.append([yoff]) + + parrx[:] = [x[0] - start_x_p for x in parrx] + parry[:] = [y[0] - start_y_p for y in parry] + + parrx = array(parrx) + parry = array(parry) + rr, cc = polygon(parrx, parry, [IMAGE_SIZE_Y, IMAGE_SIZE_X]) + + buils[cc, rr] = 127 + + bid = float(bid) + bid = int(bid) + + ids[cc, rr] = where(ids[cc, rr] != 0, ids[cc, rr], cnt) + + # print cnt + + cnt += 1 + feature_buil.Destroy() + feature_buil = layer2.GetNextFeature() + + data1 = where(buils != 127, data1, 127) + + bandOut1.WriteArray(ids, 0, 0) + + imgOut.SetGeoTransform((start_x, pixelWidth, 0, start_y, 0, pixelHeight)) + imgOut.SetProjection(proj.ExportToWkt()) + del imgOut \ No newline at end of file From 12739dc7869cb99af61da2deb4002160cd6a151f Mon Sep 17 00:00:00 2001 From: "Sweet, Levi" Date: Mon, 7 Mar 2022 22:09:42 +0000 Subject: [PATCH 18/35] Upload New File --- NATURF/Buildings_Raster.py | 168 +++++++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 NATURF/Buildings_Raster.py diff --git a/NATURF/Buildings_Raster.py b/NATURF/Buildings_Raster.py new file mode 100644 index 00000000000..b3326ce554f --- /dev/null +++ b/NATURF/Buildings_Raster.py @@ -0,0 +1,168 @@ +from sys import exit +from math import ceil +from numpy import array, uint8, uint16, indices, where, empty, float64 +from skimage.draw import polygon +import osr +from PIL import Image +import pathlib + +try: + from osgeo import gdal, ogr + from osgeo.gdalconst import * +except ImportError: + import gdal + import ogr + from gdalconst import * + +def make_raster(path, tifDir, cenlat, cenlon): + ''' + Create a raster out of a study shapefile in GeoTiff format + + Parameters + ---------- + path : PosixPath or str + Path to study shapefile + tifDir : PosixPath or str + Path to directory for tif outputs + cenlat : float + Center latitude of study area + cenlon : float + Center longitude of study area + ''' + if type(path) != 'str': + path = str(path) + if type(tifDir) != 'str': + tifDir = str(tifDir) + + + # get the shapefile driver + driver = ogr.GetDriverByName('ESRI Shapefile') + + datasource2 = driver.Open(path, 0) + if datasource2 is None: + print('Could not open shapefile') + exit(1) + + # register all of the GDAL drivers + gdal.AllRegister() + + layer2 = datasource2.GetLayer() + + extent2 = layer2.GetExtent() + + xOrigin = extent2[0] + yOrigin = extent2[3] + + PIXEL_SIZE = 0.5 + + IMAGE_SIZE_X = (2 * ceil(extent2[3]-extent2[2])) + 100 + IMAGE_SIZE_Y = (2 * ceil(extent2[1]-extent2[0])) + 100 + + pixelWidth = PIXEL_SIZE + pixelHeight = -PIXEL_SIZE + + start_x = int(xOrigin) + start_y = ceil(yOrigin) + + start_x_p = int((start_x - xOrigin) / pixelWidth) + start_y_p = int((start_y - yOrigin) / pixelHeight) + + driver_out = gdal.GetDriverByName('GTiff') + imgOut = driver_out.Create(tifDir + '/Buildings_Raster.tif', + IMAGE_SIZE_Y, IMAGE_SIZE_X, 1, 1) + + proj = osr.SpatialReference() + proj.SetWellKnownGeogCS("NAD1983") + proj.SetACEA(29.5, 45.5, cenlat, cenlon, 0, 0) + + #proj = osr.SpatialReference() + #proj.SetWellKnownGeogCS("WGS84") + #proj.SetUTM(18, False) + + bandOut1 = imgOut.GetRasterBand(1) + + data1 = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint8) + data1.fill(255) + + ids = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint16) + ids.fill(255) + + buils = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint16) + buils.fill(255) + + tempxyz = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) + + distarr = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=float64) + distarr.fill(0) + + ind = indices(data1.shape) + + ys = 0 + yl = 0 + xs = 0 + xl = 0 + + # radius = 15 + + # loop through the buildings + feature_buil = layer2.GetNextFeature() + + while feature_buil: + geomb = feature_buil.GetGeometryRef() + ring = geomb.GetGeometryRef(0) + numpoints = ring.GetPointCount() + + if numpoints != 0: + nx, ny, _ = ring.GetPoint(0) + + # print(nx, ny) + # print(xOrigin, yOrigin) + + xOffset = int((nx - xOrigin) / pixelWidth) + yOffset = int((ny - yOrigin) / pixelHeight) + + # print(xOffset, yOffset) + + parr = [[xOffset, yOffset]] + parrx = [[xOffset]] + parry = [[yOffset]] + + # print(parrx) + # print(parry) + # print(ring.GetPointCount()) + + for i in range(1, numpoints): + bpt = ring.GetPoint(i) + + xoff = int((bpt[0] - xOrigin) / pixelWidth) + yoff = int((bpt[1] - yOrigin) / pixelHeight) + + parrx.append([xoff]) + parry.append([yoff]) + + # print(parrx) + # print(parry) + + parrx[:] = [x[0] - start_x_p for x in parrx] + parry[:] = [y[0] - start_y_p for y in parry] + + # print(parrx) + # print(parry) + + parrx = array(parrx) + parry = array(parry) + rr, cc = polygon(parrx, parry, [IMAGE_SIZE_Y, IMAGE_SIZE_X]) + # print(rr, cc) + buils[cc, rr] = 127 + + feature_buil.Destroy() + feature_buil = layer2.GetNextFeature() + + + data1 = where(buils != 127, data1, 127) + + bandOut1.WriteArray(data1, 0, 0) + + imgOut.SetGeoTransform((start_x, pixelWidth, 0, start_y, 0, pixelHeight)) + imgOut.SetProjection(proj.ExportToWkt()) + del imgOut \ No newline at end of file From 8b88a7dc781b16b8d306ae35e2f234318229c981 Mon Sep 17 00:00:00 2001 From: "Sweet, Levi" Date: Mon, 7 Mar 2022 22:10:03 +0000 Subject: [PATCH 19/35] Upload New File --- NATURF/im3Workflow.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 NATURF/im3Workflow.py diff --git a/NATURF/im3Workflow.py b/NATURF/im3Workflow.py new file mode 100644 index 00000000000..4242398ef9b --- /dev/null +++ b/NATURF/im3Workflow.py @@ -0,0 +1,42 @@ +import multiprocessing +import pandas as pd +import pathlib +import Buildings_Raster as BR +import Building_IDs as BI +import Parameter_Calculations as PC +import Binary + +def processFile(shapeFile): + folder = shapeFile.parent.parent # directory housing output subdirectories + scenario = shapeFile.parent.parent.stem # first part of output directory name + buildingTile = shapeFile.stem # filename without extension + outputDir = folder/'{}_{}'.format(scenario, buildingTile) # create output directory named according to tile + tifDir = outputDir/'Tifs' + tifDir.mkdir(parents=True, exist_ok=True) # automatically also creates outputDir + + indexfile = filenames[buildingTile][0] # binary file name + cenlat = 34.0 # Center latitude of the study area + cenlon = -118.0 # Center longitude of the study area + id_field = 'ID' # Name of the field containing ID data in shapefile + height_field = 'Height' # Name of the field containing height data in shapefile + + BR.make_raster(shapeFile, tifDir, cenlat, cenlon) + BI.make_ids_image(shapeFile, tifDir, cenlat, cenlon, id_field) + PC.calculate_parameters(shapeFile, tifDir, outputDir, buildingTile, height_field, id_field) + Binary.make_binary(buildingTile, shapeFile, tifDir, cenlat, cenlon, outputDir, id_field, height_field, indexfile) + + print(buildingTile + " has finished") + +basePath = pathlib.Path('/mnt/data/UrbanMorphology/data/32x32/dilarea_testing/Shapefiles') # Path to directory containing shapefiles +shapeFiles = list(basePath.glob('*.shp')) # Creates a list of all the shapefile paths +grid = pd.read_csv(pathlib.Path('/mnt/data/UrbanMorphology/data/32x32/LA_Indices.csv')) # Path to geogrid csv +filenames = grid.set_index('GRID_ID').T.to_dict("list") # Creates a dictionary from the csv where grid IDs and the names are values + +try: + cpus = min(50, len(shapeFiles)) +except NotImplementedError: + cpus = 1 + #cpus = 96 # max +pool = multiprocessing.Pool(processes=cpus) + +pool.map(processFile, shapeFiles) \ No newline at end of file From 64050f88b76018367824b1c6de4077b7a7d1361c Mon Sep 17 00:00:00 2001 From: "Sweet, Levi" Date: Mon, 7 Mar 2022 22:10:29 +0000 Subject: [PATCH 20/35] Upload New File --- NATURF/Parameter_Calculations.py | 286 +++++++++++++++++++++++++++++++ 1 file changed, 286 insertions(+) create mode 100644 NATURF/Parameter_Calculations.py diff --git a/NATURF/Parameter_Calculations.py b/NATURF/Parameter_Calculations.py new file mode 100644 index 00000000000..0e9545b6ff0 --- /dev/null +++ b/NATURF/Parameter_Calculations.py @@ -0,0 +1,286 @@ +# GRID and BINS (WRF Pre-Processing) +from Parameter_Definitions import * +from sys import exit +import math +from numpy import array, zeros, uint8, mean +from PIL import Image +import csv +import warnings +import pickle + +try: + from osgeo import gdal, ogr + from osgeo.gdalconst import * +except ImportError: + import gdal + import ogr + from gdalconst import * + + +def calculate_parameters(path, tifDir, outputDir, name, height_field, id_field): + ''' + Use functions defined in Parameter_Definitions.py to calculate urban parameters, pickle them, and create a csv. + + Parameters + ---------- + path : PosixPath or str + Path to study shapefile. + tifDir : PosixPath or str + Path to directory for tif outputs. + outputDir : PosixPath or str + Path to directory for pickle and csv outputs. + name : str + Name of output csv with no extension. + height_field : str + Name of height field in study shapefile. + id_field : str + Name of ID field in study shapefile. + ''' + if type(path) != 'str': + path = str(path) + if type(tifDir) != 'str': + tifDir = str(tifDir) + + # get the shapefile driver + gdal.AllRegister() + driver = ogr.GetDriverByName('ESRI Shapefile') + buils_shp = path + datasource2 = driver.Open(buils_shp, 0) + if datasource2 is None: + print('Could not open shapefile') + exit(1) + buils_raster = tifDir +'/Buildings_Raster.tif' + img = gdal.Open(buils_raster, GA_ReadOnly) + if img is None: + print('Could not open image') + exit(1) + + # register all of the GDAL drivers + gdal.AllRegister() + + layer2 = datasource2.GetLayer() + + extent2 = layer2.GetExtent() + + xOrigin = extent2[0] + yOrigin = extent2[3] + + PIXEL_SIZE = 0.5 + + IMAGE_SIZE_X = (2 * math.ceil(extent2[3]-extent2[2])) + 100 + IMAGE_SIZE_Y = (2 * math.ceil(extent2[1]-extent2[0])) + 100 + + pixelWidth = PIXEL_SIZE + pixelHeight = -PIXEL_SIZE + + start_x = int(xOrigin) + start_y = math.ceil(yOrigin) + + + start_x_p = int((start_x - xOrigin) / pixelWidth) + start_y_p = int((start_y - yOrigin) / pixelHeight) + + i2arr = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint8) + + buils_ids = tifDir +'/Building_IDs.tif' + ids = Image.open(buils_ids) + + ids = array(ids) + + + filename = "%s.csv" % name + + wi = math.hypot((extent2[0] - extent2[1]), (extent2[2] - extent2[2])) + + he = math.hypot((extent2[0] - extent2[0]), (extent2[3] - extent2[2])) + + car = wi / he + + cents, hts, areas = get_cents_hts(IMAGE_SIZE_X, IMAGE_SIZE_Y, layer2, ids, PIXEL_SIZE, height_field) + + cents_ns, cents_ew, avgsa, nbarea, mean_ht_out, std_ht_out, awmh_out = avg_building_dist(IMAGE_SIZE_X, IMAGE_SIZE_Y, layer2, ids, PIXEL_SIZE, height_field, hts, areas, cents) + + fad_out, builfrac_out, fai_out, rdh_out, rrl_out, mdh_out, mrl_out, bs2par_out,\ + zo_out, zd_out, car_out = parameters1(IMAGE_SIZE_X, IMAGE_SIZE_Y, layer2, ids, PIXEL_SIZE, height_field, 'south', 0, nbarea, cents_ns, cents_ew, avgsa) + + # print car_out + + # print fad_out, builfrac_out, fai_out + + h2wratios, names = h2w(IMAGE_SIZE_X, IMAGE_SIZE_Y, layer2, xOrigin, yOrigin, pixelWidth, pixelHeight, start_x_p, start_y_p, PIXEL_SIZE, height_field, id_field) + + paras_out = [['Name', 'Frontal Area Density', 'Plan Area Density', 'Roof Area Density', + 'Plan Area Fraction', 'Mean Building Height', 'Standard Deviation of Building Heights', + 'Area Weighted Mean of Building Heights', 'Building Surface to Plan Area Ratio', + 'Frontal Area Index', 'Grimmond and Oke (GO) Roughness Length', 'GO Displacement Height', + 'Raupach Roughness Length', 'Raupach Displacement Height', 'MacDonald et al. Roughness Length', + 'MacDonald et al. Displacement Height', 'Height to Width Ratio', 'Complete Aspect Ratio']] + + # #$%#$%#$%#$%#$%#$%#$%#$%#$%#$%#$%#$%#$%#$% + + names2, fad_out2, builfrac_out2, paf_out2, fai_out2, rdh_out2, rrl_out2, mdh_out2, mrl_out2, bs2par_out2, zo_out2,\ + zd_out2, mean_ht_out2, std_ht_out2, awmh_out2, h2w_out2, car_out2 = [], [], [], [], [], [], [], [], [], [], [],\ + [], [], [], [], [], [] + + # #$%#$%#$%#$%#$%#$%#$%#$%#$%#$%#$%#$%#$%#$% + + with warnings.catch_warnings(): + warnings.simplefilter("ignore", category=RuntimeWarning) + + for i in range(len(names)): + + n1 = names[i] + + # print n1 + + if len(fad_out[i]) != 0: + + for qw in range(len(builfrac_out[i])): + builfrac_out[i][qw] = mean(builfrac_out[i][qw]) + + bui1 = builfrac_out[i] # 15 + + bs21 = mean(bs2par_out[i]) # 1 + + for qw in range(15): + + fad_out[i]['n'][qw] = mean(fad_out[i]['n'][qw]) + fad_out[i]['w'][qw] = mean(fad_out[i]['w'][qw]) + fad_out[i]['s'][qw] = mean(fad_out[i]['s'][qw]) + fad_out[i]['e'][qw] = mean(fad_out[i]['e'][qw]) + + fad1 = fad_out[i] # 15 * 4 + + fai_out[i]['n'] = mean(fai_out[i]['n']) + fai_out[i]['w'] = mean(fai_out[i]['w']) + fai_out[i]['s'] = mean(fai_out[i]['s']) + fai_out[i]['e'] = mean(fai_out[i]['e']) + + rrl_out[i]['n'] = mean(rrl_out[i]['n']) + rrl_out[i]['w'] = mean(rrl_out[i]['w']) + rrl_out[i]['s'] = mean(rrl_out[i]['s']) + rrl_out[i]['e'] = mean(rrl_out[i]['e']) + + rdh_out[i]['n'] = mean(rdh_out[i]['n']) + rdh_out[i]['w'] = mean(rdh_out[i]['w']) + rdh_out[i]['s'] = mean(rdh_out[i]['s']) + rdh_out[i]['e'] = mean(rdh_out[i]['e']) + + mrl_out[i]['n'] = mean(mrl_out[i]['n']) + mrl_out[i]['w'] = mean(mrl_out[i]['w']) + mrl_out[i]['s'] = mean(mrl_out[i]['s']) + mrl_out[i]['e'] = mean(mrl_out[i]['e']) + + fai1 = fai_out[i] # 4 + rrl1 = rrl_out[i] # 4 + rdh1 = rdh_out[i] # 4 + mrl1 = mrl_out[i] # 4 + + paf = mean(builfrac_out[i]) + + mdh1 = mean(mdh_out[i]) # 1? + + mea1 = mean_ht_out[i] # 1 mbh + std1 = std_ht_out[i] # 1 stdev + awm1 = awmh_out[i] # 1 awm + zo1 = mean(zo_out[i]) # 1 grl + zd1 = mean(zd_out[i]) # 1 gdh + h2w1 = h2wratios[i] # 1 h2w + car1 = car_out[i] + + # print n1, fad1, bui1, paf, mea1, std1, awm1, bs21, fai1, zo1, zd1, rrl1, rdh1, mrl1, mdh1, h2w1, car1 + + names2.append(n1) + fad_out2.append(fad1) + builfrac_out2.append(bui1) + paf_out2.append(paf) + fai_out2.append(fai1) + rdh_out2.append(rdh1) + rrl_out2.append(rrl1) + mdh_out2.append(mdh1) + mrl_out2.append(mrl1) + bs2par_out2.append(bs21) + zo_out2.append(zo1) + zd_out2.append(zd1) + mean_ht_out2.append(mea1) + std_ht_out2.append(std1) + awmh_out2.append(awm1) + h2w_out2.append(h2w1) + car_out2.append(car1) + + paras_out.append([n1, fad1, bui1, bui1, paf, mea1, std1, awm1, bs21, fai1, zo1, zd1, rrl1, rdh1, + mrl1, mdh1, h2w1, car1]) + + + c = open(outputDir/filename, 'w') + wr = csv.writer(c) + wr.writerows(paras_out) + c.close() + + afile = open(outputDir/'names2.pkl', 'wb') + pickle.dump(names2, afile) + afile.close() + + afile = open(outputDir/'fad_out2.pkl', 'wb') + pickle.dump(fad_out2, afile) + afile.close() + + afile = open(outputDir/'builfrac_out2.pkl', 'wb') + pickle.dump(builfrac_out2, afile) + afile.close() + + afile = open(outputDir/'paf_out2.pkl', 'wb') + pickle.dump(paf_out2, afile) + afile.close() + + afile = open(outputDir/'fai_out2.pkl', 'wb') + pickle.dump(fai_out2, afile) + afile.close() + + afile = open(outputDir/'rdh_out2.pkl', 'wb') + pickle.dump(rdh_out2, afile) + afile.close() + + afile = open(outputDir/'rrl_out2.pkl', 'wb') + pickle.dump(rrl_out2, afile) + afile.close() + + afile = open(outputDir/'mdh_out2.pkl', 'wb') + pickle.dump(mdh_out2, afile) + afile.close() + + afile = open(outputDir/'mrl_out2.pkl', 'wb') + pickle.dump(mrl_out2, afile) + afile.close() + + afile = open(outputDir/'bs2par_out2.pkl', 'wb') + pickle.dump(bs2par_out2, afile) + afile.close() + + afile = open(outputDir/'zo_out2.pkl', 'wb') + pickle.dump(zo_out2, afile) + afile.close() + + afile = open(outputDir/'zd_out2.pkl', 'wb') + pickle.dump(zd_out2, afile) + afile.close() + + afile = open(outputDir/'mean_ht_out2.pkl', 'wb') + pickle.dump(mean_ht_out2, afile) + afile.close() + + afile = open(outputDir/'std_ht_out2.pkl', 'wb') + pickle.dump(std_ht_out2, afile) + afile.close() + + afile = open(outputDir/'awmh_out2.pkl', 'wb') + pickle.dump(awmh_out2, afile) + afile.close() + + afile = open(outputDir/'h2w_out2.pkl', 'wb') + pickle.dump(h2w_out2, afile) + afile.close() + + afile = open(outputDir/'car_out2.pkl', 'wb') + pickle.dump(car_out2, afile) + afile.close() \ No newline at end of file From 0ed042751757e124708737e90e90d0540e76c6ba Mon Sep 17 00:00:00 2001 From: lg6 Date: Wed, 9 Mar 2022 18:09:07 -0500 Subject: [PATCH 21/35] Removed files From 6ccb29993cd6c9678f2d03f0a2418587295b7faf Mon Sep 17 00:00:00 2001 From: lg6 Date: Mon, 11 Apr 2022 13:32:53 -0400 Subject: [PATCH 22/35] added Parameter Definitions --- NATURF/Parameter_Definitions.py | 1331 +++++++++++++++++++++++++++++++ 1 file changed, 1331 insertions(+) create mode 100644 NATURF/Parameter_Definitions.py diff --git a/NATURF/Parameter_Definitions.py b/NATURF/Parameter_Definitions.py new file mode 100644 index 00000000000..8642bb1eb09 --- /dev/null +++ b/NATURF/Parameter_Definitions.py @@ -0,0 +1,1331 @@ +import math +from numpy import array, zeros, uint8, uint16, where, empty, sum, unique, rint +from skimage.draw import polygon +from scipy import ndimage + +def get_pixels2_c(IMAGE_SIZE_X, IMAGE_SIZE_Y, x1, y1, x2, y2): + mx = (float(y1) - float(y2)) / (float(x1) - float(x2) + 0.0000000000000000000000000000001) + yint = float(y1) - (mx * float(x1)) + px_func = [] + py_func = [] + + if abs(x1 - x2) > abs(y1 - y2) or abs(x1 - x2) == abs(y1 - y2): + if x1 > x2: + for i in range(x2, x1 + 1): + yp = int(round(mx * i + yint)) + + bx = i + by = yp + + if 0 <= bx < IMAGE_SIZE_Y and 0 <= by < IMAGE_SIZE_X: + px_func.append(i) + py_func.append(yp) + if x1 < x2: + for i in range(x1, x2 + 1): + yp = int(round(mx * i + yint)) + + bx = i + by = yp + + if 0 <= bx < IMAGE_SIZE_Y and 0 <= by < IMAGE_SIZE_X: + px_func.append(i) + py_func.append(yp) + + if abs(x1 - x2) < abs(y1 - y2): + if y1 > y2: + for i in range(y2, y1 + 1): + xp = int(round((i - yint) / mx)) + + bx = xp + by = i + + if 0 <= bx < IMAGE_SIZE_Y and 0 <= by < IMAGE_SIZE_X: + px_func.append(xp) + py_func.append(i) + if y1 < y2: + for i in range(y1, y2 + 1): + xp = int(round((i - yint) / mx)) + + bx = xp + by = i + + if 0 <= bx < IMAGE_SIZE_Y and 0 <= by < IMAGE_SIZE_X: + px_func.append(xp) + py_func.append(i) + + return px_func, py_func + +def inter4p(x1, y1, x2, y2, rad1): + + dx = x1-x2 + dy = y1-y2 + dist = math.sqrt(dx*dx + dy*dy) + dx /= (dist + 0.00000000000000000000001) + dy /= (dist + 0.00000000000000000000001) + + if y1 > y2: + x1r = x1 - rad1*dy + y1r = y1 + rad1*dx + else: + x1r = x1 + rad1*dy + y1r = y1 - rad1*dx + + return x1r, y1r + + +def inter4n(x1, y1, x2, y2, rad1): + + dx = x1-x2 + dy = y1-y2 + dist = math.sqrt(dx*dx + dy*dy) + dx /= (dist + 0.00000000000000000000001) + dy /= (dist + 0.00000000000000000000001) + + if y1 > y2: + x1l = x1 + rad1*dy + y1l = y1 - rad1*dx + else: + x1l = x1 - rad1*dy + y1l = y1 + rad1*dx + + return x1l, y1l + + +def ang2lines(linea, lineb): + # returns [0, 360] + + va = [(linea[0][0]-linea[1][0]), (linea[0][1]-linea[1][1])] + vb = [(lineb[0][0]-lineb[1][0]), (lineb[0][1]-lineb[1][1])] + + angle = math.atan2(va[1], va[0]) - math.atan2(vb[1], vb[0]) + angle = angle * 360 / (2 * math.pi) + + if angle < 0: + angle += 360 + + return angle + + +def ang2points(x1, y1, x2, y2): + dx = x2 - x1 + dy = y2 - y1 + + r = math.atan2(dy, dx) + degr = math.degrees(r) + + if degr < 0: + degr += 360 + + return degr + + +def get_cents_hts(IMAGE_SIZE_X, IMAGE_SIZE_Y, layer2, ids, PIXEL_SIZE, height_field): + cents1 = {} + heights = {} + areas = {} + i2arr = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint8) + cnt = 1 + + layer2.ResetReading() + feature_buil = layer2.GetNextFeature() + + while feature_buil: + ht = feature_buil.GetFieldAsString(height_field) + + if ht != '': + ht = float(ht) + # print cnt + heights[cnt] = ht + + geom = feature_buil.GetGeometryRef() + ring = geom.GetGeometryRef(0) + numpoints = ring.GetPointCount() + + if numpoints != 0: + + cent = geom.Centroid() + centx = cent.GetX() + centy = cent.GetY() + + centx = float(centx) + centy = float(centy) + + cents1[cnt] = [centx, centy] + + builarea = 0 + + i2arr.fill(0) + if len(ids[ids == cnt]) != 0: + i2arr[ids == cnt] = 1 + builarea = sum(i2arr) * PIXEL_SIZE**2 + + areas[cnt] = builarea + + cnt += 1 + + feature_buil.Destroy() + feature_buil = layer2.GetNextFeature() + + return cents1, heights, areas + + +def avg_building_dist(IMAGE_SIZE_X, IMAGE_SIZE_Y, layer2, ids, PIXEL_SIZE, height_field, heights, ars, cents): + + i2arr = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint8) + dils = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint8) + narr = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint8) + struct = ndimage.generate_binary_structure(2, 2) + rad = 100 + sumareas = 0 + cntr = 1 + parea = 0 + avgns = 0 + avgew = 0 + + cns_out = {} + cew_out = {} + meanht_out = [] + stdht_out = [] + awmh1_out = [] + pareas = {} + + layer2.ResetReading() + feature_buil = layer2.GetNextFeature() + + while feature_buil: + ht = feature_buil.GetFieldAsString(height_field) + + avgns = 0 + avgew = 0 + + sumarhts = 0 + sumareas2 = 0 + + hts1 = [] + + if ht != '': + + geomb = feature_buil.GetGeometryRef() + ring = geomb.GetGeometryRef(0) + numpoints = ring.GetPointCount() + + if numpoints != 0: + + i2arr.fill(0) + dils.fill(0) + narr.fill(0) + if len(ids[ids == cntr]) != 0: + i2arr[ids == cntr] = 1 + builarea = sum(i2arr) * PIXEL_SIZE**2 + i2arr = ndimage.binary_dilation(i2arr, structure=struct, iterations=rad).astype(i2arr.dtype) + # dilarea = sum(i2arr) * PIXEL_SIZE**2 + dibuils = unique(ids[where(i2arr == 1)]) + + sumareas += builarea + + # print dibuils + + if len(dibuils) != 0: + currcx = cents[cntr][0] # current building centroid + currcy = cents[cntr][1] + # print currcx, currcy + + te, tn, ts, tw = 0., 0., 0., 0. + ce, cn, cs, cw = 0., 0., 0., 0. + + for asdf in dibuils: + if asdf != 0 and asdf in heights: + hts1.append(heights[asdf]) + dils[(ids == asdf) & (i2arr == 1)] = 1 + + sumarhts += ars[asdf] * heights[asdf] + sumareas2 += ars[asdf] + + if asdf != cntr: + cx = cents[asdf][0] + cy = cents[asdf][1] + + d = math.hypot((currcx - cx), (currcy - cy)) + angle = ang2points(currcx, currcy, cx, cy) + + if (315 <= angle <= 360 or 0 <= angle < 45) and d != 0: # east + te += d + ce += 1 + + if 135 <= angle < 225 and d != 0: # west + tw += d + cw += 1 + + if 45 <= angle < 135 and d != 0: # north + tn += d + cn += 1 + + if 225 <= angle < 315 and d != 0: # south + ts += d + cs += 1 + + if cn != 0 or cs != 0: + avgns = (tn + ts) / (cn + cs) + else: + avgns = 0 + + if ce != 0 or cw != 0: + avgew = (te + tw) / (ce + cw) + else: + avgew = 0 + + # print avgns, avgew + + narr[(dils == 1) & (i2arr == 1)] = 1 + parea = sum(narr) * PIXEL_SIZE**2 + + pareas[cntr] = [ht, parea] # ####################################################### + + # if parea > dilarea: + # print parea, dilarea + + if len(hts1) != 0: + hts1 = array(hts1) + meanht_out.append(hts1.mean()) + stdht_out.append(hts1.std()) + else: + meanht_out.append(ht) + stdht_out.append(ht) + + cns_out[cntr] = avgns + cew_out[cntr] = avgew + + if sumareas2 != 0: + awmh1_out.append(sumarhts / sumareas2) + else: + awmh1_out.append(0) + + cntr += 1 + + feature_buil.Destroy() + feature_buil = layer2.GetNextFeature() + + avgsa = sumareas / cntr # sum of all of the surface areas in shapefile (used in a parameter) + + return cns_out, cew_out, avgsa, pareas, meanht_out, stdht_out, awmh1_out + + +def parameters1(IMAGE_SIZE_X, IMAGE_SIZE_Y, layer2, ids, PIXEL_SIZE, height_field, direc, bid, newbarea, cents_ns, cents_ew, avgsa): # if bid == 0, loops through all of the buildings + + i2arr = zeros((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint8) + struct = ndimage.generate_binary_structure(2, 2) + rad = 100 + + dist = -1 + builarea = 0 + dilarea = 0 + + sumarhts = 0 + sumareas = 0 + counter = 1 + + fad_out_inc = [] + builfrac_out_inc = [] + fai_out_inc = [] + rdh_out_inc = [] + rrl_out_inc = [] + mdh_out_inc = [] + mrl_out_inc = [] + bs2par_out_inc = [] + zo_out_inc = [] + zd_out_inc = [] + car_out_inc = [] + + if bid != 0: + layer2.ResetReading() + feature_buil = layer2.GetNextFeature() + while feature_buil: + ht = feature_buil.GetFieldAsString(height_field) + + fad_out = [] + builfrac_out = [] + fai_out = [] + rdh_out = [] + rrl_out = [] + mdh_out = [] + mrl_out = [] + bs2par_out = [] + zo_out = [] + zd_out = [] + + if ht != '': + ht = float(ht) + for asdf in range(5, 75, 5): + if (ht - asdf) > 0: + nht = 5 + elif (ht - asdf + 5) > 0: + nht = ht - asdf + 5 + else: + nht = 0.000000000000000001 + + zh = ht + if zh == 0: + zh = 0.000000000000000001 + + zo = 0.1 * zh + zd = 0.67 * zh + + zo_out.append(zo) + zd_out.append(zd) + + fads = [] + builfracs = [] + fais = [] + rdhs = [] + rrls = [] + mdhs = [] + mrls = [] + bs2pars = [] + + if bid == counter: + + geomb = feature_buil.GetGeometryRef() + ring = geomb.GetGeometryRef(0) + numpoints = ring.GetPointCount() + + if numpoints != 0: + + i2arr.fill(0) + builarea = 0 + dilarea = 0 + + if len(ids[ids == bid]) != 0: + i2arr[ids == bid] = 1 + builarea = sum(i2arr) * PIXEL_SIZE**2 + i2arr = ndimage.binary_dilation(i2arr, structure=struct, iterations=rad).astype(i2arr.dtype) + # i2arr[(ids != bid) & (iarr == 127)] = 0 + dilarea = sum(i2arr) * PIXEL_SIZE**2 + + sumarhts += builarea * nht + sumareas += builarea + + nx, ny, nz = ring.GetPoint(0) + + parrxc = [[nx]] + parryc = [[ny]] + + for bi in range(1, ring.GetPointCount()): + bpt = ring.GetPoint(bi) + + parrxc.append([bpt[0]]) + parryc.append([bpt[1]]) + + parrxc = array(parrxc) + parryc = array(parryc) + + for na in range(0, len(parrxc)-1): + p1x = parrxc[na] + p1y = parryc[na] + + p2x = parrxc[na+1] + p2y = parryc[na+1] + + if (p1x, p1y) != (p2x, p2y): + + perpx0 = parrxc[na] + + if parryc[na] + 1 < IMAGE_SIZE_X: + perpy0 = parryc[na] + 1 + else: + perpy0 = IMAGE_SIZE_X + + line1 = [[p1x, p1y], [p2x, p2y]] + line0deg = [[p1x, p1y], [perpx0, perpy0]] + + deg = ang2lines(line1, line0deg) + dist = math.hypot((p2x - p1x), (p2y - p1y)) + breadth = dist + + if breadth >= 1: + + # if 315 <= deg <= 360 or 0 <= deg < 45: + # direc2 = 'East' + # if 45 <= deg < 135: + # direc2 = 'South' + # if 135 <= deg < 225: + # direc2 = 'West' + # if 225 <= deg < 315: + # direc2 = 'North' + # + # if prevdir == direc2: + # dist += prevdist + + if (direc.lower() == 'east') and (315 <= deg <= 360 or 0 <= deg < 45): + if ((dist / 10) - 1) > 0: + wallarea = dist * nht + + if dilarea == 0: + break + + fad = wallarea / dilarea + + + if newbarea[counter][0] > ht: + builfrac = newbarea[counter][1] / dilarea + else: + builfrac = 0 + + if (cents_ns[counter] * cents_ew[counter]) != 0: + fai = (breadth * zh) / (cents_ns[counter] * cents_ew[counter]) + rdh = zh * (1 - (1 - math.exp(-math.sqrt(7.5 * 2 * fai))/math.sqrt(7.5 * 2 * fai))) + rrl = zh * ((1 - rdh) * math.exp(-0.4 * (1 / math.sqrt(0.003 + 0.3 * fai)) - 0.193)) + else: + fai = 0 + rdh = 0 + rrl = 0 + + mdh = zh * (1 + (1 / 3.59 ** builfrac) * (builfrac - 1)) + zxcv = 0.5 * (1.12 / 0.4 ** 2) * (1 - rdh) * (wallarea / avgsa) + + if zxcv >= 0: + mrl = zh * (1 - rdh) * math.exp(-1 / (math.sqrt(0.5 * (1.12 / 0.4 ** 2) * + (1 - rdh) * (wallarea / avgsa)))) + else: + mrl = 0 + + bs2par = newbarea[counter][1] / newbarea[counter][1] # currently always 1 + + fads.append(fad) + builfracs.append(builfrac) + fais.append(fai) + rdhs.append(rdh) + rrls.append(rrl) + mdhs.append(mdh) + mrls.append(mrl) + bs2pars.append(bs2par) + + # print bid, 'East', wallarea, dilarea, fad, builfrac, fai + + if (direc.lower() == 'north') and (45 <= deg < 135): + if ((dist / 10) - 1) > 0: + wallarea = dist * nht + + if dilarea == 0: + break + + fad = wallarea / dilarea + + if newbarea[counter][0] > ht: + builfrac = newbarea[counter][1] / dilarea + else: + builfrac = 0 + + if (cents_ns[counter] * cents_ew[counter]) != 0: + fai = (breadth * zh) / (cents_ns[counter] * cents_ew[counter]) + rdh = zh * (1 - (1 - math.exp(-math.sqrt(7.5 * 2 * fai))/math.sqrt(7.5 * 2 * fai))) + rrl = zh * ((1 - rdh) * math.exp(-0.4 * (1 / math.sqrt(0.003 + 0.3 * fai)) - 0.193)) + else: + fai = 0 + rdh = 0 + rrl = 0 + + mdh = zh * (1 + (1 / 3.59 ** builfrac) * (builfrac - 1)) + zxcv = 0.5 * (1.12 / 0.4 ** 2) * (1 - rdh) * (wallarea / avgsa) + + if zxcv >= 0: + mrl = zh * (1 - rdh) * math.exp(-1 / (math.sqrt(0.5 * (1.12 / 0.4 ** 2) * + (1 - rdh) * (wallarea / avgsa)))) + else: + mrl = 0 + + bs2par = newbarea[counter][1] / newbarea[counter][1] # currently always 1 + + fads.append(fad) + builfracs.append(builfrac) + fais.append(fai) + rdhs.append(rdh) + rrls.append(rrl) + mdhs.append(mdh) + mrls.append(mrl) + bs2pars.append(bs2par) + + # print bid, 'North', wallarea, dilarea, fad, builfrac, fai + + if (direc.lower() == 'west') and (135 <= deg < 225): + if ((dist / 10) - 1) > 0: + wallarea = dist * nht + + if dilarea == 0: + break + + fad = wallarea / dilarea + + if newbarea[counter][0] > ht: + builfrac = newbarea[counter][1] / dilarea + else: + builfrac = 0 + + if (cents_ns[counter] * cents_ew[counter]) != 0: + fai = (breadth * zh) / (cents_ns[counter] * cents_ew[counter]) + rdh = zh * (1 - (1 - math.exp(-math.sqrt(7.5 * 2 * fai))/math.sqrt(7.5 * 2 * fai))) + rrl = zh * ((1 - rdh) * math.exp(-0.4 * (1 / math.sqrt(0.003 + 0.3 * fai)) - 0.193)) + else: + fai = 0 + rdh = 0 + rrl = 0 + + mdh = zh * (1 + (1 / 3.59 ** builfrac) * (builfrac - 1)) + zxcv = 0.5 * (1.12 / 0.4 ** 2) * (1 - rdh) * (wallarea / avgsa) + + if zxcv >= 0: + mrl = zh * (1 - rdh) * math.exp(-1 / (math.sqrt(0.5 * (1.12 / 0.4 ** 2) * + (1 - rdh) * (wallarea / avgsa)))) + else: + mrl = 0 + + bs2par = newbarea[counter][1] / newbarea[counter][1] # currently always 1 + + fads.append(fad) + builfracs.append(builfrac) + fais.append(fai) + rdhs.append(rdh) + rrls.append(rrl) + mdhs.append(mdh) + mrls.append(mrl) + bs2pars.append(bs2par) + + # print bid, 'West', wallarea, dilarea, fad, builfrac, fai + + if (direc.lower() == 'south') and (225 <= deg < 315): + if ((dist / 10) - 1) > 0: + wallarea = dist * nht + + if dilarea == 0: + break + + fad = wallarea / dilarea + + if newbarea[counter][0] > ht: + builfrac = newbarea[counter][1] / dilarea + else: + builfrac = 0 + + if (cents_ns[counter] * cents_ew[counter]) != 0: + fai = (breadth * zh) / (cents_ns[counter] * cents_ew[counter]) + rdh = zh * (1 - (1 - math.exp(-math.sqrt(7.5 * 2 * fai))/math.sqrt(7.5 * 2 * fai))) + rrl = zh * ((1 - rdh) * math.exp(-0.4 * (1 / math.sqrt(0.003 + 0.3 * fai)) - 0.193)) + else: + fai = 0 + rdh = 0 + rrl = 0 + + mdh = zh * (1 + (1 / 3.59 ** builfrac) * (builfrac - 1)) + zxcv = 0.5 * (1.12 / 0.4 ** 2) * (1 - rdh) * (wallarea / avgsa) + + if zxcv >= 0: + mrl = zh * (1 - rdh) * math.exp(-1 / (math.sqrt(0.5 * (1.12 / 0.4 ** 2) * + (1 - rdh) * (wallarea / avgsa)))) + else: + mrl = 0 + + bs2par = newbarea[counter][1] / newbarea[counter][1] # currently always 1 + + fads.append(fad) + builfracs.append(builfrac) + fais.append(fai) + rdhs.append(rdh) + rrls.append(rrl) + mdhs.append(mdh) + mrls.append(mrl) + bs2pars.append(bs2par) + + # print bid, 'South', wallarea, dilarea, fad, builfrac, fai + + # prevdir = direc2 + # prevdist = dist + + fad_out.append(fads) + builfrac_out.append(builfracs) + fai_out.append(fais) + rdh_out.append(rdhs) + rrl_out.append(rrls) + mdh_out.append(mdhs) + mrl_out.append(mrls) + bs2par_out.append(bs2pars) + + fad_out_inc.append(fad_out) + builfrac_out_inc.append(builfrac_out) + fai_out_inc.append(fai_out) + rdh_out_inc.append(rdh_out) + rrl_out_inc.append(rrl_out) + mdh_out_inc.append(mdh_out) + mrl_out_inc.append(mrl_out) + bs2par_out_inc.append(bs2par_out) + zo_out_inc.append(zo_out) + zd_out_inc.append(zd_out) + + counter += 1 + + feature_buil.Destroy() + feature_buil = layer2.GetNextFeature() + + else: + layer2.ResetReading() + feature_buil = layer2.GetNextFeature() + while feature_buil: + ht = feature_buil.GetFieldAsString(height_field) + + if ht != '': + ht = float(ht) + + fad_out = {'n': [], 'w': [], 's': [], 'e': []} + fai_out = {'n': [], 'w': [], 's': [], 'e': []} + rdh_out = {'n': [], 'w': [], 's': [], 'e': []} + rrl_out = {'n': [], 'w': [], 's': [], 'e': []} + mrl_out = {'n': [], 'w': [], 's': [], 'e': []} + + builfrac_out = [] + mdh_out = [] + bs2par_out = [] + zo_out = [] + zd_out = [] + + edist = 0 + wdist = 0 + sdist = 0 + + for asdf in range(0, 75, 5): + if (ht - asdf) >= 5: + nht = 5 + elif 0 < (ht - asdf) < 5: + nht = ht - asdf + else: + nht = 0.00000000000000000000000000000001 + + # print ht, asdf, nht + + zh = ht + if zh == 0: + zh = 0.000000000000000001 + + zo = 0.1 * zh + zd = 0.67 * zh + + zo_out.append(zo) + zd_out.append(zd) + + fads = [] + fade = [] + fadn = [] + fadw = [] + + fais = [] + fain = [] + faie = [] + faiw = [] + + rdhs = [] + rdhn = [] + rdhe = [] + rdhw = [] + + rrls = [] + rrln = [] + rrle = [] + rrlw = [] + + mrls = [] + mrln = [] + mrle = [] + mrlw = [] + + builfracs = [] + mdhs = [] + bs2pars = [] + + geomb = feature_buil.GetGeometryRef() + ring = geomb.GetGeometryRef(0) + numpoints = ring.GetPointCount() + + if numpoints != 0: + + # print unique(ids) # len(ids[ids == counter]) + + i2arr.fill(0) + builarea = 0 + dilarea = 0 + # print counter + if len(ids[ids == counter]) != 0: + i2arr[ids == counter] = 1 + builarea = sum(i2arr) * PIXEL_SIZE**2 + + # i2arr[(ids != counter) & (iarr == 127)] = 0 + dilarea = sum(i2arr) * PIXEL_SIZE**2 + + sumarhts += builarea * nht + sumareas += builarea + + if dilarea == 0: + dilarea = builarea + + + nx, ny, nz = ring.GetPoint(0) + + parrxc = [[nx]] + parryc = [[ny]] + + for bi in range(1, ring.GetPointCount()): + bpt = ring.GetPoint(bi) + + parrxc.append([bpt[0]]) + parryc.append([bpt[1]]) + + parrxc = array(parrxc) + parryc = array(parryc) + + for na in range(0, len(parrxc)-1): + p1x = parrxc[na] + p1y = parryc[na] + + p2x = parrxc[na+1] + p2y = parryc[na+1] + + if (p1x, p1y) != (p2x, p2y): + + perpx0 = parrxc[na] + + if parryc[na] + 1 < IMAGE_SIZE_X: + perpy0 = parryc[na] + 1 + else: + perpy0 = IMAGE_SIZE_X + + line1 = [[p1x, p1y], [p2x, p2y]] + line0deg = [[p1x, p1y], [perpx0, perpy0]] + + deg = ang2lines(line1, line0deg) + + dist = math.sqrt((p2x - p1x)**2 + (p2y - p1y)**2) + + breadth = dist + + if breadth >= 1: + + # if 315 <= deg <= 360 or 0 <= deg < 45: + # direc2 = 'East' + # if 45 <= deg < 135: + # direc2 = 'South' + # if 135 <= deg < 225: + # direc2 = 'West' + # if 225 <= deg < 315: + # direc2 = 'North' + # + # if prevdir == direc2: + # dist += prevdist + + if 315 <= deg <= 360 or 0 <= deg < 45: + if ((dist / 10) - 1) > 0: + edist = dist + wallarea = dist * nht + + if dilarea == 0: + break + + fad = wallarea / dilarea + + if (cents_ns[counter] * cents_ew[counter]) != 0: + fai = (breadth * zh) / (cents_ns[counter] * cents_ew[counter]) + rdh = zh * (1 - (1 - math.exp(-math.sqrt(7.5 * 2 * fai))/math.sqrt(7.5 * 2 * fai))) + rrl = zh * (1 - rdh) * math.exp(-0.4 * (1 / math.sqrt(0.003 + 0.3 * fai)) - 0.193) + else: + fai = 0 + rdh = 0 + rrl = 0 + + zxcv = 0.5 * (1.12 / 0.4 ** 2) * (1 - rdh) * (wallarea / avgsa) + + if zxcv >= 0: + mrl = zh * (1 - rdh) * math.exp(-1 / (math.sqrt(0.5 * (1.12 / 0.4 ** 2) * + (1 - rdh) * (wallarea / avgsa)))) + else: + mrl = 0 + + if rrl > 3 or rrl < 0: + rrl = 0 + if rdh > 3 or rdh < 0: + rdh = 0 + + faie.append(fai) + rdhe.append(rdh) + rrle.append(rrl) + mrle.append(mrl) + + if float(fad) < 0.00000000000000000001: + fade.append(0) + else: + fade.append(fad) + + if 45 <= deg < 135: + if ((dist / 10) - 1) > 0: + wallarea = dist * nht + if asdf == 0: + dilarea = 10000 + + if dilarea == 0: + break + + fad = wallarea / dilarea + + if (cents_ns[counter] * cents_ew[counter]) != 0: + fai = (breadth * zh) / (cents_ns[counter] * cents_ew[counter]) + rdh = zh * (1 - (1 - math.exp(-math.sqrt(7.5 * 2 * fai))/math.sqrt(7.5 * 2 * fai))) + rrl = zh * (1 - rdh) * math.exp(-0.4 * (1 / math.sqrt(0.003 + 0.3 * fai)) - 0.193) + else: + fai = 0 + rdh = 0 + rrl = 0 + + zxcv = 0.5 * (1.12 / 0.4 ** 2) * (1 - rdh) * (wallarea / avgsa) + + if zxcv >= 0: + mrl = zh * (1 - rdh) * math.exp(-1 / (math.sqrt(0.5 * (1.12 / 0.4 ** 2) * + (1 - rdh) * (wallarea / avgsa)))) + else: + mrl = 0 + + if rrl > 3 or rrl < 0: + rrl = 0 + if rdh > 3 or rdh < 0: + rdh = 0 + + fain.append(fai) + rdhn.append(rdh) + rrln.append(rrl) + mrln.append(mrl) + + if float(fad) < 0.00000000000000000001: + fadn.append(0) + else: + fadn.append(fad) + + if 135 <= deg < 225: + if ((dist / 10) - 1) > 0: + wdist = dist + wallarea = dist * nht + + if dilarea == 0: + break + + fad = wallarea / dilarea + + if (cents_ns[counter] * cents_ew[counter]) != 0: + fai = (breadth * zh) / (cents_ns[counter] * cents_ew[counter]) + rdh = zh * (1 - (1 - math.exp(-math.sqrt(7.5 * 2 * fai))/math.sqrt(7.5 * 2 * fai))) + rrl = zh * (1 - rdh) * math.exp(-0.4 * (1 / math.sqrt(0.003 + 0.3 * fai)) - 0.193) + else: + fai = 0 + rdh = 0 + rrl = 0 + + zxcv = 0.5 * (1.12 / 0.4 ** 2) * (1 - rdh) * (wallarea / avgsa) + + if zxcv >= 0: + mrl = zh * (1 - rdh) * math.exp(-1 / (math.sqrt(0.5 * (1.12 / 0.4 ** 2) * + (1 - rdh) * (wallarea / avgsa)))) + else: + mrl = 0 + + if rrl > 3 or rrl < 0: + rrl = 0 + if rdh > 3 or rdh < 0: + rdh = 0 + + faiw.append(fai) + rdhw.append(rdh) + rrlw.append(rrl) + mrlw.append(mrl) + + if float(fad) < 0.00000000000000000001: + fadw.append(0) + else: + fadw.append(fad) + + if (direc.lower() == 'south') and (225 <= deg < 315): + if ((dist / 10) - 1) > 0: + sdist = dist + wallarea = dist * nht + + if dilarea == 0: + break + + fad = wallarea / dilarea + + + # print newbarea[counter][0], float(asdf), float(newbarea[counter][0]) > float(asdf) + + if float(newbarea[counter][0]) > float(asdf): + builfrac = newbarea[counter][1] / dilarea + else: + builfrac = 0 + + if (cents_ns[counter] * cents_ew[counter]) != 0: + fai = (breadth * zh) / (cents_ns[counter] * cents_ew[counter]) + rdh = zh * (1 - (1 - math.exp(-math.sqrt(7.5 * 2 * fai))/math.sqrt(7.5 * 2 * fai))) + rrl = zh * (1 - rdh) * math.exp(-0.4 * (1 / math.sqrt(0.003 + 0.3 * fai)) - 0.193) + else: + fai = 0 + rdh = 0 + rrl = 0 + + mdh = zh * (1 + (1 / 3.59 ** builfrac) * (builfrac - 1)) + zxcv = 0.5 * (1.12 / 0.4 ** 2) * (1 - rdh) * (wallarea / avgsa) + + if zxcv >= 0: + mrl = zh * (1 - rdh) * math.exp(-1 / (math.sqrt(0.5 * (1.12 / 0.4 ** 2) * + (1 - rdh) * (wallarea / avgsa)))) + else: + mrl = 0 + + bs2par = newbarea[counter][1] / newbarea[counter][1] # currently always 1 + + if rrl > 3 or rrl < 0: + rrl = 0 + if rdh > 3 or rdh < 0: + rdh = 0 + + if float(fad) < 0.00000000000000000001: + fads.append(0) + else: + fads.append(fad) + builfracs.append(builfrac) + fais.append(fai) + rdhs.append(rdh) + rrls.append(rrl) + mdhs.append(mdh) + mrls.append(mrl) + bs2pars.append(bs2par) + + + fad_out['n'].append(fadn) + fad_out['w'].append(fadw) + fad_out['s'].append(fads) + fad_out['e'].append(fade) + + fai_out['n'].append(fain) + fai_out['w'].append(faiw) + fai_out['s'].append(fais) + fai_out['e'].append(faie) + + rdh_out['n'].append(rdhn) + rdh_out['w'].append(rdhw) + rdh_out['s'].append(rdhs) + rdh_out['e'].append(rdhe) + + rrl_out['n'].append(rrln) + rrl_out['w'].append(rrlw) + rrl_out['s'].append(rrls) + rrl_out['e'].append(rrle) + + mrl_out['n'].append(mrln) + mrl_out['w'].append(mrlw) + mrl_out['s'].append(mrls) + mrl_out['e'].append(mrle) + + builfrac_out.append(builfracs) + mdh_out.append(mdhs) + bs2par_out.append(bs2pars) + + # incremental arrays # + fad_out_inc.append(fad_out) + builfrac_out_inc.append(builfrac_out) + fai_out_inc.append(fai_out) + rdh_out_inc.append(rdh_out) + rrl_out_inc.append(rrl_out) + mdh_out_inc.append(mdh_out) + mrl_out_inc.append(mrl_out) + bs2par_out_inc.append(bs2par_out) + zo_out_inc.append(zo_out) + zd_out_inc.append(zd_out) + + # print sdist, edist, wdist + + if edist != 0: + car_out_inc.append(float(sdist) / float(edist)) + elif edist == 0 and wdist != 0: + car_out_inc.append(float(sdist) / float(wdist)) + else: + car_out_inc.append(1) + + counter += 1 + + feature_buil.Destroy() + feature_buil = layer2.GetNextFeature() + + awmh = sumarhts / sumareas + + return fad_out_inc, builfrac_out_inc, fai_out_inc, rdh_out_inc, rrl_out_inc, mdh_out_inc, mrl_out_inc, \ + bs2par_out_inc, zo_out_inc, zd_out_inc, car_out_inc + + +def h2w(IMAGE_SIZE_X, IMAGE_SIZE_Y, layer2, xOrigin, yOrigin, pixelWidth, pixelHeight, start_x_p, start_y_p, PIXEL_SIZE, height_field, id_field): + names = [] + heights = [] + widths = [] + cnt = 1 + idsa = [] + ratios = [] + + buils = empty((IMAGE_SIZE_X, IMAGE_SIZE_Y), dtype=uint16) + buils.fill(255) + + layer2.ResetReading() + feature_buil = layer2.GetNextFeature() + + while feature_buil: + geomb = feature_buil.GetGeometryRef() + ring = geomb.GetGeometryRef(0) + numpoints = ring.GetPointCount() + + if numpoints != 0: + nx, ny, nz = ring.GetPoint(0) + + xOffset = int((nx - xOrigin) / pixelWidth) + yOffset = int((ny - yOrigin) / pixelHeight) + + parr = [[xOffset, yOffset]] + parrx = [[xOffset]] + parry = [[yOffset]] + + for bi in range(1, ring.GetPointCount()): + bpt = ring.GetPoint(bi) + + xoff = int((bpt[0] - xOrigin) / pixelWidth) + yoff = int((bpt[1] - yOrigin) / pixelHeight) + + parr.append([xoff, yoff]) + parrx.append([xoff]) + parry.append([yoff]) + + parrx[:] = [x[0] - start_x_p for x in parrx] + parry[:] = [y[0] - start_y_p for y in parry] + + parrx = array(parrx) + parry = array(parry) + rr, cc = polygon(parrx, parry, [IMAGE_SIZE_Y, IMAGE_SIZE_X]) + + buils[cc, rr] = 127 + + feature_buil.Destroy() + feature_buil = layer2.GetNextFeature() + + layer2.ResetReading() + feature_buil = layer2.GetNextFeature() + + while feature_buil: + ht = feature_buil.GetFieldAsString(height_field) + bid = feature_buil.GetFieldAsString(id_field) + + if ht != '': + idsa.append(cnt) + + cntr2 = 0 + summ2 = 0 + aveg2 = 0 + aveg1 = 0 + + geomb = feature_buil.GetGeometryRef() + ring = geomb.GetGeometryRef(0) + numpoints = ring.GetPointCount() + + if numpoints != 0: + cntr1 = 0 + summ1 = 0 + + nx, ny, nz = ring.GetPoint(0) + + xOffset = int((nx - xOrigin) / pixelWidth) + yOffset = int((ny - yOrigin) / pixelHeight) + + parr = [[xOffset, yOffset]] + parrx = [[xOffset]] + parry = [[yOffset]] + + parrxc = [[nx]] + parryc = [[ny]] + + for bi in range(1, ring.GetPointCount()): + bpt = ring.GetPoint(bi) + + xoff = int((bpt[0] - xOrigin) / pixelWidth) + yoff = int((bpt[1] - yOrigin) / pixelHeight) + + parr.append([xoff, yoff]) + parrx.append([xoff]) + parry.append([yoff]) + + parrxc.append([bpt[0]]) + parryc.append([bpt[1]]) + + parrx[:] = [x[0] - start_x_p for x in parrx] + parry[:] = [y[0] - start_y_p for y in parry] + + parrx = array(parrx) + parry = array(parry) + + for na in range(0, len(parrx)-1): + p1x = parrx[na] + p1y = parry[na] + + p2x = parrx[na+1] + p2y = parry[na+1] + + xarr, yarr = get_pixels2_c(IMAGE_SIZE_X, IMAGE_SIZE_Y, int(p1x), int(p1y), int(p2x), int(p2y)) + + if ((len(xarr)/20)-1) > 0: + + for nb in range(0, int(rint((len(xarr)/20.)-1))): + + tempa = 0 + x1 = xarr[(nb*20)+1] + y1 = yarr[(nb*20)+1] + + x2 = xarr[((nb+1)*20)+1] + y2 = yarr[((nb+1)*20)+1] + + for tg in range(1, 200): + perp1x, perp1y = inter4p(x1, y1, x2, y2, tg) + + if perp1x < 0: + perp1x = 0 + if perp1y < 0: + perp1y = 0 + + if int(round(perp1x)) >= IMAGE_SIZE_Y: + perp1x = IMAGE_SIZE_Y - 1 + if int(round(perp1y)) >= IMAGE_SIZE_X: + perp1y = IMAGE_SIZE_X - 1 + + if buils[int(round(perp1y)), int(round(perp1x))] == 127: + tempa = tg + if tempa > 4: + # print 'p' + break + else: + tempa = tg + + if tempa == 5: + for tg in range(1, 200): + perp1x, perp1y = inter4n(p1x, p1y, p2x, p2y, tg) + + if perp1x < 0: + perp1x = 0 + if perp1y < 0: + perp1y = 0 + + if int(round(perp1x)) >= IMAGE_SIZE_Y: + perp1x = IMAGE_SIZE_Y - 1 + if int(round(perp1y)) >= IMAGE_SIZE_X: + perp1y = IMAGE_SIZE_X - 1 + + if buils[int(round(perp1y)), int(round(perp1x))] == 127: + tempa = tg + if tempa > 4: + # print 'n' + break + else: + tempa = tg + + # print tempa + + if tempa != 5 and tempa != 199: + cntr1 += 1 + summ1 += tempa + # print tempa + + if cntr1 != 0: + aveg1 = summ1 / cntr1 + # print aveg1 + else: + aveg1 = 0 + elif len(xarr) != 0: + tempa = 0 + x1 = xarr[1] + y1 = yarr[1] + + x2 = xarr[1] + y2 = yarr[1] + + for tg in range(1, 200): + perp1x, perp1y = inter4p(x1, y1, x2, y2, tg) + + if perp1x < 0: + perp1x = 0 + if perp1y < 0: + perp1y = 0 + + if int(round(perp1x)) >= IMAGE_SIZE_Y: + perp1x = IMAGE_SIZE_Y - 1 + if int(round(perp1y)) >= IMAGE_SIZE_X: + perp1y = IMAGE_SIZE_X - 1 + + if buils[int(round(perp1y)), int(round(perp1x))] == 127: + tempa = tg + if tempa > 4: + # print 'p' + break + else: + tempa = tg + + if tempa == 5: + for tg in range(1, 200): + perp1x, perp1y = inter4n(p1x, p1y, p2x, p2y, tg) + + if perp1x < 0: + perp1x = 0 + if perp1y < 0: + perp1y = 0 + + if int(round(perp1x)) >= IMAGE_SIZE_Y: + perp1x = IMAGE_SIZE_Y - 1 + if int(round(perp1y)) >= IMAGE_SIZE_X: + perp1y = IMAGE_SIZE_X - 1 + + if buils[int(round(perp1y)), int(round(perp1x))] == 127: + tempa = tg + if tempa > 4: + # print 'n' + break + else: + tempa = tg + + # print tempa + + if tempa != 5 and tempa != 199: + cntr1 += 1 + summ1 += tempa + # print tempa + + if cntr1 != 0: + aveg1 = summ1 / cntr1 + # print aveg1 + else: + aveg1 = 0 + + cntr2 += 1 + summ2 += aveg1 + + if cntr2 != 0 and summ2 != 0: + aveg2 = summ2 / cntr2 + # print name, '=', aveg2*PIXEL_SIZE # , '\n' + + heights.append(float(ht)) + widths.append(aveg2*PIXEL_SIZE) + names.append(bid) + + cnt += 1 + feature_buil.Destroy() + feature_buil = layer2.GetNextFeature() + + for qw in range(0, len(heights)): + if widths[qw] != 0: + ratio = heights[qw] / widths[qw] + else: + ratio = 0 + + ratios.append(ratio) + + return ratios, names \ No newline at end of file From a353a1b3dc665a36c6edca331d367b05660c2e03 Mon Sep 17 00:00:00 2001 From: lg6 Date: Mon, 11 Apr 2022 13:50:40 -0400 Subject: [PATCH 23/35] added license --- NATURF/LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 NATURF/LICENSE diff --git a/NATURF/LICENSE b/NATURF/LICENSE new file mode 100644 index 00000000000..a1599a519fc --- /dev/null +++ b/NATURF/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Levi Sweet-Breu and Melissa Allen-Dumas + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file From 9dfc86fb634b1489ab775859fe8b42e15d9514ba Mon Sep 17 00:00:00 2001 From: lg6 Date: Tue, 12 Apr 2022 15:35:14 -0400 Subject: [PATCH 24/35] Updated im3Workflow and Binary for D.C. --- NATURF/Binary.py | 6 +++--- NATURF/im3Workflow.py | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/NATURF/Binary.py b/NATURF/Binary.py index 41ff0e93f02..6fd7c982fbd 100644 --- a/NATURF/Binary.py +++ b/NATURF/Binary.py @@ -453,11 +453,11 @@ def make_binary(name, path, tifDir, cenlat, cenlon, outputDir, id_field, height_ index.write(' dx=100.0\n') index.write(' known_x=1\n') index.write(' known_y=1\n') - index.write(' known_lat=33.297482\n') - index.write(' known_lon=-119.009446\n') + index.write(' known_lat=38.794034\n') + index.write(' known_lon=-77.129474\n') index.write(' truelat1=45.5\n') index.write(' truelat2=29.5\n') - index.write(' stdlon=-118.0\n') + index.write(' stdlon=-77.0\n') index.write(' wordsize=4\n') index.write(' endian=big\n') index.write(' signed=no\n') diff --git a/NATURF/im3Workflow.py b/NATURF/im3Workflow.py index 4242398ef9b..17526176bb9 100644 --- a/NATURF/im3Workflow.py +++ b/NATURF/im3Workflow.py @@ -15,10 +15,10 @@ def processFile(shapeFile): tifDir.mkdir(parents=True, exist_ok=True) # automatically also creates outputDir indexfile = filenames[buildingTile][0] # binary file name - cenlat = 34.0 # Center latitude of the study area - cenlon = -118.0 # Center longitude of the study area - id_field = 'ID' # Name of the field containing ID data in shapefile - height_field = 'Height' # Name of the field containing height data in shapefile + cenlat = 38.9 # Center latitude of the study area + cenlon = -77.0 # Center longitude of the study area + id_field = 'OBJECTID' # Name of the field containing ID data in shapefile + height_field = 'Max_HOUSE_' # Name of the field containing height data in shapefile BR.make_raster(shapeFile, tifDir, cenlat, cenlon) BI.make_ids_image(shapeFile, tifDir, cenlat, cenlon, id_field) From 003ec5369faf42333dcebd8b8d8dbb19e8579d45 Mon Sep 17 00:00:00 2001 From: erexer <13180883+erexer@users.noreply.github.com> Date: Tue, 24 May 2022 10:49:28 -0400 Subject: [PATCH 25/35] initial CI --- .github/workflows/build.yml | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000000..6d45e95300e --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,39 @@ +name: build + +on: [push, pull_request] + +jobs: + build: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [ubuntu-latest] + + env: + OS: ${{ matrix.os }} + PYTHON: '3.9' + + steps: + + - uses: actions/checkout@v1 + + - name: Set up Python + uses: actions/setup-python@master + with: + python-version: 3.8.5 + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python setup.py install + - name: Test and generate coverage report on Linux + run: | + pip install pytest + pip install pytest-cov + pytest --cov=./ --cov-report=xml + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v1 + with: + file: ./coverage.xml + fail_ci_if_error: true \ No newline at end of file From 3b8f678bcf88e714576ac3a4f3ca370c0fcf9947 Mon Sep 17 00:00:00 2001 From: erexer <13180883+erexer@users.noreply.github.com> Date: Tue, 24 May 2022 11:06:46 -0400 Subject: [PATCH 26/35] initial CI --- .github/workflows/build.yml | 2 +- README.md | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6d45e95300e..d968e86a400 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,7 +12,7 @@ jobs: env: OS: ${{ matrix.os }} - PYTHON: '3.9' + PYTHON: '3.8' steps: diff --git a/README.md b/README.md index da855851bc6..38c0fb7bafb 100755 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ -# IM3_ORNL +[![build](https://github.com/IMMM-SFA/naturf/actions/workflows/build.yml/badge.svg)](https://github.com/IMMM-SFA/naturf/actions/workflows/build.yml) -Code, data, and products related to IM3 \ No newline at end of file +# NATURF +Code, data, and products related to NATURF \ No newline at end of file From bb867da46ec3942688087833db5e56b154d7d793 Mon Sep 17 00:00:00 2001 From: erexer <13180883+erexer@users.noreply.github.com> Date: Tue, 24 May 2022 11:40:39 -0400 Subject: [PATCH 27/35] initial CI --- NATURF/__init__.py | 2 ++ README.md | 5 ++++- requirements.txt | 4 ++++ setup.cfg | 3 +++ setup.py | 34 ++++++++++++++++++++++++++++++++++ 5 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 NATURF/__init__.py create mode 100644 requirements.txt create mode 100644 setup.cfg create mode 100644 setup.py diff --git a/NATURF/__init__.py b/NATURF/__init__.py new file mode 100644 index 00000000000..9561ba9e77f --- /dev/null +++ b/NATURF/__init__.py @@ -0,0 +1,2 @@ + +__version__ = "0.0.0" diff --git a/README.md b/README.md index 38c0fb7bafb..11ea585d700 100755 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ [![build](https://github.com/IMMM-SFA/naturf/actions/workflows/build.yml/badge.svg)](https://github.com/IMMM-SFA/naturf/actions/workflows/build.yml) # NATURF -Code, data, and products related to NATURF \ No newline at end of file + +NATURF: Neighborhood Adaptive Tissues for Urban Resilience Futures + +NATURF addresses the knowledge gap of the effect of the geometry of a neighborhood on the local meteorology. \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000000..c2a7ece7c60 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +GDAL==3.4.1 +numpy==1.21.5 +pandas==1.4.1 +setuptools==61.2.0 \ No newline at end of file diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 00000000000..5a87726d0c6 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,3 @@ +[metadata] +description_file = README.md +license_files = LICENSE.txt \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 00000000000..d7728e8ebc6 --- /dev/null +++ b/setup.py @@ -0,0 +1,34 @@ +import re +from setuptools import setup, find_packages + + +def readme(): + """Return the contents of the project README file.""" + with open('README.md') as f: + return f.read() + + +def get_requirements(): + """Return a list of package requirements from the requirements.txt file.""" + with open('requirements.txt') as f: + return f.read().split() + + +version = re.search(r"__version__ = ['\"]([^'\"]*)['\"]", open('NATURF/__init__.py').read(), re.M).group(1) + +setup( + name='naturf', + version=version, + packages=find_packages(), + url='https://github.com/IMMM-SFA/naturf', + download_url=f'https://github.com/IMMM-SFA/naturf/archive/refs/tags/v{version}.tar.gz', + license='MIT', + author='Levi Sweet-Breu, Melissa Allen-Dumas, Emily Rexer', + author_email='', + description='An open-source Python package to address the effect of the geometry of a neighborhood on the local meteorology. ', + long_description=readme(), + long_description_content_type="text/markdown", + python_requires='=3.8.5', + include_package_data=True, + install_requires=get_requirements() +) \ No newline at end of file From e4ababa9b06aeeafc6d35de2b0dbae30ea07cc77 Mon Sep 17 00:00:00 2001 From: erexer <13180883+erexer@users.noreply.github.com> Date: Tue, 24 May 2022 11:43:59 -0400 Subject: [PATCH 28/35] update README --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 11ea585d700..95025ebc938 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,5 @@ [![build](https://github.com/IMMM-SFA/naturf/actions/workflows/build.yml/badge.svg)](https://github.com/IMMM-SFA/naturf/actions/workflows/build.yml) -# NATURF - -NATURF: Neighborhood Adaptive Tissues for Urban Resilience Futures +# NATURF: Neighborhood Adaptive Tissues for Urban Resilience Futures NATURF addresses the knowledge gap of the effect of the geometry of a neighborhood on the local meteorology. \ No newline at end of file From fd9dda849fd8b84264e0b93b109597ff1037a9b4 Mon Sep 17 00:00:00 2001 From: erexer <13180883+erexer@users.noreply.github.com> Date: Tue, 24 May 2022 11:46:27 -0400 Subject: [PATCH 29/35] fix python_requires --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index d7728e8ebc6..7a3eeff878b 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ def get_requirements(): description='An open-source Python package to address the effect of the geometry of a neighborhood on the local meteorology. ', long_description=readme(), long_description_content_type="text/markdown", - python_requires='=3.8.5', + python_requires='>=3.8.5', include_package_data=True, install_requires=get_requirements() ) \ No newline at end of file From 4f51a0a4f3d223fa1cb8ff4588b631aab1a1702d Mon Sep 17 00:00:00 2001 From: erexer <13180883+erexer@users.noreply.github.com> Date: Thu, 26 May 2022 14:57:34 -0400 Subject: [PATCH 30/35] add libgdal as requirement --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index c2a7ece7c60..e2a2d7e782b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ GDAL==3.4.1 +libgdal==3.4.1 numpy==1.21.5 pandas==1.4.1 setuptools==61.2.0 \ No newline at end of file From fc45f34e33542f9bb4ea3566cd9d5edf0d6353d0 Mon Sep 17 00:00:00 2001 From: erexer <13180883+erexer@users.noreply.github.com> Date: Thu, 26 May 2022 15:02:51 -0400 Subject: [PATCH 31/35] remove libgdal as requirement, add libgdal to build --- .github/workflows/build.yml | 1 + requirements.txt | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d968e86a400..18f74b739c7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,6 +26,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip + apt-get install libgdal-dev python setup.py install - name: Test and generate coverage report on Linux run: | diff --git a/requirements.txt b/requirements.txt index e2a2d7e782b..c2a7ece7c60 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,4 @@ GDAL==3.4.1 -libgdal==3.4.1 numpy==1.21.5 pandas==1.4.1 setuptools==61.2.0 \ No newline at end of file From ab181dcac34ecbc92c30807bad879e7064fa1e8e Mon Sep 17 00:00:00 2001 From: erexer <13180883+erexer@users.noreply.github.com> Date: Thu, 26 May 2022 15:07:43 -0400 Subject: [PATCH 32/35] add libgdal to build --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 18f74b739c7..429c040f885 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,7 +26,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - apt-get install libgdal-dev + sudo apt-get install libgdal-dev python setup.py install - name: Test and generate coverage report on Linux run: | From 3c7e83e62a54e39219e431626c2032e63f484766 Mon Sep 17 00:00:00 2001 From: erexer <13180883+erexer@users.noreply.github.com> Date: Thu, 26 May 2022 15:14:51 -0400 Subject: [PATCH 33/35] add libgdal to build --- .github/workflows/build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 429c040f885..2d812561302 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,6 +26,8 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip + sudo apt-add-repository ppa:ubuntugis/ubuntugis-unstable + sudo apt-get update sudo apt-get install libgdal-dev python setup.py install - name: Test and generate coverage report on Linux From aa31f2ea0e817d89903af163fe9a1701402ebf86 Mon Sep 17 00:00:00 2001 From: erexer <13180883+erexer@users.noreply.github.com> Date: Fri, 27 May 2022 16:20:11 -0400 Subject: [PATCH 34/35] temporary output files to compare to before and after the refactor --- NATURF/tests/00065-00096.00065-00096 | Bin 0 -> 540720 bytes NATURF/tests/C-5.csv | 261 +++++++++++++++++++++++++++ NATURF/tests/compare_dc_output.py | 12 ++ NATURF/tests/index | 21 +++ 4 files changed, 294 insertions(+) create mode 100644 NATURF/tests/00065-00096.00065-00096 create mode 100644 NATURF/tests/C-5.csv create mode 100644 NATURF/tests/compare_dc_output.py create mode 100644 NATURF/tests/index diff --git a/NATURF/tests/00065-00096.00065-00096 b/NATURF/tests/00065-00096.00065-00096 new file mode 100644 index 0000000000000000000000000000000000000000..c101cfdc37bf40e83d3864325a34515b3831c7a4 GIT binary patch literal 540720 zcmeI*36v~VeFxxMJ@fWO7G)8|C&J?hF2EB37d9aXN{$9lL`B756cpSS+yFsE+!4j_ z(4e4E6hU*`B1YpDCGH;O7?&J(qes-ZpeRYz^jx}nx@Wq&yOy4rug?C1_OBYqeqk>24Y~80PLq9W3hEP+yeovb z_qknpQ~mowK!5-N0t5&UAh1LQk|Jw_isrs@Q$+(WFl;OSJwNTU;(iNstm@X6s~ULlxUH9k z5ck2o%kMFhU38uK#q#rq8nJ}@R$R|76#U%w&1C-&Ry}IAhPn__#~4 z=YbDs&uZ5jm*VWqi2wlt1PBlyK!8B=0?FUhUqgQVUw^v9JR-(8MSq&{GW`PvNWEH>;I)O8?zulfB*pk1PBlyKp+!H&f>5r1WH(c zk2TK{@(ZoM$0~B+hnvn{xVp)@yYafosz)^h2oNAZfB*pk1PBmVHUcHAzsIsFA;0PM zchmV}`FofE0RjXF5FkK+009C7mWRML4NtR#{HE96P3JfK85B=|009C72oNAZfB*pk z1Zojzdi~vWel5sC2oNAZfB*pk1PBlyK!8Bg0!4qUl ze4Mj<{?uK%N4nQ9XRovTbX)oC_OYsubMxos?D_O|OY4NWcj~*|YfXJwk_ZqWK!5-N z0t5&&A5o(~>cV3tmv`<@UDi3T?X2Lsa@C3DRTS6%;jihKaW8N9;v=Qm zt+NVtFX&WowBfszke^?F&s)Ik`aAhTr$=&X=X{*Ae139N_egcG|L5j+R}+Hu|6CE* z1PBlyK!5-N0tA+rz|Hl~C%^u$KfRg6{cmh0w_j>$}qrC%Q_-5gcE{7K#pJiJ}quD_b(D%D1S009C72oNAZ zVDSnh2iISFe*Is6y2S8)23-R2`yuJqLhFF8JM~<|{GZelH>oLc{XePosfz#s0t5&U zAV7csf#C&OKN$WQPY@umv;{U^x3uSHb_56zAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB=ETBCz7q4OaU42C|=!%e;T?yspy=iv>;pvRJ<& zy$;%Kw%5RqegKZ&U5~Mkhdk009C72oNC9v_P^`a}`W| zqWS7u9=ztCp=zmSf51PBlyK!5-N0tA+T zz~}0pLw@~Ve|j^C``_41Zokyz*nX{j+G<*V_epLy)s=rnJ1%)-`n{1C&09@%H)iw0 zBdUuiGP3o55hZ;H5FkK+009C72oM-XAlWiZZ+#mRsB8T_-vpb^pRcYZ+P?P8_Qaa} z_y4V{mME@i5g=Z5Ae z)}2^?_WI48%$M%hIj`&N@FVL=>diUe{1D>ad$;YPqfdPe|t;_l`n+XIb{%2iKRk7?Sp#UF$#R7a_dy z+IGctuK#2HGGG6%+4}1ld+Yzj@I|9W0t5&UAV7csfki3M^!k5MqAl{Gt^d0}fpPtv zU;lUasP-!6SH1qPb{1og9@qb44`cuW1PBlyK!5-N0t6;UApidVNll zUo-&%1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkJx zFL2Hc`Kx-**PU2zUY53gb0_nq`*qIiIy?Nxx{`Wx4mdxAxcAN=mF(vHx z;t=k5UI<&R4B@mb?aH5gN%=E4`tc!Le)rySv;1uP%^vMzRUfnbN#538JX77&>2IFo zD%D1S009C72oNAZU_5~)*Z;@7WW3r(dHR5-cAi>p>;DtdxyQYuP~TaWz4yWOJ! zeP`GD&-q0NZ@ji$ah>b`n7_=||7*7XddA-Re=&T~sF45x0t5&UAV6SI3N*d`UzBKz zylCtH?oVJ`f9Kc#-94(kiuqNq|ErzF*rUhw|JVZ=fB*pk1PBlyK!5;&$q~rE|35iZ zse}N51_iAD8^jk)fB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5XcK``;h!qz2|GMtv4@ATleEm=C(iToY!@>`kQqn_2#TOHH5hL-mShR z%U=1q>T?!T!kRyako+-(?av5dm%Ftq-*{H}Gg$K8hTz2j#2*|yJp+Q+IsX89Am zCBK~gv*4NkHo;XYjR1jVBXG+#%Vw%Q6aD0)dYUv4s72u1@6-|_q>n)MSJXa#P3`G< zwz{v}0e<-InE-SVQZOboftS z7Q&VP)Y-ceJ6A_NG$gxL@OAZ?Pt0T|?>fJeHTUe?--nRqhuzN&$+g?fy<5t4@|jQc zjFX&tpOEe0_-P$+ha3@Ft(S-Jm<=I(B(0-_ ztt%C3%mYj<18>;IX-4}C%iuRE->cPDnP-uT%Nu0FYQUDnx6>DOzP|D22F zAMpoY4q6_E-w)xVp9;xI({p=`f4%hu>DOAi$L;v*Lbz~U2x)$@;iDn>+U22j^7PCeyOes& zXJ3(i-9PG*c76=G&+})_l8e3=Tk1U?m45GOyY$~EJZr~#bEOd=K%k$1_y7B;Xd_Uq zfcO8a^<8N6?0x7W??pd4{rl@lzg%df$-Os0@Bb%frtiULTM_ei&(S~5dH+8-?#z%p z`mm5}I(+mo3qIM}dRAz?Y;$Ox``lZfNKU*oB)i=bl8w*0wJkeIPA~aA$jAO~XeAqG z^21I4*OfJMalx9dwk*HQ8nXBQlkJZP$-Q24>)sWZyGX8obx6*h^Zk(A{ZUU_)9c#V z7pC8HnP*FWGaZum{AURFep8q_b@zFCjn|yqd}Gf5$@Sj|Gy7E+hvW&zhp9`CC?&t^ z{r8^Kc0+R0d1?0ZLhG9C!_))c7LqM#{{FX}r}uEpUHLb>ID~AU-IDXaACk|0In3n$ z^?_mf?>-r(Kl{>|J@zT}n9siAts!~A6KC>cM(e!x_l2gv|EJhg>#_B!H-*+ID?@9$ zKHs0KwGv?j2oNAZfB*pk1S%BRbDIhWA24*?*;!sbGk=~hb-wm|pJC5qc9F4*^cglk z>tCdXs^VMEu_ClF?m%3}1n;oy`t9R7)`Noa&jmJ^PAM{++;}6OobU)S?kAwQV zPk;ac0t5&UAV6SI3cRnms;BQ)fA*TKoy@84bk6HKo4%s1q~4sVr-cyr-n-SeWZ4^@ zUVYADOi1=iKR25eW93Vu=IQI(^JrbTH0EO#1PBlyK!5-N0tEUABd$WoY!?WwXv?G-kjuJ>H2?m z@4Z`nOP0Ojrs{JRWkUKh|C75e%F35S(cb@G5}!tsAV7cs0RjXF5EvwI)}Rj6-A{iH zSnb=Y+|L(J8pu!nq4p_v0>7M|#=X;8-&vZy&KkF`_tZ)0`u}hH-dYxo)30w&v-Q~K zraPVfo=zJ90t6;OU^)LRlI1w}Y|hJZ-r3jMB+Yx0YMF#ThvuuH3a4z$BI6eAS5@r` z)ws~Tte!#l=c{>cdl};#xT!sA8Dq_@Z|?QnjN{Vx!n3xy?Q@?i<2vSS$^CBilb_l@ zzwCNqc6NNuPkZM(H*fCsDD$5?Ms|H-`tL2`KHr#Gzq!xO*LS}5e$U7JZPVYgHs2Pr z`#nG3GgF*m%f7f8PXZPa1P+pn$R_z(WzL$ouYTxvDTs!|kXO@}J z9&4u$g|N%#yT{Gun&oH5)1KFTuk5QVKW@=D9%Flx$E=oYi^ukrj|2!1Xhz`pA2*XL zmB4Zq*yHibdG_YMoCMbWqPf}b{FeH&x6iGuw%xh@{B@TV%iQpqV*Q5cwIW^r$9RagGDt3z1(ln`$F=k(u3w0{R)$p0IavgWsH*Zw1A`PsJi zN$q1*AM^QZ|2>3P{HiSl8t@wM8t@wM z8t@wM8t@wM8t@wM8t@ue+OL7)-zm_O009ES3+(*d;h$M5Pi+6Nr7{!qSZo3tc35l` zFP(bVpPl}U@N^%vt^NB!Jtp`5HoHwuZ95*^uBC|ixK*$JO7{qRZ|c6T}zA!l725mK7W_9L)bmdh}&JSZl7iO*>=~8 ze=lX0AGbB9rFpaYu`Ry;fA-sAOTEWKJ{ZD%zm$H@;;eder4b-Npr63IEB-UNU*@E= zo%5n2%fa2{&|& zkZdZr7VLUzyo=;}zwHcg{UbZ)Rh}K#>Wu!5-2VsNY3)6`rM&NNCFdNP{(t{lLiqU0 zJ9}?p^(|?Ba>4@(<+R?ss!+dSJJp##b@iVHmX{oq{yfT)z8aGIY!i|*XI~p%e8#}% zigf78|L~z9{BfIGA4_&TZ039>KRru!xaHP+m7HYxaXV!D5c6YGa@EggPNyFIt=LrS zF?siQL-N{dLy}xyYpyT?1PBlyK!5-N0t6})*zt}P4qjmB)eZgs%`>HC|E3`B1!^t5 zOPYO9d!1MM&;}$xfB*pk1PBlyK!5;&$rafB`1)%*D)+wf(VwqBf88JI&y0!NZ4Dvr zv8~QymVLMMXWiKd5FkK+009C72oNAZfB=D|EpWH}miGM2jsO7y1PBlyK!5-N0t9*m zHs{`p@4Z`1%L(u5jQf<;o%6cRPJLWmNt2ng(>0S>*K(`s)b!^;+6WLJK!5-N0t5&U zAh47L&iF#Zv)iTNeDMSb5FkK+009C72oNAZpk{$RPN_LCjoa>kPUg|y=$zMew*H58 zCH3ZP_)hw}=4SWayVbX3*~g|o1HeXr009C72oNAZfB*pk1gaL;cuds^#$QNahxB(4 z+6WLJK!5-N0t5&UAV6Sw3G8%j{qtS(qxv%?b_DL!z|UOhq&p)(fB*pk1PBlyK!5;& z7djQlH~F}S+BygOb0&zb9ndkucBNRNE}%2)P(BFoRVo&TkMtm@-@`Bmi^mjD3* z1PBlyK!5-N0(;($0fEU8xczt2_5Z2e^=xy8?&~tH*8Xz{>-O#)Da+5cs^9<5@@)hN z5FkK+009C72oR`KpmlSdX`^S|?x4}1o%`e@z5n0(`rPXJU!VTP{_S<$K*!{tWiKID~zF*E?>OpKZrIt$nQOW0pV3+eLqESGVQZNv=|D1PCk}fz8Wi zro9tg&U5e8&{C&>*Iu34-C3D^5&t56x<{Uzt4XRo))J3ZD$UKvuH#;1ZZ>wz$=A@Y zE%q(5o|qZ)=8hfj$M*U9#rwk^<9PYwd}G8u^W7h(y~xG4?6**sqqDo#n*)@mOYdk+EVeP30Ght41S62S8pYLJ&51QvN0GWy2(mob(x2oNAZfB*pk1PBly zK%kgF(`&J^@`qi^4%>f_<}l;MIS=#9p!`wpH Date: Fri, 27 May 2022 16:25:16 -0400 Subject: [PATCH 35/35] call test function --- NATURF/tests/compare_dc_output.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NATURF/tests/compare_dc_output.py b/NATURF/tests/compare_dc_output.py index 0b4b5cfc0f2..d9b6f24621c 100644 --- a/NATURF/tests/compare_dc_output.py +++ b/NATURF/tests/compare_dc_output.py @@ -10,3 +10,7 @@ def test_DC(): for file in files: assert filecmp.cmp(f"{actual_dir}{file}", f"{expected_dir}{file}") + + +if __name__ == "__main__": + test_DC() \ No newline at end of file