| Conditions | 5 |
| Total Lines | 57 |
| Code Lines | 33 |
| 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 | """ |
||
| 87 | def import_cutout(boundary="Europe"): |
||
| 88 | """Import weather data from cutout |
||
| 89 | |||
| 90 | Returns |
||
| 91 | ------- |
||
| 92 | cutout : atlite.cutout.Cutout |
||
| 93 | Weather data stored in cutout |
||
| 94 | |||
| 95 | """ |
||
| 96 | for scn in set(egon.data.config.settings()["egon-data"]["--scenarios"]): |
||
| 97 | weather_year = get_sector_parameters("global", scn)["weather_year"] |
||
| 98 | |||
| 99 | if boundary == "Europe": |
||
| 100 | xs = slice(-12.0, 35.1) |
||
| 101 | ys = slice(72.0, 33.0) |
||
| 102 | |||
| 103 | elif boundary == "Germany": |
||
| 104 | geom_de = ( |
||
| 105 | gpd.read_postgis( |
||
| 106 | "SELECT geometry as geom FROM boundaries.vg250_sta_bbox", |
||
| 107 | db.engine(), |
||
| 108 | ) |
||
| 109 | .to_crs(4326) |
||
| 110 | .geom |
||
| 111 | ) |
||
| 112 | xs = slice(geom_de.bounds.minx[0], geom_de.bounds.maxx[0]) |
||
| 113 | ys = slice(geom_de.bounds.miny[0], geom_de.bounds.maxy[0]) |
||
| 114 | |||
| 115 | elif boundary == "Germany-offshore": |
||
| 116 | xs = slice(5.5, 14.5) |
||
| 117 | ys = slice(55.5, 53.5) |
||
| 118 | |||
| 119 | else: |
||
| 120 | print( |
||
| 121 | f"Boundary {boundary} not defined. " |
||
| 122 | "Choose either 'Europe' or 'Germany'" |
||
| 123 | ) |
||
| 124 | |||
| 125 | directory = ( |
||
| 126 | Path(".") |
||
| 127 | / ( |
||
| 128 | egon.data.config.datasets()["era5_weather_data"]["targets"][ |
||
| 129 | "weather_data" |
||
| 130 | ]["path"] |
||
| 131 | ) |
||
| 132 | / f"{boundary.lower()}-{str(weather_year)}-era5.nc" |
||
| 133 | ) |
||
| 134 | |||
| 135 | cutout = atlite.Cutout( |
||
| 136 | path=directory.absolute(), |
||
| 137 | module="era5", |
||
| 138 | x=xs, |
||
|
|
|||
| 139 | y=ys, |
||
| 140 | years=slice(weather_year, weather_year), |
||
| 141 | ) |
||
| 142 | |||
| 143 | return cutout |
||
| 144 | |||
| 215 |