|
18 | 18 | __revision__ = "$Format:%H$" |
19 | 19 |
|
20 | 20 | import sys |
| 21 | +import csv |
| 22 | +import os |
21 | 23 | from datetime import datetime, time, timedelta |
22 | 24 | from pathlib import Path |
23 | 25 |
|
|
40 | 42 | # assert (ruta_data / "Estaciones.csv").is_file() |
41 | 43 |
|
42 | 44 |
|
| 45 | +def transform_weather_file(filename): |
| 46 | + """Flip the direction of the wind in a weather file. Column containing wind direction must be called "WD".\ |
| 47 | + this changes the contents of the given file.""" |
| 48 | + temp_name = f"{filename}_tmp" |
| 49 | + with open(filename, newline='') as csvfile, open(temp_name, mode='w') as outfile: |
| 50 | + reader = csv.DictReader(csvfile) |
| 51 | + writer = csv.DictWriter(outfile, reader.fieldnames) |
| 52 | + writer.writeheader() |
| 53 | + for i in reader: |
| 54 | + i['WD'] = flip_wind(float(i["WD"])) |
| 55 | + writer.writerow(i) |
| 56 | + if os.path.isfile(filename): |
| 57 | + os.remove(filename) |
| 58 | + os.rename(temp_name, filename) |
| 59 | + |
| 60 | + |
43 | 61 | def is_qgis_running(): |
44 | 62 | qgis = False |
45 | 63 | try: |
@@ -87,16 +105,7 @@ def distance(fila, lat, lon): |
87 | 105 | return eucl_distance(fila, lat, lon) |
88 | 106 |
|
89 | 107 |
|
90 | | -def meteo_to_c2f(alfa): |
91 | | - """@private""" |
92 | | - if alfa >= 0 and alfa < 180: |
93 | | - return round(alfa + 180, 2) |
94 | | - elif alfa >= 180 and alfa <= 360: |
95 | | - return round(alfa - 180, 2) |
96 | | - return np.nan |
97 | | - |
98 | | - |
99 | | -def barlo_sota(a): |
| 108 | +def flip_wind(a): |
100 | 109 | """Leeward to Windward wind angle direction flip. Barlovento a sotavento. Downwind to upwind.""" |
101 | 110 | return round((a + 180) % 360, 2) |
102 | 111 |
|
@@ -215,8 +224,6 @@ def generate( |
215 | 224 | # drop station |
216 | 225 | # TODO no drop ? |
217 | 226 | # chosen_meteo = chosen_meteo.drop(columns=["station"]) |
218 | | - # wind direction |
219 | | - chosen_meteo.loc[:, "WD"] = chosen_meteo["WD"].apply(barlo_sota) |
220 | 227 | # scenario name |
221 | 228 | chosen_meteo.loc[:, "Scenario"] = "DMC" if numsims == 1 else f"DMC_{i+1}" |
222 | 229 | # TODO sobra: datetime format |
|
0 commit comments