From dbb03485210d688caf267fb9c0ec2642da5bcf02 Mon Sep 17 00:00:00 2001 From: fdobad <8339628-fdobad@users.noreply.gitlab.com> Date: Mon, 15 Jul 2024 16:17:11 -0400 Subject: [PATCH] minor fixes --- pyproject.toml | 2 +- src/fire2a/cell2fire.py | 16 ++++++++-------- src/fire2a/managedata.py | 25 ++++++++++++++++++++----- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index b041878..7df9ae4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -101,7 +101,7 @@ enabled = true [tool.ruff] line-length = 120 -[tool.ruff.lint] # Disable fix for unused imports (`F401`). +[tool.ruff.lint] unfixable = ["F401"] diff --git a/src/fire2a/cell2fire.py b/src/fire2a/cell2fire.py index 65ce8bc..4f1547d 100644 --- a/src/fire2a/cell2fire.py +++ b/src/fire2a/cell2fire.py @@ -115,7 +115,7 @@ def get_scars_files(sample_file: Path): from re import search as re_search ext = sample_file.suffix - if match := re_search("(\d+)$", sample_file.stem): + if match := re_search(r"(\d+)$", sample_file.stem): num = match.group() else: msg = f"sample_file: {sample_file} does not contain a number at the end" @@ -124,7 +124,7 @@ def get_scars_files(sample_file: Path): parent = sample_file.absolute().parent root = sample_file.absolute().parent.parent parent = parent.relative_to(root) - if match := re_search("(\d+)$", parent.name): + if match := re_search(r"(\d+)$", parent.name): num = match.group() else: msg = f"sample_file:{sample_file} parent:{parent} does not contain a number at the end" @@ -136,7 +136,7 @@ def get_scars_files(sample_file: Path): for par in root.glob(parent_wo_num + "[0-9]*"): if par.is_dir(): par = par.relative_to(root) - parent_ids += [int(re_search("(\d+)$", par.name).group(0))] + parent_ids += [int(re_search(r"(\d+)$", par.name).group(0))] parent_dirs += [par] adict = dict(zip(parent_dirs, parent_ids)) parent_dirs.sort(key=lambda x: adict[x]) @@ -150,7 +150,7 @@ def get_scars_files(sample_file: Path): for afile in (root / par).glob(file_name_wo_num + "[0-9]*" + ext): if afile.is_file() and afile.stat().st_size > 0: afile = afile.relative_to(root) - chl_ids += [int(re_search("(\d+)$", afile.stem).group(0))] + chl_ids += [int(re_search(r"(\d+)$", afile.stem).group(0))] chl_files += [afile] adict = dict(zip(chl_files, chl_ids)) chl_files.sort(key=lambda x: adict[x]) @@ -194,7 +194,7 @@ def get_scars_indexed(sample_file: Path): from numpy import fromiter as np_fromiter ext = sample_file.suffix - if match := re_search("(\d+)$", sample_file.stem): + if match := re_search(r"(\d+)$", sample_file.stem): num = match.group() else: msg = f"sample_file: {sample_file} does not contain a number at the end" @@ -203,7 +203,7 @@ def get_scars_indexed(sample_file: Path): parent = sample_file.absolute().parent root = sample_file.absolute().parent.parent parent = parent.relative_to(root) - if match := re_search("(\d+)$", parent.name): + if match := re_search(r"(\d+)$", parent.name): num = match.group() else: msg = f"sample_file:{sample_file} parent:{parent} does not contain a number at the end" @@ -222,8 +222,8 @@ def get_scars_indexed(sample_file: Path): if sep == "\\": sep = "\\\\" indexes = np_fromiter( - # re_findall(parent_wo_num + "(\d+)" + sep + child_wo_num + "(\d+)" + ext, " ".join(map(str, files))), - re_findall("(\d+)" + sep + child_wo_num + "(\d+)", " ".join(map(str, files))), + # re_findall(parent_wo_num + r"(\d+)" + sep + child_wo_num + r"(\d+)" + ext, " ".join(map(str, files))), + re_findall(r"(\d+)" + sep + child_wo_num + r"(\d+)", " ".join(map(str, files))), dtype=[("sim", int), ("per", int)], count=len(files), ) diff --git a/src/fire2a/managedata.py b/src/fire2a/managedata.py index fea059e..d9406cf 100644 --- a/src/fire2a/managedata.py +++ b/src/fire2a/managedata.py @@ -6,18 +6,19 @@ __revision__ = "$Format:%H$" from pathlib import Path +from typing import Any, Dict, List, Optional, Tuple, Union +from numpy import dtype from numpy import empty as npempty from numpy import full as npfull from numpy import max as npmax from numpy import nan as npnan +from numpy import ndarray from numpy import zeros as npzeros -from numpy import ndarray, dtype from pandas import DataFrame -from typing import Any, Dict, List, Optional, Tuple -def Lookupdict(filename: Optional[Path,str]) -> Tuple[dict, dict]: +def Lookupdict(filename: Union[Path, str]) -> Tuple[dict, dict]: """Reads lookup_table.csv and creates dictionaries for the fuel types and cells' colors Args: @@ -58,9 +59,12 @@ def Lookupdict(filename: Optional[Path,str]) -> Tuple[dict, dict]: return row, colors + # Tuple[(list, list, int, int, list, list, int)] # Tuple[list[Any], list[Any], int, int, list[Any], list[Any], int] -def ForestGrid(filename: str, Lookupdict: dict) -> Tuple[list[int], list[str], int, int, list[dict[str, Optional[list[int]]]], ndarray[Any, dtype[Any]], float]: +def ForestGrid( + filename: str, Lookupdict: dict +) -> Tuple[list[int], list[str], int, int, list[dict[str, Optional[list[int]]]], ndarray[Any, dtype[Any]], float]: """Reads fuels.asc file and returns an array with all the cells, and grid dimension nxm Args: @@ -327,8 +331,19 @@ def ForestGrid(filename: str, Lookupdict: dict) -> Tuple[list[int], list[str], i return gridcell3, gridcell4, len(grid), tcols - 1, AdjCells, CoordCells, cellsize + # Tuple[(list, list, list, list, list, list, list, list, list)] -def DataGrids(InFolder: str, NCells: int) -> Tuple[ndarray[Any, dtype[Any]], ndarray[Any, dtype[Any]], ndarray[Any, dtype[Any]], ndarray[Any, dtype[Any]], ndarray[Any, dtype[Any]], ndarray[Any, dtype[Any]], ndarray[Any, dtype[Any]], ndarray[Any, dtype[Any]], ndarray[Any, dtype[Any]]]: +def DataGrids(InFolder: str, NCells: int) -> Tuple[ + ndarray[Any, dtype[Any]], + ndarray[Any, dtype[Any]], + ndarray[Any, dtype[Any]], + ndarray[Any, dtype[Any]], + ndarray[Any, dtype[Any]], + ndarray[Any, dtype[Any]], + ndarray[Any, dtype[Any]], + ndarray[Any, dtype[Any]], + ndarray[Any, dtype[Any]], +]: """ Reads *.asc files and returns an array per each ASCII file with the correspondant information per each cell. Currently supports elevation, ascpect, slope, curing, canopy bulk density, crown base height, conifer percent dead fir, probability of ignition and foliar moisture content.