fire2a.treatmentpreproccessing
Fuelbreak treatment pre proccessing functions
1#!python3 2""" 3Fuelbreak treatment pre proccessing functions 4""" 5__author__ = "David Palacios Meneses" 6__revision__ = "$Format:%H$" 7from numpy import insert as npinsert 8from pandas import DataFrame 9 10 11def bin_to_nod(solution: list, filename="treatment.csv") -> None: 12 """Transforms a binary array to a Cell2Fire firebreak file 13 14 Args: 15 solution (list[int]): List with id of treatment cell 16 filename (string): Path and name of the destiny folder (should be a .csv) 17 18 Returns: 19 None 20 Appends to filename.csv with columns "Year Number", "Cell Numbers" 21 22 Raises: 23 ValueError: If the extension of the filename is not a csv 24 """ 25 if filename[-4:] != ".csv": 26 raise ValueError("Extension must be .csv or .txt") 27 nod = [i + 1 for i in solution] 28 datos = [npinsert(nod, 0, 1)] 29 if len(nod) == 0: 30 cols = ["Year Number"] 31 else: 32 colu = ["Year Number", "Cell Numbers"] 33 col2 = [""] * (len(nod) - 1) 34 cols = colu + col2 35 df = DataFrame(datos, columns=cols) 36 df.to_csv(filename, index=None, mode="a") 37 38 39if __name__ == "__main__": 40 vector_test = [1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1] 41 name = "test_treatment.csv" 42 bin_to_nod(vector_test, name)
def
bin_to_nod(solution: list, filename='treatment.csv') -> None:
12def bin_to_nod(solution: list, filename="treatment.csv") -> None: 13 """Transforms a binary array to a Cell2Fire firebreak file 14 15 Args: 16 solution (list[int]): List with id of treatment cell 17 filename (string): Path and name of the destiny folder (should be a .csv) 18 19 Returns: 20 None 21 Appends to filename.csv with columns "Year Number", "Cell Numbers" 22 23 Raises: 24 ValueError: If the extension of the filename is not a csv 25 """ 26 if filename[-4:] != ".csv": 27 raise ValueError("Extension must be .csv or .txt") 28 nod = [i + 1 for i in solution] 29 datos = [npinsert(nod, 0, 1)] 30 if len(nod) == 0: 31 cols = ["Year Number"] 32 else: 33 colu = ["Year Number", "Cell Numbers"] 34 col2 = [""] * (len(nod) - 1) 35 cols = colu + col2 36 df = DataFrame(datos, columns=cols) 37 df.to_csv(filename, index=None, mode="a")
Transforms a binary array to a Cell2Fire firebreak file
Args: solution (list[int]): List with id of treatment cell filename (string): Path and name of the destiny folder (should be a .csv)
Returns: None Appends to filename.csv with columns "Year Number", "Cell Numbers"
Raises: ValueError: If the extension of the filename is not a csv