def ephsun(date): # Moscow coordinates (lat, lon) = (55.7522200, 37.6155600) date2 = date - datetime.timedelta(days=1) time = "21:00" # sun = ephem.Sun() # gatech = ephem.Observer() # gatech.lon, gatech.lat = str(lon), str(lat) gatech = date.strftime("%Y/%m/%d") + " " + time # , sun.compute(gatech) sun1 = [parse_coord(str(sun.a_ra), "ra"), parse_coord(str(sun.a_dec), "deg")] gatech = date2.strftime("%Y/%m/%d") + " " + time # , '%d/%m/%Y' sun.compute(gatech) sun2 = [parse_coord(str(sun.a_ra), "ra"), parse_coord(str(sun.a_dec), "deg")] return sun2, sun1
def handle_date(date, records, catalogue, vphi = 15): mdays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] sun = [] for i in xrange(len(records[0])): sun.append([parse_date(records[0][i]), parse_coord(records[1][i], 'ra'), parse_coord(records[2][i], 'deg')]) ay = sun[ 0][0][-1] by = sun[-1][0][-1] if len(date) == 3: im = 1 # index of month iy = 2 # index of year (in date list) elif len(date) == 2: im = 0 iy = 1 assert (date[im] > 0) and (date[im] <= 12), "Inccorect month value" assert (date[iy] >= ay) and (date[iy] <= by), "Selected year is not presented in current sun ephemeris" if catalogue == 'V/50': fields = ['Name', 'HD', 'Vmag'] entry_phrase = "Catalogue V50: stars with m <= 6.5" elif catalogue == 'VII/239A/icpos': entry_phrase = "\nCatalogue VII/239A/icpos: mean position of NGC/IC objects" fields = ['NGC/IC', 'Cat'] else: print "Unknown catalogue" return None if date[iy] % 4 == 0: mdays[1] += 1 if len(date) == 3: days = [date[0]] elif len(date) == 2: days = range(1, mdays[date[im]-1] + 1) for ind0, row in enumerate(sun): if [days[0], date[im], date[iy]] in row: break print entry_phrase for ind in xrange(ind0, ind0 + len(days)): ra_interest = str(sun[ind-1][1]) + '..' + str(sun[ind+1][1]) a = sun[ind-1][2] b = sun[ind+1][2] if a.f2s() < b.f2s(): c = a d = b else: c = b d = a phi = coord(vphi,0,0,1,'deg') dec_interest = str(c - phi) + '..' + str(d + phi) print ra_interest, dec_interest ra_interest = ra_interest.replace(' ', '') dec_interest = dec_interest.replace(' ', '') if ind != ind0: prhead = False else: prhead= True process_vdb(catalogue, fields, sun, ind, ra_interest, dec_interest, print_head = prhead) print
def process_vdb(vdbname, gfields, sun, ind, ra_interest, dec_interest, print_coord = True, print_head = True): lcol = 12 fields = [] + gfields fields.append('RAJ2000') fields.append('DEJ2000') v = Vizier(columns = fields, catalog = vdbname) v.ROW_LIMIT = -1 result = v.query_constraints(catalog = vdbname, RAJ2000 = ra_interest, DEJ2000 = dec_interest) #result[result.keys()[0]].pprint() numobjs = len(result[0]) twelveoc = 12*60*60 tms = twelveoc*np.array([1., 3., 4.]) prline = '==========' + '=' + '============' prhead = 'Date ' + ' ' + ' Time ' l = len(fields) if not print_coord: l -= 2 for i in xrange(l): prline = prline + '=' + '='*lcol tmp = fields[i] if len(tmp) < lcol: tmp = tmp + ' '*(lcol - len(tmp)) prhead = prhead + ' ' + tmp prhead = prhead + ' ' + 'Dec distance' prline = prline + '=' + '============' if print_head: print prline print prhead print prline for i in xrange(numobjs): ri = result[0][i].as_void() ri= list(ri) ri=ri[:-2] [ra, dec] = [ri[-2], ri[-1]] ra = parse_coord( ra, 'ra', ' ') dec = parse_coord( dec, 'deg', ' ') t, num = comp_time(sun[ind-1][1], sun[ind][1], sun[ind+1][1], ra) t = t.f2s() if num > 0: t += 2*twelveoc tmp = tms - t sz = tmp[tmp > 0].size if sz == 1: idx = ind+1 elif sz == 2: idx = ind elif sz == 3: idx = ind-1 t = coord(0, 0, t + twelveoc, 1, 'ra') if idx == ind: curdate = sun[idx][0] tmp = str(curdate[0]) if len(tmp) < 2: tmp = ' ' + tmp date = '' + tmp + '/' tmp = str(curdate[1]) if len(tmp) < 2: tmp = ' ' + tmp date = date + tmp + '/' + str(curdate[2]) dist = comp_dist(curdate[0], curdate[1], t, dec) printer = '' + date + ' ' + str(t) stri = [str(x) for x in ri[:-2]] if print_coord: stri = stri + [str(ra), str(dec)] for x in stri: if len(x) < lcol: x = ' '*(lcol - len(x)) + x printer = printer + ' ' + x printer = printer + ' ' + str(dist) print printer
def aw_main_process( code, day_start, day_end, mpf=12, directory=CATLISTDIR, filename=DEFAULTSETTINGSFILE, progressBar=None ): style_string = "font: bold on" style = xlwt.easyxf(style_string) code_table = loadTableParameters(directory, filename) curdate = day_start curmonth = curdate.month wb = xlwt.Workbook() sheetname = curdate.strftime("%h") + " " + str(curdate.year)[-2:] sheet_num = 0 ws = wb.add_sheet(sheetname.decode("utf8")) rowx, colx = make_list_header(ws, code, code_table) customSimbad = Simbad() if len(code_table[code]["columns"]) > 0: customSimbad.add_votable_fields("id(" + code + ")") if code_table[code]["phi_vec"]: customSimbad.add_votable_fields("flux(V)") customSimbad.ROW_LIMIT = -1 # additionalSimbad = {} # for x in code_table[code]['columns']: # additionalSimbad[x] = Simbad() # additionalSimbad[x].add_votable_fields('id('+x+')') all_days = (day_end - day_start).days for numday in xrange(all_days): objects_per_day = 0 if curdate.month != curmonth: curmonth = curdate.month sheet_num += 1 if sheet_num == mpf: filename = code.upper() + "_" filename += day_start.strftime("%d-%m-%Y") filename += "--" filename += (curdate - datetime.timedelta(days=1)).strftime("%d-%m-%Y") filename += ".xls" wb.save(OUTPUTDIR + filename) wb = xlwt.Workbook() sheet_num = 0 day_start = curdate + datetime.timedelta(days=0) sheetname = curdate.strftime("%h") + " " + str(curdate.year)[-2:] ws = wb.add_sheet(sheetname.decode("utf8")) rowx, colx = make_list_header(ws, code, code_table) vphi = code_table[code]["vphi"][0][1] [[ra1, dec1], [ra2, dec2]] = ephsun(curdate) if dec1.f2s() < dec2.f2s(): [c, d] = [dec1, dec2] else: [c, d] = [dec2, dec1] phi = coord(vphi, 0, 0, 1, "deg") ra_interest = [ra1.f2hd(), ra2.f2hd()] dec_interest = [(c - phi).f2hd(), (d + phi).f2hd()] query = formulate_query(code, ra_interest, dec_interest) result = customSimbad.query_criteria(query) if result is not None: lenres = len(result) result.sort("RA") else: print "Day %d/%d finished w/o output" % (numday + 1, all_days) if progressBar is not None: progressBar.setValue((numday + 1.0) / all_days * 100) curdate = curdate + datetime.timedelta(days=1) continue for i in xrange(lenres): row = result[i] [ra, dec] = [row["RA"], row["DEC"]] ra = parse_coord(ra, "ra", " ") dec = parse_coord(dec, "deg", " ") try: t = comp_time(ra1, ra2, ra) except: print ra1, ra2, ra, row["MAIN_ID"] continue dist = comp_dist(curdate.day, curdate.month, t, dec) hdist = abs(dist.f2s() / 3600.0) if code_table[code]["phi_vec"]: refuse = True vmag = row["FLUX_V"] if str(vmag) != "--": for [vml, hdl] in code_table[code]["vphi"]: if vml is None: if hdist >= hdl: break else: refuse = False break elif vmag < vml: if hdist >= hdl: break else: refuse = False break if refuse: print "refused: %s" % (row["MAIN_ID"]) continue line = [curdate.strftime("%d/%m/%Y"), t.__str__(rpar=0)] name = row["MAIN_ID"] if code_table[code]["use_name"]: if name.startswith("NAME "): name = name.replace("NAME ", "") line.append(name) alt_names = Simbad.query_objectids(row["MAIN_ID"]) for colname in code_table[code]["columns"]: locid = "" for an in alt_names: if an["ID"].startswith(colname.upper() + " "): if len(locid) > 0: locid += " / " lname = an["ID"].replace("NAME", "") locid = locid + lname.replace("*", "") line.append(locid) if code_table[code]["phi_vec"]: line.append(str(row["FLUX_V"])) line.append(str(dist)) line.append(str(ra)) line.append(str(dec)) rowx, colx = write_row(ws, line, rowx, colx) objects_per_day += 1 curdate = curdate + datetime.timedelta(days=1) if objects_per_day > 0: rowx, colx = write_row(ws, [""], rowx, colx) print "Day %d/%d finished" % (numday + 1, all_days) if progressBar is not None: progressBar.setValue((numday + 1.0) / all_days * 100) filename = code.upper() + "_" filename += day_start.strftime("%d-%m-%Y") filename += "--" filename += day_end.strftime("%d-%m-%Y") filename += ".xls" full_filename = OUTPUTDIR + filename print full_filename wb.save(full_filename) return