def calculate_radiation_for_surfaces(observers_path, data_factor_centroids_csv, sunny_hours_of_year, temporary_folder, path_arcgis_db): arcpy.env.workspace = path_arcgis_db arcpy.env.overwriteOutput = True arcpy.CheckOutExtension("spatial") # local variables CQSegments_centroid = os.path.join(path_arcgis_db, 'CQSegmentCentro') Outjoin = os.path.join(path_arcgis_db, 'Outjoin') CQSegments = os.path.join(path_arcgis_db, 'CQSegment') OutTable = 'CentroidsIDobserver.dbf' # Create Join of features Observers and CQ_sementscentroids to # assign Names and IDS of observers (field TARGET_FID) to the centroids of the lines of the buildings, # then create a table to import as a Dataframe arcpy.SpatialJoin_analysis(CQSegments_centroid, observers_path, Outjoin, "JOIN_ONE_TO_ONE", "KEEP_ALL", match_option="CLOSEST", search_radius="10 METERS") arcpy.JoinField_management( Outjoin, 'OBJECTID', CQSegments, 'OBJECTID') # add the lenghts of the Lines to the File arcpy.TableToTable_conversion(Outjoin, temporary_folder, OutTable) # ORIG_FID represents the points in the segments of the simplified shape of the building # ORIG_FID_1 is the observers ID Centroids_ID_observers0_dbf5 = Dbf5( os.path.join(temporary_folder, OutTable)).to_dataframe() Centroids_ID_observers_dbf5 = Centroids_ID_observers0_dbf5[[ 'Name', 'height_ag', 'ORIG_FID', 'ORIG_FID_1', 'Shape_Leng' ]].copy() Centroids_ID_observers_dbf5.rename(columns={'ORIG_FID_1': 'ID'}, inplace=True) # Create a Join of the Centroid_ID_observers and Datacentroids in the Second Chapter to get values of surfaces Shaded. Datacentroids = pd.read_csv(data_factor_centroids_csv) DataCentroidsFull = pd.merge(Centroids_ID_observers_dbf5, Datacentroids, left_on='ORIG_FID', right_on='ORIG_FID') # Read again the radiation table and merge values with the Centroid_ID_observers under the field ID in Radiationtable and 'ORIG_ID' in Centroids... DataRadiation = pd.merge(left=DataCentroidsFull, right=sunny_hours_of_year, left_on='ID', right_on='ID') return DataRadiation
def calculate_radiation_for_all_days(daily_transmissivity, dem_rasterfinal_path, latitude, locator, observers_path, path_arcgis_db): # let's just be sure this is set arcpy.env.workspace = path_arcgis_db arcpy.env.overwriteOutput = True arcpy.CheckOutExtension("spatial") aspect_slope = "FROM_DEM" heightoffset = 1 temporary_folder = locator.get_temporary_folder() for day in range(1, 366): calculate_radiation_single_day(day, dem_rasterfinal_path, observers_path, daily_transmissivity, latitude, temporary_folder, aspect_slope, heightoffset, path_arcgis_db)
def calculate_radiation_single_day(day, in_surface_raster, in_points_feature, T_G_day, latitude, locationtemp1, aspect_slope, heightoffset, path_arcgis_db): # Local Variables Latitude = str(latitude) skySize = '1400' # max 10000 dayInterval = '1' hourInterval = '1' calcDirections = '32' zenithDivisions = '512' # max 1200cor hlaf the skysize azimuthDivisions = '80' # max 160 diffuseProp = str(T_G_day.loc[day, 'diff']) transmittivity = str(T_G_day.loc[day, 'trr']) heightoffset = str(heightoffset) global_radiation = locationtemp1 + '\\' + 'Day_' + str(day) + '.shp' timeConfig = 'WithinDay ' + str(day) + ', 0, 24' arcpy.env.workspace = path_arcgis_db arcpy.env.overwriteOutput = True arcpy.CheckOutExtension("spatial") # Run the extension of arcgis, retry max_retries times before giving up... max_retries = 3 for _ in range(max_retries): try: arcpy.sa.PointsSolarRadiation( in_surface_raster, in_points_feature, global_radiation, heightoffset, Latitude, skySize, timeConfig, dayInterval, hourInterval, "INTERVAL", "1", aspect_slope, calcDirections, zenithDivisions, azimuthDivisions, "STANDARD_OVERCAST_SKY", diffuseProp, transmittivity, "#", "#", "#") print('complete calculating radiation of day No. %(day)i' % locals()) return arcpy.GetMessages() except: print(traceback.format_exc()) raise AssertionError( 'CalcRadiation failed %(max_retries)i times... giving up!' % locals())
def solar_radiation_vertical(locator, path_arcgis_db, latitude, longitude, year, weather_path): """ algorithm to calculate the hourly solar isolation in vertical building surfaces. The algorithm is based on the Solar Analyst Engine of ArcGIS 10. For more info check the integrated demand model of Fonseca et al. 2015. Appl. energy. :param locator: input locator for file paths :type locator: cea.inputlocator.InputLocator :param path_arcgis_db: path to default database of Arcgis. E.g.``c:\users\your_name\Documents\Arcgis\Default.gdb`` :type path_arcgis_db: str :param latitude: latitude north at the centre of the location :type latitude: float :param longitude: latitude north :type longitude: float :param year: year of calculation :type year: int :param gv: global context and constants :param weather_path: path to the weather file :type weather_path: str :returns: produces ``radiation.csv``, solar radiation file in vertical surfaces of buildings. """ print(weather_path) # Set environment settings arcpy.env.workspace = path_arcgis_db arcpy.env.overwriteOutput = True arcpy.CheckOutExtension("spatial") # local variables simple_cq_shp = locator.get_temporary_file('Simple_CQ_shp.shp') simple_context_shp = locator.get_temporary_file('Simple_Context.shp') dem_rasterfinal_path = os.path.join(path_arcgis_db, 'DEM_All2') observers_path = os.path.join(path_arcgis_db, 'observers') data_factors_boundaries_csv = locator.get_temporary_file( 'DataFactorsBoundaries.csv') data_factors_centroids_csv = locator.get_temporary_file( 'DataFactorsCentroids.csv') sunrise = calculate_sunrise(year, longitude, latitude) sunrise_pickle = locator.get_temporary_file('sunrise.pickle') pickle.dump(sunrise, open(sunrise_pickle, 'wb')) daily_transmissivity = calculate_daily_transmissivity_and_daily_diffusivity( weather_path) daily_transmissivity_pickle = locator.get_temporary_file( 'daily_transmissivity.pickle') daily_transmissivity.to_pickle(daily_transmissivity_pickle) dem_raster_extent = simplify_building_geometries(locator, simple_context_shp, simple_cq_shp) burn_buildings_into_raster(simple_context_shp, locator.get_terrain(), dem_rasterfinal_path, locator.get_temporary_folder(), dem_raster_extent) calculate_boundaries_of_buildings(simple_cq_shp, locator.get_temporary_folder(), path_arcgis_db, data_factors_centroids_csv, data_factors_boundaries_csv) calculate_observers(simple_cq_shp, observers_path, data_factors_boundaries_csv, path_arcgis_db) run_script_in_subprocess('calculate_radiation_for_all_days', '--daily-transmissivity-pickle', daily_transmissivity_pickle, '--dem-rasterfinal-path', dem_rasterfinal_path, '--latitude', latitude, '--observers-path', observers_path, '--arcgis_db', path_arcgis_db) print('complete raw radiation files') sunny_hours_pickle = locator.get_temporary_file('sunny_hours.pickle') run_script_in_subprocess('calculate_sunny_hours_of_year', '--scenario', locator.scenario, '--sunrise-pickle', sunrise_pickle, '--sunny-hours-pickle', sunny_hours_pickle) print('complete transformation radiation files') # Assign radiation to every surface of the buildings radiation_pickle_path = locator.get_temporary_file('radiation.pickle') run_script_in_subprocess( 'calculate_radiation_for_surfaces', '--observers-path', observers_path, '--data-factors-centroids', data_factors_centroids_csv, '--sunny-hours-pickle', sunny_hours_pickle, '--temp-folder', locator.get_temporary_folder(), '--arcgis-db', path_arcgis_db, '--radiation-pickle', radiation_pickle_path) run_script_in_subprocess('calculate_wall_areas', '--radiation-pickle', radiation_pickle_path) radiation = pd.read_pickle(radiation_pickle_path) export_surface_properties(radiation, locator.get_surface_properties()) # get solar insolation @ daren: this is a A BOTTLE NECK run_script_in_subprocess('calculate_incident_radiation', '--radiation-pickle', radiation_pickle_path, '--radiation-csv', locator.get_radiation()) print('done')