Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 changes: 1 addition & 1 deletion bats_ai/core/management/commands/copy_recordings.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def add_arguments(self, parser):
),
)

def handle(self, *args, **options):
def handle(self, *args, **options): # noqa: C901, PLR0912, PLR0915
count = options["count"]
tags_raw = options["tags"] or ",".join(DEFAULT_TAGS)
tag_texts = [t.strip() for t in tags_raw.split(",") if t.strip()]
Expand Down
2 changes: 1 addition & 1 deletion bats_ai/core/management/commands/importRecordings.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def add_arguments(self, parser):
),
)

def handle(self, *args, **options):
def handle(self, *args, **options): # noqa: C901, PLR0912, PLR0915
directory_path = Path(options["directory"])
owner_username = options.get("owner")
is_public = options.get("public", False)
Expand Down
2 changes: 1 addition & 1 deletion bats_ai/core/management/commands/loadGRTS.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _download_file(self, url: str, zip_path: Path) -> None:
with zip_path.open("wb") as f:
f.write(response.content)

def handle(self, *args, **options):
def handle(self, *args, **options): # noqa: C901, PLR0912, PLR0915
batch_size = options["batch_size"]

# Track existing IDs to avoid duplicates
Expand Down
2 changes: 1 addition & 1 deletion bats_ai/core/management/commands/load_public_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def _try_start_spectrogram_generation(recording_id: int):
recording_compute_spectrogram.delay(recording_id)


