From 1f2d1c454dc9200e0aaf84e4491a726a4a432b08 Mon Sep 17 00:00:00 2001 From: mati Date: Fri, 22 Aug 2025 15:25:33 -0400 Subject: [PATCH 1/3] No longer changes wind direction when creating weather data. Add function to apply transformation to entire file --- src/fire2a/meteo.py | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/fire2a/meteo.py b/src/fire2a/meteo.py index 3720640..e86d526 100644 --- a/src/fire2a/meteo.py +++ b/src/fire2a/meteo.py @@ -18,6 +18,8 @@ __revision__ = "$Format:%H$" import sys +import csv +import os from datetime import datetime, time, timedelta from pathlib import Path @@ -40,6 +42,22 @@ # assert (ruta_data / "Estaciones.csv").is_file() +def transform_weather_file(filename): + """Flip the direction of the wind in a weather file. Column containing wind direction must be called "WD".\ + this changes the contents of the given file.""" + temp_name = f"{filename}_tmp" + with open(filename, newline='') as csvfile, open(temp_name, mode='w') as outfile: + reader = csv.DictReader(csvfile) + writer = csv.DictWriter(outfile, reader.fieldnames) + writer.writeheader() + for i in reader: + i['WD'] = flip_wind(float(i["WD"])) + writer.writerow(i) + if os.path.isfile(filename): + os.remove(filename) + os.rename(temp_name, filename) + + def is_qgis_running(): qgis = False try: @@ -87,16 +105,7 @@ def distance(fila, lat, lon): return eucl_distance(fila, lat, lon) -def meteo_to_c2f(alfa): - """@private""" - if alfa >= 0 and alfa < 180: - return round(alfa + 180, 2) - elif alfa >= 180 and alfa <= 360: - return round(alfa - 180, 2) - return np.nan - - -def barlo_sota(a): +def flip_wind(a): """Leeward to Windward wind angle direction flip. Barlovento a sotavento. Downwind to upwind.""" return round((a + 180) % 360, 2) @@ -216,7 +225,7 @@ def generate( # TODO no drop ? # chosen_meteo = chosen_meteo.drop(columns=["station"]) # wind direction - chosen_meteo.loc[:, "WD"] = chosen_meteo["WD"].apply(barlo_sota) + chosen_meteo.loc[:, "WD"] = chosen_meteo["WD"] # scenario name chosen_meteo.loc[:, "Scenario"] = "DMC" if numsims == 1 else f"DMC_{i+1}" # TODO sobra: datetime format From d431b05a33fee7bbfeed2bfbb82fdeb9dface8cd Mon Sep 17 00:00:00 2001 From: mati Date: Fri, 22 Aug 2025 15:39:14 -0400 Subject: [PATCH 2/3] update meteo test --- tests/test_meteo.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_meteo.py b/tests/test_meteo.py index cf7ea6f..93645dd 100644 --- a/tests/test_meteo.py +++ b/tests/test_meteo.py @@ -33,9 +33,9 @@ def test_weather_lenght(tmp_path): def test_invert_wind(): from numpy import linspace - from fire2a.meteo import barlo_sota, meteo_to_c2f + from fire2a.meteo import flip_wind - for a in linspace(1, 360, 12): - assert barlo_sota(a) - meteo_to_c2f(a) < 0.01, "Conversion incorrecta" + for a in linspace(0, 359, 12): + assert round(a,2) - flip_wind(flip_wind(a)) < 0.01, "Conversion incorrecta" # for a in np.linspace(-360, 720, 12): # print(a, barlo_sota(a), meteo_to_c2f(a)) From 23a4e899a9a7d4291cdeb955ca749d376713cbd7 Mon Sep 17 00:00:00 2001 From: fdobad <29801096+fdobad@users.noreply.github.com> Date: Wed, 27 Aug 2025 15:17:54 -0400 Subject: [PATCH 3/3] remove wind flip --- src/fire2a/meteo.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/fire2a/meteo.py b/src/fire2a/meteo.py index e86d526..ac76990 100644 --- a/src/fire2a/meteo.py +++ b/src/fire2a/meteo.py @@ -224,8 +224,6 @@ def generate( # drop station # TODO no drop ? # chosen_meteo = chosen_meteo.drop(columns=["station"]) - # wind direction - chosen_meteo.loc[:, "WD"] = chosen_meteo["WD"] # scenario name chosen_meteo.loc[:, "Scenario"] = "DMC" if numsims == 1 else f"DMC_{i+1}" # TODO sobra: datetime format