Add logging on console and ASI fixes
parent
4fac038f7f
commit
6da82ff94d
69
acquire.py
69
acquire.py
|
@ -17,6 +17,7 @@ import configparser
|
|||
import argparse
|
||||
import zwoasi as asi
|
||||
|
||||
|
||||
# Capture images from cv2
|
||||
def capture_cv2(buf, z1, t1, z2, t2, nx, ny, nz, tend, device_id, live):
|
||||
# Array flag
|
||||
|
@ -35,7 +36,7 @@ def capture_cv2(buf, z1, t1, z2, t2, nx, ny, nz, tend, device_id, live):
|
|||
for i in range(nz):
|
||||
# Store start time
|
||||
t0 = float(time.time())
|
||||
|
||||
|
||||
# Get frame
|
||||
res, frame = device.read()
|
||||
|
||||
|
@ -71,11 +72,13 @@ def capture_cv2(buf, z1, t1, z2, t2, nx, ny, nz, tend, device_id, live):
|
|||
first = not first
|
||||
|
||||
# End capture
|
||||
logging.info("Exiting capture")
|
||||
logger.info("Exiting capture")
|
||||
device.release()
|
||||
|
||||
|
||||
# Capture images
|
||||
def capture_asi(buf, z1, t1, z2, t2, nx, ny, nz, tend, device_id, live, gain, maxgain, autogain, exposure, bins, brightness, bandwidth):
|
||||
def capture_asi(buf, z1, t1, z2, t2, nx, ny, nz, tend, device_id, live, gain,
|
||||
maxgain, autogain, exposure, bins, brightness, bandwidth, high_speed):
|
||||
# Array flag
|
||||
first = True
|
||||
|
||||
|
@ -84,11 +87,11 @@ def capture_asi(buf, z1, t1, z2, t2, nx, ny, nz, tend, device_id, live, gain, ma
|
|||
|
||||
camera = asi.Camera(device_id)
|
||||
camera_info = camera.get_camera_property()
|
||||
logging.info('ASI Camera info: %s' % camera_info)
|
||||
logger.info('ASI Camera info: %s' % camera_info)
|
||||
logger.info(camera_info['MaxHeight'])
|
||||
|
||||
camera.set_control_value(asi.ASI_BANDWIDTHOVERLOAD, bandwidth)
|
||||
camera.disable_dark_subtract()
|
||||
|
||||
camera.set_control_value(asi.ASI_GAIN, gain, auto=autogain)
|
||||
camera.set_control_value(asi.ASI_EXPOSURE, exposure, auto=False)
|
||||
camera.set_control_value(asi.ASI_AUTO_MAX_GAIN, maxgain)
|
||||
|
@ -97,7 +100,10 @@ def capture_asi(buf, z1, t1, z2, t2, nx, ny, nz, tend, device_id, live, gain, ma
|
|||
camera.set_control_value(asi.ASI_GAMMA, 50)
|
||||
camera.set_control_value(asi.ASI_BRIGHTNESS, brightness)
|
||||
camera.set_control_value(asi.ASI_FLIP, 0)
|
||||
camera.set_roi(bins=bins)
|
||||
camera.set_control_value(asi.ASI_HIGH_SPEED_MODE, high_speed)
|
||||
camera.set_roi(bins=binning)
|
||||
if 'HardwareBin' in camera.get_controls():
|
||||
camera.set_control_value(asi.ASI_HARDWARE_BIN, 1)
|
||||
camera.start_video_capture()
|
||||
camera.set_image_type(asi.ASI_IMG_RAW8)
|
||||
|
||||
|
@ -121,7 +127,7 @@ def capture_asi(buf, z1, t1, z2, t2, nx, ny, nz, tend, device_id, live, gain, ma
|
|||
gain = settings["Gain"]
|
||||
temp = settings["Temperature"]/10.0
|
||||
logging.info("Capturing frame with gain %d, temperature %.1f" % (gain, temp))
|
||||
|
||||
|
||||
# Set gain
|
||||
if autogain:
|
||||
camera.set_control_value(asi.ASI_GAIN, gain, auto=autogain)
|
||||
|
@ -160,9 +166,10 @@ def capture_asi(buf, z1, t1, z2, t2, nx, ny, nz, tend, device_id, live, gain, ma
|
|||
first = not first
|
||||
|
||||
# End capture
|
||||
logging.info("Exiting capture")
|
||||
logger.info("Exiting capture")
|
||||
camera.stop_video_capture()
|
||||
|
||||
|
||||
def compress(buf, z1, t1, z2, t2, nx, ny, nz, tend, path):
|
||||
# Flag to keep track of processed buffer
|
||||
process_buf = 1
|
||||
|
@ -239,14 +246,14 @@ def compress(buf, z1, t1, z2, t2, nx, ny, nz, tend, path):
|
|||
hdu = fits.PrimaryHDU(data=np.array([zavg, zstd, zmax, znum]),
|
||||
header=hdr)
|
||||
hdu.writeto(os.path.join(path, fname))
|
||||
logging.info("Compressed %s" % fname)
|
||||
logger.info("Compressed %s" % fname)
|
||||
|
||||
# Exit on end of capture
|
||||
if t[-1] > tend:
|
||||
break
|
||||
|
||||
# Exiting
|
||||
logging.info("Exiting compress")
|
||||
logger.info("Exiting compress")
|
||||
|
||||
|
||||
# Main function
|
||||
|
@ -299,7 +306,7 @@ if __name__ == '__main__':
|
|||
|
||||
# Get obsid
|
||||
t = time.gmtime()
|
||||
obsid = "%s_%d/%s"%(time.strftime("%Y%m%d", t), device_id, time.strftime("%H%M%S", t))
|
||||
obsid = "%s_%d/%s" % (time.strftime("%Y%m%d", t), device_id, time.strftime("%H%M%S", t))
|
||||
|
||||
# Generate directory
|
||||
if testing:
|
||||
|
@ -310,8 +317,18 @@ if __name__ == '__main__':
|
|||
os.makedirs(path)
|
||||
|
||||
# Setup logging
|
||||
logging.basicConfig(filename=os.path.join(path, "acquire.log"),
|
||||
level=logging.DEBUG)
|
||||
logFormatter = logging.Formatter("%(asctime)s [%(threadName)-12.12s] " +
|
||||
"[%(levelname)-5.5s] %(message)s")
|
||||
logger = logging.getLogger()
|
||||
|
||||
fileHandler = logging.FileHandler(os.path.join(path, "acquire.log"))
|
||||
fileHandler.setFormatter(logFormatter)
|
||||
logger.addHandler(fileHandler)
|
||||
|
||||
consoleHandler = logging.StreamHandler(sys.stdout)
|
||||
consoleHandler.setFormatter(logFormatter)
|
||||
logger.addHandler(consoleHandler)
|
||||
logger.setLevel(logging.DEBUG)
|
||||
|
||||
# Set location
|
||||
loc = EarthLocation(lat=cfg.getfloat('Common', 'observer_lat')*u.deg,
|
||||
|
@ -328,29 +345,29 @@ if __name__ == '__main__':
|
|||
|
||||
# Start/end logic
|
||||
if state == "sun never rises":
|
||||
logging.info("The sun never rises. Exiting program.")
|
||||
logger.info("The sun never rises. Exiting program.")
|
||||
sys.exit()
|
||||
elif state == "sun never sets":
|
||||
logging.info("The sun never sets.")
|
||||
logger.info("The sun never sets.")
|
||||
tend = tnow+24*u.h
|
||||
elif (trise < tset):
|
||||
logging.info("The sun is below the horizon.")
|
||||
logger.info("The sun is below the horizon.")
|
||||
tend = trise
|
||||
elif (trise >= tset):
|
||||
dt = np.floor((tset-tnow).to(u.s).value)
|
||||
logging.info("The sun is above the horizon. Sunset at %s."
|
||||
% tset.isot)
|
||||
logging.info("Waiting %.0f seconds." % dt)
|
||||
logger.info("The sun is above the horizon. Sunset at %s."
|
||||
% tset.isot)
|
||||
logger.info("Waiting %.0f seconds." % dt)
|
||||
tend = trise
|
||||
try:
|
||||
time.sleep(dt)
|
||||
except KeyboardInterrupt:
|
||||
sys.exit()
|
||||
else:
|
||||
tend = tnow+31.0*u.s
|
||||
tend = tnow+31.0*u.minute
|
||||
|
||||
logging.info("Starting data acquisition.")
|
||||
logging.info("Acquisition will end at "+tend.isot)
|
||||
logger.info("Starting data acquisition.")
|
||||
logger.info("Acquisition will end at "+tend.isot)
|
||||
|
||||
# Get settings
|
||||
nx = cfg.getint(camera_type, 'nx')
|
||||
|
@ -361,9 +378,10 @@ if __name__ == '__main__':
|
|||
maxgain = cfg.getint(camera_type, 'maxgain')
|
||||
autogain = cfg.getboolean(camera_type, 'autogain')
|
||||
exposure = cfg.getint(camera_type, 'exposure')
|
||||
bins = cfg.getint(camera_type, 'bin')
|
||||
binning = cfg.getint(camera_type, 'bin')
|
||||
brightness = cfg.getint(camera_type, 'brightness')
|
||||
bandwidth = cfg.getint(camera_type, 'bandwidth')
|
||||
high_speed = cfg.getint(camera_type, 'high_speed')
|
||||
|
||||
# Initialize arrays
|
||||
z1base = multiprocessing.Array(ctypes.c_uint8, nx*ny*nz)
|
||||
|
@ -387,8 +405,9 @@ if __name__ == '__main__':
|
|||
elif camera_type == "ASI":
|
||||
pcapture = multiprocessing.Process(target=capture_asi,
|
||||
args=(buf, z1, t1, z2, t2,
|
||||
nx, ny, nz, tend.unix, device_id, live, gain, maxgain, autogain,
|
||||
exposure, bins, brightness, bandwidth))
|
||||
nx, ny, nz, tend.unix, device_id, live, gain,
|
||||
maxgain, autogain, exposure, binning,
|
||||
brightness, bandwidth, high_speed))
|
||||
|
||||
# Start
|
||||
pcapture.start()
|
||||
|
|
|
@ -40,6 +40,7 @@ exposure = 100000 # Exposure time in microseconds
|
|||
bin = 2 # Binning factor (1: 1x2, 2: 2x2 etc)
|
||||
brightness = 10 # Target brightness of pixels
|
||||
bandwidth = 90 # Bandwidth usage (percent)
|
||||
high_speed = 1 # High speed mode (0 for False, 1 for True)
|
||||
|
||||
[Astrometry]
|
||||
sex_config = /path/to/solve.sex
|
||||
|
|
12
process.py
12
process.py
|
@ -93,7 +93,7 @@ if __name__ == "__main__":
|
|||
os.makedirs(os.path.join(results_dir, "not_seen"))
|
||||
if not os.path.exists(processed_dir):
|
||||
os.makedirs(processed_dir)
|
||||
|
||||
|
||||
# Forever loop
|
||||
while True:
|
||||
# Get files
|
||||
|
@ -107,18 +107,18 @@ if __name__ == "__main__":
|
|||
# Create reference calibration file
|
||||
if not os.path.exists("test.fits"):
|
||||
solved = generate_reference_with_anet(fname, "")
|
||||
|
||||
|
||||
# Calibrate astrometry
|
||||
calibrate_from_reference(fname, "test.fits", pix_catalog)
|
||||
|
||||
# Redo refence if astrometry failed
|
||||
if not is_calibrated(fourframe(fname)) and pix_catalog.nstars>10:
|
||||
if not is_calibrated(fourframe(fname)) and pix_catalog.nstars > 10:
|
||||
print(colored("Recomputing astrometric calibration for %s" % fname, "yellow"))
|
||||
solved = generate_reference_with_anet(fname, "")
|
||||
|
||||
# Calibrate astrometry
|
||||
calibrate_from_reference(fname, "test.fits", pix_catalog)
|
||||
|
||||
|
||||
# Generate satellite predictions
|
||||
generate_satellite_predictions(fname)
|
||||
|
||||
|
@ -127,11 +127,11 @@ if __name__ == "__main__":
|
|||
|
||||
# Get properties
|
||||
ff = fourframe(fname)
|
||||
|
||||
|
||||
# Extract tracks
|
||||
if is_calibrated(ff):
|
||||
extract_tracks(fname, trkrmin, drdtmin, trksig, ntrkmin, root_dir, results_dir)
|
||||
|
||||
|
||||
# Stars available and used
|
||||
nused = np.sum(pix_catalog.flag == 1)
|
||||
nstars = pix_catalog.nstars
|
||||
|
|
|
@ -10,6 +10,7 @@ from scipy import optimize, ndimage
|
|||
from termcolor import colored
|
||||
import datetime
|
||||
|
||||
|
||||
# Gaussian model
|
||||
def model(a, nx, ny):
|
||||
x, y = np.meshgrid(np.arange(nx), np.arange(ny))
|
||||
|
@ -180,6 +181,7 @@ def store_results(ident, fname, path, iod_line):
|
|||
|
||||
return
|
||||
|
||||
|
||||
def store_not_seen(ident, fname, path):
|
||||
# Find destination
|
||||
dest = os.path.join(path, "not_seen")
|
||||
|
@ -344,7 +346,7 @@ def extract_tracks(fname, trkrmin, drdtmin, trksig, ntrkmin, path, results_path)
|
|||
|
||||
# Store results
|
||||
store_results(ident, fname, results_path, iod_line)
|
||||
object_detected = True
|
||||
|
||||
elif ident.catalog.find("classfd.tle") > 0:
|
||||
# Track and stack
|
||||
t = np.linspace(0.0, ff.texp)
|
||||
|
@ -387,12 +389,12 @@ def extract_tracks(fname, trkrmin, drdtmin, trksig, ntrkmin, path, results_path)
|
|||
|
||||
# Skip if peak is not significant
|
||||
if sigma < trksig:
|
||||
store_not_seen(ident, fname, results_path)
|
||||
store_not_seen(ident, fname, results_path)
|
||||
continue
|
||||
|
||||
# Skip if point is outside selection area
|
||||
if inside_selection(ident, tmid, x0, y0) is False:
|
||||
store_not_seen(ident, fname, results_path)
|
||||
store_not_seen(ident, fname, results_path)
|
||||
continue
|
||||
|
||||
# Format IOD line
|
||||
|
@ -431,6 +433,3 @@ def extract_tracks(fname, trkrmin, drdtmin, trksig, ntrkmin, path, results_path)
|
|||
|
||||
# Store results
|
||||
store_results(ident, fname, results_path, iod_line)
|
||||
object_detected = True
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue