<commit_before>import datetime
from operator import attrgetter, itemgetter

import unittest2 as unittest

from tkp.testutil.decorators import requires_database
from tkp.db.orm import DataSet
from tkp.db.orm import Image
import tkp.db
import tkp.db.transients as dbtransients


class TestLightCurve(unittest.TestCase):
    def setUp(self):
        self.database = tkp.db.Database()
        self.dataset = DataSet(data={'description': 'dataset with images'}, database=self.database)

    def tearDown(self):
        tkp.db.rollback()

    @requires_database()
    def test_lightcurve(self):
        # make 4 * 5 images with different date
        images = []
        for day in [3, 4, 5, 6]:
            data = {'taustart_ts': datetime.datetime(2010, 3, day),
                    'tau_time': 3600,
                    'url': '/',
                    'freq_eff': 80e6,
                    'freq_bw': 1e6,
                    'beam_smaj_pix': float(2.7),
                    'beam_smin_pix': float(2.3),
                    'beam_pa_rad': float(1.7),
                    'deltax': float(-0.01111),
                    'deltay': float(0.01111),
                    'centre_ra': 111,
                    'centre_decl': 11,
                    'xtr_radius' : 3
            }
            image = Image(dataset=self.dataset, data=data)
            images.append(image)

        # 3 sources per image, with different coordinates & flux
        data_list = []
        for i in range(1, 4):
            data_list.append({
                'ra': 111.11 + i,
                'decl': 11.11 + i,
                'ra_fit_err': 0.01,
                'decl_fit_err': 0.01,
                'ra_sys_err': 20,
                'decl_sys_err': 20,
                'i_peak': 10 * i ,
                'i_peak_err': 0.1
            #  x=0.11, y=0.22, z=0.33, det_sigma=11.1, zone=i
            })
        # Insert the 3 sources in each image, while further varying the flux
        for i, image in enumerate(images):
            # Create the "source finding results"
            # Note that we reuse 'i_peak' as both peak & integrated flux.
            sources = []
            for data in data_list:
                source = (data['ra'], data['decl'],
                     data['ra_fit_err'], data['decl_fit_err'], # Gaussian fit errors
                     data['i_peak'] * (1 + i), data['i_peak_err'], # Peak
                     data['i_peak'] * (1 + i), data['i_peak_err'], # Integrated
                     10., # Significance level
                     1, 1, 0, # Beam params (width arcsec major, width arcsec minor, parallactic angle)
                     data['ra_sys_err'], data['decl_sys_err']) # Systematic errors
                sources.append(source)

            # Insert the sources
            image.insert_extracted_sources(sources)

            # Run the association for each list of source for an image
            image.associate_extracted_sources(deRuiter_r=3.7)
<commit_msg>fix spacing<commit_after>from operator import attrgetter, itemgetter

import unittest2 as unittest

import datetime
from tkp.testutil.decorators import requires_database
from tkp.db.orm import DataSet
from tkp.db.orm import Image
import tkp.db
import tkp.db.transients as dbtransients


class TestLightCurve(unittest.TestCase):
    def setUp(self):
        self.database = tkp.db.Database()
        self.dataset = DataSet(data={'description': 'dataset with images'},
                               database=self.database)

    def tearDown(self):
        tkp.db.rollback()

    @requires_database()
    def test_lightcurve(self):
        # make 4 * 5 images with different date
        images = []
        for day in [3, 4, 5, 6]:
            data = {'taustart_ts': datetime.datetime(2010, 3, day),
                    'tau_time': 3600,
                    'url': '/',
                    'freq_eff': 80e6,
                    'freq_bw': 1e6,
                    'beam_smaj_pix': float(2.7),
                    'beam_smin_pix': float(2.3),
                    'beam_pa_rad': float(1.7),
                    'deltax': float(-0.01111),
                    'deltay': float(0.01111),
                    'centre_ra': 111,
                    'centre_decl': 11,
                    'xtr_radius' : 3
            }
            image = Image(dataset=self.dataset, data=data)
            images.append(image)

        # 3 sources per image, with different coordinates & flux
        data_list = []
        for i in range(1, 4):
            data_list.append({
                'ra': 111.11 + i,
                'decl': 11.11 + i,
                'ra_fit_err': 0.01,
                'decl_fit_err': 0.01,
                'ra_sys_err': 20,
                'decl_sys_err': 20,
                'i_peak': 10 * i ,
                'i_peak_err': 0.1
            #  x=0.11, y=0.22, z=0.33, det_sigma=11.1, zone=i
            })
        # Insert the 3 sources in each image, while further varying the flux
        for i, image in enumerate(images):
            # Create the "source finding results"
            # Note that we reuse 'i_peak' as both peak & integrated flux.
            sources = []
            for data in data_list:
                source = (data['ra'], data['decl'],
                     data['ra_fit_err'], data['decl_fit_err'],  # Gaussian fit errors
                     data['i_peak'] * (1 + i), data['i_peak_err'],  # Peak
                     data['i_peak'] * (1 + i), data['i_peak_err'],  # Integrated
                     10.,  # Significance level
                     1, 1,  0, # Beam params (width arcsec major, width arcsec minor, parallactic angle)
                     data['ra_sys_err'], data['decl_sys_err'])  # Systematic errors
                sources.append(source)

            # Insert the sources
            image.insert_extracted_sources(sources)

            # Run the association for each list of source for an image
            image.associate_extracted_sources(deRuiter_r=3.7)

{'fraction_non_alphanumeric': 0.10949271722752386, 'fraction_numerical': 0.0311401305876444, 'mean_word_length': 1.6030501089324618, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5700512', 'n_tokens_mistral': 1923, 'n_tokens_neox': 1698, 'n_words': 451}