diff --git a/conf/hermes.conf b/conf/hermes.conf index 4ab152fc89dc3807c125b689a75ee9db53b18edc..e9a15390b4da6095d7e5af75c8c4ed7ff31ab308 100755 --- a/conf/hermes.conf +++ b/conf/hermes.conf @@ -9,8 +9,8 @@ start_date = 2016/11/29 00:00:00 # ----- end_date = start_date [DEFAULT] ----- # end_date = 2010/01/01 00:00:00 output_timestep_num = 24 -auxiliary_files_path = /scratch/Earth/HERMESv3_BU_aux/_ -erase_auxiliary_files = 0 +auxiliary_files_path = /scratch/Earth/HERMESv3_BU_aux/test/_ +erase_auxiliary_files = 1 [DOMAIN] @@ -135,10 +135,10 @@ shipping_port_processors = 0 livestock_processors = 0 crop_operations_processors = 0 crop_fertilizers_processors = 0 -agricultural_machinery_processors = 0 +agricultural_machinery_processors = 1 residential_processors = 0 recreational_boats_processors = 0 -point_sources_processors = 1 +point_sources_processors = 0 traffic_processors = 0 traffic_area_processors = 0 diff --git a/hermesv3_bu/sectors/agricultural_machinery_sector.py b/hermesv3_bu/sectors/agricultural_machinery_sector.py index 25f965932c240a36c9797a782e6c6636756f157e..c82b9ed48ebfbd06bb7f1e626c3ca5e3933f57e6 100755 --- a/hermesv3_bu/sectors/agricultural_machinery_sector.py +++ b/hermesv3_bu/sectors/agricultural_machinery_sector.py @@ -118,13 +118,23 @@ class AgriculturalMachinerySector(AgriculturalSector): spent_time = timeit.default_timer() def get_n(df): - df['N'] = self.vehicle_units.loc[self.vehicle_units['nuts3_id'] == df.name[0], df.name[1]].values[0] + try: + df['N'] = self.vehicle_units.loc[self.vehicle_units['nuts3_id'] == df.name[0], df.name[1]].values[0] + except IndexError: + warn("*WARNING*: NUT3_ID {0} not found in the {1} file".format( + df.name[0], 'crop_machinery_vehicle_units_path')) + df['N'] = 0.0 return df.loc[:, ['N']] def get_s(df): - df['S'] = self.vehicle_ratio.loc[ - (self.vehicle_ratio['nuts3_id'] == df.name[0]) & (self.vehicle_ratio['technology'] == df.name[2]), - df.name[1]].values[0] + try: + df['S'] = self.vehicle_ratio.loc[ + (self.vehicle_ratio['nuts3_id'] == df.name[0]) & (self.vehicle_ratio['technology'] == df.name[2]), + df.name[1]].values[0] + except IndexError: + warn("*WARNING*: NUT3_ID {0} not found in the {1} file".format( + df.name[0], 'crop_machinery_vehicle_ratio_path')) + df['S'] = 0.0 return df.loc[:, ['S']] def get_t(df): @@ -135,14 +145,23 @@ class AgriculturalMachinerySector(AgriculturalSector): df.name[1]].values[0] except IndexError: df['T'] = np.nan - df.loc[df['T'].isna(), 'T'] = self.vehicle_workhours.loc[ - (self.vehicle_workhours['nuts3_id'] == df.name[0]) & (self.vehicle_workhours['technology'] == - 'default'), - df.name[1]].values[0] + try: + df.loc[df['T'].isna(), 'T'] = self.vehicle_workhours.loc[ + (self.vehicle_workhours['nuts3_id'] == df.name[0]) & (self.vehicle_workhours['technology'] == + 'default'), df.name[1]].values[0] + except IndexError: + warn("*WARNING*: NUT3_ID {0} not found in the {1} file".format( + df.name[0], 'crop_machinery_vehicle_workhours_path')) + df.loc[df['T'].isna(), 'T'] = 0.0 return df.loc[:, ['T']] def get_p(df): - df['P'] = self.vehicle_power.loc[self.vehicle_power['nuts3_id'] == df.name[0], df.name[1]].values[0] + try: + df['P'] = self.vehicle_power.loc[self.vehicle_power['nuts3_id'] == df.name[0], df.name[1]].values[0] + except IndexError: + warn("*WARNING*: NUT3_ID {0} not found in the {1} file".format( + df.name[0], 'crop_machinery_vehicle_power_path')) + df['P'] = 0.0 return df.loc[:, ['P']] def get_lf(df): diff --git a/hermesv3_bu/sectors/residential_sector.py b/hermesv3_bu/sectors/residential_sector.py index d098775f7e9346b0f6cb2ed9f27ecca03a0cd7e3..ae9c9b3e73ad991b2b39284a9612fc86c8028c78 100755 --- a/hermesv3_bu/sectors/residential_sector.py +++ b/hermesv3_bu/sectors/residential_sector.py @@ -7,6 +7,7 @@ import timeit import numpy as np import pandas as pd import geopandas as gpd +from warnings import warn from hermesv3_bu.sectors.sector import Sector from hermesv3_bu.io_server.io_raster import IoRaster @@ -217,27 +218,43 @@ class ResidentialSector(Sector): population_density['ccaa'] == ccaa, fuel] = population_density['pop'].multiply( energy_consumption / total_pop) else: - total_pop = self.pop_type_by_ccaa.loc[ - (self.pop_type_by_ccaa.index.get_level_values('ccaa') == ccaa) & - (self.pop_type_by_ccaa.index.get_level_values('type') == spatial_proxy['proxy_type']), - 'pop'].values[0] - energy_consumption = self.energy_consumption_nuts2.loc[ - self.energy_consumption_nuts2['nuts2_id'] == ccaa, fuel].values[0] - - fuel_distribution.loc[(population_density['ccaa'] == ccaa) & - (population_density['type'] == spatial_proxy['proxy_type']), - fuel] = population_density['pop'].multiply( - energy_consumption / total_pop) + try: + total_pop = self.pop_type_by_ccaa.loc[ + (self.pop_type_by_ccaa.index.get_level_values('ccaa') == ccaa) & + (self.pop_type_by_ccaa.index.get_level_values('type') == spatial_proxy[ + 'proxy_type']), + 'pop'].values[0] + try: + energy_consumption = self.energy_consumption_nuts2.loc[ + self.energy_consumption_nuts2['nuts2_id'] == ccaa, fuel].values[0] + except IndexError: + warn("*WARNING*: NUT2_ID {0} not found in the ".format(ccaa) + + "energy_consumption_nuts2 file. Setting it to 0.") + energy_consumption = 0.0 + fuel_distribution.loc[(population_density['ccaa'] == ccaa) & + (population_density['type'] == spatial_proxy['proxy_type']), + fuel] = population_density['pop'].multiply( + energy_consumption / total_pop) + except IndexError: + warn("*WARNING*: NUT2_ID {0} not found in the ".format(ccaa) + + "population_type_nuts2 file. Setting it to 0.") + fuel_distribution.loc[(population_density['ccaa'] == ccaa) & + (population_density['type'] == spatial_proxy['proxy_type']), + fuel] = 0.0 if spatial_proxy['nut_level'] == 'prov': for prov in np.unique(population_density['prov']): if spatial_proxy['proxy_type'] == 'all': total_pop = self.pop_type_by_prov.loc[self.pop_type_by_prov.index.get_level_values( 'prov') == prov, 'pop'].sum() - energy_consumption = self.energy_consumption_nuts3.loc[ - self.energy_consumption_nuts3['nuts3_id'] == prov, fuel].values[0] - - fuel_distribution.loc[population_density['prov'] == prov, fuel] = population_density[ - 'pop'].multiply(energy_consumption / total_pop) + try: + energy_consumption = self.energy_consumption_nuts3.loc[ + self.energy_consumption_nuts3['nuts3_id'] == prov, fuel].values[0] + fuel_distribution.loc[population_density['prov'] == prov, fuel] = population_density[ + 'pop'].multiply(energy_consumption / total_pop) + except IndexError: + warn("*WARNING*: NUT3_ID {0} not found in the ".format(prov) + + "energy_consumption_nuts3 file. Setting it to 0.") + fuel_distribution.loc[population_density['prov'] == prov, fuel] = 0.0 else: total_pop = self.pop_type_by_prov.loc[ (self.pop_type_by_prov.index.get_level_values('prov') == prov) &