Skip to content

Commit a95ca8f

Browse files
authored
Merge pull request #35 from directelectron/UpdateBeteVersion
Replaced some print function as log.info
2 parents bfa70b8 + 7271f3d commit a95ca8f

2 files changed

Lines changed: 17 additions & 19 deletions

File tree

deapi/client.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# File containing the Client for connecting to the DE-Server
22
#
3-
# Last update: 2024-08-07
3+
# Last update: 2025-11-13
44
# cfrancis@directelectron.com
55

66

@@ -51,11 +51,13 @@
5151
logLevel = logging.INFO
5252
logging.basicConfig(format="%(asctime)s DE %(levelname)-8s %(message)s", level=logLevel)
5353
log = logging.getLogger("DECameraClientLib")
54-
log.info("Python : " + sys.version.split("(")[0])
55-
log.info("DEClient : " + version)
56-
log.info("CommandVer: " + str(commandVersion))
57-
log.info("logLevel : " + str(logging.getLevelName(logLevel)))
5854

55+
def print_info():
56+
log.info(f"DEAPI Version: {version} (Command Version: {commandVersion})")
57+
log.info("Python : " + sys.version.split("(")[0])
58+
log.info("DEClient : " + version)
59+
log.info("CommandVer: " + str(commandVersion))
60+
log.info("logLevel : " + str(logging.getLevelName(logLevel)))
5961

6062
class Client:
6163
"""A class for connecting to the DE-Server
@@ -217,7 +219,7 @@ def connect(self, host: str = "127.0.0.1", port: int = 13240, read_only=False):
217219
self.commandVersion = 3
218220
else:
219221
self.commandVersion = commandVersion
220-
print("Command Version: ", self.commandVersion)
222+
log.info(f"Command Version: {self.commandVersion}")
221223
self._initialize_attributes()
222224
self.update_scan_size()
223225
self.update_image_size()
@@ -989,7 +991,7 @@ def set_binning(self, bin_x, bin_y, use_hw=True):
989991
retval = True
990992
if commandVersion < 10:
991993
retval = self.SetProperty(
992-
"Binning Mode", "Hardware and Software" if useHW else "Software Only"
994+
"Binning Mode", "Hardware and Software" if use_hw else "Software Only"
993995
)
994996
retval &= self.SetProperty("Binning X", bin_x)
995997
retval &= self.SetProperty("Binning Y", bin_y)
@@ -1408,7 +1410,7 @@ def set_xy_array(self, positions, width=None, height=None):
14081410
packet = struct.pack("I", command.ByteSize()) + command.SerializeToString()
14091411
self.socket.send(packet)
14101412
ret = self.__ReceiveResponseForCommand(command) != False
1411-
print("response", ret)
1413+
log.info(f"response {ret}")
14121414
except socket.error:
14131415
raise socket.error(
14141416
"Error sending x-y scan positions to socket. Is the server running?"
@@ -1771,7 +1773,7 @@ def set_virtual_mask(self, id, w, h, mask):
17711773
log.warning("Virtual mask must be a numpy array of type uint8")
17721774
mask = mask.astype(np.uint8)
17731775
mask_bytes = mask.tobytes()
1774-
print("Sending mask of size", len(mask_bytes))
1776+
log.info(f"Sending mask of size {len(mask_bytes)}")
17751777
self.__sendToSocket(self.socket, mask_bytes, len(mask_bytes))
17761778

17771779
ret = self.__ReceiveResponseForCommand(command) != False
@@ -1900,9 +1902,9 @@ def get_movie_buffer(
19001902
f"expected: {totalBytes}, received: {movieBufferSize}"
19011903
)
19021904
else:
1903-
print("reading movie buffer", totalBytes)
1905+
log.info(f"reading movie buffer {totalBytes}", )
19041906
movieBuffer = self._recvFromSocket(self.socket, totalBytes)
1905-
print("Done reading movie buffer")
1907+
log.info("Done reading movie buffer")
19061908
else:
19071909
retval = False
19081910

@@ -2216,7 +2218,7 @@ def wait_for_saving_files(self, quiet=True):
22162218

22172219
duration = self.GetTime() - t0
22182220
if not quiet:
2219-
print(" %.1fs" % duration)
2221+
log.info(f" {duration:.1f}s")
22202222
sys.stdout.flush()
22212223

22222224
def _get_auto_attributes(self, frame_type: FrameType):
@@ -2386,11 +2388,7 @@ def take_trial_gain_reference(
23862388
self.SetProperty("Exposure Time (seconds)", prevExposureTime)
23872389

23882390
num_el = np.max([attr.eppixpf * frame_rate, attr.eppixps])
2389-
print(
2390-
"The number of electrons per pixel per second (eppixps): {:.2f}".format(
2391-
num_el
2392-
)
2393-
)
2391+
log.info(f"The number of electrons per pixel per second (eppixps): {num_el:.2f}")
23942392

23952393
if attr.saturation > 0.0001: # Nothing should be saturated in a gain image.
23962394
raise ValueError(
@@ -2450,7 +2448,7 @@ def take_gain_reference(
24502448
frame_rate, target_electrons_per_pixel, counting
24512449
)
24522450

2453-
print(
2451+
log.info(
24542452
f"Gain reference: {exposure_time:.2f} seconds, "
24552453
f"total acquisitions: {num_acquisitions}, "
24562454
)

deapi/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
version = "5.3.0"
22
versionInfo = list(map(int, version.split(".")))
33
commandVersion = (versionInfo[0] - 4) * 10 + versionInfo[1] + 2
4-
print(f"DEAPI Version: {version} (Command Version: {commandVersion})")
4+

0 commit comments

Comments
 (0)