Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
6c74da7
Use namedtuple for FLAG and FLAG_CRITERIA
emmleroy Jun 26, 2026
02606fb
Replace single-filter flag command with multi-filter flagging
emmleroy Jun 26, 2026
28197e1
Add util for determining the timestamp col
emmleroy Jun 26, 2026
1f8f9ba
Refactor - rename bit to flag_value, fix click commands
emmleroy Jun 29, 2026
79e26bf
Update tests
emmleroy Jun 29, 2026
003d5ad
Fix indentation
emmleroy Jun 29, 2026
d4b2c97
Remove relative imports
emmleroy Jun 30, 2026
22b7560
Remove arisense flagging functionality
emmleroy Jun 30, 2026
61f6d34
Modify safe_loader() to add device serial number to rawSD columns
emmleroy Jun 30, 2026
f0b40aa
Add func to infer data model from the sn column
emmleroy Jun 30, 2026
5ad1d1f
Add func to infer data source from the dataframe sampling frequency (…
emmleroy Jun 30, 2026
045e34b
Infer data model and source in flag_dataframe() instead of taking args
emmleroy Jun 30, 2026
d04686a
Define identical FLAG_DEFINITIONS for QuantAQ products and modifiable…
emmleroy Jun 30, 2026
e19c028
Convert model-specific FLAG_DEFINITIONS into one generic list
emmleroy Jun 30, 2026
fe018eb
Remove tests for rawSD flagging - currently not implemented
emmleroy Jun 30, 2026
30646f7
Upgrade deps to Click8.x
emmleroy Jun 30, 2026
89a2ce6
Port expunge_dataframe() and echo_flag_table() from Isoprene
emmleroy Jun 30, 2026
49c186a
Move flag_summary and echo_flag_table to flag.py and fix all_nan_colu…
emmleroy Jun 30, 2026
cae63d5
Remove arisense from test_expunge() and add some expunge tests from I…
emmleroy Jun 30, 2026
2e67857
Remove feather tests and fix --wind unpack error in resample CLI
emmleroy Jun 30, 2026
eb2c043
Remove data model and data source as required args to flag_command
emmleroy Jul 1, 2026
04d34ed
Remove data model and data source as required args in cli logic and t…
emmleroy Jul 1, 2026
9e729a7
Fix cli args again
emmleroy Jul 1, 2026
cf1fe9a
Add jupyter for playbook notebooks
emmleroy Jul 1, 2026
61ccdea
Rename quantaq_cli to quantaq_py
emmleroy Jul 1, 2026
7d09cc4
Add logging configuration file
emmleroy Jul 1, 2026
b11c7c5
Create importable concat_files() function and move concat_command() t…
emmleroy Jul 1, 2026
554d0fe
Create importable merge_files() function and move merge_command() to …
emmleroy Jul 1, 2026
6afab69
Create importable resample_dataframe() function and move resample_com…
emmleroy Jul 1, 2026
736358d
Add importable flag_dataframe() and echo_flag_table(), move flag_comm…
emmleroy Jul 1, 2026
6db884c
Create importable expunge_dataframe(), move expunge_command to cli.py
emmleroy Jul 1, 2026
ace9101
Create importable clean_file(), move clean_command to cli.py
emmleroy Jul 1, 2026
134f7b0
Remove feather functionality for parquet
emmleroy Jul 1, 2026
63fee0d
Make add_sn_column an optional arg
emmleroy Jul 1, 2026
ee78d7f
Remove console/commands sub-dirs
emmleroy Jul 1, 2026
4f332ba
Add tests for parquet file support
emmleroy Jul 1, 2026
bfe66fb
Move library function into quantaq_py/toolkit
emmleroy Jul 1, 2026
c50de58
Add pandera
emmleroy Jul 2, 2026
a625733
Add Pandera schema checks, always add sn column when safe_loading raw…
emmleroy Jul 2, 2026
9966b89
Define dtypes and schema checks in schema.py
emmleroy Jul 2, 2026
8162df4
Remove tests for arisense
emmleroy Jul 2, 2026
349b388
Update docstrings with types, add helper for fixing timestamps
emmleroy Jul 2, 2026
2ca1564
Add MOD-UFP to sn_to_model docstrings and tests
emmleroy Jul 2, 2026
d838aaa
Infer data source based on the frequency of tdiffs, add tests for mod…
emmleroy Jul 2, 2026
583a903
Fix: only local timezone if tscol is timestamp or timestamp_iso, and …
emmleroy Jul 2, 2026
84d4fc0
Fix: raise error if no files found before fixing timestamps and log e…
emmleroy Jul 2, 2026
44a89e5
Remove echo_flag_table() from flag_command, rely on logging in _add_f…
emmleroy Jul 2, 2026
7cf009c
Create a save_file utility function
emmleroy Jul 2, 2026
e739f6d
Passed desired suffixes for overlapping columns, and add option to ke…
emmleroy Jul 2, 2026
a49159a
Fix: merge_df bug and add error for attempting to merge >2 files
emmleroy Jul 2, 2026
1e1d347
Ensure all errors are logged and that errors are referenced when raised
emmleroy Jul 6, 2026
c3a2060
More informative docstring for clean_dataframe()
emmleroy Jul 6, 2026
405bc1d
Move drop_unnamed() to a helper func used in safe_load and clean_data…
emmleroy Jul 6, 2026
69b39e2
Update docstring
emmleroy Jul 6, 2026
1311341
Specify that u/v columns don't need be present in dataframe, but the …
emmleroy Jul 6, 2026
537bb1e
Add intercept handler to route standard logging calls through loguru
emmleroy Jul 6, 2026
e981a49
Rename quantaq_py to quantaq_tools
emmleroy Jul 6, 2026
8839d93
Set log level for noisy loggers to WARNING
emmleroy Jul 8, 2026
a294b6a
Add init file
emmleroy Jul 8, 2026
06e2356
Undo package rename
emmleroy Jul 8, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,111 changes: 2,106 additions & 5 deletions poetry.lock

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "quantaq-cli"
version = "1.0.0rc0"
description = "The QuantAQ CLI"
description = "The QuantAQ Python Toolkit and CLI"
authors = ["David H Hagan <david.hagan@quant-aq.com>"]
license = "Apache-2.0"
readme = "README.md"
Expand All @@ -13,13 +13,15 @@ classifiers = []
[tool.poetry.dependencies]
python = ">=3.9, <3.14"
pandas = ">=2.1.4,<2.2"
click = "^7.1.2"
click = "^8.1"
pyarrow = ">=14.0.2"
terminaltables = "^3.1.0"
urllib3 = "^1.26.10"
numpy = "^1.23.2"
rich-click = ">=1.7.2"
loguru = "^0.7.3"
jupyter = "^1.1.1"
pandera = ">=0.24,<0.29"

[tool.poetry.group.dev.dependencies]
pytest = "^6.2.5"
Expand All @@ -32,7 +34,7 @@ sphinx-rtd-theme = "^2.0"
setuptools = "^65.6.3"

[tool.poetry.scripts]
quantaq-cli = "quantaq_cli.console:main"
quantaq-cli = "quantaq_cli.cli:main"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
18 changes: 18 additions & 0 deletions quantaq_cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from quantaq_cli.toolkit.concat import concat_files
from quantaq_cli.toolkit.merge import merge_files
from quantaq_cli.toolkit.resample import resample_dataframe
from quantaq_cli.toolkit.flag import flag_dataframe, echo_flag_table, flag_summary
from quantaq_cli.toolkit.expunge import expunge_dataframe
from quantaq_cli.toolkit.munge import clean_dataframe


__all__ = [
"concat_files",
"merge_files",
"resample_dataframe",
"flag_dataframe",
"echo_flag_table",
"expunge_dataframe",
"flag_summary",
"clean_dataframe"
]
242 changes: 242 additions & 0 deletions quantaq_cli/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
from pathlib import Path

import pkg_resources
import rich_click as click
from loguru import logger

from quantaq_cli import concat_files, merge_files, resample_dataframe, clean_dataframe
from quantaq_cli import flag_dataframe, echo_flag_table, expunge_dataframe
from quantaq_cli.exceptions import InvalidFileExtension
from quantaq_cli.log import configure_logging, LOG_LEVELS
from quantaq_cli.toolkit.resample import WIND_COLUMNS
from quantaq_cli.utilities import safe_load
from quantaq_cli.variables import SUPPORTED_MODELS, SUPPORTED_SOURCES


CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])

__version__ = pkg_resources.get_distribution('quantaq_cli').version


@click.group(context_settings=CONTEXT_SETTINGS)
@click.version_option(__version__)
@click.pass_context
def main(ctx):
pass


def save_file(df, output):
"""Helper func to save a DataFrame to disk as CSV or parquet.

Args:
df (pd.DataFrame): DataFrame to save
output (str): Destination filepath.
"""
logger.info("Saving file to {}", output)
output = Path(output)
if output.suffix == ".csv":
df.to_csv(output, index=False)
else:
df.to_parquet(output, index=False)

def check_extension(output):
"""Helper func to check if the output extension is either a csv or parquet
format.

Args:
output (str): Destination filepath.
"""
output = Path(output)
if output.suffix not in (".csv", ".parquet"):
error = InvalidFileExtension(f"Invalid file extension; got {output.suffix!r}")
logger.error(error)
raise error
return output


@click.command("concat")
@click.argument("files", nargs=-1, type=click.Path())
@click.option("-o", "--output", default="output.csv", help="The filepath where you would like to save the file", type=str)
@click.option("--log-level", default="INFO",
type=click.Choice(LOG_LEVELS, case_sensitive=False),
help="loguru log level (default: INFO)")
def concat_command(files, output, log_level):
"""Concat FILES and save to OUTPUT."""
configure_logging(log_level)