def _ingest_files_from_manifest(
def _ingest_files_from_manifest( # noqa: C901, PLR0912, PLR0913, PLR0915
*,
s3_client,
bucket: str,
Expand Down
2 changes: 1 addition & 1 deletion bats_ai/core/management/commands/load_species_geojson.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def add_arguments(self, parser):
help="Delete all SpeciesRange rows before loading.",
)

def handle(self, *args, **options):
def handle(self, *args, **options): # noqa: C901
path = Path(options["geojson_path"] or DEFAULT_GEOJSON).resolve()
if not path.is_file():
raise CommandError(f"GeoJSON file not found: {path}")
Expand Down
2 changes: 1 addition & 1 deletion bats_ai/core/tasks/export_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def annotation_to_dict(
return data


def write_csv_and_json(
def write_csv_and_json( # noqa: PLR0913
zipf,
name_prefix,
queryset,
Expand Down
2 changes: 1 addition & 1 deletion bats_ai/core/tasks/nabat/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
logger = logging.getLogger("NABatDataRetrieval")


def generate_spectrograms(
def generate_spectrograms( # noqa: C901, PLR0915
self, nabat_recording: NABatRecording, presigned_url: str, processing_task: ProcessingTask
):
from bats_ai.core.utils.batbot_metadata import generate_spectrogram_assets
Expand Down
2 changes: 1 addition & 1 deletion bats_ai/core/tasks/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@


@app.task(bind=True)
def recording_compute_spectrogram(self, recording_id: int):
def recording_compute_spectrogram(self, recording_id: int): # noqa: C901, PLR0912, PLR0915
from bats_ai.core.utils.batbot_metadata import generate_spectrogram_assets

celery_id = getattr(self.request, "id", None)
Expand Down
6 changes: 3 additions & 3 deletions bats_ai/core/utils/contour_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def auto_histogram_levels(
return groups


def compute_auto_levels(
def compute_auto_levels( # noqa: PLR0913
data: npt.NDArray,
mode: str,
percentile_values,
Expand Down Expand Up @@ -227,7 +227,7 @@ def apply_transparency_mask(mat, threshold_percent):
# -----------------------------------------------------------------------------


def extract_contours(
def extract_contours( # noqa: PLR0913
image_path: Path,
*,
levels_mode: str,
Expand Down Expand Up @@ -277,7 +277,7 @@ def extract_contours(
return sorted(contours, key=lambda x: x[1]), img.shape


def process_spectrogram_assets_for_contours(
def process_spectrogram_assets_for_contours( # noqa: C901, PLR0913
assets: dict[str, Any],
*,
levels_mode: str = "percentile",
Expand Down
2 changes: 1 addition & 1 deletion bats_ai/core/utils/guano_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def extract_metadata_from_filename(filename: str) -> dict:
return metadata


def extract_guano_metadata(file_path: str | Path, *, check_filename: bool = False) -> dict:
def extract_guano_metadata(file_path: str | Path, *, check_filename: bool = False) -> dict: # noqa: C901
"""Extract GUANO metadata from a WAV file.
Args:
Expand Down
4 changes: 2 additions & 2 deletions bats_ai/core/views/nabat/nabat_recording.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def decode_jwt(token):
return json.loads(decoded_str)


def get_email_if_authorized(
def get_email_if_authorized( # noqa: PLR0911
request: HttpRequest,
api_token: str,
recording_id: int | None = None,
Expand Down Expand Up @@ -196,7 +196,7 @@ def update_nabat_species(species_id: int, api_token: str, recording_id: int, sur


@router.post("/", auth=None)
def generate_nabat_recording(
def generate_nabat_recording( # noqa: PLR0911
request: HttpRequest,
payload: Form[NABatRecordingGenerateSchema],
):
Expand Down
11 changes: 4 additions & 7 deletions bats_ai/core/views/recording.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def create_recording(


@router.patch("/{pk}")
def update_recording(request: HttpRequest, pk: int, recording_data: RecordingUploadSchema):
def update_recording(request: HttpRequest, pk: int, recording_data: RecordingUploadSchema): # noqa: C901, PLR0912
try:
recording = Recording.objects.get(pk=pk, owner=request.user)
except Recording.DoesNotExist:
Expand Down Expand Up @@ -484,7 +484,7 @@ def delete_recording(


@router.get("/", response=RecordingPaginatedResponse)
def get_recordings(
def get_recordings( # noqa: C901
request: HttpRequest,
q: Query[RecordingListQuerySchema],
):
Expand Down Expand Up @@ -1085,7 +1085,7 @@ def put_annotation(


@router.patch("/{recording_pk}/annotations/{annotation_pk}")
def patch_annotation(
def patch_annotation( # noqa: C901, PLR0912
request,
recording_pk: int,
annotation_pk: int,
Expand Down Expand Up @@ -1168,10 +1168,7 @@ def patch_sequence_annotation(
annotation_instance.end_time = annotation.end_time
if annotation.comments:
annotation_instance.comments = annotation.comments
if annotation.type:
annotation_instance.type = annotation.type
else:
annotation_instance.type = None
annotation_instance.type = annotation.type or None
annotation_instance.save()

# Clear existing species associations
Expand Down
2 changes: 1 addition & 1 deletion bats_ai/core/views/recording_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def _split_tags(tags: str | None) -> list[str]:
return [t.strip() for t in tags.split(",") if t.strip()]


def _apply_recording_filters_and_sort(
def _apply_recording_filters_and_sort( # noqa: PLR0913
*,
qs: QuerySet[Recording],
exclude_submitted: bool,
Expand Down
5 changes: 0 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,10 @@ ignore = [

# Project-specific
"BLE001", # blind-except
"C901", # complex-structure
"DJ001", # django-nullable-model-string-field
"N815", # mixed-case-variable-in-class-scope
"N999", # invalid-module-name
"PLC0415", # import-outside-top-level
"PLR0911", # too-many-return-statements
"PLR0912", # too-many-branches
"PLR0913", # too-many-arguments
"PLR0915", # too-many-statements
"PLW2901", # redefined-loop-name
"PTH", # flake8-use-pathlib
"S110", # try-except-pass
Expand Down
6 changes: 3 additions & 3 deletions scripts/contours/extract_contours.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def auto_histogram_levels(
return groups


def compute_auto_levels(
def compute_auto_levels( # noqa: PLR0913
data: np.ndarray,
mode: str,
percentile_values,
Expand Down Expand Up @@ -315,7 +315,7 @@ def apply_transparency_mask(mat, threshold_percent):
# -----------------------------------------------------------------------------


def extract_contours(
def extract_contours( # noqa: PLR0913
image_path: Path,
*,
output_path: Path | None = None,
Expand Down Expand Up @@ -410,7 +410,7 @@ def extract_contours(
is_flag=True,
help="Save debug images (filtered and unfiltered) to the output directory",
)
def main(input_path: str, out_dir, verbose, debug_images, **kwargs):
def main(input_path: str, out_dir, verbose, debug_images, **kwargs): # noqa: C901, PLR0912, PLR0915
logging.basicConfig(level=logging.INFO if verbose else logging.WARNING)

out_dir = Path(out_dir)
Expand Down
2 changes: 1 addition & 1 deletion scripts/generateSpectrograms.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
COLORMAP_ALLOWED = [None, "gist_yarg", "turbo"]


def generate_spectrogram(wav_path, output_folder, colormap=None):
def generate_spectrogram(wav_path, output_folder, colormap=None): # noqa: C901, PLR0915
try:
sig, sr = librosa.load(wav_path, sr=None)
duration = len(sig) / sr
Expand Down
2 changes: 1 addition & 1 deletion scripts/synthetic/waveGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def generate_spectrogram(wav_path, output_path, colormap="turbo"):
return None, None


def generate_compressed(img_path, duration, annotation_path, output_path):
def generate_compressed(img_path, duration, annotation_path, output_path): # noqa: C901
try:
img = np.array(Image.open(img_path))
canvas = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY).astype(np.float32)
Expand Down