-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(examples): added a dedicated examples folder
added a sample function example, with valid plots and products output
- Loading branch information
Showing
4 changed files
with
61 additions
and
24 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
"""Sample CHIME/FRB Workflow Compatible Function.""" | ||
|
||
from pathlib import Path | ||
from typing import Dict, List, Tuple | ||
|
||
|
||
def math( | ||
a: float | int, b: float | int | ||
) -> Tuple[Dict[str, float], List[str], List[str]]: | ||
"""Sample CHIME/FRB Workflow Compatible Function. | ||
Args: | ||
a (float | int): A number | ||
b (float | int): Another number | ||
Raises: | ||
error: If the arguments are not | ||
Returns: | ||
Tuple[Dict[str, float], List[str], List[str]]: | ||
The results, products, and plots | ||
""" | ||
try: | ||
assert isinstance(a, (float, int)), "a must be a number" | ||
assert isinstance(b, (float, int)), "b must be a number" | ||
results: Dict[str, float] = { | ||
"sum": a + b, | ||
"difference": a - b, | ||
"product": a * b, | ||
"quotient": a / b, | ||
"power": a**b, | ||
"root": a ** (1 / b), | ||
"log": a ** (1 / b), | ||
} | ||
# Make a csv file with results | ||
with open("/tmp/sample.csv", "w") as file: | ||
for key, value in results.items(): | ||
file.write(f"{key},{value}\n") | ||
products: List[str] = ["/tmp/sample.csv"] | ||
# Get the directory of whereever this file is | ||
current: Path = Path(__file__).parent | ||
# Copy sample svg file to /tmp | ||
source: Path = current / "sample.svg" | ||
destination: Path = Path("/tmp/sample.svg") | ||
destination.write_text(source.read_text()) | ||
plots: List[str] = [destination.as_posix()] | ||
return results, products, plots | ||
except AssertionError as error: | ||
raise error |
File renamed without changes.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.