# make sure the extension is either a csv or parquet format
check_extension(output)

# concat everything in filepath
logger.info("Files to read: {}", files)

df = concat_files(files)

# save the file
save_file(df, output)


@click.command("merge", short_help="merge two files together on their timestamp")
@click.argument("files", nargs=-1, type=click.Path())
@click.option("-ts", "--tscol", default="timestamp", help="The column by which to join the files", type=str)
@click.option("-o", "--output", default="output.csv", help="The filepath where you would like to save the file", type=str)
@click.option("--log-level", default="INFO",
type=click.Choice(LOG_LEVELS, case_sensitive=False),
help="loguru log level (default: INFO)")
def merge_command(files, output, tscol, log_level):
"""Merge FILES together and save to OUTPUT."""
configure_logging(log_level)

# make sure the extension is either a csv or parquet format
check_extension(output)

# merge everything in filepath
logger.info("Files to read: {}", files)

df = merge_files(files, tscol)

# save the file
save_file(df, output)


@click.command("resample", short_help="up/down sample data")
@click.argument("file", nargs=1, type=click.Path())
@click.argument("rule", nargs=1, type=str)
@click.option("-o", "--output", default="output.csv", help="The filepath where you would like to save the file", type=str)
@click.option("--on", default="timestamp", help="Name of the datetime column to resample over.", type=str)
@click.option("--by", default=None, help="Optional column(s) to group by first")
@click.option(
"--wind",
nargs=4,
Comment thread
dhhagan marked this conversation as resolved.
type=str,
default=("wx_u", "wx_v", "wx_ws", "wx_wd"),
help="(u, v, speed, direction) column names. The u/v columns don't need to be present in the dataframe, but the column names need to be specified.",
)
@click.option("--numeric_how", default="mean", help="Aggregation for numeric columns.")
@click.option("--nonnumeric_how", default="first", help="Aggregation for non-numeric columns.")
@click.option("--log-level", default="INFO",
type=click.Choice(LOG_LEVELS, case_sensitive=False),
help="loguru log level (default: INFO)")
def resample_command(file, rule, output, log_level, **kwargs):
"""Resample FILE at INTERVAL and save to OUTPUT."""
configure_logging(log_level)

