Skip to content

Commit

Permalink
Merge pull request #328 from LSSTDESC/py3notebooks
Browse files Browse the repository at this point in the history
print statements now have brackets
  • Loading branch information
elisachisari committed Feb 12, 2018
2 parents 70d03c8 + c2a6b45 commit 915ae8d
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 307 deletions.
117 changes: 25 additions & 92 deletions tests/Distance Calculations Example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"metadata": {},
"source": [
"# Calculate cosmological distances with CCL\n",
"In this example, we will calculate various cosmological distances for an example cosmology."
Expand All @@ -15,9 +12,7 @@
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true,
"deletable": true,
"editable": true
"collapsed": true
},
"outputs": [],
"source": [
Expand All @@ -28,10 +23,7 @@
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"metadata": {},
"source": [
"### Set up a Cosmology object\n",
"`Cosmology` objects contain the parameters and metadata needed as inputs to most functions. Each `Cosmology` object has a set of cosmological parameters attached to it. In this example, we will only use the parameters of a vanilla LCDM model, but simple extensions (like curvature, neutrino mass, and w0/wa) are also supported.\n",
Expand All @@ -42,11 +34,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"cosmo = ccl.Cosmology(Omega_c=0.27, Omega_b=0.045, h=0.67, A_s=2.1e-9, n_s=0.96)"
Expand All @@ -55,11 +43,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"metadata": {},
"outputs": [
{
"name": "stdout",
Expand Down Expand Up @@ -102,37 +86,27 @@
}
],
"source": [
"print cosmo"
"print(cosmo)"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"metadata": {},
"source": [
"As you can see, a number of cosmological parameters have been set to default values, or derived from the input parameters. Some, like `sigma_8`, have been left undefined; this is because calculating them from the input parameters is non-trivial, so this will only be done if needed (or if the user explicitly requests it)."
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"metadata": {},
"source": [
"Parameter values can be accessed from the `Parameters` object that the `Cosmology` object contains, like so:"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"metadata": {},
"outputs": [
{
"name": "stdout",
Expand All @@ -143,15 +117,13 @@
}
],
"source": [
"print cosmo.params['Omega_c']"
"print(cosmo.params['Omega_c'])"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true,
"deletable": true,
"editable": true
"collapsed": true
},
"source": [
"### Cosmological Distances\n",
Expand All @@ -162,11 +134,7 @@
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"metadata": {},
"outputs": [
{
"data": {
Expand All @@ -186,22 +154,15 @@
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"metadata": {},
"source": [
"Note that all distance function calls require scale factors, not redshifts. This function can take a `numpy` array of values as well."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"metadata": {},
"outputs": [
{
"data": {
Expand All @@ -223,22 +184,15 @@
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"metadata": {},
"source": [
"CCL also supports calculation of the comoving angular distance. In flat spacetime (like the cosmology we have here) it is the same as the radial distance. "
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"metadata": {},
"outputs": [
{
"data": {
Expand All @@ -257,22 +211,15 @@
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"metadata": {},
"source": [
"If we create a cosmology with curvature, we'll get a different result. "
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"metadata": {},
"outputs": [
{
"name": "stdout",
Expand All @@ -288,27 +235,20 @@
"chi_rad = ccl.comoving_radial_distance(curved_cosmo, 1/(1+z))\n",
"chi_curved = ccl.comoving_angular_distance(curved_cosmo, 1/(1+z))\n",
"\n",
"print 'Radial Dist. = %.2f Mpc \\t Angular Dist. = %.2f Mpc'%(chi_rad, chi_curved)"
"print ('Radial Dist. = %.2f Mpc \\t Angular Dist. = %.2f Mpc'%(chi_rad, chi_curved))"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"metadata": {},
"source": [
"CCL explictly supports the calculation of the luminosity distance and the distance modulus too:"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"metadata": {},
"outputs": [
{
"name": "stdout",
Expand All @@ -321,27 +261,20 @@
"source": [
"chi_lum = ccl.luminosity_distance(cosmo, 1/(1+z))\n",
"DM = ccl.distance_modulus(cosmo, 1/(1+z))\n",
"print 'Luminosity Dist = %.2f Mpc \\t Distance Modulus = %.2f ' % (chi_lum, DM)"
"print('Luminosity Dist = %.2f Mpc \\t Distance Modulus = %.2f ' % (chi_lum, DM))"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"metadata": {},
"source": [
"Finally, CCL supports an inverse operation, which calculates the scale factor for a given comoving distance:"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"metadata": {},
"outputs": [
{
"data": {
Expand Down Expand Up @@ -384,7 +317,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.12"
"version": "2.7.10"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 915ae8d

Please sign in to comment.