Skip to content

Commit e41b100

Browse files
committed
correct pylint
1 parent 4d64be0 commit e41b100

File tree

6 files changed

+49
-33
lines changed

6 files changed

+49
-33
lines changed

climada/engine/cost_benefit.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def plot_waterfall(self, hazard, entity, haz_future, ent_future,
320320
risk_curr = self._npv_unaverted_impact(risk_future, entity.disc_rates,
321321
time_dep)
322322
LOGGER.info('Risk function at {:d}: {:.3e}'.format(self.present_year,
323-
risk_future))
323+
risk_future))
324324

325325
# changing future
326326
time_dep = self._time_dependency_array(imp_time_depen)
@@ -335,7 +335,7 @@ def plot_waterfall(self, hazard, entity, haz_future, ent_future,
335335
risk_tot = self._npv_unaverted_impact(risk_future, entity.disc_rates,
336336
time_dep, curr_risk)
337337
LOGGER.info('Risk function at {:d}: {:.3e}'.format(self.future_year,
338-
risk_future))
338+
risk_future))
339339

340340
axis.bar(1, risk_curr/norm_fact)
341341
axis.text(1, risk_curr/norm_fact, str(int(round(risk_curr/norm_fact))), \
@@ -357,7 +357,7 @@ def plot_waterfall(self, hazard, entity, haz_future, ent_future,
357357
'Economic \ndevelopment', 'Climate \nchange', 'Risk ' + str(self.future_year)])
358358
axis.set_ylabel('Impact (' + self.unit + ' ' + norm_name + ')')
359359
axis.set_title('Total accumulated damage from {:d} to {:d}'.format(
360-
self.present_year, self.future_year))
360+
self.present_year, self.future_year))
361361

362362
return fig, axis
363363

@@ -515,7 +515,7 @@ def _print_results(self):
515515

516516
table = []
517517
headers = ['Measure', 'Cost ' + norm_name, 'Benefit ' + norm_name, 'Benefit/Cost']
518-
for meas_name in self.benefit.keys():
518+
for meas_name in self.benefit:
519519
table.append([meas_name, \
520520
self.cost_ben_ratio[meas_name]*self.benefit[meas_name]/norm_fact, \
521521
self.benefit[meas_name]/norm_fact, 1/self.cost_ben_ratio[meas_name]])

climada/engine/test/test_cost_benefit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ def test_impact(self):
382382
impact = Impact()
383383
ent.exposures.assign_centroids(hazard)
384384
impact.calc(ent.exposures, ent.impact_funcs, hazard)
385-
return impact
385+
return impact
386386

387387
def test_risk_aai_agg_pass(self):
388388
"""Test risk_aai_agg"""

