Skip to content
Snippets Groups Projects
Commit 1e498b0d authored by Carl Schaffer's avatar Carl Schaffer
Browse files

cleaning

parent 635f2427
No related branches found
No related tags found
No related merge requests found
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 11 11:56:49 2018
@author: schaffer
"""
import pandas as pd
from tkinter import *
from PIL import ImageTk, Image, ImageOps
from os.path import exists
import datetime
from os.path import basename, exists
from sdc_importer.util.util import gris_run_number
class GrisTagger():
def __init__(
self,
possible_tags=[
'Quiet Sun', 'Lightbridge', 'Spicule', 'Emerging Flux Region',
'Pore', 'Flare', 'Sunspot(s)', 'Facula/Plage', 'USAF', 'Umbra',
'Network', 'Penumbra', 'Filament/Prominence'
]):
# Store Inputs:
self.possible_tags = possible_tags
# Setup data containers
self.tagged = []
def store_tags(self):
tags = {'path': self.current_file}
for tag_name, tag_var in self.box_vars.items():
res = tag_var.get()
tags[tag_name] = res
self.tagged.append(tags)
self.root.destroy()
def get_tags(self, filename,existing_tags=[]):
if not exists(filename):
print(f'Warning! File {filename} does not exist. could not tag!')
return
self.current_file = filename
self.root = Tk()
self.box_vars = {}
for t in self.possible_tags:
self.box_vars[t] = IntVar()
# Label
l = Label(self.root, text='Please select correct tags', anchor='w')
l.grid(column=0, row=0)
# checkboxes:
checkboxes = []
for i, t in enumerate(self.possible_tags):
checkboxes.append(
Checkbutton(self.root, variable=self.box_vars[t], text=t))
checkboxes[i].grid(column=0, row=i + 1, sticky='w')
if t in existing_tags:
checkboxes[i].select()
# Add finish button
button = Button(self.root, text="Done", command=self.store_tags)
button.grid(column=0, row=len(self.possible_tags) + 1, sticky='w')
# Add frame for Image
image = Image.open(self.current_file)
# image = ImageOps.fit(image, (500, 500), Image.ANTIALIAS) #The (250, 250) is (height, width)
image.thumbnail((800, 800), Image.ANTIALIAS)
img = ImageTk.PhotoImage(image)
panel = Label(
self.root, image=img).grid(
column=1, row=0, rowspan=len(self.possible_tags) + 2)
#Begin
self.root.mainloop()
def to_df(self):
df = pd.DataFrame()
for t in self.tagged:
df = df.append(t, ignore_index=True)
df['date']=df.path.apply(lambda x: datetime.datetime.strptime(basename(x).split('.')[0],'%d%b%y'))
df['run'] = df.path.apply(gris_run_number)
df = df.set_index(['date', 'run'])
return df
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment