Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import CNN junk predictions and add them to Zooniverse metadata
- Loading branch information
1 parent
b758d09
commit c748c5b
Showing
7 changed files
with
112 additions
and
4 deletions.
There are no files selected for viewing
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
38 changes: 38 additions & 0 deletions
38
starcatalogue/management/commands/create_all_zoo_subjects.py
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,38 @@ | ||
from django.core.management.base import BaseCommand, CommandError | ||
|
||
import csv | ||
|
||
from starcatalogue.models import Star, FoldedLightcurve, ZooniverseSubject | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Imports folded lightcurve data (lookup.dat)" | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument("file", nargs=1, type=open) | ||
|
||
def handle(self, *args, **options): | ||
r = csv.reader(options["file"][0], delimiter=" ", skipinitialspace=True) | ||
imported_total = 0 | ||
for count, row in enumerate(r): | ||
try: | ||
subject_id = int(row[0]) | ||
superwasp_id = row[1] | ||
period_number = int(row[3]) | ||
except IndexError: | ||
print("Warning: Skipping row {} due to IndexError".format(count)) | ||
continue | ||
|
||
star = Star.objects.get_or_create(superwasp_id=superwasp_id) | ||
lightcurve = FoldedLightcurve.objects.get_or_create( | ||
star=star, | ||
period_number=period_number, | ||
) | ||
|
||
ZooniverseSubject.objects.get_or_create( | ||
zooniverse_id=subject_id, lightcurve=lightcurve | ||
) | ||
|
||
imported_total += 1 | ||
|
||
self.stdout.write("Total imported: {}".format(imported_total)) |
40 changes: 40 additions & 0 deletions
40
starcatalogue/management/commands/importjunkpredictions.py
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,40 @@ | ||
from django.core.management.base import BaseCommand, CommandError | ||
|
||
import csv | ||
import pandas | ||
|
||
from starcatalogue.models import FoldedLightcurve | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Imports CNN junk predictions from a DataFrame into FoldedLightcurves" | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument("file", nargs=1, type=str) | ||
|
||
def handle(self, *args, **options): | ||
df = pandas.read_pickle(options["file"][0]) | ||
imported_total = 0 | ||
lcs = [] | ||
total = len(df) | ||
updated = 0 | ||
for n, (i, row) in enumerate(df.iterrows(), start=1): | ||
superwasp_id, period_number, _ = i.replace(".gif", "").split("_") | ||
period_number = int(period_number.replace("P", "")) | ||
try: | ||
lcs.append( | ||
FoldedLightcurve.objects.get( | ||
star__superwasp_id=superwasp_id, period_number=period_number | ||
) | ||
) | ||
lcs[-1].cnn_junk_prediction = row["prediction"] | ||
except FoldedLightcurve.DoesNotExist: | ||
pass | ||
if n % 100 == 0 or n == total: | ||
print(f"\r{n} / {total} ({(n / total) * 100:.2f}%)", end="") | ||
if len(lcs) > 0: | ||
updated += FoldedLightcurve.objects.bulk_update( | ||
lcs, ["cnn_junk_prediction"] | ||
) | ||
lcs = [] | ||
print(f"\nUpdated {updated}") |
18 changes: 18 additions & 0 deletions
18
starcatalogue/migrations/0045_foldedlightcurve_cnn_junk_prediction.py
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,18 @@ | ||
# Generated by Django 4.2.11 on 2024-04-12 10:06 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('starcatalogue', '0044_alter_dataexport_doi'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='foldedlightcurve', | ||
name='cnn_junk_prediction', | ||
field=models.FloatField(null=True), | ||
), | ||
] |
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
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
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