How to display data in Mollweide projection in a shinyapp

...I created some Cosmic Microwave Background data to plot as a Mollweide projection.

I need some help to find what is the package, the syntax to make a Mollweide plot.

> df0
# A tibble: 3,072 x 8
   index   ind        x        y     z  theta   phi density
   <dbl> <dbl>    <dbl>    <dbl> <dbl>  <dbl> <dbl>   <dbl>
 1  6144  0.23  0.00830  0.00830 0.230 0.0510 0.785 -0.124 
 2  6145  0.23 -0.00830  0.00830 0.230 0.0510 2.36   0.0613
 3  6146  0.23 -0.00830 -0.00830 0.230 0.0510 3.93  -0.407 
 4  6147  0.23  0.00830 -0.00830 0.230 0.0510 5.50  -0.527 
 5  6148  0.23  0.0217   0.00897 0.229 0.102  0.393 -1.32  
 6  6149  0.23  0.00897  0.0217  0.229 0.102  1.18  -1.49  
 7  6150  0.23 -0.00897  0.0217  0.229 0.102  1.96  -0.0184
 8  6151  0.23 -0.0217   0.00897 0.229 0.102  2.75   0.761 
 9  6152  0.23 -0.0217  -0.00897 0.229 0.102  3.53   0.205 
10  6153  0.23 -0.00897 -0.0217  0.229 0.102  4.32  -0.357 

I am returning to R just to create this shinyapp. I need to plot (theta, phi) with the color controlled by density.

This is the current state of the shinyapp
https://qsnyc.shinyapps.io/UniverseMap/?_ga=2.263388808.509163910.1601941058-1505942256.1600516222

I don't see it as useful, so I need to create the Mollweide plot.

Any help would be welcomed.

Thanks

PS - This is the python code to generate the data if needed

import healpy as hp
import numpy as np
import pandas as pd
from matplotlib import cm
from scipy.stats import norm
nside=16
xx, yy, zz = hp.pix2vec(nside=nside, ipix=np.arange(hp.nside2npix(nside)))
ones = np.ones(xx.shape[0])
theta, phi = hp.pix2ang(nside=nside, ipix=np.arange(hp.nside2npix(nside)))
df = pd.DataFrame(np.empty([0,7]), columns=["ind","x","y","z","theta","phi","density"])
df1 = pd.DataFrame(np.empty([0,7]), columns=["ind","x","y","z","theta","phi","density"])

for r in np.linspace(0.01, 1.0, 10):
    df.ind=r*ones
    df.x=xx*r
    df.y=yy*r
    df.z=zz*r
    df.theta=theta
    df.phi=phi
    df.density=np.random.rand(xx.shape[0])
    title="Radius={}".format(r)
    
    mu, sigma = norm.fit(df.density)
    df.density =(df.density-mu)/sigma
    hp.mollview(df.density.squeeze(), title=title, min=-4 * sigma,
                        max=4 * sigma, unit="K", cmap=cm.RdBu_r)
    df1 = pd.concat([df1,df])
    
df1=df1.reset_index()
df1["index"]=df1.index
df1.to_feather("df.feather")

and here the selection by "ind" in the R script:

library(feather)
library(mapproj)
library(ggpubr)
df <- feather::read_feather('./df.feather')
# https://cran.r-project.org/web/packages/ebirdst/vignettes/ebirdst-intro-mapping.html

ind <- unique(df$ind)
df0 <- df[df$ind==ind[3],]
x <- df0$theta*180/pi
y <- df0$phi*180/pi
        
mapproject(x, y,"mollweide")

ggscatter(df0, x="x",y="y",color="density", pallete="jco",    main="Univerrse Map")

I am trying to use ggscatter but can't figure out how to choose the projection

This is an interesting problem; you don't seem to be working with geographical data.

What is your area of interest and coordinate reference system? Is there a way to shoehorn it to a lat - lon point of looking at things? There are a ton of resources in the geo area, potentially saving you a lot of coding from scratch. I see your phi in range of 0 to 360 (which is good) but theta only 0 to 180 (not so good).

Dear Jlacko,

I am working with the Cosmic Microwave Background (CMB) data.
SMICA

Celestial coordinates behave like that.

What I did was to replicate the observed CMB modulation using hyperspherical harmonics (hyperspherical acoustic oscillations). With the hyperspherical spectral decomposition, I created the 3D map of the Universe as a series of spherical CMB data for different distances.

https://qsnyc.shinyapps.io/UniverseMap/?_ga=2.32790202.509163910.1601941058-1505942256.1600516222

Those CMB data are shown as layers in this shinyapp.

The problem is that this presentation is not clear and I need to create Mollweide projections for people to see that data clearer.

I can change the range of theta. That is just a mapping to the sliders. What is the appropriate range for theta? I think that that is a small problem.

So my problem is how to create a Mollweide plot starting with my data.

Thanks

I think I solved the problem.

library(feather)
library(mapproj)
df <- feather::read_feather('./df.feather')
# https://cran.r-project.org/web/packages/ebirdst/vignettes/ebirdst-intro-mapping.html

ind <- unique(df$ind)
df0 <- df[df$ind==ind[3],]
x <- df0$theta*180/pi -90
y <- df0$phi*180/pi -180

ccc <- mapproject(y, x,"mollweide")

df0$xx <- ccc$x
df0$yy <- ccc$y

ggscatter(df0, x="xx",y="yy",color="density", pallete="jco", xlim=c(-2,2),ylim=c(-2,2),    main="Univerrse Map")

RplotB

Please, advise.

Thanks,

Marco

1 Like

You were fast!

I confess I have little understanding of celestial data (I am stuck to Earth, a mudworm eternal) but yes - the general shape of your projected data is what should be expected for a Mollweide projection.

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.