<commit_before>"""
Solar vertical insolation algorithm based on ArcGIS Solar Analyst
"""
from __future__ import division

import datetime
import os

import numpy as np
import pandas as pd
import pytz
from astral import Location
from simpledbf import Dbf5
from timezonefinder import TimezoneFinder
import pickle

from cea.interfaces.arcgis.modules import arcpy
from cea.utilities import epwreader

__author__ = "<NAME>"
__copyright__ = "Copyright 2013, Architecture and Building Systems - ETH Zurich"
__credits__ = ["<NAME>", "<NAME>"]
__license__ = "MIT"
__version__ = "0.1"
__maintainer__ = "<NAME>"
__email__ = "<EMAIL>"
__status__ = "Production"


def solar_radiation_vertical(locator, path_arcgis_db, latitude, longitude, year, gv, 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
    :type gv: cea.globalvar.GlobalVariables

    :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)

    gv.log('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_path,
                             '--sunrise-pickle', sunrise_pickle,
                             '--sunny-hours-pickle', sunny_hours_pickle)

    gv.log('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,<commit_msg>no multiprocessing for Argcis points solar radiation<commit_after>"""
Solar vertical insolation algorithm based on ArcGIS Solar Analyst
"""
from __future__ import division

import datetime
import os

import numpy as np
import pandas as pd
import pytz
from astral import Location
from simpledbf import Dbf5
from timezonefinder import TimezoneFinder
import pickle

from cea.interfaces.arcgis.modules import arcpy
from cea.resources.radiation_arcgis.calculate_radiation_for_all_days import calculate_radiation_for_all_days
from cea.utilities import epwreader

__author__ = "<NAME>"
__copyright__ = "Copyright 2013, Architecture and Building Systems - ETH Zurich"
__credits__ = ["<NAME>", "<NAME>"]
__license__ = "MIT"
__version__ = "0.1"
__maintainer__ = "<NAME>"
__email__ = "<EMAIL>"
__status__ = "Production"


def solar_radiation_vertical(locator, path_arcgis_db, latitude, longitude, year, gv, 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
    :type gv: cea.globalvar.GlobalVariables

    :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)

    calculate_radiation_for_all_days(daily_transmissivity, dem_rasterfinal_path, latitude, locator, observers_path,
                                     path_arcgis_db)
    gv.log('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_path,
                             '--sunrise-pickle', sunrise_pickle,
                             '--sunny-hours-pickle', sunny_hours_pickle)

    gv.log('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,
{'fraction_non_alphanumeric': 0.07663633373533604, 'fraction_numerical': 0.0030698388334612432, 'mean_word_length': 3.7985270910047344, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '663423', 'n_tokens_mistral': 2935, 'n_tokens_neox': 2799, 'n_words': 604}