Skip to content

Commit

Permalink
Merge pull request #15 from NeoGeographyToolkit/estimate-ages-error-fix
Browse files Browse the repository at this point in the history
Crater and Rock fixes
  • Loading branch information
rbeyer authored Jan 14, 2023
2 parents 9b82c50 + 4558829 commit 3adc1c8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/python/synthterrain/crater/age.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ def estimate_age_by_bin(
is compared to the d/D ratios from the diffusion run, and an estimated age
is assigned.
"""
if df.empty:
raise ValueError("The provided dataframe has no rows.")

logger.info("estimate_age_by_bin start.")
bin_edges = np.geomspace(
df["diameter"].min(), df["diameter"].max(), num=num + 1
Expand Down
16 changes: 11 additions & 5 deletions src/python/synthterrain/crater/cli_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,18 @@ def main():
b = df["diameter"].max()
pd_func = crater_func.GNPF(a=a, b=b)
eq_func = crater_func.VIPER_Env_Spec(a=a, b=b)
if "age" in df.columns:
df[df["age"] == 0] = estimate_age_by_bin(
df[df["age"] == 0], pd_func.csfd, eq_func.csfd, num=50
try:
if "age" in df.columns:
df[df["age"] == 0] = estimate_age_by_bin(
df[df["age"] == 0], pd_func.csfd, eq_func.csfd, num=50
)
else:
df = estimate_age_by_bin(df, pd_func.csfd, eq_func.csfd, num=50)
except ValueError:
logger.error(
"The provided file has no craters with an age of zero."
)
else:
df = estimate_age_by_bin(df, pd_func.csfd, eq_func.csfd, num=50)
return 1

crater.to_file(df, args.outfile, xml=(args.outfile.suffix.casefold() == ".xml"))

Expand Down
2 changes: 1 addition & 1 deletion src/python/synthterrain/rock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def place_rocks(
position_idxs = rng.choice(
len(flat_prob_map),
size=len(diameters),
replace=False,
replace=True,
p=flat_prob_map,
)

Expand Down
7 changes: 6 additions & 1 deletion src/python/synthterrain/rock/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ def arg_parser():
"in XML output that conforms to the old MATLAB code.",
)
parser.add_argument(
"-o", "--outfile", default=None, type=Path, help="Path to output file."
"-o",
"--outfile",
required=True,
default=None,
type=Path,
help="Path to output file.",
)

return parser
Expand Down

0 comments on commit 3adc1c8

Please sign in to comment.