Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 62 additions & 54 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,8 @@ def index():
tempData = andor.getStatusTEC()["temperature"]
return render_template("index.html", tempData=tempData)

# REMEMBER: localhost:5000/temperature
@app.route("/getTemperature")
def route_getTemperature():
# return str(andor.getStatusTEC()['temperature'])
print(andor.getStatusTEC())
return jsonify(andor.getStatusTEC())

@app.route("/setTemperature", methods=["POST"])
Expand All @@ -106,35 +103,6 @@ def route_setTemperature():

return str(req["temperature"])

# def route_setTemperature():
# """
# Sets the temperature of the camera in Celsius. Uses the 'POST' method
# to take in form requests from the front end.

# Returns the set temperature for display on the front end.
# """
# if request.method == "POST":
# app.logger.info('setting temperature')
# req = request.get_json(force=True)

# #change_temp = andor.setTemperature(req['temp'])
# activateCooling(req['temp'])

# curr_temp = andor.getStatusTEC()['temperature']
# while curr_temp != req['temp']:
# curr_temp = andor.getStatusTEC()['temperature']
# deactivateCooling()

# app.logger.info(andor.getStatusTEC()['temperature'])

# res = req['temp']

# return res

# @app.route('/getStatusTEC')
# def route_getStatusTEC():
# return str(andor.getStatusTEC()['status'])