on = kwargs.pop("on", "timestamp")
by = kwargs.pop("by", None)
wind = kwargs.pop("wind", WIND_COLUMNS)
numeric_how = kwargs.pop("numeric_how", "mean")
nonnumeric_how = kwargs.pop("nonnumeric_how", "first")

# make sure the extension is either a csv or parquet format
check_extension(output)

logger.info("File to read: {}", file)

# load the file
df = safe_load(file)

# if column to resample over needs to be made a datetime obj, do so
if on not in df.columns:
error = ValueError(f"Invalid column name for the timestamp; got {on!r}")
logger.error(error)
raise error

# resample
df = resample_dataframe(
df,
rule,
on=on,
by=by,
wind=wind,
numeric_how=numeric_how,
nonnumeric_how=nonnumeric_how,
)

# save the file
save_file(df, output)


@click.command("flag")
@click.argument("file", nargs=1, type=click.Path())
@click.option("-o", "--output", default="output.csv", help="The filepath where you would like to save the file", type=str)
@click.option("--log-level", default="INFO",
type=click.Choice(LOG_LEVELS, case_sensitive=False),
help="loguru log level (default: INFO)")
def flag_command(file, output, log_level):
"""Flag FILE and save to OUTPUT."""
configure_logging(log_level)

# make sure the extension is either a csv or parquet format
check_extension(output)

logger.info("File to read: {}", file)

# load the file
df = safe_load(file)

# flag the dataframe
df = flag_dataframe(df)

# save the file
save_file(df, output)


@click.command("expunge")
@click.argument("file", nargs=1, type=click.Path())
@click.option("-d", "--dry-run", is_flag=True, help="Print table to screen and bypass file save")
@click.option("-o", "--output", default="output.csv", help="The filepath where you would like to save the file", type=str)
@click.option("--log-level", default="INFO",
type=click.Choice(LOG_LEVELS, case_sensitive=False),
help="loguru log level (default: INFO)")
def expunge_command(file, output, log_level, dry_run):
"""Expunge FILE and save to OUTPUT."""
configure_logging(log_level)

# make sure the extension is either a csv or parquet format
check_extension(output)

logger.info("Expunging data for {}", file)

df = safe_load(file)
show_summary = dry_run or log_level == "INFO"

if show_summary:
logger.info("Original flag summary:")
echo_flag_table(df)

df_expunged = expunge_dataframe(df)

if show_summary:
logger.info("New flag summary:")
echo_flag_table(df_expunged)

if not dry_run:
save_file(df, output)


@click.command("clean")
@click.argument("file", nargs=1, type=click.Path())
@click.option("-o", "--output", default="output.csv", help="The filepath where you would like to save the file", type=str)
@click.option("--log-level", default="INFO",
type=click.Choice(LOG_LEVELS, case_sensitive=False),
help="loguru log level (default: INFO)")
def clean_command(file, output, log_level):
"""Clean FILE and save to OUTPUT."""
configure_logging(log_level)

# make sure the extension is either a csv or parquet format
check_extension(output)

logger.info("Cleaning data for {}", file)
df = safe_load(file)
df = clean_dataframe(df)
# save the file
save_file(df, output)

# add the commands one-by-one
main.add_command(concat_command)
main.add_command(merge_command)
main.add_command(resample_command)
main.add_command(expunge_command)
main.add_command(flag_command)
main.add_command(clean_command)
Loading
Loading