RE: [pyngl-talk] native mercator projection still having problems.

From: Ertl, John C CIV 63134 <john.ertl_at_nyahnyahspammersnyahnyah>
Date: Tue, 7 Oct 2008 10:14:45 -0700

Classification: UNCLASSIFIED
Caveat (s): FOUO


Thanks for the help. Yes the grid is a native mercator grid so I do not want to do any transforms. I have the data plotting but the map does not line up with the grid. The date is plotting for the western Pacific but the map is most of the globe...see attached. I am having the same kind of problem with the Lambert Conformal.

For the west pac grid the max/min Lon/Lat

latMin = -7.31
lonMin = 94.8
latMax = 51.735433
lonMax = -174.616947
I haver also tried lonMax = 185.383053

Thanks again for the help

PyNGL code

        #### Uses PyNGL to view/image feilds.
        wks = Ngl.open_wks(self.outPutType,fileName,None)

        #### This is set to allow very "buisy" contour plots to
        #### to be made.
        ws_id = Ngl.get_workspace_id()
        rlist = Ngl.Resources()

        rlist.wkColorMap = colorScale

        rlist.wsMaximumSize = 90000000


        resources = Ngl.Resources()

        resources.mpGeophysicalLineThicknessF = 3.

        ## Automaticly set the contour levels or use set vlaues to contour
        if contourMethod.upper() == "AUTO":
            resources.cnLevelSelectionMode = "AutomaticLevels"
            resources.cnLevelSelectionMode = "ManualLevels"
            resources.cnMinLevelValF = minValue # contour levels.
            resources.cnMaxLevelValF = maxValue
            resources.cnLevelSpacingF = interval

        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.tfDoNDCOverlay = True # do not change data plot

            print "latMin = %s" % self.minLat
            print "lonMin = %s" % self.minLon
            print "latMax = %s" % self.maxLat
            print "lonMax = %s" % self.maxLon
        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.
        # 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

                map = Ngl.contour_map(wks,self.grid,resources) # make the plot
                print "sorry %s could not be made" % title

John Ertl

7 Grace Hopper Ave.
Monterey, CA 93943
(831) 656-5704

Classification: UNCLASSIFIED
Caveat (s): FOUO

From: Mary Haley
Sent: Tue 10/7/2008 7:34 AM
To: Ertl, John C CIV 63134
Subject: Re: native mercator projection still having problems.


To back up for a bit, is your data already on a mercator grid? I'm
assuming it is, as that's what I think of when I hear "native mercator

If this is the case, then you need to make sure you have the map
projection resources set up exactly to match the projection that the
grid is defined on. Then, you do *not* want to set the
sfXArray/sfYArray resources, and instead, set "tfDoNDCOverlay" to
True. This tells PyNGL not to put your data through the equations for
a map projection, because they are already projected.

We do actually have an example of this. The pynglex example "panel2" is
done on a native mercator grid, but oddly, it uses the
sfXArray/sfYArray route, rather than the tfDoNDCOverlay route.

Try running:

   pynglex panel2

and then modify to change the lines:

res.sfYArray = lat # Where to overlay
res.sfXArray = lon # contours on map


#res.sfYArray = lat # Where to overlay
#res.sfXArray = lon # contours on map
res.tfDoNDCOverlay = True # don't put data through
                                         # map projection equations and

rerun. You will see that you get the same results, and this is because
the mercator projection is set up to match the data exactly.

I think I need to change this example to reflect that the sfXArray and
sfYArray resources are not needed (this is a bit of overkill).


On Mon, 6 Oct 2008, Ertl, John C CIV 63134 wrote:

> Classification: UNCLASSIFIED
> Caveat (s): FOUO
> Seth,
> Thanks for the help...The mercator projection looks to still have big problems but I was able to make a good step forward on the Lambert Conformal.
> I think it is plotting the data correctly but the map is very wrong. It looks to be showing the entire northern hemisphere map (in a Lambert conformal plot) but the data is only for a portion of the east pacific. What are you using for plotting the map on top of the data?
> Thanks for you help.
> John Ertl
> Meteorologist
> 7 Grace Hopper Ave.
> Monterey, CA 93943
> (831) 656-5704
> Classification: UNCLASSIFIED
> Caveat (s): FOUO
> From: Seth McGinnis
> Sent: Fri 10/3/2008 3:58 PM
> To: Ertl, John C CIV 63134;
> Subject: Re: native mercator projection
>> 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 don't know how a native mercator grid works, but for Lambert grids, here's the chunk of (NCL) code I use to define the map projection. ("proj" is a variable from my NetCDF file that holds the projection information.)
> res_at_mpProjection = "LambertConformal"
> res_at_mpLambertMeridianF = proj_at_longitude_of_central_meridian
> res_at_mpLambertParallel1F = proj_at_standard_parallel(0)
> res_at_mpLambertParallel2F = proj_at_standard_parallel(1)
> res_at_tfDoNDCOverlay = True ;; Lambert Conformal generally needs this
> For all the other projections I've worked with (polar stereographic, transverse mercator, and rotated pole), you just have to set the "mpCenterLatF" and "mpCenterLonF" attributes. So if lat looks correct but lon is off, my guess would be that you need to set resources.mpCenterLonF to something non-default.
> Cheers,
> Seth McGinnis
> Associate Scientist

Received on Tue Oct 07 2008 - 11:14:45 MDT

This archive was generated by hypermail 2.2.0 : Wed Oct 08 2008 - 10:08:39 MDT