def test_written_obs_sorted_chronologically_on_flush(self): self.undertest = mpc.MPCWriter(self.outputfile, auto_flush=False, include_comments=False) obs1 = mpc.Observation( provisional_name="A234567", discovery="*", note1="H", note2="N", date="2012 10 21.405160", ra="26.683336700", # 01 46 44.001 dec="29.220353200", # +29 13 13.27 mag="123.5", band="A", observatory_code="523") obs2 = mpc.Observation( provisional_name="A234567", discovery="*", note1="H", note2="N", date="2012 11 21.405160", ra="26.683336700", # 01 46 44.001 dec="29.220353200", # +29 13 13.27 mag="123.5", band="A", observatory_code="523") obs3 = mpc.Observation( provisional_name="A234567", discovery="*", note1="H", note2="N", date="2012 12 21.405160", ra="26.683336700", # 01 46 44.001 dec="29.220353200", # +29 13 13.27 mag="123.5", band="A", observatory_code="523") self.undertest.write(obs3) self.undertest.write(obs1) self.undertest.write(obs2) self.assertTrue( obs1 in self.undertest.get_chronological_buffered_observations()) self.assertTrue( obs2 in self.undertest.get_chronological_buffered_observations()) self.assertTrue( obs3 in self.undertest.get_chronological_buffered_observations())
def test_write_comment(self): self.undertest = mpc.MPCWriter(self.outputfile, auto_flush=True, include_comments=True) frame = "1234567p00" xpos = 334.56 ypos = 884.22 comment = "Something fishy." obs = mpc.Observation(provisional_name="A234567", discovery="*", note1="H", note2="N", date="2012 10 21.405160", ra="26.683336700", dec="29.220353200", mag="23.50", band="A", observatory_code="523", comment=comment, frame=frame, xpos=xpos, ypos=ypos) self.undertest.write(obs) expected = (" A234567*HN2012 10 21.40516001 46 44.001+29 13 13.27" " 23.5 A 523 O 1234567p00 A234567 ZH" " 334.56 884.22 0.20 0 23.50 ---- % Something fishy.\n") self.assertEqual(self.read_outputfile(), expected)
def test_write_rejection_line(self): self.undertest = mpc.MPCWriter(self.outputfile, auto_flush=True, include_comments=True) frame = "1234567p00" xpos = 334.56 ypos = 884.22 comment = "Something fishy." obs = mpc.Observation( provisional_name="A234567", date="2012 10 21.405160", ra="26.683336700", # 01 46 44.001 dec="29.220353200", # +29 13 13.27 comment=comment, frame=frame, xpos=xpos, ypos=ypos) obs.null_observation = True self.undertest.write(obs) expected = ("! A234567 2012 10 21.40516001 46 44.001+29 13 13.27" " 568 O 1234567p00 A234567 Z" " 334.56 884.22 0.20 0 ----- ---- % Something fishy.\n") actual = self.read_outputfile() self.assertEqual(actual, expected)
def on_do_reject(self, comment): self.view.close_reject_source_dialog() if not self.model.is_current_source_named(): self.model.set_current_source_name( self._generate_provisional_name()) reading = self.model.get_current_reading() mpc_observation = mpc.Observation( provisional_name=self.model.get_current_source_name(), date=self.model.get_current_observation_date(), ra=self.model.get_current_ra(), dec=self.model.get_current_dec(), xpos=reading.x, ypos=reading.y, frame=reading.obs.rawname, comment=comment) mpc_observation.null_observation = True self.model.get_writer().write(mpc_observation) self.model.reject_current_item() self.model.next_item()
def on_do_accept( self, minor_planet_number, provisional_name, note1, note2, date_of_obs, ra, dec, obs_mag, obs_mag_err, band, observatory_code, comment, ): """ Final acceptance with collected data. """ # Just extract the character code from the notes, not the # full description note1_code = note1.split(" ")[0] note2_code = note2.split(" ")[0] self.view.close_accept_source_dialog() self.model.set_current_source_name(provisional_name) reading = self.model.get_current_reading() source_cutout = self.model.get_current_cutout() mpc_observation = mpc.Observation(null_observation=False, provisional_name=provisional_name, note1=note1_code, note2=note2_code, date=date_of_obs, ra=ra, dec=dec, mag=obs_mag, mag_err=obs_mag_err, band=band, observatory_code=observatory_code, discovery=self.is_discovery, comment=comment, xpos=source_cutout.observed_x, ypos=source_cutout.observed_y, frame=reading.obs.rawname) self.model.get_writer().write(mpc_observation) self.model.accept_current_item() if self.model.get_current_workunit().get_current_source_readings( ).is_on_last_item(): self.view.clear() self.model.next_item()
def test_rejected_line_not_discovery_asterisk(self): self.undertest = mpc.MPCWriter(self.outputfile, auto_flush=False, include_comments=False) obs1 = mpc.Observation( provisional_name="A234567", date="2012 10 21.405160", ra="26.683336700", # 01 46 44.001 dec="29.220353200", # +29 13 13.27 observatory_code="523") obs1.null_observation = True obs2 = mpc.Observation( provisional_name="A234567", discovery=True, note1="H", note2="N", date="2012 11 21.405160", ra="26.683336700", # 01 46 44.001 dec="29.220353200", # +29 13 13.27 mag="23.5", band="A", observatory_code="523") self.undertest.write(obs2) self.undertest.write(obs1) self.undertest.flush() expected_first_line = ( "! A234567 2012 10 21.40516001 46 44.001+29 13 13.27 523\n" ) # " A234567 HN2012 11 21.40516001 46 44.001+29 13 13.27 123.5A 523\n" expected_second_line = ( " A234567*HN2012 11 21.40516001 46 44.001+29 13 13.27 23.5 A 523\n" ) self.assertEqual(self.read_outputfile(), expected_first_line + expected_second_line)
def test_flush(self): self.undertest = mpc.MPCWriter(self.outputfile, auto_flush=False, include_comments=False) obs1 = mpc.Observation( provisional_name="A234567", discovery="*", note1="H", note2="N", date="2012 10 21.405160", ra="26.683336700", # 01 46 44.001 dec="29.220353200", # +29 13 13.27 mag="123.5", band="A", observatory_code="523") self.undertest.write(obs1) self.assertEqual(self.read_outputfile(), "") obs2 = mpc.Observation( date="2012 10 22.405160", ra="26.683336700", # 01 46 44.001 dec="29.220353200", # +29 13 13.27 ) obs2.null_observation = True self.undertest.write(obs2) self.assertEqual(self.read_outputfile(), "") expected_mpcline = " A234567*HN2012 10 21.40516001 46 44.001+29 13 13.27 123.5A 523\n" expected_reject_line = "! 2012 10 22.40516001 46 44.001+29 13 13.27 568\n" self.undertest.flush() self.assertEqual(self.read_outputfile(), expected_mpcline + expected_reject_line)
def test_default_line(self): expected = " K04K18V**C2004 05 24.36017 15 06 36.120-18 56 49.50 23.5 g 568" actual = str( mpc.Observation(provisional_name="K04K18V", discovery="*", note1='*', note2='C', date="2004 05 24.36017", ra="15 06 36.12", dec="-18 56 49.5", mag=23.5, band='g', observatory_code=568)) self.assertEquals(expected, actual)
def test_obs_mag_too_long(self): obs = mpc.Observation(provisional_name="A234567", discovery="*", note1="H", note2="N", date="2012 10 21.405160", ra="26.683336700", dec="29.220353200", mag="12.3456", band="A", observatory_code="523") self.undertest.write(obs) expected = " A234567*HN2012 10 21.40516001 46 44.001+29 13 13.27 12.3 A 523\n" actual = self.read_outputfile() self.assertEqual(actual, expected)
def test_format_line(self): actual = str( mpc.Observation( None, "A234567", "*", "H", "N", "2012 10 21.405160", "26.683336700", # 01 46 44.001 "29.220353200", # +29 13 13.27 "12.4", "A", "523")) expected = " A234567*HN2012 10 21.40516001 46 44.001+29 13 13.27 12.4 A 523" self.assertEqual(len(actual), 80) self.assertEquals(actual, expected)
def test_write_line_valid_pad_empties(self): obs = mpc.Observation( provisional_name="A234567", discovery=True, note1="", note2="", date="2013 04 09.36658", ra="26.683336700", # 01 46 44.001 dec="29.220353200", # +29 13 13.27 mag="123.5", band="A", observatory_code="523") self.undertest.write(obs) expected = " A234567* 2013 04 09.36658 01 46 44.001+29 13 13.27 123.5A 523\n" actual = self.read_outputfile() self.assertEqual(actual, expected)
def test_write_line_empty_minor_planet_number(self): obs = mpc.Observation( provisional_name="A234567", discovery="*", note1="H", note2="N", date="2012 10 21.405160", ra="26.683336700", # 01 46 44.001 dec="29.220353200", # +29 13 13.27 mag="123.5", band="A", observatory_code="523") self.undertest.write(obs) expected = " A234567*HN2012 10 21.40516001 46 44.001+29 13 13.27 123.5A 523\n" actual = self.read_outputfile() self.assertEqual(actual, expected)
def test_write_line_round_obs_mag_str(self): obs = mpc.Observation( provisional_name="A234567", discovery="*", note1="H", note2="N", date="2012 10 21.405160", ra=26.683336700, dec=29.220353200, mag="22.5211", # In string form band="A", observatory_code=523) self.undertest.write(obs) expected = " A234567*HN2012 10 21.40516001 46 44.001+29 13 13.27 22.5 A 523\n" actual = self.read_outputfile() self.assertEqual(actual, expected)
def test_write_line_round_obs_mag(self): obs = mpc.Observation( provisional_name="A234567", discovery="*", note1="H", note2="N", date="2012 10 21.405160", ra=26.683336700, # 01 46 44.001 dec=29.220353200, # +29 13 13.27 mag=22.5211, band="A", observatory_code=523) self.undertest.write(obs) expected = " A234567*HN2012 10 21.40516001 46 44.001+29 13 13.27 22.5 A 523\n" actual = self.read_outputfile() self.assertTrue(actual.endswith("\n")) self.assertEqual(len(actual), 81) self.assertEqual(actual, expected)
mjd_obs = float(header.get('MJD-OBS')) exptime = float(header.get('EXPTIME')) mpc_date = Time(mjd_obs, format='mjd', scale='utc', precision=5) mpc_date += TimeDelta(exptime * units.second) / 2.0 date = mpc_date.mpc obs = mpc.Observation(null_observation=False, minor_planet_number=None, provisional_name=name, discovery=True, note1=None, note2=config.read('MPC.NOTE2DEFAULT')[0], date=date, ra=cutout.ra, dec=cutout.dec, mag=obs_mag, mag_err=obs_mag_err, frame=reading.obs.rawname, band=header['FILTER'], xpos=cutout.observed_x, ypos=cutout.observed_y, comment='AUTO', astrometric_level=cutout.astrom_header.get( 'ASTLEVEL', None)) source_obs.append(obs) with open(name + ".mpc", 'a') as fout: fout.write(obs.to_tnodb() + "\n") if len(source_obs) == 3: mags = 0