Skip to content

Commit

Permalink
Proper nside change in tutorial_datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
luizfelippesr committed Oct 2, 2020
1 parent 3a4a86a commit cd213e7
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions tutorials/tutorial_datasets.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,14 @@
"from imagine.observables import FaradayDepthHEALPixDataset\n",
"import numpy as np\n",
"from astropy import units as u\n",
"import healpy as hp\n",
"\n",
"# Adjusts the data to the right format\n",
"fd_raw = raw_dataset[3].data.astype(np.float)\n",
"sigma_fd_raw = raw_dataset[4].data.astype(np.float)\n",
"# Makes it small, to save memory\n",
"fd_raw = fd_raw[::256]\n",
"sigma_fd_raw = sigma_fd_raw[::256]\n",
"# Makes it smaller, to save memory\n",
"fd_raw = hp.pixelfunc.ud_grade(fd_raw, 4)\n",
"sigma_fd_raw = hp.pixelfunc.ud_grade(sigma_fd_raw, 4)\n",
"# We need to include units the data\n",
"# (this avoids later errors and inconsistencies)\n",
"fd_raw *= u.rad/u.m/u.m\n",
Expand Down Expand Up @@ -108,28 +109,23 @@
"metadata": {},
"outputs": [],
"source": [
"import requests, io\n",
"import numpy as np\n",
"from astropy.io import fits\n",
"from astropy import units as u\n",
"from imagine.observables import FaradayDepthHEALPixDataset\n",
"\n",
"class FaradayDepthOppermann2012(FaradayDepthHEALPixDataset):\n",
" def __init__(self, skip=None):\n",
" def __init__(self, Nside=None):\n",
" # Fetches and reads the \n",
" download = requests.get('https://wwwmpa.mpa-garching.mpg.de/ift/faraday/2012/faraday.fits')\n",
" raw_dataset = fits.open(io.BytesIO(download.content))\n",
" # Adjusts the data to the right format\n",
" fd_raw = raw_dataset[3].data.astype(np.float)\n",
" sigma_fd_raw = raw_dataset[4].data.astype(np.float)\n",
" # Reduces the resolution\n",
" if Nside is not None:\n",
" fd_raw = hp.pixelfunc.ud_grade(fd_raw, Nside)\n",
" sigma_fd_raw = hp.pixelfunc.ud_grade(sigma_fd_raw, Nside)\n",
" # Includes units in the data\n",
" fd_raw *= u.rad/u.m/u.m\n",
" sigma_fd_raw *= u.rad/u.m/u.m\n",
" \n",
" # If requested, makes it small, to save memory in this example\n",
" if skip is not None:\n",
" fd_raw = fd_raw[::skip]\n",
" sigma_fd_raw = sigma_fd_raw[::skip]\n",
" # Loads into the Dataset\n",
" super().__init__(data=fd_raw, error=sigma_fd_raw)"
]
Expand All @@ -147,7 +143,7 @@
"metadata": {},
"outputs": [],
"source": [
"dset = FaradayDepthOppermann2012(skip=256)"
"dset = FaradayDepthOppermann2012(Nside=4)"
]
},
{
Expand Down Expand Up @@ -199,7 +195,7 @@
"data": {
"text/html": [
"<i>Table length=3</i>\n",
"<table id=\"table139726377436496\" class=\"table-striped table-bordered table-condensed\">\n",
"<table id=\"table140085692999504\" class=\"table-striped table-bordered table-condensed\">\n",
"<thead><tr><th>RAJ2000</th><th>DEJ2000</th><th>GLON</th><th>GLAT</th><th>RM</th><th>e_RM</th><th>PI</th><th>I</th><th>S5.2</th><th>f_S5.2</th><th>NVSS</th></tr></thead>\n",
"<thead><tr><th>&quot;h:m:s&quot;</th><th>&quot;d:m:s&quot;</th><th>deg</th><th>deg</th><th>rad / m2</th><th>rad / m2</th><th>mJy</th><th>mJy</th><th></th><th></th><th></th></tr></thead>\n",
"<thead><tr><th>bytes11</th><th>bytes11</th><th>float32</th><th>float32</th><th>int16</th><th>int16</th><th>float32</th><th>float64</th><th>bytes3</th><th>bytes1</th><th>bytes4</th></tr></thead>\n",
Expand Down Expand Up @@ -322,11 +318,11 @@
"output_type": "stream",
"text": [
"Measurement keys:\n",
"\t ('fd', None, 8, None)\n",
"\t ('fd', None, 4, None)\n",
"\t ('fd', None, 'tab', None)\n",
"\n",
"Covariance keys:\n",
"\t ('fd', None, 8, None)\n",
"\t ('fd', None, 4, None)\n",
"\t ('fd', None, 'tab', None)\n"
]
}
Expand All @@ -352,8 +348,15 @@
"\n",
"* If data is independent from frequency, data-freq is set `None`, otherwise it is the frequency in GHz.\n",
"* The third value in the key-tuple is the HEALPix Nside (for maps) or the string 'tab' for tabular data. \n",
"* Finally, the last value, `ext` can be 'I','Q','U','PI','PA', None or other customized tags depending on the nature of the observable.\n",
" \n",
"* Finally, the last value, `ext` can be 'I','Q','U','PI','PA', None or other customized tags depending on the nature of the observable."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Manually including data\n",
"\n",
"An alternative way to include data into an Observables dictionary is explicitly choosing the key and adjusting the data shape. One can see how this is handled by the Dataset object in the following cell"
]
},
Expand All @@ -366,14 +369,16 @@
"name": "stdout",
"output_type": "stream",
"text": [
"The key used in the \"name\" arg was: ('fd', None, 8, None)\n",
"The shape of data used in the \"new\" arg was: (1, 768)\n"
"The key used in the \"name\" arg was: ('fd', None, 4, None)\n",
"The shape of data used in the \"new\" arg was: (1, 192)\n"
]
}
],
"source": [
"# This is how HEALPix data can be included without the mediation of Datasets:\n",
"mea.append(name=dset.key, data=dset.data)\n",
"# The units of covariance matrices have to be provided separately\n",
"# (as sparse matrices to not support them)\n",
"cov.append(name=dset.key, data=dset.cov)\n",
"# This is what Dataset is doing:\n",
"print('The key used in the \"name\" arg was:', dset.key)\n",
Expand Down

0 comments on commit cd213e7

Please sign in to comment.