Project

General

Profile

Testing if pyscope is working with your TEM or CCD

Added by Jim Pulokas over 16 years ago

Without starting Leginon, you can test pyScope all by itself from a python command line. Start a python command line and try this (using Tecnai in the example):

from pyScope import tecnai
mytem = tecnai.Tecnai()
mytem.getMagnification()
If that is successful, the current magnification of the TEM should be printed out. Here are some other examples... For a CM:
from pyScope import CM
mytem = CM.CM()
mytem.getMagnification()
For a gatan CCD camera:
from pyScope import gatan
myccd = gatan.Gatan()
myccd.getBinning()
You should see something like: {'x': 1, 'y': 1} for the binning. For Tietz CCDs, it is more tricky, because there are a few different drivers to choose from, for instance: TietzSCX, TietzPXL, etc. You may have to try a few of them to find the one that is set up on you system. In general the testing of a pyScope module follows this pattern:

- import the pyScope module for your instrument

- create an instance of your instrument class to work with

- test out a method of that instrument (for instance, getMagnification, getDefocus, etc)


Replies (12)

pyscope and Gatan K2 computer - Added by Jason de la Cruz about 11 years ago

Hello,

I am testing pyscope on a computer controlling a Gatan K2 camera, following instructions mentioned here: http://emg.nysbc.org/projects/leginon/wiki/Gatan_K2_Installation_Notes. I get an error after attempting the following command:

k = pyscope.dmsem.GatanK2Counting()

The error states that the instruments.cfg config file could not be read in three places, when in fact it is present in C:\Program Files\myami\ and is read-write accessible by all (user is Administrator). I made sure that C:\Program Files\myami\instruments.cfg is there with proper extension (this is not explicitly mentioned in the attached screenshot). DM is running, and Leginon trunk revision 17905 is installed.

Please advise.

Thanks,
--Jason de la Cruz

Attachment: 20131018_leginon-K2-python-error.jpg (169 KB)

RE: Testing if pyScope is working with your TEM or CCD - Added by Anchi Cheng about 11 years ago

Jason,

The error did not say which file it is reading, but it only occurs after it has found at least one of the three. Therefore, it did find the file you made. However, we've experimented with an instruments.cfg that can not be parsed correctly, and were able to get the same error.

Please check the content of the instruments.cfg. Attach it if you can't spot the error. We will look through it for you.

RE: Testing if pyScope is working with your TEM or CCD - Added by Jason de la Cruz about 11 years ago

Thanks,

I only found the problem after copying the file to a linux computer and checking it for syntax errors. It turns out that when I edited the file in Windows Notepad, it placed a extra (or different?) newline character into the file, so the file had extra alternating lines when opened in linux. In a few cases there were newline characters placed in the middle of a line which was previously commented-out, so linux treated the text following the newline characters as separate, uncommented lines. This is probably what confused the python interpreter. In Windows Notepad I didn't see anything wrong with the syntax.

After correcting the file in linux and copying it back to the Windows PC, commands succeeded without errors.

RE: Testing if pyScope is working with your TEM or CCD - Added by Jason de la Cruz about 11 years ago

Actually, I spoke too soon. I was able to initialize the camera, and set exposure time, but not getImage(). The python window froze after attempting to set the proper K2 parameters in DM. DM showed an error in the output in the form of an executable script which I loaded and run separately within DM. The error states that "The camera is not a ImageAcq camera" (see attachment for screenshot). It seems that there is some sort of communication, as DM automatically switches to the Orius camera and retracts it (instead of retracting the Orius, inserting the K2, and taking a Counted-mode image).

Thanks again for your help.

Attachment: 20131018_k2-pyscope-error_ImageAcq.jpg (427 KB)

RE: Testing if pyScope is working with your TEM or CCD - Added by Anchi Cheng about 11 years ago

Did you install the SEMCCD-GMS2-64.dll from our site? Is it possible that there is another version of it such as a similar plug-in directly from SerialEM there ?

How many camera are on the computer?

Could you show us your instruments.cfg on that computer?

RE: Testing if pyScope is working with your TEM or CCD - Added by Jason de la Cruz about 11 years ago

Yes, I am using SEMCCD-GMS2-64.dll sourced from your site, even though our version of the file is more recent. This computer is controlling only two physical cameras, situated post-GIF. Please see the instruments.cfg attached within the tar-gzipped archive.

I noticed that though the instruments.cfg file looks fine under linux, under Windows it looks terrible, with some commented lines appearing onto others. However, under Windows, I made sure that commented lines were commented out, and that uncommented lines contained proper text and syntax before the commands were run. This file is located under the "original" subdirectory in the archive.

