import numpy as np
diva=np.load('borg_sdss_diva.npz')

"""
Explanation: BORG SDSS data products
borg_sdss_diva package

Authors: Florent Leclercq, Jens Jasche, Guilhem Lavaux, Benjamin Wandelt, Will Percival
Last update: 09/10/2018

This package contains the maps obtained by Leclercq et al. (2017), who performed a Bayesian analysis of the cosmic web in the SDSS volume.
The results are four probabilistic maps of the voids, sheets, filaments, and clusters. Structures are defined using the DIVA algorithm (Lavaux & Wandelt 2010). Data are provided in terms of a standard 3D numpy array and can easily be accessed and processed using python.
For further details on the data and employed methods please consult Leclercq et al. (2017) (reference below).
File content
This package consists of two files:
* borg_sdss_diva.ipynb: The file you are currently reading.
* borg_sdss_diva.tar.gz: Archive available on GitHub LFS and on the author's website.
The archive borg_sdss_diva.tar.gz can be extracted using
bash
tar -xzf borg_sdss_diva.tar.gz
It contains the file borg_sdss_diva.npz.
Usage
Loading and accessing the data
The file borg_sdss_diva.npz contains the probabilistic structure types maps in a standard uncompressed .npz format. To load and process the data execute the following commands:
End of explanation
"""


#3D probabilistic maps for DIVA structures
voids=diva['voids']
sheets=diva['sheets']
filaments=diva['filaments']
clusters=diva['clusters']

"""
Explanation: To access the 3D structure maps use:
End of explanation
"""


k=10;j=127;i=243
voids_ijk=voids[k,j,i]

"""
Explanation: Individual voxels in this 3D volumetric data cube can be accessed as follows:
End of explanation
"""


#Minimum and maximum position along the x-axis in Mpc/h
xmin=diva['ranges'][0]
xmax=diva['ranges'][1]

#Minimum and maximum position along the y-axis in Mpc/h
ymin=diva['ranges'][2]
ymax=diva['ranges'][3]

#Minimum and maximum position along the z-axis in Mpc/h
zmin=diva['ranges'][4]
zmax=diva['ranges'][5]

"""
Explanation: where i,j and k index voxel positions along the x,y and z axes respectively. All indices run from 0 to 255.
The ranges describing the extent of the cubic cartesian volume along the x,y and z axes can be accessed as follows:
End of explanation
"""


from matplotlib import pyplot as plt
%matplotlib inline
f, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, sharex='row', sharey='col', figsize=(12,12))
ax1.imshow(voids[:,:,128], origin='lower', extent=[ymin,ymax,zmin,zmax], vmin=0., vmax=1., cmap="viridis")
ax1.set_title("voids")
ax2.imshow(sheets[:,:,128], origin='lower', extent=[ymin,ymax,zmin,zmax], vmin=0., vmax=1., cmap="viridis")
ax2.set_title("sheets")
ax3.imshow(filaments[:,:,128], origin='lower', extent=[ymin,ymax,zmin,zmax], vmin=0., vmax=1., cmap="viridis")
ax3.set_title("filaments")
ax4.imshow(clusters[:,:,128], origin='lower', extent=[ymin,ymax,zmin,zmax], vmin=0., vmax=1., cmap="viridis")
ax4.set_title("clusters")
plt.show()

"""
Explanation: Units are Mpc/h.
(Note that all the maps that are part of the BORG SDSS data products have consistent coordinate systems. The coordinate transform to change from Cartesian to spherical coordinates and vice versa is given in appendix B of Jasche et al. 2015).
Example plot
The following code can be used to reproduce figure 8 (top row) in Leclercq et al. (2017).
End of explanation
"""


