| Conditions | 4 |
| Total Lines | 64 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | #!/usr/bin/python3 |
||
| 65 | def get_timeseries(self, conn, **kwargs): |
||
| 66 | '' |
||
| 67 | weather = coastdat.get_weather( |
||
| 68 | conn, kwargs['geometry'], kwargs['year'] |
||
| 69 | ) |
||
| 70 | |||
| 71 | pv_df = 0 |
||
| 72 | pv_cap = {} |
||
| 73 | wind_df = 0 |
||
| 74 | wind_cap = {} |
||
| 75 | |||
| 76 | if not isinstance(weather, list): |
||
| 77 | weather = [weather] |
||
| 78 | |||
| 79 | for w_cell in weather: |
||
| 80 | ee_pps = pg_pp.get_energymap_pps( |
||
| 81 | conn, geometry1=w_cell.geometry, geometry2=kwargs['geometry'] |
||
| 82 | ) |
||
| 83 | |||
| 84 | # Find type of wind turbine and its parameters according to the |
||
| 85 | # windzone. |
||
| 86 | wz = tools.get_windzone(conn, w_cell.geometry) |
||
| 87 | |||
| 88 | kwargs['wind_conv_type'] = kwargs['wka_model_dc'].get( |
||
| 89 | wz, kwargs['wka_model'] |
||
| 90 | ) |
||
| 91 | kwargs['d_rotor'] = kwargs['d_rotor_dc'].get(wz, kwargs['d_rotor']) |
||
| 92 | kwargs['h_hub'] = kwargs['h_hub_dc'].get(wz, kwargs['h_hub']) |
||
| 93 | |||
| 94 | # Determine the feedin time series for the weather cell |
||
| 95 | # Wind energy |
||
| 96 | wind_peak_power = ee_pps[ee_pps.type == 'wind_power'].cap.sum() |
||
| 97 | wind_power_plant = pp.WindPowerPlant(**kwargs) |
||
| 98 | wind_series = wind_power_plant.feedin( |
||
| 99 | weather=w_cell, installed_capacity=wind_peak_power |
||
| 100 | ) |
||
| 101 | wind_series.name = w_cell.name |
||
| 102 | wind_cap[w_cell.name] = wind_peak_power |
||
| 103 | |||
| 104 | # PV |
||
| 105 | pv_peak_power = ee_pps[ee_pps.type == 'solar_power'].cap.sum() |
||
| 106 | pv_plant = pp.Photovoltaic(**kwargs) |
||
| 107 | pv_series = pv_plant.feedin( |
||
| 108 | weather=w_cell, peak_power=pv_peak_power |
||
| 109 | ) |
||
| 110 | pv_series.name = w_cell.name |
||
| 111 | pv_cap[w_cell.name] = pv_peak_power |
||
| 112 | |||
| 113 | # Combine the results to a DataFrame |
||
| 114 | try: |
||
| 115 | pv_df = pd.concat([pv_df, pv_series], axis=1) |
||
| 116 | wind_df = pd.concat([wind_df, wind_series], axis=1) |
||
| 117 | except Exception: |
||
| 118 | pv_df = pv_series.to_frame() |
||
| 119 | wind_df = wind_series.to_frame() |
||
| 120 | |||
| 121 | # Write capacity into a dataframe |
||
| 122 | capw = pd.Series(pd.DataFrame.from_dict(wind_cap, orient='index')[0]) |
||
| 123 | capw.name = 'wind_pwr' |
||
| 124 | cappv = pd.Series(pd.DataFrame.from_dict(pv_cap, orient='index')[0]) |
||
| 125 | cappv.name = 'pv_pwr' |
||
| 126 | cap = pd.concat([capw, cappv], axis=1) |
||
| 127 | |||
| 128 | return pv_df, wind_df, cap |
||
| 129 | |||
| 143 |