Converting position of the pixels of an image to Lat / Lon

Cool displays
Post Reply
User avatar
Posts: 87
Joined: Thu May 05, 2011 9:19 pm

Converting position of the pixels of an image to Lat / Lon

Post by glez_b »

I share part of code that converts the position of the pixels to coordinates Lat / Lon

Code: Select all

# Call data from the directory(/home/mcidasv/Documentos/SSEC/20040601)

def scm(directory):
  import os;
  fs = os.listdir(directory);

  # now fs will be a list of all the files in directory

  from edu.wisc.ssec.mcidas import AreaFile;
  for name in fs:

      # Coordinates are converted to Lat / Lon
      print "Reading in:",name
      af = AreaFile(directory+"/"+name);
      navblock = af.getNav();
      nav = af.getNavigation();
      nav2 = nav.makeAreaNav(navblock);
      ad = af.getAreaDirectory();
      areaDir = ad.getDirectoryBlock();
      nlines = ad.getLines();
      nelems = ad.getElements();
      nav2.setImageStart(areaDir[5], areaDir[6]);
      nav2.setRes(areaDir[11], areaDir[12]);
      count = 0;
      data = af.getFloatData();

      # now look through the first band y count pixels
      # MCS detected when his temperature infrared (TIR) is < 208
      for i in xrange(ad.getLines()):
          for j in xrange(ad.getElements()):
              if 489 < i < 927 and 14 < j < 562:
                  if (data[0][i][j]) > 207 and (data[0][i][j]) < 209:
                      pt = nav2.toLatLon(((j,),(i,)))
                      lat= pt[0][0]
                      lon= pt[1][0]
                      print i, j, data[0][i][j], lat, lon;

Now I would like to ask some idea:

1. How I can localize, track or target only the brightness values ??that are equal to or greater than 208 and that this region of brightness remain for three hours.

2. Once regionalized the corresponding brightness values??, is possible display them in a image in McIDAS-V
User avatar
Posts: 1120
Joined: Mon Jan 19, 2009 7:16 pm

Re: Converting position of the pixels of an image to Lat / Lon

Post by joleenf »


Interactively use,
mask(Field, "ge", 208) masks a flat field within McIDAS-V.

The easiest way is to load the data in the field selector and then from the jython shell, type

a=selectData() # this pops up a window to select the desired field.

b=mask(a, "ge",208) # creates a field of 0 and 1

panels = buildWindow() # this builds the McIDAS-V window within which is an array of panels
maskLayer = panels[0].createLayer('Image Display', b*a) # this displays the area with only the mask values visible as a layer in the initial panel (Zero based array of panels)

Note, the scripting methods in this post are available in the latest version of McIDAS-V 1.2. If you have not yet upgraded, I recommend that you do, there are a number of useful features.

Documentation for the new scripting methods can be found in the user's guide (search on "Scripting"):

Documentation for the mask method can be found here: ... thods.html

To achieve this from a script, use the "find" method, which returns the indices of the pixels which meet the criteria. To follow the correct pixels through time, you will have to write code to group locations and maintain time information from the files. Documentation for the find method is also at ... thods.html

Two new methods have been added to 1.2, they are maskWithinRange, and findWIthinRange, which allow masking within a certain range of values.

Post Reply