Skip to content

Commit

Permalink
Merge pull request #31 from ConorMacBride/include-ibis-data
Browse files Browse the repository at this point in the history
Include example with real IBIS data
  • Loading branch information
ConorMacBride committed May 12, 2021
2 parents 0bf27e5 + ddda5b4 commit 66d6389
Show file tree
Hide file tree
Showing 10 changed files with 586 additions and 40 deletions.
51 changes: 42 additions & 9 deletions docs/guide/examples/neural_network/LabellingTutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"[Download LabellingTutorial.ipynb](LabellingTutorial.ipynb)"
"[Download LabellingTutorial.ipynb](https://mcalf.macbride.me/en/stable/guide/examples/neural_network/LabellingTutorial.ipynb)"
]
},
{
Expand All @@ -36,11 +36,34 @@
"source": [
"import mcalf.models\n",
"from mcalf.utils.spec import normalise_spectrum\n",
"import requests\n",
"import numpy as np\n",
"from astropy.io import fits\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "markdown",
"source": [
"Download sample data"
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"path = 'https://raw.githubusercontent.com/ConorMacBride/mcalf/main/examples/data/ibis8542data/'\n",
"path = 'https://raw.githubusercontent.com/ConorMacBride/mcalf/include-ibis-data/examples/data/ibis8542data/'\n",
"\n",
"for file in ('wavelengths.txt', 'spectra.fits'):\n",
" r = requests.get(path + file, allow_redirects=True)\n",
" with open(file, 'wb') as f:\n",
" f.write(r.content)"
],
"metadata": {}
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -54,11 +77,9 @@
"metadata": {},
"outputs": [],
"source": [
"wavelengths = np.loadtxt('wavelengths.csv', delimiter=',') # Original wavelengths\n",
"prefilter_response_wvscl = np.loadtxt('prefilter_response_wvscl.csv', delimiter=',')\n",
"prefilter_response_main = np.loadtxt('prefilter_response_main.csv', delimiter=',')\n",
"wavelengths = np.loadtxt('wavelengths.txt') # Original wavelengths\n",
"\n",
"with fits.open('spectral_data.fits') as hdul: # Raw spectral data\n",
"with fits.open('spectra.fits') as hdul: # Raw spectral data\n",
" datacube = np.asarray(hdul[0].data, dtype=np.float64)"
]
},
Expand All @@ -75,17 +96,29 @@
"metadata": {},
"outputs": [],
"source": [
"model = mcalf.models.IBIS8542Model(original_wavelengths=wavelengths, prefilter_ref_main=prefilter_response_main, \n",
" prefilter_ref_wvscl=prefilter_response_wvscl)"
"model = mcalf.models.IBIS8542Model(original_wavelengths=wavelengths)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Select the points to label"
"Select the spectra to label"
]
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"n_points = 50\n",
"\n",
"flat_choice = np.random.choice(np.arange(datacube[0].size), n_points, replace=False)\n",
"i_points, j_points = np.unravel_index(flat_choice, datacube[0].shape)\n",
"np.save('labelled_points.npy', np.array([i_points, j_points]))"
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -265,4 +298,4 @@
},
"nbformat": 4,
"nbformat_minor": 4
}
}
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ sphinx==3.1.2
#sphinx-automodapi==0.12
-e git+https://github.com/astropy/sphinx-automodapi.git@refs/pull/121/head#egg=sphinx-automodapi
ipykernel
nbsphinx==0.7.1
nbsphinx==0.8.5
sphinx-rtd-theme==0.5.0
sphinx-gallery
pytest
Binary file added examples/data/ibis8542data/results.fits
Binary file not shown.
Binary file added examples/data/ibis8542data/spectra.fits
Binary file not shown.
1 change: 1 addition & 0 deletions examples/data/ibis8542data/training_data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"0": [[0, 5], [10, 1], [1, 5], [21, 1], [3, 39], [0, 18], [6, 22], [10, 18], [7, 21], [11, 28], [12, 16], [25, 2], [19, 1], [9, 18], [14, 49], [26, 49], [16, 24], [30, 2], [1, 38], [14, 42], [19, 4], [2, 27], [23, 5], [9, 49], [29, 28], [4, 14], [22, 10], [18, 9], [9, 10], [13, 3], [3, 14], [16, 21], [26, 1], [0, 48], [40, 2], [17, 38], [19, 0], [34, 6], [9, 38], [6, 13]], "1": [[24, 29], [5, 48], [18, 37], [39, 0], [35, 14], [41, 7], [31, 13], [33, 7], [33, 8], [20, 31], [18, 28], [23, 19], [43, 6], [28, 0], [17, 30], [58, 41], [25, 19], [31, 8], [28, 12], [0, 39], [58, 37], [30, 29], [23, 21], [54, 22], [34, 28], [34, 8], [22, 20], [32, 29], [36, 26], [28, 29], [26, 29], [35, 12], [57, 8], [59, 8], [28, 3], [35, 27], [30, 0], [16, 31], [32, 2], [6, 49]], "2": [[33, 15], [37, 14], [58, 5], [45, 0], [50, 28], [45, 3], [20, 23], [51, 27], [56, 8], [19, 38], [59, 22], [37, 28], [29, 26], [26, 20], [55, 20], [57, 30], [32, 48], [52, 24], [43, 47], [54, 21], [46, 5], [35, 35], [18, 42], [38, 49], [54, 30], [45, 1], [57, 20], [44, 23], [28, 14], [52, 25], [20, 35], [30, 49], [53, 30], [22, 32], [55, 26], [23, 42], [56, 7], [42, 25], [37, 27], [23, 35]], "3": [[56, 48], [32, 24], [59, 29], [59, 15], [50, 6], [40, 28], [50, 2], [47, 34], [30, 41], [47, 5], [40, 31], [52, 16], [44, 11], [31, 25], [48, 29], [47, 8], [58, 42], [47, 3], [46, 36], [58, 26], [57, 2], [30, 24], [25, 40], [43, 32], [43, 12], [49, 49], [27, 41], [58, 18], [24, 36], [47, 29], [56, 10], [58, 28], [49, 3], [59, 30], [52, 14], [45, 46], [47, 26], [32, 15], [29, 17], [50, 44]], "4": [[32, 16], [48, 17], [44, 20], [39, 30], [38, 31], [56, 34], [47, 23], [33, 37], [34, 16], [41, 17], [35, 42], [28, 40], [49, 33], [41, 12], [46, 17], [32, 42], [39, 39], [39, 28], [44, 28], [33, 38], [34, 43], [43, 11], [53, 32], [33, 41], [44, 18], [37, 17], [43, 15], [42, 10], [47, 39], [42, 38], [45, 21], [52, 35], [44, 29], [51, 13], [55, 33], [37, 32], [45, 45], [45, 37], [45, 14], [43, 16]]}
27 changes: 27 additions & 0 deletions examples/data/ibis8542data/wavelengths.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
8.540944335937500000e+03
8.541143554687500000e+03
8.541343750000000000e+03
8.541494140625000000e+03
8.541643554687500000e+03
8.541744140625000000e+03
8.541843750000000000e+03
8.541893554687500000e+03
8.541944335937500000e+03
8.541994140625000000e+03
8.542043945312500000e+03
8.542093750000000000e+03
8.542119140625000000e+03
8.542143554687500000e+03
8.542168945312500000e+03
8.542194335937500000e+03
8.542244140625000000e+03
8.542293945312500000e+03
8.542343750000000000e+03
8.542393554687500000e+03
8.542444335937500000e+03
8.542543945312500000e+03
8.542643554687500000e+03
8.542793945312500000e+03
8.542944335937500000e+03
8.543143554687500000e+03
8.543343750000000000e+03

0 comments on commit 66d6389

Please sign in to comment.