@app.route("/get_filter_position")
def route_get_filter():
pass
Expand Down Expand Up @@ -219,14 +187,17 @@ def route_capture():
Throws an error if status code is not 20002 (success).
"""
if request.method == "POST":
req = request.get_json(force=True)
req = json.loads(req)
req = json.loads(request.get_json(force=True))
dim = andor.getDetector()["dimensions"]

# check if acquisition is already in progress
status = andor.getStatus()
if status == 20072:
return {"message": str("Acquisition already in progress.")}
return {
"filename": fname,
"url": "",
"status": str(status)
}

# handle filter type - untested, uncomment if using filter wheel

Expand Down Expand Up @@ -259,40 +230,68 @@ def route_capture():
elif req["exptype"] == "Series":
andor.setAcquisitionMode(3)
andor.setNumberKinetics(int(req["expnum"]))
andor.setNumberAccumulations(int(req["accumnum"]))
andor.setExposureTime(float(req["exptime"]))
andor.setKineticCycleTime(float(req["kinetictime"]))
andor.setAccumulationCycleTime(float(req["cycletime"]))

file_name = f"{req['filename']}.fits"

andor.startAcquisition()
status = andor.getStatus()
# todo: review parallelism, threading behavior is what we want?
while status == 20072:
status = andor.getStatus()
app.logger.info("Acquisition in progress")
try:
andor.startAcquisition()
except AndorCameraError as ae:
return {
"filename": fname,
"url": "",
"status": str(ae.error_code)
}

time.sleep(float(req["exptime"]) + 0.5)
img = andor.getAcquiredData(
dim
) # TODO: throws an error here! gotta wait for acquisition
img = andor.getAcquiredData(dim)

if img["status"] == 20002:
# use astropy here to write a fits file
andor.setShutter(1, 0, 50, 50) # closes shutter
# home_filter() # uncomment if using filter wheel
hdu = fits.PrimaryHDU(img["data"])
hdu.header["EXP_TIME"] = (
float(req["exptime"]),
"Exposure Time (Seconds)",
"Exposure Time (Seconds)"
)
hdu.header["EXP_TYPE"] = (
str(req["exptype"]),
"Exposure Type (Single, Real Time, or Series)",
"Exposure Type (Single, Real Time, or Series)"
)
# TODO: for a series exposure, make a fits file with different entries
accum_num = "N/A"
cycle_time = "N/A"
accum_time = "N/A"

if str(req["exptype"]) == "Series":
accum_num = str(req["accumnum"])
cycle_time = str(req["kinetictime"])
accum_time = str(req["accumtime"])

hdu.header["ACCUM_NUM"] = (
accum_num,
"The number of accumulations per set"
)
hdu.header["CYCLE_TIME"] = (
cycle_time,
"The time between the start of sets of scans"
)
hdu.header["ACCUM_TIME"] = (
accum_time,
"The time between the start of individual scans"
)

hdu.header["IMG_TYPE"] = (
str(req["imgtype"]),
"Image Type (Bias, Flat, Dark, or Object)",
"Image Type (Bias, Flat, Dark, or Object)"
)
hdu.header["FILTER"] = (
str(req["filtype"]),
"Filter (Ha, B, V, g, r)"
)
hdu.header["FILTER"] = (str(req["filtype"]), "Filter (Ha, B, V, g, r)")

fname = req["filename"]
fname = formatFileName(fname)
Expand All @@ -301,13 +300,24 @@ def route_capture():
return {
"filename": fname,
"url": url_for("static", filename=f"fits_files/{fname}"),
"message": "Capture Successful",
"status": img["status"]
}

else:
andor.setShutter(1, 0, 50, 50)
home_filter() # uncomment if using filter wheel
return {"message": str("Capture Unsuccessful")}
# home_filter() # uncomment if using filter wheel
return {
"filename": fname,
"url": "",
"status": img["status"]
}

else:
return {
"filename": "",
"url": "",
"status": "-1"
}

# we shouldn't download files locally - instead, lets upload them to server instead
# def send_file(file_name):
Expand Down Expand Up @@ -339,11 +349,9 @@ async def route_fw_test():
def OnExitApp():
andor.shutdown()


atexit.register(OnExitApp)

app = create_app()


if __name__ == "__main__":
app.run(host="127.0.0.1", port=3000)
44 changes: 24 additions & 20 deletions evora/andor_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,31 @@ PYBIND11_MODULE(andor_wrapper, m) {
py::arg("andor_dir") = "/usr/local/etc/andor"
);

m.def("setReadMode", &SetReadMode, "Set Read Mode");
m.def("shutdown", &ShutDown, "Shutdown the Andor Camera");
m.def("setAcquisitionMode", &SetAcquisitionMode, "Set acquisition mode");
m.def("setExposureTime", &SetExposureTime, "Set exposure time of shot");
m.def("setReadMode", &SetReadMode, "Set Read Mode");
m.def("shutdown", &ShutDown, "Shutdown the Andor Camera");
m.def("setAcquisitionMode", &SetAcquisitionMode, "Set acquisition mode");
m.def("setExposureTime", &SetExposureTime, "Set exposure time of shot");
m.def("setAccumulationCycleTime", &SetAccumulationCycleTime, "Set the time between the start of individual scans");
m.def("setNumberAccumulations", &SetNumberAccumulations, "Set the number of accumulations in a set");
m.def("setNumberKinetics", &SetNumberKinetics, "Set the number of SETS of accumulated scans");
m.def("setKineticCycleTime", &SetKineticCycleTime, "Set the time between the start of SETS of accumulated scans");
m.def("getAcquisitionTimings",
[](void) {
float exposure, accumulate, kinetic;
exposure = -1;
accumulate = -1;
kinetic = -1;

int status;
status = GetAcquisitionTimings(&exposure, &accumulate, &kinetic);
py::dict out;
out["exposure"] = exposure;
out["accumulate"] = accumulate;
out["kinetic"] = kinetic;
out["status"] = status;

return out;
}, "Get current camera timing settings");
[](void) {
float exposure, accumulate, kinetic;
exposure = -1;
accumulate = -1;
kinetic = -1;

int status;
status = GetAcquisitionTimings(&exposure, &accumulate, &kinetic);
py::dict out;
out["exposure"] = exposure;
out["accumulate"] = accumulate;
out["kinetic"] = kinetic;
out["status"] = status;

return out;
}, "Get current camera timing settings");
m.def("getStatus",
[](void) {
int status;
Expand Down
20 changes: 0 additions & 20 deletions evora/dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,26 +143,6 @@ def getAcquiredData(cls, dim):
if cls.initialized:
if not cls.acquiring:
data = randint(65535, size=dim)
# img = 'space.txt'
# if randint(0, 1000) >= 999:
# img = 'server/evora/space0.txt'

# #time_sec = int(exp_time)
# #while time_sec:
# # mins, secs = divmod(time_sec, 60)
# # timer = '{:02d}:{:02d}'.format(mins, secs)
# # print(timer, end="\r")
# # time.sleep(1)
# # time_sec -= 1

# #import os
# #list = os.listdir('.')

# with open(img) as f:
# data = asarray(Image.open(BytesIO(base64.b64decode(f.read()))))

# This might not work, passing by reference is weird in Python

return {"data": data, "status": DRV_SUCCESS}
else:
return {"data": array([], dtype="uint8"), "status": DRV_ACQUIRING}
Expand Down
Loading