From 72ecf2d2c79815f5f39fec71c43cb886985d9837 Mon Sep 17 00:00:00 2001 From: Carles Tena Date: Thu, 29 Aug 2019 14:49:23 +0200 Subject: [PATCH 1/2] - Residential: Corrected gap on some NUT to avoid to do some region --- conf/hermes.conf | 8 ++-- hermesv3_bu/sectors/residential_sector.py | 49 +++++++++++++++-------- 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/conf/hermes.conf b/conf/hermes.conf index 4ab152f..613f6ce 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] @@ -136,9 +136,9 @@ livestock_processors = 0 crop_operations_processors = 0 crop_fertilizers_processors = 0 agricultural_machinery_processors = 0 -residential_processors = 0 +residential_processors = 1 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/residential_sector.py b/hermesv3_bu/sectors/residential_sector.py index d098775..ae9c9b3 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) & -- GitLab From 854c88e30ef6719cf1db9a81c3a3af982001633a Mon Sep 17 00:00:00 2001 From: Carles Tena Date: Thu, 29 Aug 2019 16:04:08 +0200 Subject: [PATCH 2/2] - Agricultural Machinery: Corrected gap on some NUT to avoid to do some region --- conf/hermes.conf | 4 +- .../sectors/agricultural_machinery_sector.py | 37 ++++++++++++++----- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/conf/hermes.conf b/conf/hermes.conf index 613f6ce..e9a1539 100755 --- a/conf/hermes.conf +++ b/conf/hermes.conf @@ -135,8 +135,8 @@ shipping_port_processors = 0 livestock_processors = 0 crop_operations_processors = 0 crop_fertilizers_processors = 0 -agricultural_machinery_processors = 0 -residential_processors = 1 +agricultural_machinery_processors = 1 +residential_processors = 0 recreational_boats_processors = 0 point_sources_processors = 0 traffic_processors = 0 diff --git a/hermesv3_bu/sectors/agricultural_machinery_sector.py b/hermesv3_bu/sectors/agricultural_machinery_sector.py index 25f9659..c82b9ed 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): -- GitLab