Пример #1
0
def genImageDotHead(image_id):
	"""
	Generate a FITS image's .head file. The image file is first accessed to get the number 
	of HDUs (extansions). Then keywords mapping is retrieved from the instrument's ITT in 
	order to get a proper HDU data.
	@return tuple of hdudata and total number of hdus in this image (primary + extansions)
	"""
	db = DB(host = settings.DATABASE_HOST,
			user = settings.DATABASE_USER,
			passwd = settings.DATABASE_PASSWORD,
			db = settings.DATABASE_NAME)

	# Beginning transaction
	g = DBGeneric(db.con)

	if type(image_id) != types.IntType:
		raise ValueError, "first argument image_id must be an integer"

	r = g.execute("""
SELECT im.path, im.name, ru.name, ins.itt, ins.name, im.dateobs, cha.name, im.flat, 
im.airmass, im.equinox, im.object, im.exptime, im.mask, im.alpha, im.delta
FROM youpi_image AS im, youpi_instrument AS ins, youpi_channel AS cha, youpi_rel_ri AS ri, youpi_run AS ru
WHERE im.id=%d 
AND im.instrument_id=ins.id
AND im.channel_id=cha.id
AND ri.image_id = im.id
AND ru.id = ri.run_id
""" % image_id)
	if not r: raise LookupError, "no image found with ID: %s" % image_id
	r = r[0]

	fname = os.path.join(r[0], r[1] + '.fits')
	if not os.path.exists(fname):
		fname = re.sub(r'_\d+\.fits$', '.fits', fname)

	hdulist = pyfits.open(fname)
	hdulist.close()

	# Get instrument translation table
	itt = marshal.loads(zlib.decompress(base64.decodestring(r[3])))

	try: run = r[2]
	except: run = None

	data = {
		'YRUN'			: run, 
#		'YDETECTOR': , 
#		'YTELESCOP': , 
		'YINSTRUMENT'	: r[4],
		'YDATEOBS'		: r[5],
		'YFILTER'		: r[6],
		'YFLAT'			: r[7],
		'YAIRMASS'		: r[8],
		'YEQUINOX'		: r[9],
		'YOBJECT'		: r[10],
		'YEXPTIME'		: r[11],
		'YMASK'			: r[12],
		'YRA'			: r[13],
		'YDEC'			: r[14],
	}

	hdudata = {}
	for k, v in data.iteritems():
		try: 
			val = float(str(v))
		except ValueError:
			if isinstance(v, datetime.datetime):
				v = v.isoformat()
			val = "'%s'" % v

		if itt[k].has_key('MAP'): 
			# Unmapped keyword are ignored since they are available in 
			# the image's header
			hdudata[itt[k]['MAP']] = val

	missing = []
	# Keyword copy feature (+KEYWORD)
	if itt.has_key('+COPY'):
		# List of missing keywords (not found in src image)
		for kw in itt['+COPY']:
			data = None
			# Search keyword in all extensions
			for hdu in hdulist:
				try: data = str(hdu.header[kw]).strip()
				except KeyError:
					# Keyword not found in this extension, continue
					pass
			if data: hdudata[kw] = data
			else: missing.append(kw)

	return (hdudata, len(hdulist), missing)
Пример #2
0
				end_ingestion_date = getNowDateTime(duration_etime),
				wheres = {'id' : ingestionId} )

	return fitsNoExt + FITSEXT

if __name__ == '__main__':
	print "Running from the CLI"
	# Connection object to MySQL database 
	try:
		db = DB(host = DATABASE_HOST,
				user = DATABASE_USER,
				passwd = DATABASE_PASSWORD,
				db = DATABASE_NAME)

		# Beginning transaction
		g = DBGeneric(db.con)

		res = g.execute("SELECT id, username FROM auth_user LIMIT 1")
		debug("Proceeding as user '%s'" % res[0][1])
		user_id = res[0][0]

		# Transaction begins here
		g.begin()
		run_stack_ingestion(g, sys.argv[1], user_id)
		# Commits for that image
		g.con.commit()
	
	except Exception, e:
		debug(e, FATAL)
		g.con.rollback()
		sys.exit(1)
Пример #3
0

if __name__ == '__main__':
    try:
        csvFile = sys.argv[1]
    except:
        print "Usage: %s <csv_file>" % sys.argv[0]
        sys.exit(1)

    db = DB(
        host=DATABASE_HOST,
        user=DATABASE_USER,
        passwd=DATABASE_PASSWORD,
        db=DATABASE_NAME)

    g = DBGeneric(db.con)

    report, photcs, dbEntries = get_report(g, csvFile)
    print report

    try:
        ans = raw_input(
            "Do you want to merge PHOTC data from the file into the database? "
        )
        if ans in ('y', 'Y', 'yes', 'YES'):
            start = time.time()
            g.begin()
            g.setTableName('youpi_image')

            try:
                update = 0
Пример #4
0
    for i in info:
        report += "%-20s : %s\n" % (i[0], str(i[1]))

    return (report, photcs, res)


if __name__ == "__main__":
    try:
        csvFile = sys.argv[1]
    except:
        print "Usage: %s <csv_file>" % sys.argv[0]
        sys.exit(1)

    db = DB(host=DATABASE_HOST, user=DATABASE_USER, passwd=DATABASE_PASSWORD, db=DATABASE_NAME)

    g = DBGeneric(db.con)

    report, photcs, dbEntries = get_report(g, csvFile)
    print report

    try:
        ans = raw_input("Do you want to merge PHOTC data from the file into the database? ")
        if ans in ("y", "Y", "yes", "YES"):
            start = time.time()
            g.begin()
            g.setTableName("youpi_image")

            try:
                update = 0
                for e in dbEntries:
                    g.update(photc=photcs[e[0]], wheres={"name": e[0]})