Basemap projection issue

Hi

I'm running into a problem using the mollweide projection, with the
following simplified code, my actual code doesn't use random data for
values but this is a clearer example to the problem I'm experiencing:

lon = numpy.arange(0, 361, 1)
lat = numpy.arange(-90, 91, 1)
x, y = numpy.meshgrid(lon, lat)
values = numpy.random.random((181, 361))

map = basemap.Basemap(projection='moll', lon_0=0, resolution='c')
map.drawcoastlines()
map.drawcountries()
map.drawmapboundary()
map.drawmeridians(numpy.arange(0,360,30))
map.drawparallels(numpy.arange(-90,90,30))

X, Y = map(x, y)

map.contourf(X, Y, values)

I get the following error:

WARNING: x coordinate not montonically increasing - contour plot
may not be what you expect. If it looks odd, your can either
adjust the map projection region to be consistent with your data, or
(if your data is on a global lat/lon grid) use the shiftgrid
function to adjust the data to be consistent with the map projection
region (see examples/contour_demo.py).

And the resulting map is incorrect due to the horizontal trends, see
http://tier2.ihepa.ufl.edu/~ram/files/moll.jpg

but if I use the orthographic projection ie:

map = basemap.Basemap(projection='ortho', lat_0=-20, lon_0=-30, resolution='c')

Then there are no errors, and the map is displayed as expected, see
http://tier2.ihepa.ufl.edu/~ram/files/ortho.jpg

I am unsure as to why I am receiving this error for the mollweide
projection, as my coordinate grid is covering the entire surface. I
am clearly doing something wring here but I don't know what - does
anyone know what is causing this issue?

Cheers

Adam

Adam Mercer wrote:

Hi

I'm running into a problem using the mollweide projection, with the
following simplified code, my actual code doesn't use random data for
values but this is a clearer example to the problem I'm experiencing:

lon = numpy.arange(0, 361, 1)
lat = numpy.arange(-90, 91, 1)
x, y = numpy.meshgrid(lon, lat)
values = numpy.random.random((181, 361))

map = basemap.Basemap(projection='moll', lon_0=0, resolution='c')
map.drawcoastlines()
map.drawcountries()
map.drawmapboundary()
map.drawmeridians(numpy.arange(0,360,30))
map.drawparallels(numpy.arange(-90,90,30))

X, Y = map(x, y)

map.contourf(X, Y, values)

I get the following error:

WARNING: x coordinate not montonically increasing - contour plot
may not be what you expect. If it looks odd, your can either
adjust the map projection region to be consistent with your data, or
(if your data is on a global lat/lon grid) use the shiftgrid
function to adjust the data to be consistent with the map projection
region (see examples/contour_demo.py).

And the resulting map is incorrect due to the horizontal trends, see
http://tier2.ihepa.ufl.edu/~ram/files/moll.jpg

but if I use the orthographic projection ie:

map = basemap.Basemap(projection='ortho', lat_0=-20, lon_0=-30, resolution='c')

Then there are no errors, and the map is displayed as expected, see
http://tier2.ihepa.ufl.edu/~ram/files/ortho.jpg

I am unsure as to why I am receiving this error for the mollweide
projection, as my coordinate grid is covering the entire surface. I
am clearly doing something wring here but I don't know what - does
anyone know what is causing this issue?

Cheers

Adam
  
Adam: I assume your data is on a latitude-longitude grid? You've asked for a mollweide projection centered on the Greenwich meridian. Your data is not centered on Greenwich - but the error message is trying to say that you can shift your grid (with the shiftgrid function) so that is has the same orientation as the map projection region. This only comes into play with global projections that 'wrap-around' at the edges, like the mollweide and mercator projections. The orthographic projection does not 'wrap around' - hence you don't get the error message.

-Jeff

···