climada/entity/exposures/base.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,10 @@ def plot_raster(self, res=None, raster_res=None, save_tiff=None,
351351

352352
def plot_basemap(self, mask=None, ignore_zero=False, pop_name=True,
353353
buffer=0.0, extend='neither', zoom=10,
354-
url='http://tile.stamen.com/terrain/tileZ/tileX/tileY.png',
354+
url='http://tile.stamen.com/terrain/tileZ/tileX/tileY.png',
355355
**kwargs):
356-
""" Scatter points over satellite image using contextily
357-
356+
""" Scatter points over satellite image using contextily
357+
358358
Parameters:
359359
mask (np.array, optional): mask to apply to eai_exp plotted.
360360
ignore_zero (bool, optional): flag to indicate if zero and negative
@@ -364,7 +364,7 @@ def plot_basemap(self, mask=None, ignore_zero=False, pop_name=True,
364364
extend (str, optional): extend border colorbar with arrows.
365365
[ 'neither' | 'both' | 'min' | 'max' ]
366366
zoom (int, optional): zoom coefficient used in the satellite image
367-
url (str, optional): satellite image source.
367+
url (str, optional): image source, e.g. ctx.sources.OSM_C
368368
kwargs (optional): arguments for scatter matplotlib function, e.g.
369369
cmap='Greys'. Default: 'Wistia'
370370
Returns:
@@ -374,12 +374,12 @@ def plot_basemap(self, mask=None, ignore_zero=False, pop_name=True,
374374
self.set_geometry_points()
375375
crs_ori = self.crs
376376
self.to_crs(epsg=3857, inplace=True)
377-
fig, ax = self.plot_scatter(mask, ignore_zero, pop_name, buffer, extend,
378-
shapes=False, **kwargs)
379-
u_plot.add_basemap(ax[0, 0], zoom, url, flip=True)
380-
ax[0, 0].set_axis_off()
377+
fig, axis = self.plot_scatter(mask, ignore_zero, pop_name, buffer,
378+
extend, shapes=False, **kwargs)
379+
u_plot.add_basemap(axis[0, 0], zoom, url, flip=True)
380+
axis[0, 0].set_axis_off()
381381
self.to_crs(crs_ori, inplace=True)
382-
return fig, ax
382+
return fig, axis
383383

384384
def write_hdf5(self, file_name):
385385
""" Write data frame and metadata in hdf5 format """

climada/entity/exposures/test/test_base.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import unittest
2323
import numpy as np
2424
import pandas as pd
25-
import geopandas
25+
import geopandas as gpd
2626
import cartopy
2727
from sklearn.neighbors import DistanceMetric
2828
from climada.util.coordinates import coord_on_land
@@ -47,7 +47,7 @@ def good_exposures():
4747
data['region_id'] = np.array([1, 2, 3])
4848
data[INDICATOR_CENTR + 'TC'] = np.array([1, 2, 3])
4949

50-
expo = Exposures(geopandas.GeoDataFrame(data=data))
50+
expo = Exposures(gpd.GeoDataFrame(data=data))
5151
return expo
5252

5353
class TestFuncs(unittest.TestCase):
@@ -272,6 +272,15 @@ def test_to_crs_pass(self):
272272
self.assertEqual(exp_tr.tag.description, '')
273273
self.assertEqual(exp_tr.tag.file_name, '')
274274

275+
def test_constructoer_pass(self):
276+
""" Test initialization with input GeiDataFrame """
277+
in_gpd = gpd.GeoDataFrame()
278+
in_gpd['value'] = np.zeros(10)
279+
in_gpd.ref_year = 2015
280+
in_exp = Exposures(in_gpd)
281+
self.assertEqual(in_exp.ref_year, 2015)
282+
self.assertTrue(np.array_equal(in_exp.value, np.zeros(10)))
283+
275284
# Execute Tests
276285
TESTS = unittest.TestLoader().loadTestsFromTestCase(TestChecker)
277286
TESTS.addTests(unittest.TestLoader().loadTestsFromTestCase(TestFuncs))

climada/entity/measures/measure_set.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ def size(self, haz_type=None, name=None):
257257
int
258258
"""
259259
if (haz_type is not None) and (name is not None) and \
260-
(isinstance(self.get_func(haz_type, name), Measure)):
260+
(isinstance(self.get_measure(haz_type, name), Measure)):
261261
return 1
262262
if (haz_type is not None) or (name is not None):
263263
return len(self.get_measure(haz_type, name))
@@ -276,7 +276,7 @@ def check(self):
276276
LOGGER.error("Wrong Measure.name: %s != %s.", name, \
277277
meas.name)
278278
raise ValueError
279-
if (key_haz != meas.haz_type):
279+
if key_haz != meas.haz_type:
280280
LOGGER.error("Wrong Measure.haz_type: %s != %s.",\
281281
key_haz, meas.haz_type)
282282
raise ValueError
@@ -456,19 +456,19 @@ def write_meas(row_ini, imp_ws, xls_data):
456456
var_names['col_name']['paa_b'], var_names['col_name']['fun_map'],
457457
var_names['col_name']['exp_set'], var_names['col_name']['exp_reg'],
458458
var_names['col_name']['risk_att'], var_names['col_name']['risk_cov'],
459-
var_names['col_name']['haz']]
459+
var_names['col_name']['haz']]
460460
for icol, head_dat in enumerate(header):
461461
mead_ws.write(0, icol, head_dat)
462462
row_ini = 1
463-
for haz_type, haz_dict in self._data.items():
463+
for _, haz_dict in self._data.items():
464464
for meas_name, meas in haz_dict.items():
465-
xls_data = [meas_name, ' '.join(list(map(str, meas.color_rgb))),
466-
meas.cost, meas.hazard_inten_imp[0],
467-
meas.hazard_inten_imp[1], meas.hazard_freq_cutoff,
468-
meas.hazard_set, meas.mdd_impact[0], meas.mdd_impact[1],
469-
meas.paa_impact[0], meas.paa_impact[1], meas.imp_fun_map,
470-
meas.exposures_set, meas.exp_region_id, meas.risk_transf_attach,
471-
meas.risk_transf_cover, meas.haz_type]
465+
xls_data = [meas_name, ' '.join(list(map(str, meas.color_rgb))),
466+
meas.cost, meas.hazard_inten_imp[0],
467+
meas.hazard_inten_imp[1], meas.hazard_freq_cutoff,
468+
meas.hazard_set, meas.mdd_impact[0], meas.mdd_impact[1],
469+
meas.paa_impact[0], meas.paa_impact[1], meas.imp_fun_map,
470+
meas.exposures_set, meas.exp_region_id, meas.risk_transf_attach,
471+
meas.risk_transf_cover, meas.haz_type]
472472
write_meas(row_ini, mead_ws, xls_data)
473473
row_ini += 1
474-
meas_wb.close()
474+
meas_wb.close()

climada/util/plot.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
from mpl_toolkits.axes_grid1 import make_axes_locatable
3535
from shapely.geometry import box
3636
import cartopy.crs as ccrs
37-
import contextily as ctx
3837
from cartopy.io import shapereader
3938
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
39+
import contextily as ctx
4040

4141
from climada.util.files_handler import to_list
4242

@@ -509,11 +509,18 @@ def _get_borders(geo_coord, buffer=0, proj=ccrs.PlateCarree()):
509509
max_lat = min(np.max(geo_coord[:, 0])+buffer, proj.y_limits[1])
510510
return [min_lon, max_lon, min_lat, max_lat]
511511

512-
def add_basemap(ax, zoom, url='http://tile.stamen.com/terrain/tileZ/tileX/tileY.png',
512+
def add_basemap(axis, zoom, url='http://tile.stamen.com/terrain/tileZ/tileX/tileY.png',
513513
flip=False):
514-
xmin, xmax, ymin, ymax = ax.axis()
514+
""" Add image to given axis. Coordinates need to be in epsg=3857.
515+
516+
Parameters:
517+
(cartopy.mpl.geoaxes.GeoAxesSubplot): plot axis
518+
zoom (int, optional): zoom coefficient used in the satellite image
519+
url (str, optional): image source, e.g. ctx.sources.OSM_C
520+
"""
521+
xmin, xmax, ymin, ymax = axis.axis()
515522
basemap, extent = ctx.bounds2img(xmin, ymin, xmax, ymax, zoom=zoom, url=url)
516523
if flip:
517524
basemap = np.flip(basemap, 0)
518-
ax.imshow(basemap, extent=extent, interpolation='bilinear')
519-
ax.axis((xmin, xmax, ymin, ymax))
525+
axis.imshow(basemap, extent=extent, interpolation='bilinear')
526+
axis.axis((xmin, xmax, ymin, ymax))

0 commit comments

Comments
 (0)