@@ -124,13 +124,15 @@ def set_country(self, countries, **args):
124124 To use population count alone: [0, 1].
125125 fin_mode (str, optional): define what total country economic value
126126 is to be used as an asset base and distributed to the grid:
127- - gdp: gross-domestic product (Source: World Bank)
128- - income_group: gdp multiplied by country's income group+1
129- - nfw: non-financial wealth (Source: Credit Suisse, of households only)
130- - tw : total wealth (Source: Credit Suisse, of households only)
131- - pc : produced capital (Source: World Bank), incl. manufactured or
127+ - ' gdp' : gross-domestic product (Source: World Bank)
128+ - ' income_group' : gdp multiplied by country's income group+1
129+ - ' nfw' : non-financial wealth (Source: Credit Suisse, of households only)
130+ - 'tw' : total wealth (Source: Credit Suisse, of households only)
131+ - 'pc' : produced capital (Source: World Bank), incl. manufactured or
132132 built assets such as machinery, equipment, and physical structures
133133 (pc is in constant 2014 USD)
134+ - 'norm': normalized by country
135+ - 'none': LitPop per pixel is returned unchanged
134136 admin1_calc (boolean): distribute admin1-level GDP if available?
135137 (default False)
136138 conserve_cntrytotal (boolean): given admin1_calc, conserve national
@@ -209,11 +211,13 @@ def set_country(self, countries, **args):
209211
210212 for cntry_iso , cntry_val in country_info .items ():
211213 if fin_mode == 'pc' :
212- _ , total_asset_val = world_bank_wealth_account (cntry_iso , \
214+ total_asset_val = world_bank_wealth_account (cntry_iso , \
213215 reference_year , \
214- no_land = True )
216+ no_land = True )[ 1 ]
215217 # here, total_asset_val is Produced Capital "pc"
216218 # no_land=True returns value w/o the mark-up of 24% for land value
219+ elif fin_mode in ['norm' , 'none' ]:
220+ total_asset_val = 1
217221 else :
218222 _ , total_asset_val = gdp (cntry_iso , reference_year , shp_file )
219223 cntry_val .append (total_asset_val )
@@ -227,7 +231,9 @@ def set_country(self, countries, **args):
227231 points2check = all_coords )
228232 litpop_curr = litpop_data [mask .sp_index .indices ]
229233 lon , lat = zip (* np .array (all_coords )[mask .sp_index .indices ])
230- if admin1_calc == 1 :
234+ if fin_mode == 'none' :
235+ LOGGER .info ('fin_mode=none --> no downscaling; admin1_calc is ignored' )
236+ elif admin1_calc == 1 :
231237 litpop_curr = _calc_admin1 (curr_country ,\
232238 country_info [curr_country ],
233239 admin1_info [curr_country ],\
@@ -255,8 +261,9 @@ def set_country(self, countries, **args):
255261 self .plot_log (admin1_plot = 0 )
256262 LOGGER .info ("Creating the LitPop exposure took " \
257263 + str (round (time .time () - start_time , 2 )) + "s" )
264+
265+ # self.set_geometry_points()
258266 self .check ()
259- self .set_geometry_points ()
260267
261268 @staticmethod
262269 def _set_one_country (cntry_info , litpop_data , lon , lat , curr_country ):
@@ -1026,7 +1033,7 @@ def _get_gdp2asset_factor(cntry_info, ref_year, shp_file, fin_mode='income_group
10261033 for cntry_iso , cntry_val in cntry_info .items ():
10271034 _ , inc_grp = income_group (cntry_iso , ref_year , shp_file )
10281035 cntry_val .append (inc_grp + 1 )
1029- elif fin_mode in ['gdp' , 'pc' ]:
1036+ elif fin_mode in ['gdp' , 'pc' , 'none' , 'norm' ]:
10301037 for cntry_iso , cntry_val in cntry_info .items ():
10311038 cntry_val .append (1 )
10321039 elif fin_mode == 'nfw' or fin_mode == 'tw' :
@@ -1811,20 +1818,6 @@ def admin1_validation(country, methods, exponents, **args):
18111818 LOGGER .error ('Country parameter data type not recognised. ' \
18121819 + 'Operation aborted.' )
18131820 raise TypeError
1814- all_coords = _litpop_box2coords (cut_bbox , resolution , 1 )
1815- # Get LitPop, Lit and Pop, etc:
1816- nightlights = _get_box_blackmarble (cut_bbox ,\
1817- resolution = resolution , return_coords = 0 )
1818- gpw = gpw_import ._get_box_gpw (cut_bbox = cut_bbox , resolution = resolution ,\
1819- return_coords = 0 , reference_year = reference_year )
1820- bm_temp = np .ones (nightlights .shape )
1821-
1822- # Lit = Lit + 1 if Population is included, c.f. int(exponents[1]>0):
1823- bm_temp [nightlights .sp_index .indices ] = (np .array (nightlights .sp_values , \
1824- dtype = 'uint16' )+ int (exponents [1 ]> 0 ))
1825- nightlights = pd .SparseArray (bm_temp , fill_value = int (exponents [1 ]> 0 ))
1826- del bm_temp
1827-
18281821 shp_file = shapereader .natural_earth (resolution = '10m' ,
18291822 category = 'cultural' ,
18301823 name = 'admin_0_countries' )
@@ -1836,9 +1829,31 @@ def admin1_validation(country, methods, exponents, **args):
18361829 _get_gdp2asset_factor (country_info , reference_year , shp_file , fin_mode = fin_mode )
18371830
18381831 curr_shp = _get_country_shape (country_list [0 ], 0 )
1832+
1833+ all_coords = _litpop_box2coords (cut_bbox , resolution , 1 )
18391834 mask = _mask_from_shape (curr_shp , resolution = resolution ,\
18401835 points2check = all_coords )
1841- nightlights = nightlights [mask .sp_index .indices ]
1836+
1837+
1838+ # Get LitPop, Lit and Pop, etc:
1839+ nightlights = _get_box_blackmarble (cut_bbox ,\
1840+ resolution = resolution , return_coords = 0 )
1841+
1842+ bm_temp = np .ones (nightlights .shape )
1843+
1844+ # Lit = Lit + 1 if Population is included, c.f. int(exponents[1]>0):
1845+ bm_temp [nightlights .sp_index .indices ] = (np .array (nightlights .sp_values , \
1846+ dtype = 'uint16' ))
1847+ del nightlights
1848+
1849+ nightlights0 = pd .SparseArray (bm_temp , fill_value = 0 )
1850+ nightlights0 = nightlights0 [mask .sp_index .indices ]
1851+ nightlights1 = pd .SparseArray (bm_temp + 1 , fill_value = 1 )
1852+ del bm_temp
1853+ nightlights1 = nightlights1 [mask .sp_index .indices ]
1854+
1855+ gpw = gpw_import ._get_box_gpw (cut_bbox = cut_bbox , resolution = resolution ,\
1856+ return_coords = 0 , reference_year = reference_year )
18421857 gpw = gpw [mask .sp_index .indices ]
18431858
18441859 lon , lat = zip (* np .array (all_coords )[mask .sp_index .indices ])
@@ -1854,8 +1869,13 @@ def admin1_validation(country, methods, exponents, **args):
18541869 LOGGER .info ('Loop through methods...' )
18551870 for i in np .arange (0 , len (methods )):
18561871 LOGGER .info ('%s :' , methods [i ])
1857- _data = _LitPop_multiply_box (nightlights , gpw , \
1858- x = exponents [i ][0 ], y = exponents [i ][1 ])
1872+ if exponents [i ][1 ]== 0 : # Lit only, use Lit in [0, 255]
1873+ _data = _LitPop_multiply_box (nightlights0 , gpw , \
1874+ x = exponents [i ][0 ], y = 0 )
1875+ else : # Pop is used, use Lit+1 in [1, 256]
1876+ _data = _LitPop_multiply_box (nightlights1 , gpw , \
1877+ x = exponents [i ][0 ], y = exponents [i ][1 ])
1878+
18591879 _ , rho [i * n_scores :(i * n_scores )+ n_scores ], adm0 [methods [i ]], adm1 [methods [i ]] = \
18601880 _calc_admin1 (country_list [0 ],\
18611881 country_info [country_list [0 ]], admin1_info [country_list [0 ]],\
0 commit comments