-
Notifications
You must be signed in to change notification settings - Fork 1
Issue 239 generate smooth svg #276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
naglepuff
wants to merge
9
commits into
main
Choose a base branch
from
issue-239-generate-smooth-svg
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e80479a
Add model for vector version of spectrogram
naglepuff 54bec46
Add contour generation
naglepuff f5da84b
Add migration and admin model
naglepuff 472a31a
Save contour image objects
naglepuff 11e0571
WIP toggle between vector and raster images
naglepuff 9efabf4
Add model for computed pulse annotations
naglepuff bc8722e
Generate contours for each pulse
naglepuff 026d993
Fetch and display pulse contours
naglepuff 1bb667e
Small fix to contour generation
naglepuff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,13 @@ | ||
| from django.contrib import admin | ||
|
|
||
| from bats_ai.core.models import ComputedPulseAnnotation | ||
|
|
||
|
|
||
| @admin.register(ComputedPulseAnnotation) | ||
| class ComputedPulseAnnotationAdmin(admin.ModelAdmin): | ||
| list_display = [ | ||
| 'id', | ||
| 'recording', | ||
| 'bounding_box', | ||
| ] | ||
| list_select_related = True |
This file contains hidden or 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,22 @@ | ||
| from django.contrib import admin | ||
|
|
||
| from bats_ai.core.models import SpectrogramSvg | ||
|
|
||
|
|
||
| @admin.register(SpectrogramSvg) | ||
| class SpectrogramSvgAdmin(admin.ModelAdmin): | ||
| list_display = [ | ||
| 'pk', | ||
| 'content_type', | ||
| 'object_id', | ||
| 'index', | ||
| 'image_file', | ||
| ] | ||
| list_select_related = True | ||
| readonly_fields = [ | ||
| 'pk', | ||
| 'content_type', | ||
| 'object_id', | ||
| 'index', | ||
| 'image_file', | ||
| ] |
41 changes: 41 additions & 0 deletions
41
bats_ai/core/migrations/0024_spectrogramsvg_computedpulseannotation.py
This file contains hidden or 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,41 @@ | ||
| # Generated by Django 4.2.23 on 2025-12-08 22:19 | ||
|
|
||
| import bats_ai.core.models.spectrogram_vector | ||
| import django.contrib.gis.db.models.fields | ||
| from django.db import migrations, models | ||
| import django.db.models.deletion | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('contenttypes', '0002_remove_content_type_name'), | ||
| ('core', '0023_recordingtag_recording_tags_and_more'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name='SpectrogramSvg', | ||
| fields=[ | ||
| ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
| ('object_id', models.PositiveIntegerField()), | ||
| ('type', models.CharField(choices=[('spectrogram', 'Spectrogram'), ('compressed', 'Compressed')], default='spectrogram', max_length=20)), | ||
| ('index', models.PositiveIntegerField()), | ||
| ('image_file', models.FileField(upload_to=bats_ai.core.models.spectrogram_vector.spectrogram_svg_upload_to)), | ||
| ('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.contenttype')), | ||
| ], | ||
| options={ | ||
| 'ordering': ['index'], | ||
| }, | ||
| ), | ||
| migrations.CreateModel( | ||
| name='ComputedPulseAnnotation', | ||
| fields=[ | ||
| ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
| ('index', models.IntegerField()), | ||
| ('bounding_box', django.contrib.gis.db.models.fields.PolygonField(srid=4326)), | ||
| ('contours', models.JSONField()), | ||
| ('recording', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.recording')), | ||
| ], | ||
| ), | ||
| ] |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,10 @@ | ||
| from django.contrib.gis.db import models | ||
|
|
||
| from .recording import Recording | ||
|
|
||
|
|
||
| class ComputedPulseAnnotation(models.Model): | ||
| recording = models.ForeignKey(Recording, on_delete=models.CASCADE) | ||
| index = models.IntegerField(null=False, blank=False) | ||
| bounding_box = models.PolygonField(null=False, blank=False) | ||
| contours = models.JSONField() |
This file contains hidden or 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
This file contains hidden or 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,43 @@ | ||
| from django.contrib.contenttypes.fields import GenericForeignKey | ||
| from django.contrib.contenttypes.models import ContentType | ||
| from django.db import models | ||
| from django.dispatch import receiver | ||
|
|
||
|
|
||
| def spectrogram_svg_upload_to(instance, filename): | ||
| related = instance.content_object | ||
|
|
||
| recording = getattr(related, 'recording', None) or getattr(related, 'nabat_recording', None) | ||
| recording_id = getattr(recording, 'id', None) | ||
|
|
||
| if not recording_id: | ||
| raise ValueError('Related content must have a recording or nabat_recording.') | ||
|
|
||
| return f'recording_{recording_id}/{instance.type}/svg_{instance.index}_{filename}' | ||
|
|
||
|
|
||
| class SpectrogramSvg(models.Model): | ||
| SPECTROGRAM_TYPE_CHOICES = [ | ||
| ('spectrogram', 'Spectrogram'), | ||
| ('compressed', 'Compressed'), | ||
| ] | ||
| content_object = GenericForeignKey('content_type', 'object_id') | ||
|
|
||
| content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE) | ||
| object_id = models.PositiveIntegerField() | ||
| type = models.CharField( | ||
| max_length=20, | ||
| choices=SPECTROGRAM_TYPE_CHOICES, | ||
| default='spectrogram', | ||
| ) | ||
| index = models.PositiveIntegerField() | ||
| image_file = models.FileField(upload_to=spectrogram_svg_upload_to) | ||
|
|
||
| class Meta: | ||
| ordering = ['index'] | ||
|
|
||
|
|
||
| @receiver(models.signals.pre_delete, sender=SpectrogramSvg) | ||
| def delete_content(sender, instance, **kwargs): | ||
| if instance.image_file: | ||
| instance.image_file.delete(save=False) |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename file to
computed_pulse_annotation.py