Skip to content

Commit

Permalink
Merge pull request #13 from fire2a/publish
Browse files Browse the repository at this point in the history
minor typing fixes
  • Loading branch information
fdobad authored Jul 15, 2024
2 parents 14cf384 + dbb0348 commit 2f9e7aa
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

16 changes: 8 additions & 8 deletions src/fire2a/cell2fire.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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])
Expand All @@ -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])
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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),
)
Expand Down
25 changes: 20 additions & 5 deletions src/fire2a/managedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 2f9e7aa

Please sign in to comment.