POV-Ray : Newsgroups : povray.general : Map Mollweide projection (elliptical) onto sphere Server Time
29 Jul 2024 14:19:27 EDT (-0400)
  Map Mollweide projection (elliptical) onto sphere (Message 4 to 13 of 13)  
<<< Previous 3 Messages Goto Initial 10 Messages
From: clipka
Subject: Re: Map Mollweide projection (elliptical) onto sphere
Date: 7 Nov 2011 12:09:18
Message: <4eb810be$1@news.povray.org>
Am 07.11.2011 11:49, schrieb Adrian:
> I have an image [1] of a spherical surface that I want to map onto a sphere, but
> it is a Mollweide projection. I tried to convert it to a rectangular Mercator
> projection (is that even the right one?) with Mathematica [2], but it doesn't
> really work. I do get a rectangular image which kind of looks right, but when I
> use the texture in Povray with
>
> pigment { image_map { png "text.png" map_type 1 } }
>
> the edges don't seem to match up and the texture looks distorted around the
> poles. In the end, I want to create something similar to this [3]. What can I
> do?

You want to convert the image to an "equirectangular projection" (see 
http://en.wikipedia.org/wiki/Equirectangular_projection); that'll allow 
you to use map type 1.


Post a reply to this message

From: Christian Froeschlin
Subject: Re: Map Mollweide projection (elliptical) onto sphere
Date: 7 Nov 2011 12:17:24
Message: <4eb812a4@news.povray.org>
Adrian wrote:

> Yes, I am not entirely sure that this is the case. My Mathematica implementation
> of the conversion may be faulty (even though I followed mathworld [1]), is there
> a standard way to deal with this? Some UNIX tool or even a built-in feature of
> povray?

There appears to be a unix tool at

http://www.users.globalnet.co.uk/~arcus/mmps/

I think the unprojected latlong format will be the
correct one for map_type 1.

Regarding the WMAP data it seems they already provide it in latlong
format for the "Science on a Sphere" 3d visualization system, so you
might be able to simply use these:

http://lambda.gsfc.nasa.gov/product/map/current/sos/7year/


Post a reply to this message

From: Adrian
Subject: Re: Map Mollweide projection (elliptical) onto sphere
Date: 10 Nov 2011 09:55:01
Message: <web.4ebbe3485ab24bf331dc6fa00@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:
> Am 07.11.2011 11:49, schrieb Adrian:
> > I have an image [1] of a spherical surface that I want to map onto a sphere, but
> > it is a Mollweide projection. I tried to convert it to a rectangular Mercator
> > projection (is that even the right one?) with Mathematica [2], but it doesn't
> > really work. I do get a rectangular image which kind of looks right, but when
> You want to convert the image to an "equirectangular projection" (see
> http://en.wikipedia.org/wiki/Equirectangular_projection); that'll allow
> you to use map type 1.

Thanks, I guess I was over-complicating things! Also thanks to Christian for the
hint at Matthew's "project". Unfortunately it yields a wrong result for my case.
I am considering letting him know about it, because that would have been a great
tool otherwise. I appreciate the hint at the WMAP data as well, but I was
curious on how to handle this for future projects as well.

For the record, since Mathematica didn't yield a satisfactory result for
whatever reason, I wrote a small Python script using SciPy that takes a cropped
*ppm Mollweide projection and converts it to plate carree, which can be mapped
onto a sphere by Povray just fine. Of course, it is much slower than a C/C++
solution, but it's fast enough for my purposes (around 2m on my PC for a
2048x1024 image). If anyone wants to use it, see below for the source.

Adrian




#!/usr/bin/python

import numpy as np
from scipy import misc
import sys

infile = "wmap.ppm"
outfile = "wmap2.ppm"

arr = misc.imread(infile)
result = np.empty(arr.shape)
height, width, depth = arr.shape # Backwards but correct
print "Dimensions: %ix%i" % (width, height)

class memoized(object):
   def __init__(self, func):
      self.func = func
      self.cache = {}
   def __call__(self, *args):
      try:
         return self.cache[args]
      except KeyError:
         value = self.func(*args)
         self.cache[args] = value
         return value

@memoized #Improves runtime by factor of 2 easily
def theta(phi):
    # First guess for newton method
    xn = 0
    old = xn + 1.
    while abs(xn - old)>1e-6:
        old = xn
        xn = xn - (xn + np.sin(xn) - np.pi * np.sin(phi)) / (1 + np.cos(xn))
    return xn / 2.

def mollweide(x, y):
    th = theta(y)
    return np.sqrt(8) * x * np.cos(th) / np.pi, np.sqrt(2) * np.sin(th)

def img2coord(a, b):
    return (a * 1. / width - .5) * 2 * np.pi, (b * 1. / height - .5) * np.pi

def coord2img(x, y):
    # Try to stay inside ellipse to minimize background effects
    xround = yround = np.floor
    if x<0: xround = lambda z: -np.floor(-z)
    if y<0: yround = lambda z: -np.floor(-z)
    return (xround((x / (2 * np.sqrt(8)) + .5) * width),
            yround((y / (2 * np.sqrt(2)) + .5) * height))

for a in range(width):
    sys.stdout.write("\r%i%%" % ( 100 * a / width ))
    sys.stdout.flush()
    for b in range(height):
        x, y = img2coord(a, b)
        x, y = mollweide(x, y)
        x, y = coord2img(x, y)
        result[b, a] = arr[y-1, x-1]

misc.imsave(outfile, result)
sys.stdout.write("\nDone\n")


Post a reply to this message

From: Stephen Mather
Subject: Re: Map Mollweide projection (elliptical) onto sphere
Date: 16 Dec 2011 16:55:01
Message: <web.4eebbd2c5ab24bf32cf1bdcc0@news.povray.org>
Nice solution.  You could also use GDAL utilities to handle this-- which are
written in C++ (and also have APIs for Python, etc).

Best,
Steve


"Adrian" <nomail@nomail> wrote:
> clipka <ano### [at] anonymousorg> wrote:
> > Am 07.11.2011 11:49, schrieb Adrian:
> > > I have an image [1] of a spherical surface that I want to map onto a sphere, but
> > > it is a Mollweide projection. I tried to convert it to a rectangular Mercator
> > > projection (is that even the right one?) with Mathematica [2], but it doesn't
> > > really work. I do get a rectangular image which kind of looks right, but when
> > You want to convert the image to an "equirectangular projection" (see
> > http://en.wikipedia.org/wiki/Equirectangular_projection); that'll allow
> > you to use map type 1.
>
> Thanks, I guess I was over-complicating things! Also thanks to Christian for the
> hint at Matthew's "project". Unfortunately it yields a wrong result for my case.
> I am considering letting him know about it, because that would have been a great
> tool otherwise. I appreciate the hint at the WMAP data as well, but I was
> curious on how to handle this for future projects as well.
>
> For the record, since Mathematica didn't yield a satisfactory result for
> whatever reason, I wrote a small Python script using SciPy that takes a cropped
> *ppm Mollweide projection and converts it to plate carree, which can be mapped
> onto a sphere by Povray just fine. Of course, it is much slower than a C/C++
> solution, but it's fast enough for my purposes (around 2m on my PC for a
> 2048x1024 image). If anyone wants to use it, see below for the source.
>
> Adrian
>
>
>
>
> #!/usr/bin/python
>
> import numpy as np
> from scipy import misc
> import sys
>
> infile = "wmap.ppm"
> outfile = "wmap2.ppm"
>
> arr = misc.imread(infile)
> result = np.empty(arr.shape)
> height, width, depth = arr.shape # Backwards but correct
> print "Dimensions: %ix%i" % (width, height)
>
> class memoized(object):
>    def __init__(self, func):
>       self.func = func
>       self.cache = {}
>    def __call__(self, *args):
>       try:
>          return self.cache[args]
>       except KeyError:
>          value = self.func(*args)
>          self.cache[args] = value
>          return value
>
> @memoized #Improves runtime by factor of 2 easily
> def theta(phi):
>     # First guess for newton method
>     xn = 0
>     old = xn + 1.
>     while abs(xn - old)>1e-6:
>         old = xn
>         xn = xn - (xn + np.sin(xn) - np.pi * np.sin(phi)) / (1 + np.cos(xn))
>     return xn / 2.
>
> def mollweide(x, y):
>     th = theta(y)
>     return np.sqrt(8) * x * np.cos(th) / np.pi, np.sqrt(2) * np.sin(th)
>
> def img2coord(a, b):
>     return (a * 1. / width - .5) * 2 * np.pi, (b * 1. / height - .5) * np.pi
>
> def coord2img(x, y):
>     # Try to stay inside ellipse to minimize background effects
>     xround = yround = np.floor
>     if x<0: xround = lambda z: -np.floor(-z)
>     if y<0: yround = lambda z: -np.floor(-z)
>     return (xround((x / (2 * np.sqrt(8)) + .5) * width),
>             yround((y / (2 * np.sqrt(2)) + .5) * height))
>
> for a in range(width):
>     sys.stdout.write("\r%i%%" % ( 100 * a / width ))
>     sys.stdout.flush()
>     for b in range(height):
>         x, y = img2coord(a, b)
>         x, y = mollweide(x, y)
>         x, y = coord2img(x, y)
>         result[b, a] = arr[y-1, x-1]
>
> misc.imsave(outfile, result)
> sys.stdout.write("\nDone\n")


Post a reply to this message

From: Yukterez Enabled Io
Subject: Re: Map Mollweide projection (elliptical) onto sphere
Date: 22 Apr 2013 16:20:05
Message: <web.51759aac5ab24bf3c83525700@news.povray.org>
The problem is, the python script does not work on my PC. Is there anything I
need to modify in the source code, for example, if the width is 2000px and the
height 1000px, or is the code ready to use? I get a synatx error when I run the
script 1 to 1: http://img28.imageshack.us/img28/1204/screenshotj.gif


Post a reply to this message

From: "Jérôme M. Berger"
Subject: Re: Map Mollweide projection (elliptical) onto sphere
Date: 22 Apr 2013 17:59:44
Message: <5175b2d0$1@news.povray.org>
Yukterez_Enabled_Io wrote:
> The problem is, the python script does not work on my PC. Is there anyt
hing I
> need to modify in the source code, for example, if the width is 2000px 
and the
> height 1000px, or is the code ready to use? I get a synatx error when I
 run the
> script 1 to 1: http://img28.imageshack.us/img28/1204/screenshotj.gif
> 
> 
	That's a Python 2 script and you're trying to run it on a Python 3
install. They are not compatible...

		Jerome
-- 
mailto:jeb### [at] freefr
http://jeberger.free.fr
Jabber: jeb### [at] jabberfr


Post a reply to this message


Attachments:
Download 'us-ascii' (1 KB)

From: Yukterez Enabled Io
Subject: Re: Map Mollweide projection (elliptical) onto sphere
Date: 23 Apr 2013 15:00:01
Message: <web.5176d9135ab24bf3593487030@news.povray.org>
I now installed Python 2.6 and the numpy, scipy and imread modules from
http://www.lfd.uci.edu/~gohlke/pythonlibs
but it still says

Traceback (most recent call last):
  File "C:\Users\Yukterez\Documents\pythonscriptcmb.py", line 9, in <module>
    arr = misc.imread(infile)
AttributeError: 'module' object has no attribute 'imread'

why?


Post a reply to this message

From: "Jérôme M. Berger"
Subject: Re: Map Mollweide projection (elliptical) onto sphere
Date: 24 Apr 2013 13:10:29
Message: <51781205$1@news.povray.org>
Yukterez_Enabled_Io wrote:
> I now installed Python 2.6 and the numpy, scipy and imread modules from

> http://www.lfd.uci.edu/~gohlke/pythonlibs
> but it still says
> 
> Traceback (most recent call last):
>   File "C:\Users\Yukterez\Documents\pythonscriptcmb.py", line 9, in <mo
dule>
>     arr = misc.imread(infile)
> AttributeError: 'module' object has no attribute 'imread'
> 
> why?
> 
	No idea. imread has been in scipy.misc for a while and still is in
the current development version according to the docs. Note that you
shouldn't need to install the imread module (scipy supports ppm
reading and writing out of the box), but I don't see why it should
cause issues. Sorry I can't be more help.

		Jerome
-- 
mailto:jeb### [at] freefr
http://jeberger.free.fr
Jabber: jeb### [at] jabberfr


Post a reply to this message


Attachments:
Download 'us-ascii' (1 KB)

From: Yukterez Enabled Io
Subject: Re: Map Mollweide projection (elliptical) onto sphere
Date: 26 Apr 2013 23:00:00
Message: <web.517b3ed25ab24bf3d8692d490@news.povray.org>
I found the problem. You need
http://www.pythonware.com/products/pil/
installed for scipy imread.
Now it works fine (:


yukterez.enabled.io/cmb2013_mollweide-mercator-3d.png

http://yukterez.ist.org/planck_2013_3d.gif


Post a reply to this message

From: Yukterez Enabled Io
Subject: Re: Map Mollweide projection (elliptical) onto sphere
Date: 27 Apr 2013 18:50:01
Message: <web.517c55a75ab24bf3593487030@news.povray.org>
I tried to reverse the Script, to have Mercator transformed to Mollweide, but my
Python Skills are to low. Anyone any idea how to rewrite the code to run reverse
?


Post a reply to this message

<<< Previous 3 Messages Goto Initial 10 Messages

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.