{ "cells": [ { "cell_type": "markdown", "id": "931fb80f-26f3-4980-a040-4c17b3e13f06", "metadata": {}, "source": [ "# Notebook showing the MaficAnalysis method implemented in pyFRESCO" ] }, { "cell_type": "code", "execution_count": 1, "id": "64fa6b08-95d6-4089-914a-62a29f99dfde", "metadata": {}, "outputs": [], "source": [ "import pyfresco" ] }, { "cell_type": "markdown", "id": "4b61083f-0ce3-4983-b702-8c228640b33f", "metadata": {}, "source": [ "## Data import\n", "\n", "In the following code cell we define the paths pointing to the img and header files of the proper hyperspectral datacube and of the summary parameters datacube.\n", "These two datacubes are the ones needed by pyFRESCO to work properly." ] }, { "cell_type": "code", "execution_count": 2, "id": "fade6b0e-6d27-41ad-a2a7-d3e547802a00", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['R770', 'RBR', 'BD530_2', 'SH600_2', 'SH770', 'BD640_2', 'BD860_2', 'BD920_2', 'RPEAK1', 'BDI1000VIS', 'R440', 'IRR1', 'BDI1000IR', 'OLINDEX3', 'R1330', 'BD1300', 'LCPINDEX2', 'HCPINDEX2', 'VAR', 'ISLOPE1', 'BD1400', 'BD1435', 'BD1500_2', 'ICER1_2', 'BD1750_2', 'BD1900_2', 'BD1900R2', 'BDI2000', 'BD2100_2', 'BD2165', 'BD2190', 'MIN2200', 'BD2210_2', 'D2200', 'BD2230', 'BD2250', 'MIN2250', 'BD2265', 'BD2290', 'D2300', 'BD2355', 'SINDEX2', 'ICER2_2', 'MIN2295_2480', 'MIN2345_2537', 'BD2500_2', 'BD3000', 'BD3100', 'BD3200', 'BD3400_2', 'CINDEX2', 'BD2600', 'IRR2', 'IRR3', 'R530', 'R600', 'R1080', 'R1506', 'R2529', 'R3920']\n" ] } ], "source": [ "path_if_mtrdr = \"FRT00009b5a/frt00009b5a_07_if165j_mtr3.img\" # Path to the proper hyperspectral datacube\n", "head_if_mtrdr = \"FRT00009b5a/frt00009b5a_07_if165j_mtr3.hdr\" # Path to the header of the proper hyperspectral datacube\n", "\n", "path_sr_mtrdr = \"FRT00009b5a/frt00009b5a_07_sr165j_mtr3.img\" # Path to the summary parameters datacube\n", "head_sr_mtrdr = \"FRT00009b5a/frt00009b5a_07_sr165j_mtr3.hdr\" # Path to the header of the summary parameters datacube\n", "\n", "img , img_sr , wavelength , sr_names = pyfresco.open_raw(path_if_mtrdr , head_if_mtrdr , path_sr_mtrdr , head_sr_mtrdr) # Open the two datacubes\n", "\n", "Nbands = len(wavelength)\n", "print(sr_names)" ] }, { "cell_type": "markdown", "id": "fcec594b-839d-4e87-8815-7eb9914e3e92", "metadata": {}, "source": [ "## Target extraction and normalization\n", "\n", "The mafic analysis works on a spectrum.\n", "Here we reproduce a compact extraction plus normalization workflow to create the input spectrum.\n", "For a real analysis, select the target and neutral ROIs on mafic-rich and spectrally neutral areas respectively." ] }, { "cell_type": "code", "execution_count": 3, "id": "0ca73990-0e80-49a4-9d09-3015eab0f5a0", "metadata": {}, "outputs": [], "source": [ "SE = pyfresco.SpectraExtract(img , Nbands , wavelength , 750 , 2600) # Definition of the object for spectral extraction\n", "\n", "RGB = SE.upload_map('MAF' , folder = 'FRT00009b5a/') # Upload an RGB map for the ROI selection" ] }, { "cell_type": "code", "execution_count": 4, "id": "8c312ddb-da8a-4012-b15a-9d77f5e50bf3", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of points inside the drewn polygon: 262\n", "100.0 % of the errors, set to zero for simplicity, are in reality NaN values.\n" ] } ], "source": [ "target_spectra , L_target , target_mask = SE.polygon_spectra(save_pixel = True ,\n", " folder = 'FRT00009b5a' ,\n", " name = 'mafic_target_coordinates') # Select the target ROI\n", "\n", "target_spectrum , target_error = SE.final_spectra(mean = True , c = 'blue') # Target mean spectrum\n", "\n", "SN = pyfresco.SpectraNorm(RGB , Nbands , img , img_sr , wavelength ,\n", " target_spectrum , target_error , target_spectra ,\n", " 750 , 2600)\n", "\n", "neutral_spectra , neutral_spectrum , hull_error = SN.neutral_convex_hull() # Select the neutral ROI\n", "\n", "mafic_norm , mafic_norm_error = SN.norm_spectra(convex_hull = True) # Normalized mafic spectrum\n", "SN.normplot()" ] }, { "cell_type": "markdown", "id": "8c60b940-0620-4c82-8c19-6fa0aaff0eb9", "metadata": {}, "source": ["The output of the above cell should look like this: \n", "![polygon selection](notebook4_images/target_ROI.png)\n", "![convex hull](notebook4_images/convex_hull.png)\n"] }, { "cell_type": "markdown", "id": "4834bfc3-2cdc-4521-8e15-5d9163b40ff7", "metadata": {}, "source": [ "## Definition of the MaficAnalysis object\n", "\n", "The object takes the normalized spectrum, the wavelength array and the spectral interval used for the analysis." ] }, { "cell_type": "code", "execution_count": 5, "id": "c24632cb-c46f-4aee-ae48-cec929866e2b", "metadata": {}, "outputs": [], "source": [ "MA = pyfresco.MaficAnalysis(mafic_norm , wavelength , 750 , 2600 ,\n", " fsize = 15 ,\n", " pre_normed = True) # Definition of the object for mafic analysis" ] }, { "cell_type": "markdown", "id": "158f8c0b-7938-46c6-8e8e-27cfb3db2403", "metadata": {}, "source": [ "## Band-parameter extraction\n", "\n", "The core of the mafic analysis estimates the band extremes, band minimum, band center, band depth, band area and band asymmetry." ] }, { "cell_type": "code", "execution_count": 6, "id": "00bed81a-95ab-49b7-ba26-ac2afb9b2ca5", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[np.int64(0), np.int64(1), np.int64(2), np.int64(4), np.int64(117), np.int64(256), np.int64(263), np.int64(268), np.int64(274), np.int64(276)] [[ 0]\n", " [ 1]\n", " [ 2]\n", " [ 4]\n", " [117]\n", " [256]\n", " [263]\n", " [268]\n", " [274]\n", " [276]]\n", "Band number 1\n", "Band extremes = (np.float64(774.92), np.float64(1539.48)) nm\n", "Band minimum = 1010.18 nm\n", "Band center = 1023.24 nm\n", "Band depth = 0.05\n", "Band area = 36.03 nm\n", "Band asymmetry = 0.14 %\n", "--------------------------------\n", "Band number 2\n", "Band extremes = (np.float64(1546.06), np.float64(2456.79)) nm\n", "Band minimum = 2000.63 nm\n", "Band center = 2053.06 nm\n", "Band depth = 0.01\n", "Band area = 17.2 nm\n", "Band asymmetry = 0.33 %\n", "--------------------------------\n" ] } ], "source": [ "parameters = MA.band_parameters(windows_nm = 75 ,\n", " resolution_nm = 5 ,\n", " plot = True ,\n", " tol = 10 ,\n", " smoothed_after_removed = False) # Compute mafic band parameters" ] }, { "cell_type": "markdown", "id": "975b17ce-3103-4618-be2c-846514bd7e74", "metadata": {}, "source": ["The output of the above cell should look like this: \n", "![mafan](notebook4_images/maficanalysis.png)"] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.20" }, "nbsphinx": { "execute": "never" } }, "nbformat": 4, "nbformat_minor": 5 }