--
Jeffrey S. Whitaker Phone : (303)497-6313
Meteorologist FAX : (303)497-6449
NOAA/OAR/PSD R/PSD1 Email : Jeffrey.S.Whitaker@...259...
325 Broadway Office : Skaggs Research Cntr 1D-124
Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg

Thanks, that makes sense now.

Cheers

Adam

···

On 11/10/2007, Jeff Whitaker <jswhit@...146...> wrote:

Adam: I assume your data is on a latitude-longitude grid? You've asked
for a mollweide projection centered on the Greenwich meridian. Your
data is not centered on Greenwich - but the error message is trying to
say that you can shift your grid (with the shiftgrid function) so that
is has the same orientation as the map projection region. This only
comes into play with global projections that 'wrap-around' at the edges,
like the mollweide and mercator projections. The orthographic
projection does not 'wrap around' - hence you don't get the error message.

Looking at the shiftmap function it looks like I should shift the
co-ordinate grid so that my longitude runs from -180 to 180 instead of
0 to 360, therefore the following shiftgrid call should do this

values, lon = basemap.shiftgrid(180, values, lon)

However I still get the same error and the corruption in the resulting
plot. I feel like I'm missing something obvious here but can't find
it.

Cheers

Adam

···

On 11/10/2007, Jeff Whitaker <jswhit@...146...> wrote:

Adam: I assume your data is on a latitude-longitude grid? You've asked
for a mollweide projection centered on the Greenwich meridian. Your
data is not centered on Greenwich - but the error message is trying to
say that you can shift your grid (with the shiftgrid function) so that
is has the same orientation as the map projection region. This only
comes into play with global projections that 'wrap-around' at the edges,
like the mollweide and mercator projections. The orthographic
projection does not 'wrap around' - hence you don't get the error message.

Adam Mercer wrote:

Adam: I assume your data is on a latitude-longitude grid? You've asked
for a mollweide projection centered on the Greenwich meridian. Your
data is not centered on Greenwich - but the error message is trying to
say that you can shift your grid (with the shiftgrid function) so that
is has the same orientation as the map projection region. This only
comes into play with global projections that 'wrap-around' at the edges,
like the mollweide and mercator projections. The orthographic
projection does not 'wrap around' - hence you don't get the error message.
    
Looking at the shiftmap function it looks like I should shift the
co-ordinate grid so that my longitude runs from -180 to 180 instead of
0 to 360, therefore the following shiftgrid call should do this

values, lon = basemap.shiftgrid(180, values, lon)

However I still get the same error and the corruption in the resulting
plot. I feel like I'm missing something obvious here but can't find
it.

Cheers

Adam
  

Adam:

From the basemap docs;

shiftgrid(lon0, datain, lonsin, start=True)
    shift global lat/lon grid east or west.
    assumes wraparound (or cyclic point) is included.
         lon0: starting longitude for shifted grid
           (ending longitude if start=False). lon0 must be on
           input grid (within the range of lonsin).
    datain: original data.
    lonsin: original longitudes.
    start[True]: if True, lon0 represents the starting longitude
    of the new grid. if False, lon0 is the ending longitude.
         returns dataout,lonsout (data and longitudes on shifted grid).

You did

values, lon = basemap.shiftgrid(180, values, lon)

but I think you want

values, lon = basemap.shiftgrid(180, values, lon, start=False)

HTH,

-Jeff

···

On 11/10/2007, Jeff Whitaker <jswhit@...146...> wrote:

--
Jeffrey S. Whitaker Phone : (303)497-6313
Meteorologist FAX : (303)497-6449
NOAA/OAR/PSD R/PSD1 Email : Jeffrey.S.Whitaker@...259...
325 Broadway Office : Skaggs Research Cntr 1D-124
Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg

Thats it! Thanks a lot!

Cheers

Adam

···

On 11/10/2007, Jeff Whitaker <jswhit@...146...> wrote:

but I think you want

values, lon = basemap.shiftgrid(180, values, lon, start=False)