To see if this was a text encoding issue, I made a new file under Windows and typed out only the necessary lines for the cameras in instruments.cfg, and saved it each as an ANSI-, Unicode-, Unicode Big-endian-, and UTF-8-encoded file. The files are included for your reference. I tested each file with the python commands by saving each as instruments.cfg. As expected, the ANSI-encoded file had similar behavior to the original, while the other files simply couldn't be read.

Attachment: 20131019_instruments-cfg-test.tar.gz (1.8 KB)

RE: Testing if pyScope is working with your TEM or CCD - Added by Anchi Cheng about 11 years ago

In other words, you do have SerialEM installed on there? Is it operational? Could you give the version number? It might be an issue we need to ask David Mastronarde about.

There is another simpler reason. I saw that your instruments.cfg lists K2 Counting width and height the same as the K2 Super. You should change it to half of the size, like the one in K2 Linear. The width and height refers to the expected array dimension of the image it will produce.

RE: Testing if pyScope is working with your TEM or CCD - Added by Anchi Cheng about 11 years ago

Jason,

Here is our theory:

We select the index of the camera (which we called cameraid in our script) in the cameras listed in DM to choose which physical camera we interact with. You will find this in pyscope/dmsem.py.
Currently, the class GatanK2Base is set as cameraid = 0 while the class GatanOrius is set as cameraid = 1. It is possible that this is reversed on your system, judging from the fact that you said Orius was inserted in your testing.

We've found two ways to find out this information.

1. Use DM GUI. When you go under menu bar for Camera/Camera, it shows the cameras controlled by DM. Other than the camera name, it also has a number at the end.

We think the order of this display is according to the index in camera selection we pass in DM Scripting. Therefore, in our case, GatanK2Summit cameraid set in our script is 0.

2. Get the value from DM Scripting using this script:

Object manager = CM_GetCameraManager()
Object cameralist = CM_GetCameras(manager)
Object camera = ObjectAt(cameralist, 0)
string retval = CM_GetCameraIdentification(camera)
Result(retval)

This should show the same kind of string as in DM menu Camera/Camera but is specific to the cameraid we use to select the camera.

Once you know the cameraid Leginon should send to DM from these, you can change the python script pyscope/dmsem.py to that.

For example, if you found that K2 is selected by index 1 instead of 0, change this line:

class GatanK2Base(DMSEM):
  name = 'GatanK2Base'
  cameraid = 0

To
class GatanK2Base(DMSEM):
  name = 'GatanK2Base'
  cameraid = 1

You will need to change cameraid in the same python script for the one assigning GatanOrius, too if you make the change in K2. If this works, we will make this configurable in the future rather than the hardcode.

pyscope testing: Gatan Orius camera insertion problem - Added by Jason de la Cruz about 11 years ago

The solution mentioned above worked; I simply switched the cameraid values for 'class GatanOrius(DMSEM)' and 'class GatanK2Bse(DMSEM)'. However, the DM script above did not work for us; the system complained that the CM_GetCameraIdentification() function was not found.

Testing pyscope with the K2 camera worked as it should, retracting the Orius camera if it is inserted, inserting the K2 camera if necessary, and properly controlling the pre-specimen shutter to take an exposure. The Orius camera is able to take an image, however it immediately takes an exposure without checking camera insertion, even if the camera is retracted. I used the following commands at the python prompt:

import pyscope.dmsem
k=pyscope.dmsem.GatanOrius()
k.setExposureTime(200)
k.getImage()

Also, I am using the latest build of myami (version 18005). Please advise.

RE: Testing if pyScope is working with your TEM or CCD - Added by Anchi Cheng about 11 years ago

Jason,

I think Orius is not made to automatically insert when a command requests an image while K2 is. Therefore, the direct commands we issue does not cause it to insert. You should be safe to not worrying about this since the insertion will be handled at a higher level in Leginon when it is used.

Give it a try in a regular Leginon session.

RE: Testing if pyScope is working with your TEM or CCD - Added by Mario Borgnia over 10 years ago

I wonder if this behavior is new.
The following fails under windows:

from pyScope import tecnai

The module is not called pyScope but rather pyscope and hence this works:

from pyscope import tecnai

RE: Testing if pyscope is working with your TEM or CCD - Added by Anchi Cheng over 10 years ago

pyScope is the old name for the sub package. It is now called pyscope

    (1-12/12)