native mercator projection

From: Ertl, John C CIV 63134 <john.ertl_at_nyahnyahspammersnyahnyah>
Date: Fri, 3 Oct 2008 15:08:40 -0700

All

I have some old PyNGL code that displays Spherical grids and it works great. I want to now display native mercator and eventually Lambert grids.

I looked at the NCL page and found a simple script that does this but when I tried to convert it to PyNGL it failed miserably. Is there a PyGNL script that displays a native mercator grid?

The code that does the plot I below. I set all of the meta data in another script and pass it as an object. I was able to get a plot before I tried the
 wks = Ngl.open_wks(self.outPutType,fileName,"native")
line but the plot area/map was all wrong. The map lat was correct but the lon was all wrong.

The lat lon printed out from the code is:
latMin = -7.31
lonMin = 94.8
latMax = 51.560224
lonMax = 185.207844

Do I need to upgrade to PyNIO? and Python 2.5?

Thanks for any help.

        #### Uses PyNGL to view/image fields.
        if self.projection == "spherical":
            wks = Ngl.open_wks(self.outPutType,fileName,None)
        else:
            wks = Ngl.open_wks(self.outPutType,fileName,"native")
 
        if colorScale == "redYellowGreen":
          cmap = Numeric.array([[1.00, 1.00, 1.00], [0.00, 0.00, 0.00], \
                                       [255, 0, 0], \
                                       [255, 255, 0], \
                                       [ 0, 255, 0]],Numeric.Float0)
                                
          colorScale = cmap
            
 
        #### This is set to allow very "busy" contour plots to
        #### to be made.
        ws_id = Ngl.get_workspace_id()
        rlist = Ngl.Resources()
 
        rlist.wkColorMap = colorScale
 
        rlist.wsMaximumSize = 90000000
        Ngl.set_values(ws_id,rlist)
 
 
        Ngl.set_values(wks,rlist)
 
        resources = Ngl.Resources()
 
        resources.mpGeophysicalLineThicknessF = 3.
 
        ## Automatically set the contour levels or use set values to contour
        if contourMethod.upper() == "AUTO":
            resources.cnLevelSelectionMode = "AutomaticLevels"
        else:
            resources.cnLevelSelectionMode = "ManualLevels"
            resources.cnMinLevelValF = minValue # contour levels.
            resources.cnMaxLevelValF = maxValue
            resources.cnLevelSpacingF = interval
##
        if self.projection == "spherical":
            resources.sfMissingValueV = 1.0e10
            resources.sfXCStartV = self.minLon # Set the plot based on grid lat lon
            resources.sfXCEndV = self.maxLon
            resources.sfYCStartV = self.minLat
            resources.sfYCEndV = self.maxLat
 
            resources.mpLimitMode = "LatLon" # Limit the map view.
            resources.mpMinLonF = self.minLon
            resources.mpMaxLonF = self.maxLon
            resources.mpMinLatF = self.minLat
            resources.mpMaxLatF = self.maxLat
            resources.mpPerimOn = True # Turn on map perimeter.
 
        if self.projection == "mercator":
            # set the map view to only show the grid region.
            resources.mpProjection = "mercator" # projection
            resources.mpLimitMode = "Corners" # method to zoom
 
            resources.mpLeftCornerLatF = self.minLat
            resources.mpLeftCornerLonF = self.minLon
            resources.mpRightCornerLatF = self.maxLat
            resources.mpRightCornerLonF = self.maxLon
            resources.tfDonDCOverlyay = True
 
            print "latMin = %s" % self.minLat
            print "lonMin = %s" % self.minLon
            print "latMax = %s" % self.maxLat
            print "lonMax = %s" % self.maxLon
             
         
        if self.geometry[0:5] == "global":
            #Set the center longitude for a global plot to what is selected
            #check to see if geom has global in name
            if self.geom.find("global") != -1 and resources.sfXCStartV == 0.0 and resources.sfYCStartV == -90.0:
               resources.mpCenterLonF = globalCenter
            elif resources.sfXCStartV < 180.0 and resources.sfXCEndV > 180.0:
               resources.mpCenterLonF = 180.0
            else:
                pass
 
        resources.tiMainFontHeightF = .015 # Main title font size
        resources.tiMainJust = "CENTERCENTER" # Main title justification
 
        resources.tiMainString = title
                                                                                                                                                     
        resources.cnFillDrawOrder = "Predraw" # Draw contours first.
 
         
        if colorFill == "True":
            ##print "In color fill"
            resources.cnFillOn = True # Turn on contour fill.
            resources.cnLinesOn = False
            resources.cnLineLabelsOn = False # Turn off line labels.
 
        # if colorFill = false then plot with contours only
        elif colorFill == "False":
            ##print "In contour"
            resources.cnFillOn = False # Turn off contour fill.
            resources.cnLinesOn = True
            resources.cnLineLabelsOn = True # Turn on line labels.
            resources.cnMonoLineColor = False # Allow multiple colors for contour lines.
        else:
        # plot both contour and color fill.
            resources.cnFillOn = True # Turn on contour fill.
            resources.cnLinesOn = True
            resources.cnLineLabelsOn = True # Turn on line labels.
            resources.cnMonoLineColor = False # Allow multiple colors for contour lines.
 
   
        resources.cnInfoLabelOn = False # Turn off info label.
 
        resources.lbPerimOn = False # Turn off label bar perim.
        resources.pmLabelBarSide = "Bottom" # Change orientation of
        resources.lbOrientation = "Horizontal" # label bar.
        resources.lbLabelAngleF = 90
 
        ### if an operation was selected then do it now
        if operation != "None":
            ##print "doing an operation grid %s %s " %(operation,value)
            operation2Grid(self,operation,value)
 
             
        if self.deBug:
            print "Max = ", max(Numeric.ravel(self.grid))
            print "Min = ", min(Numeric.ravel(self.grid))
 
        if max(Numeric.ravel(self.grid)) == "inf" or min(Numeric.ravel(self.grid)) == "inf":
            print "problem with grid ",title
            
        else:
            try:
                map = Ngl.contour_map(wks,self.grid,resources) # make the plot
                Ngl.destroy(wks)
            except:
                print "sorry %s could not be made" % title

_______________________________________________
pyngl-talk mailing list
pyngl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/pyngl-talk
Received on Fri Oct 03 2008 - 16:08:40 MDT

This archive was generated by hypermail 2.2.0 : Tue Oct 07 2008 - 09:10:08 MDT