• NEON AOP Hyperspectral Data in HDF5 format with Python - Tiled Data

    AUTHORS: 
    Bridget Hass
    In this introductory tutorial, we discuss how to read NEON AOP hyperspectral tiled data using Python. We develop tools to manipulate and visualize the spectral data.
    If you are interested in learning how to do this for flightline NEON AOP hyperspectral data, please see NEON AOP Hyperspectral Data in HDF5 format with Python - Flightlines.

    Learning Objectives

    After completing this tutorial, you will be able to:
    • Import and use Python packages numpy, matplotlib, and h5py.
    • Use the package h5py and the visititems functionality to read an HDF5 file and view data attributes.
    • Read the data ignore value and scaling factor and apply these values to produce a cleaned reflectance array.
    • Extract and plot a single band of reflectance data
    • Plot a histogram of reflectance values to visualize the range and distribution of values.

    Install Python Packages

    • numpy
    • matplotlib
    • h5py

    Download Data

    NEON Teaching Data Subset: Data Institute 2018

    To complete these materials, you will use data available from the NEON 2018 Data Institute teaching datasets available for download.
    The combined data sets below contain about 10 GB of data. Please consider how large your hard drive is prior to downloading. If needed you may want to use an external hard drive.
    The LiDAR and imagery data used to create this raster teaching data subset were collected over the National Ecological Observatory Network's field sites and processed at NEON headquarters. All NEON data products can be accessed on the NEON data portal.
    The link below contains all the data from the 2017 Data Institute (17 GB). For 2018, we ONLY need the data in the CHEQ, F07A, and PRIN subfolders. To minimize the size of your download, please select only these subdirectories to download.
    Hyperspectral remote sensing data is a useful tool for measuring changes to our environment at the Earth’s surface. In this tutorial we explore how to extract information from a tile (1000m x 1000m x 426 bands) of NEON AOP orthorectified surface reflectance data, stored in hdf5 format. For more information on this data product, refer to the NEON Data Product Catalog.

    Mapping the Invisible: Introduction to Spectral Remote Sensing

    For more information on spectral remote sensing watch this video.

    Set up

    Before we start coding, make sure you are using the correct version of Python. As of July 2018, the gdal package is compatible with Python versions 3.5 and earlier. For these lessons we will use Python version 3.5.
    #Check that you are using the correct version of Python (should be 3.5 for these tutorials)
    import sys
    sys.version
    '3.5.4 |Anaconda, Inc.| (default, Nov  8 2017, 14:34:30) [MSC v.1900 64 bit (AMD64)]'
    
    First let's import the required packages:
    import numpy as np
    import h5py
    import gdal, osr, os
    import matplotlib.pyplot as plt
    Next, set display preferences so that plots are inline (meaning any images you output from your code will show up below the cell in the notebook) and turn off plot warnings:
    %matplotlib inline
    import warnings
    warnings.filterwarnings('ignore')

    Read in hdf5

    f = h5py.File('file.h5','r') reads in an h5 file to the variable f.

    Getting help on functions: help and ?

    We will be using a number of built-in and user-defined functions and methods throughout the tutorial. If you are uncertain what a certain function does, or how to call it, you can type help() or type ? at the end of the function or method and run the cell (either select Cell > Run Cells or Shift Enter with your cursor in the cell you want to run). The ? will pop up a window at the bottom of the notebook displaying the function's docstrings, which includes information about the function and usage. We encourage you to use help and ? throughout the tutorial as you come across functions you are unfamiliar with. Let's try this out with h5py.File:
    help(h5py)
    
    Help on package h5py:
    NAME h5py
    This is the h5py package, a Python interface to the HDF5
    DESCRIPTION
    scientific data format.
    _hl (package)
    PACKAGE CONTENTS _conv _errors
    h5a
    _objects _proxy defs h5 h5ac
    h5l
    h5d h5ds h5f h5fd h5g h5i
    highlevel
    h5o h5p h5r h5s h5t h5z
    version
    ipy_completer tests (package) utils SUBMODULES
    Call this from an interactive IPython session to enable tab-completion
    filters FUNCTIONS enable_ipython_completer()
    get_config(...)
    of group and attribute names.
    () => H5PYConfig
    Get a reference to the global library configuration object.
    get_enum = py_get_enum(...)
    (DTYPE dt_in) => DICT
    Deprecated; use check_dtype() instead.
    get_vlen = py_get_vlen(...)
    (OBJECT dt_in) => TYPE
    Deprecated; use check_dtype() instead.
    new_enum = py_new_enum(...)
    (DTYPE dt_in, DICT enum_vals) => DTYPE
    Deprecated; use special_dtype() instead.
    new_vlen = py_new_vlen(...)
    (OBJECT kind) => DTYPE
    Deprecated; use special_dtype() instead.
    DATA
    absolute_import = _Feature((2, 5, 0, 'alpha', 1), (3, 0, 0, 'alpha', 0...
    VERSION
    2.7.1
    FILE
    c:\users\bhass\appdata\local\continuum\anaconda3\envs\py35\lib\site-packages\h5py\__init__.py
    h5py.File?
    
    Now that we have an idea of how to use h5py to read in an h5 file, let's try it out. Note that if the h5 file is stored in a different directory than where you are running your notebook, you need to include the path (either relative or absolute) to the directory where that data file is stored. Use os.path.join to create the full path of the file.
    f = h5py.File('../../data/NEON_D02_SERC_DP3_368000_4306000_reflectance.h5','r') 
    

    Explore NEON AOP HDF5 Reflectance Files

    We can look inside the HDF5 dataset with the h5py visititems function. The list_dataset function defined below displays all datasets stored in the hdf5 file and their locations within the hdf5 file:
    #list_dataset lists the names of datasets in an hdf5 file
    def list_dataset(name,node):
    if isinstance(node, h5py.Dataset):
    print(name)
    f.visititems(list_dataset)
    SERC/Reflectance/Metadata/Ancillary_Imagery/Aerosol_Optical_Depth
    SERC/Reflectance/Metadata/Ancillary_Imagery/Aspect
    SERC/Reflectance/Metadata/Ancillary_Imagery/Dark_Dense_Vegetation_Classification
    SERC/Reflectance/Metadata/Ancillary_Imagery/Cast_Shadow
    SERC/Reflectance/Metadata/Ancillary_Imagery/Haze_Cloud_Water_Map
    SERC/Reflectance/Metadata/Ancillary_Imagery/Data_Selection_Index
    SERC/Reflectance/Metadata/Ancillary_Imagery/Sky_View_Factor
    SERC/Reflectance/Metadata/Ancillary_Imagery/Illumination_Factor SERC/Reflectance/Metadata/Ancillary_Imagery/Path_Length
    SERC/Reflectance/Metadata/Ancillary_Imagery/Visibility_Index_Map
    SERC/Reflectance/Metadata/Ancillary_Imagery/Slope SERC/Reflectance/Metadata/Ancillary_Imagery/Smooth_Surface_Elevation
    SERC/Reflectance/Metadata/Coordinate_System/Coordinate_System_String
    SERC/Reflectance/Metadata/Ancillary_Imagery/Water_Vapor_Column SERC/Reflectance/Metadata/Ancillary_Imagery/Weather_Quality_Indicator
    SERC/Reflectance/Metadata/Logs/160154/ATCOR_Input_file
    SERC/Reflectance/Metadata/Coordinate_System/EPSG Code SERC/Reflectance/Metadata/Coordinate_System/Map_Info SERC/Reflectance/Metadata/Coordinate_System/Proj4
    SERC/Reflectance/Metadata/Logs/160154/Solar_Azimuth_Angle
    SERC/Reflectance/Metadata/Logs/160154/ATCOR_Processing_Log SERC/Reflectance/Metadata/Logs/160154/Shadow_Processing_Log SERC/Reflectance/Metadata/Logs/160154/Skyview_Processing_Log
    SERC/Reflectance/Metadata/Logs/160742/Shadow_Processing_Log
    SERC/Reflectance/Metadata/Logs/160154/Solar_Zenith_Angle SERC/Reflectance/Metadata/Logs/160742/ATCOR_Input_file SERC/Reflectance/Metadata/Logs/160742/ATCOR_Processing_Log SERC/Reflectance/Metadata/Logs/160742/Skyview_Processing_Log
    SERC/Reflectance/Metadata/Logs/161252/Shadow_Processing_Log
    SERC/Reflectance/Metadata/Logs/160742/Solar_Azimuth_Angle SERC/Reflectance/Metadata/Logs/160742/Solar_Zenith_Angle SERC/Reflectance/Metadata/Logs/161252/ATCOR_Input_file SERC/Reflectance/Metadata/Logs/161252/ATCOR_Processing_Log SERC/Reflectance/Metadata/Logs/161252/Skyview_Processing_Log
    SERC/Reflectance/Metadata/to-sensor_zenith_angle
    SERC/Reflectance/Metadata/Logs/161252/Solar_Azimuth_Angle SERC/Reflectance/Metadata/Logs/161252/Solar_Zenith_Angle SERC/Reflectance/Metadata/Spectral_Data/FWHM SERC/Reflectance/Metadata/Spectral_Data/Wavelength SERC/Reflectance/Metadata/to-sensor_azimuth_angle
    SERC/Reflectance/Reflectance_Data
    You can see that there is a lot of information stored inside this reflectance hdf5 file. Most of this information is metadata (data about the reflectance data), for example, this file stores input parameters used in the atmospheric correction. For this introductory lesson, we will only work with two of these datasets, the reflectance data (hyperspectral cube), and the corresponding geospatial information, stored in Metadata/Coordinate_System:
    • SERC/Reflectance/Reflectance_Data
    • SERC/Reflectance/Metadata/Coordinate_System/
    We can also display the name, shape, and type of each of these datasets using the ls_dataset function defined below, which is also called with the visititems method:
    #ls_dataset displays the name, shape, and type of datasets in hdf5 file
    def ls_dataset(name,node):
    if isinstance(node, h5py.Dataset):
    print(node)
    #to see what the visititems methods does, type ? at the end:
    f.visititems?
    f.visititems(ls_dataset)
    
    <HDF5 dataset "Aerosol_Optical_Depth": shape (1000, 1000), type "<i2">
    <HDF5 dataset "Aspect": shape (1000, 1000), type "<f4">
    <HDF5 dataset "Cast_Shadow": shape (1000, 1000), type "|u1">
    <HDF5 dataset "Dark_Dense_Vegetation_Classification": shape (1000, 1000), type "|u1">
    <HDF5 dataset "Data_Selection_Index": shape (1000, 1000), type "<i4">
    <HDF5 dataset "Haze_Cloud_Water_Map": shape (1000, 1000), type "|u1">
    <HDF5 dataset "Illumination_Factor": shape (1000, 1000), type "|u1">
    <HDF5 dataset "Path_Length": shape (1000, 1000), type "<f4">
    <HDF5 dataset "Sky_View_Factor": shape (1000, 1000), type "|u1">
    <HDF5 dataset "Slope": shape (1000, 1000), type "<f4">
    <HDF5 dataset "Smooth_Surface_Elevation": shape (1000, 1000), type "<f4">
    <HDF5 dataset "Visibility_Index_Map": shape (1000, 1000), type "|u1">
    <HDF5 dataset "Water_Vapor_Column": shape (1000, 1000), type "<f4">
    <HDF5 dataset "Weather_Quality_Indicator": shape (1000, 1000, 3), type "|u1">
    <HDF5 dataset "Coordinate_System_String": shape (), type "|O">
    <HDF5 dataset "EPSG Code": shape (), type "|O">
    <HDF5 dataset "Map_Info": shape (), type "|O">
    <HDF5 dataset "Proj4": shape (), type "|O">
    <HDF5 dataset "ATCOR_Input_file": shape (), type "|O">
    <HDF5 dataset "ATCOR_Processing_Log": shape (), type "|O">
    <HDF5 dataset "Shadow_Processing_Log": shape (), type "|O">
    <HDF5 dataset "Skyview_Processing_Log": shape (), type "|O">
    <HDF5 dataset "Solar_Azimuth_Angle": shape (), type "<f4">
    <HDF5 dataset "Solar_Zenith_Angle": shape (), type "<f4">
    <HDF5 dataset "ATCOR_Input_file": shape (), type "|O">
    <HDF5 dataset "ATCOR_Processing_Log": shape (), type "|O">
    <HDF5 dataset "Shadow_Processing_Log": shape (), type "|O">
    <HDF5 dataset "Skyview_Processing_Log": shape (), type "|O">
    <HDF5 dataset "Solar_Azimuth_Angle": shape (), type "<f4">
    <HDF5 dataset "Solar_Zenith_Angle": shape (), type "<f4">
    <HDF5 dataset "ATCOR_Input_file": shape (), type "|O">
    <HDF5 dataset "ATCOR_Processing_Log": shape (), type "|O">
    <HDF5 dataset "Shadow_Processing_Log": shape (), type "|O">
    <HDF5 dataset "Skyview_Processing_Log": shape (), type "|O">
    <HDF5 dataset "Solar_Azimuth_Angle": shape (), type "<f4">
    <HDF5 dataset "Solar_Zenith_Angle": shape (), type "<f4">
    <HDF5 dataset "FWHM": shape (426,), type "<f4">
    <HDF5 dataset "Wavelength": shape (426,), type "<f4">
    <HDF5 dataset "to-sensor_azimuth_angle": shape (1000, 1000), type "<f4">
    <HDF5 dataset "to-sensor_zenith_angle": shape (1000, 1000), type "<f4">
    <HDF5 dataset "Reflectance_Data": shape (1000, 1000, 426), type "<i2">
    Now that we can see the structure of the hdf5 file, let's take a look at some of the information that is stored inside. Let's start by extracting the reflectance data, which is nested under SERC/Reflectance/Reflectance_Data:
    serc_refl = f['SERC']['Reflectance']
    print(serc_refl)
    <HDF5 group "/SERC/Reflectance" (2 members)>
    
    The two members of the HDF5 group /SERC/Reflectance are Metadata and Reflectance_Data. Let's save the reflectance data as the variable serc_reflArray:
    serc_reflArray = serc_refl['Reflectance_Data']
    print(serc_reflArray)
    <HDF5 dataset "Reflectance_Data": shape (1000, 1000, 426), type "<i2">
    
    We can extract the size of this reflectance array that we extracted using the shape method:
    refl_shape = serc_reflArray.shape
    print('SERC Reflectance Data Dimensions:',refl_shape)
    SERC Reflectance Data Dimensions: (1000, 1000, 426)
    
    This 3-D shape (1000,1000,426) corresponds to (y,x,bands), where (x,y) are the dimensions of the reflectance array in pixels. Hyperspectral data sets are often called cubes to reflect this 3-dimensional shape.
    NEON hyperspectral data contain around 426 spectral bands, and when working with tiled data, the spatial dimensions are 1000 x 1000, where each pixel represents 1 meter. Now let's take a look at the wavelength values. First, we will extract wavelength information from the serc_refl variable that we created:
    #define the wavelengths variable
    wavelengths = serc_refl['Metadata']['Spectral_Data']['Wavelength']
    #View wavelength information and values
    print('wavelengths:',wavelengths)
    wavelengths: <HDF5 dataset "Wavelength": shape (426,), type "<f4">
    
    We can then use numpy (imported as np) to see the minimum and maximum wavelength values:
    # Display min & max wavelengths
    print('min wavelength:', np.amin(wavelengths),'nm')
    print('max wavelength:', np.amax(wavelengths),'nm')
    min wavelength: 383.534 nm
    max wavelength: 2511.89 nm
    Finally, we can determine the band widths (distance between center bands of two adjacent bands). Let's try this for the first two bands and the last two bands. Remember that Python uses 0-based indexing ([0] represents the first value in an array), and note that you can also use negative numbers to splice values from the end of an array ([-1] represents the last value in an array).
    #show the band widths between the first 2 bands and last 2 bands
    print('band width between first 2 bands =',(wavelengths.value[1]-wavelengths.value[0]),'nm')
    print('band width between last 2 bands =',(wavelengths.value[-1]-wavelengths.value[-2]),'nm')
    band width between first 2 bands = 5.0079 nm
    band width between last 2 bands = 5.00781 nm
    The center wavelengths recorded in this hyperspectral cube range from 383.66 - 2511.94 nm, and each band covers a range of ~5 nm. Now let's extract spatial information, which is stored under SERC/Reflectance/Metadata/Coordinate_System/Map_Info:
    serc_mapInfo = serc_refl['Metadata']['Coordinate_System']['Map_Info']
    print('SERC Map Info:',serc_mapInfo.value)
    SERC Map Info: b'UTM,  1.000,  1.000,       368000.00,       4307000.0,       1.0000000,       1.0000000,  18,  North,  WGS-84,  units=Meters, 0'
    
    Understanding the output:
    Here we can spatial information about the reflectance data. Below is a break down of what each of these values means:
    • UTM - coordinate system (Universal Transverse Mercator)
    • 1.000, 1.000 - pixel origin
    • 368000.000, 4307000.0 - UTM coordinates (meters) of the map origin, which refers to the upper-left corner of the image (xMin, yMax).
    • 1.0000000, 1.0000000 - pixel resolution (meters)
    • 18 - UTM zone
    • N - UTM hemisphere (North for all NEON sites)
    • WGS-84 - reference ellipoid
    The letter b that appears before UTM signifies that the variable-length string data is stored in binary format when it is written to the hdf5 file. Don't worry about it for now, as we will convert the numerical data we need into floating point numbers. For more information on hdf5 strings read the h5py documentation.
    Let's extract relevant information from the Map_Info metadata to define the spatial extent of this dataset. To do this, we can use the split method to break up this string into separate values:
    #First convert mapInfo to a string
    mapInfo_string = str(serc_mapInfo.value) #convert to string
    #see what the split method does
    mapInfo_string.split?
    #split the strings using the separator ","
    mapInfo_split = mapInfo_string.split(",")
    print(mapInfo_split)
    ["b'UTM", '  1.000', '  1.000', '       368000.00', '       4307000.0', '       1.0000000', '       1.0000000', '  18', '  North', '  WGS-84', '  units=Meters', " 0'"]
    
    Now we can extract the spatial information we need from the map info values, convert them to the appropriate data type (float) and store it in a way that will enable us to access and apply it later when we want to plot the data:
    #Extract the resolution & convert to floating decimal number
    res = float(mapInfo_split[5]),float(mapInfo_split[6])
    print('Resolution:',res)
    Resolution: (1.0, 1.0)
    
    #Extract the upper left-hand corner coordinates from mapInfo
    xMin = float(mapInfo_split[3])
    yMax = float(mapInfo_split[4])
    #Calculate the xMax and yMin values from the dimensions
    xMax = xMin + (refl_shape[1]*res[0]) #xMax = left edge + (# of columns * x pixel resolution)
    yMin = yMax - (refl_shape[0]*res[1]) #yMin = top edge - (# of rows * y pixel resolution)
    Now we can define the spatial exten as the tuple (xMin, xMax, yMin, yMax). This is the format required for applying the spatial extent when plotting with matplotlib.pyplot.
    #Define extent as a tuple:
    serc_ext = (xMin, xMax, yMin, yMax)
    print('serc_ext:',serc_ext)
    print('serc_ext type:',type(serc_ext))
    serc_ext: (368000.0, 369000.0, 4306000.0, 4307000.0)
    serc_ext type: <class 'tuple'>

    Extract a Single Band from Array

    While it is useful to have all the data contained in a hyperspectral cube, it is difficult to visualize all this information at once. We can extract a single band (representing a ~5nm band, approximating a single wavelength) from the cube by using splicing as follows. Note that we have to cast the reflectance data into the type float. Recall that since Python indexing starts at 0 instead of 1, in order to extract band 56, we need to use the index 55.
    b56 = serc_reflArray[:,:,55].astype(float)
    print('b56 type:',type(b56))
    print('b56 shape:',b56.shape)
    print('Band 56 Reflectance:\n',b56)
    b56 type: <class 'numpy.ndarray'>
    b56 shape: (1000, 1000)
    Band 56 Reflectance:
    [[ 254. 241. 250. ..., 334. 313. 330.]
    [ 253. 260. 624. ..., 281. 311. 291.]
    [ 262. 413. 1050. ..., 295. 349. 280.]
    ...,
    [ 281. 231. 292. ..., 1168. 978. 916.]
    [ 240. 222. 189. ..., 1654. 1728. 1694.]
    [ 319. 329. 317. ..., 1176. 1466. 1582.]]
    Here we can see that we extracted a 2-D array (1000 x 1000) of the scaled reflectance data corresponding to the wavelength band 56. Before we can use the data, we need to clean it up a little. We'll show how to do this below.

    Scale factor and No Data Value

    This array represents the scaled reflectance for band 56. Recall from exploring the HDF5 data in HDFViewer that NEON AOP reflectance data uses a Data_Ignore_Value of -9999 to represent missing data (often called NaN), and a reflectance Scale_Factor of 10000.0 in order to save disk space (can use lower precision this way).
    Screenshot of the NEON HDF5 file format. Source: National Ecological Observatory Network
    We can extract and apply the Data_Ignore_Value and Scale_Factor as follows:
    #View and apply scale factor and data ignore value
    scaleFactor = serc_reflArray.attrs['Scale_Factor']
    noDataValue = serc_reflArray.attrs['Data_Ignore_Value']
    print('Scale Factor:',scaleFactor)
    print('Data Ignore Value:',noDataValue)
    b56[b56==int(noDataValue)]=np.nan
    b56 = b56/scaleFactor
    print('Cleaned Band 56 Reflectance:\n',b56)
    Scale Factor: 10000.0
    Data Ignore Value: -9999.0
    Cleaned Band 56 Reflectance:
    [[ 0.0254 0.0241 0.025 ..., 0.0334 0.0313 0.033 ]
    [ 0.0253 0.026 0.0624 ..., 0.0281 0.0311 0.0291]
    [ 0.0262 0.0413 0.105 ..., 0.0295 0.0349 0.028 ]
    ...,
    [ 0.0281 0.0231 0.0292 ..., 0.1168 0.0978 0.0916]
    [ 0.024 0.0222 0.0189 ..., 0.1654 0.1728 0.1694]
    [ 0.0319 0.0329 0.0317 ..., 0.1176 0.1466 0.1582]]

    Plot single reflectance band

    Now we can plot this band using the Python package matplotlib.pyplot, which we imported at the beginning of the lesson as plt. Note that the default colormap is jet unless otherwise specified. You can explore using different colormaps on your own; see the mapplotlib colormaps for for other options.
    serc_plot = plt.imshow(b56,extent=serc_ext,cmap='Greys') 
    
    We can see that this image looks pretty washed out. To see why this is, it helps to look at the range and distribution of reflectance values that we are plotting. We can do this by making a histogram.

    Plot histogram

    We can plot a histogram using the matplotlib.pyplot.hist function. Note that this function won't work if there are any NaN values, so we can ensure we are only plotting the real data values using the call below. You can also specify the # of bins you want to divide the data into.
    plt.hist(b56[~np.isnan(b56)],50); #50 signifies the # of bins
    
    We can see that most of the reflectance values are < 0.4. In order to show more contrast in the image, we can adjust the colorlimit (clim) to 0-0.4:
    serc_plot = plt.imshow(b56,extent=serc_ext,cmap='Greys',clim=(0,0.4))
    plt.title('SERC Band 56 Reflectance');
    Here you can see that adjusting the colorlimit displays features (eg. roads, buildings) much better than when we set the colormap limits to the entire range of reflectance values.

    Get Lesson Code: 


    ব্রিজেট হাস
    এই প্রবর্তক টিউটোরিয়ালে আমরা পাইথন ব্যবহার করে কীভাবে নিওন এওপি হাইপারস্পেকট্রাল টাইল্ড ডেটা পড়তে হবে তা নিয়ে আলোচনা করব। বর্ণালী ডেটা পরিচালনা ও কল্পনা করার জন্য আমরা সরঞ্জামগুলি বিকাশ করি।
    আপনি যদি ফ্লাইটলাইন নিওন এওপি হাইপারস্পেকট্রাল ডেটার জন্য এটি কীভাবে শিখতে আগ্রহী হন তবে দয়া করে পাইথন - ফ্লাইটলাইনগুলির সাথে এইচডিএফ 5 ফর্ম্যাটে নিওন এওপি হাইপারস্পেকট্রাল ডেটা দেখুন 

    শিক্ষার উদ্দেশ্য

    After completing this tutorial, you will be able to:
    • Import and use Python packages numpy, matplotlib, and h5py.
    • Use the package h5py and the visititems functionality to read an HDF5 file and view data attributes.
    • Read the data ignore value and scaling factor and apply these values to produce a cleaned reflectance array.
    • Extract and plot a single band of reflectance data
    • Plot a histogram of reflectance values to visualize the range and distribution of values.

    Install Python Packages

    • numpy
    • matplotlib
    • h5py

    Download Data

    NEON Teaching Data Subset: Data Institute 2018

    To complete these materials, you will use data available from the NEON 2018 Data Institute teaching datasets available for download.
    নীচে সম্মিলিত ডেটা সেটগুলিতে প্রায় 10 জিবি ডেটা থাকে। ডাউনলোডের আগে আপনার হার্ড ড্রাইভটি কত বড় তা দয়া করে বিবেচনা করুন। প্রয়োজনে আপনি একটি বাহ্যিক হার্ড ড্রাইভ ব্যবহার করতে পারেন।
    এই রাস্টার শিক্ষণ ডেটা উপসেট তৈরি করতে ব্যবহৃত লিডার এবং চিত্রের ডেটা জাতীয় পরিবেশগত পর্যবেক্ষণ নেটওয়ার্কের ফিল্ড সাইটগুলিতে সংগ্রহ করা হয়েছিল এবং নিওনের সদর দফতরে প্রক্রিয়াজাত করা হয়েছিল। নিওন ডেটা পোর্টালে সমস্ত নিওন ডেটা পণ্য অ্যাক্সেস করা যায় 
    নীচের লিঙ্কটিতে 2017 ডেটা ইনস্টিটিউট (17 গিগাবাইট) এর সমস্ত ডেটা রয়েছে। 2018 এর জন্য আমাদের কেবল CHEQ, F07A এবং PRIN সাবফোল্ডারগুলির ডেটা প্রয়োজন। আপনার ডাউনলোডের আকার হ্রাস করতে, দয়া করে ডাউনলোড করতে কেবল এই সাব-ডিরেক্টরিটি নির্বাচন করুন।
    হাইপারস্পেকট্রাল রিমোট সেন্সিং ডেটা পৃথিবীর পৃষ্ঠে আমাদের পরিবেশের পরিবর্তনগুলি পরিমাপের জন্য একটি দরকারী সরঞ্জাম। এই টিউটোরিয়ালে আমরা এক্সপ্লোর পরিচালনা করি যে কীভাবে এইচডিএফ 5 ফর্ম্যাটে সঞ্চিত নিওন এওপি orthorecised পৃষ্ঠের প্রতিবিম্ব ডেটা থেকে একটি টাইল (1000 মি x 1000 মি x 426 ব্যান্ড) থেকে তথ্য বের করা যায়। এই ডেটা পণ্য সম্পর্কে আরও তথ্যের জন্য, নিওন ডেটা পণ্য ক্যাটালগ দেখুন ।

    অদৃশ্য ম্যাপিং: বর্ণালী দূরবর্তী সংবেদনের পরিচিতি

    বর্ণালী দূরবর্তী সেন্সিং সম্পর্কিত আরও তথ্যের জন্য এই ভিডিওটি দেখুন।

    সেট আপ করুন

    আমরা কোডিং শুরু করার আগে নিশ্চিত হয়ে নিন যে আপনি পাইথনের সঠিক সংস্করণটি ব্যবহার করছেন। জুলাই 2018 পর্যন্ত, gdalপ্যাকেজটি পাইথন সংস্করণ 3.5 এবং তার আগের সংস্করণের সাথে সামঞ্জস্যপূর্ণ। এই পাঠগুলির জন্য আমরা পাইথন সংস্করণ 3.5 ব্যবহার করব।
    #Check that you are using the correct version of Python (should be 3.5 for these tutorials)
    import sys
    sys.version
    '3.5.4 |Anaconda, Inc.| (default, Nov  8 2017, 14:34:30) [MSC v.1900 64 bit (AMD64)]'
    
    প্রথমে প্রয়োজনীয় প্যাকেজগুলি আমদানি করা যাক:
    import numpy as np
    import h5py
    import gdal, osr, os
    import matplotlib.pyplot as plt
    এরপরে, প্রদর্শন পছন্দগুলি সেট করুন যাতে প্লটগুলি ইনলাইন হয় (অর্থাত আপনার কোড থেকে আউটপুট করা কোনও চিত্র নোটবুকের ঘরের নীচে প্রদর্শিত হবে) এবং প্লটের সতর্কতা বন্ধ করে:
    %matplotlib inline
    import warnings
    warnings.filterwarnings('ignore')

    এইচডিএফ 5 এ পড়ুন

    f = h5py.File('file.h5','r') ভেরিয়েবল এফ 5 এ h5 ফাইল পড়ে reads

    ফাংশনে সহায়তা পাওয়া: helpএবং?

    আমরা টিউটোরিয়াল জুড়ে অনেকগুলি অন্তর্নির্মিত এবং ব্যবহারকারী-সংজ্ঞায়িত ফাংশন এবং পদ্ধতি ব্যবহার করব। কোনও নির্দিষ্ট ফাংশন কী করে বা কীভাবে এটি কল করতে পারে তা আপনি যদি অনিশ্চিত থাকেন তবে আপনি ফাংশন বা পদ্ধতির শেষে টাইপ help()বা টাইপ করতে পারেন ?এবং সেলটি চালাতে পারেন (হয় সেল> রান সেল নির্বাচন করুন বা সেলটিতে আপনার কার্সারটি দিয়ে শিফট এন্টারটি নির্বাচন করুন আপনি নিজের ঘরে) চালাতে চান)। ?প্রদর্শন করার নোটবুক নীচে একটি উইন্ডো পপ আপ করবে ফাংশনের docstrings, যা ফাংশন এবং ব্যবহার সম্পর্কে তথ্য রয়েছে। আপনি অপরিচিত না এমন ফাংশনগুলি জুড়ে আসার সাথে সাথে আপনাকে টিউটোরিয়ালটি ব্যবহার করতে helpএবং উত্সাহিত করব ?। এর সাথে এটি ব্যবহার করে দেখুন h5py.File:
    help(h5py)
    
    Help on package h5py:
    NAME
    h5py
    DESCRIPTION
    This is the h5py package, a Python interface to the HDF5
    scientific data format.
    PACKAGE CONTENTS
    _conv
    _errors
    _hl (package)
    _objects
    _proxy
    defs
    h5
    h5a
    h5ac
    h5d
    h5ds
    h5f
    h5fd
    h5g
    h5i
    h5l
    h5o
    h5p
    h5r
    h5s
    h5t
    h5z
    highlevel
    ipy_completer
    tests (package)
    utils
    version
    SUBMODULES
    filters
    FUNCTIONS
    enable_ipython_completer()
    Call this from an interactive IPython session to enable tab-completion
    of group and attribute names.
    get_config(...)
    () => H5PYConfig
    Get a reference to the global library configuration object.
    get_enum = py_get_enum(...)
    (DTYPE dt_in) => DICT
    Deprecated; use check_dtype() instead.
    get_vlen = py_get_vlen(...)
    (OBJECT dt_in) => TYPE
    Deprecated; use check_dtype() instead.
    new_enum = py_new_enum(...)
    (DTYPE dt_in, DICT enum_vals) => DTYPE
    Deprecated; use special_dtype() instead.
    new_vlen = py_new_vlen(...)
    (OBJECT kind) => DTYPE
    Deprecated; use special_dtype() instead.
    DATA
    absolute_import = _Feature((2, 5, 0, 'alpha', 1), (3, 0, 0, 'alpha', 0...
    VERSION
    2.7.1
    FILE
    c:\users\bhass\appdata\local\continuum\anaconda3\envs\py35\lib\site-packages\h5py\__init__.py
    h5py.File?
    
    এখন যেহেতু h5pyএইচ 5 ফাইলে পড়তে কীভাবে ব্যবহার করতে হয় সে সম্পর্কে আমাদের ধারণা রয়েছে , আসুন এটি ব্যবহার করে দেখুন। নোট করুন যে আপনি যদি এইচ 5 ফাইলটি আপনার নোটবুকটি চালাচ্ছেন তার চেয়ে আলাদা ডিরেক্টরিতে সঞ্চিত থাকে তবে আপনাকে সেই ডিরেক্টরিটি যেখানে (ফাইলটি আপেক্ষিক বা নিখুঁত) অন্তর্ভুক্ত করতে হবে যেখানে সেই ফাইল ফাইলটি সঞ্চয় করা আছে। os.path.joinফাইলটির সম্পূর্ণ পথ তৈরি করতে ব্যবহার করুন।
    f = h5py.File('../../data/NEON_D02_SERC_DP3_368000_4306000_reflectance.h5','r') 
    

    নিওন এওপি এইচডিএফ 5 প্রতিবিম্ব ফাইলগুলি অন্বেষণ করুন

    আমরা h5py visititemsফাংশনটির সাথে এইচডিএফ 5 ডেটাসেটের ভিতরে দেখতে পারি । list_datasetফাংশন প্রদর্শন নিম্নে বর্ণিত সব ডেটাসেট hdf5 ফাইল এবং hdf5 ফাইল মধ্যে তাদের অবস্থানে সঞ্চিত:
    #list_dataset lists the names of datasets in an hdf5 file
    def list_dataset(name,node):
    if isinstance(node, h5py.Dataset):
    print(name)
    f.visititems(list_dataset)
    SERC/Reflectance/Metadata/Ancillary_Imagery/Aerosol_Optical_Depth
    SERC/Reflectance/Metadata/Ancillary_Imagery/Aspect
    SERC/Reflectance/Metadata/Ancillary_Imagery/Cast_Shadow
    SERC/Reflectance/Metadata/Ancillary_Imagery/Dark_Dense_Vegetation_Classification
    SERC/Reflectance/Metadata/Ancillary_Imagery/Data_Selection_Index
    SERC/Reflectance/Metadata/Ancillary_Imagery/Haze_Cloud_Water_Map
    SERC/Reflectance/Metadata/Ancillary_Imagery/Illumination_Factor
    SERC/Reflectance/Metadata/Ancillary_Imagery/Path_Length
    SERC/Reflectance/Metadata/Ancillary_Imagery/Sky_View_Factor
    SERC/Reflectance/Metadata/Ancillary_Imagery/Slope
    SERC/Reflectance/Metadata/Ancillary_Imagery/Smooth_Surface_Elevation
    SERC/Reflectance/Metadata/Ancillary_Imagery/Visibility_Index_Map
    SERC/Reflectance/Metadata/Ancillary_Imagery/Water_Vapor_Column
    SERC/Reflectance/Metadata/Ancillary_Imagery/Weather_Quality_Indicator
    SERC/Reflectance/Metadata/Coordinate_System/Coordinate_System_String
    SERC/Reflectance/Metadata/Coordinate_System/EPSG Code
    SERC/Reflectance/Metadata/Coordinate_System/Map_Info
    SERC/Reflectance/Metadata/Coordinate_System/Proj4
    SERC/Reflectance/Metadata/Logs/160154/ATCOR_Input_file
    SERC/Reflectance/Metadata/Logs/160154/ATCOR_Processing_Log
    SERC/Reflectance/Metadata/Logs/160154/Shadow_Processing_Log
    SERC/Reflectance/Metadata/Logs/160154/Skyview_Processing_Log
    SERC/Reflectance/Metadata/Logs/160154/Solar_Azimuth_Angle
    SERC/Reflectance/Metadata/Logs/160154/Solar_Zenith_Angle
    SERC/Reflectance/Metadata/Logs/160742/ATCOR_Input_file
    SERC/Reflectance/Metadata/Logs/160742/ATCOR_Processing_Log
    SERC/Reflectance/Metadata/Logs/160742/Shadow_Processing_Log
    SERC/Reflectance/Metadata/Logs/160742/Skyview_Processing_Log
    SERC/Reflectance/Metadata/Logs/160742/Solar_Azimuth_Angle
    SERC/Reflectance/Metadata/Logs/160742/Solar_Zenith_Angle
    SERC/Reflectance/Metadata/Logs/161252/ATCOR_Input_file
    SERC/Reflectance/Metadata/Logs/161252/ATCOR_Processing_Log
    SERC/Reflectance/Metadata/Logs/161252/Shadow_Processing_Log
    SERC/Reflectance/Metadata/Logs/161252/Skyview_Processing_Log
    SERC/Reflectance/Metadata/Logs/161252/Solar_Azimuth_Angle
    SERC/Reflectance/Metadata/Logs/161252/Solar_Zenith_Angle
    SERC/Reflectance/Metadata/Spectral_Data/FWHM
    SERC/Reflectance/Metadata/Spectral_Data/Wavelength
    SERC/Reflectance/Metadata/to-sensor_azimuth_angle
    SERC/Reflectance/Metadata/to-sensor_zenith_angle
    SERC/Reflectance/Reflectance_Data
    আপনি দেখতে পাচ্ছেন যে এই প্রতিবিম্ব এইচডিএফ 5 ফাইলের অভ্যন্তরে প্রচুর তথ্য সঞ্চিত রয়েছে। এই তথ্যগুলির বেশিরভাগই মেটাডেটা (প্রতিবিম্ব সম্পর্কিত ডেটা), উদাহরণস্বরূপ, এই ফাইলটি বায়ুমণ্ডলীয় সংশোধনে ব্যবহৃত ইনপুট পরামিতিগুলি সঞ্চয় করে। এই প্রাথমিক পাঠের জন্য, আমরা কেবলমাত্র এই দুটি ডেটাসেটের সাথে কাজ করব, মেটাডাটা / স্থানাঙ্ক_ সিস্টেমে সঞ্চিত প্রতিবিম্ব ডেটা (হাইপারস্পেক্ট্রাল কিউব) এবং সংশ্লিষ্ট ভূ-স্থান সংক্রান্ত তথ্য:
    • SERC/Reflectance/Reflectance_Data
    • SERC/Reflectance/Metadata/Coordinate_System/
    ls_datasetনীচে সংজ্ঞায়িত ফাংশনটি ব্যবহার করে আমরা এই প্রতিটি ডেটাসেটের নাম, আকৃতি এবং প্রকারটি প্রদর্শন করতে পারি, যাকে visititemsপদ্ধতির সাথেও ডাকা হয় :
    #ls_dataset displays the name, shape, and type of datasets in hdf5 file
    def ls_dataset(name,node):
    if isinstance(node, h5py.Dataset):
    print(node)
    #to see what the visititems methods does, type ? at the end:
    f.visititems?
    f.visititems(ls_dataset)
    
    <HDF5 dataset "Aerosol_Optical_Depth": shape (1000, 1000), type "<i2">
    <HDF5 dataset "Aspect": shape (1000, 1000), type "<f4">
    <HDF5 dataset "Cast_Shadow": shape (1000, 1000), type "|u1">
    <HDF5 dataset "Dark_Dense_Vegetation_Classification": shape (1000, 1000), type "|u1">
    <HDF5 dataset "Data_Selection_Index": shape (1000, 1000), type "<i4">
    <HDF5 dataset "Haze_Cloud_Water_Map": shape (1000, 1000), type "|u1">
    <HDF5 dataset "Illumination_Factor": shape (1000, 1000), type "|u1">
    <HDF5 dataset "Path_Length": shape (1000, 1000), type "<f4">
    <HDF5 dataset "Sky_View_Factor": shape (1000, 1000), type "|u1">
    <HDF5 dataset "Slope": shape (1000, 1000), type "<f4">
    <HDF5 dataset "Smooth_Surface_Elevation": shape (1000, 1000), type "<f4">
    <HDF5 dataset "Visibility_Index_Map": shape (1000, 1000), type "|u1">
    <HDF5 dataset "Water_Vapor_Column": shape (1000, 1000), type "<f4">
    <HDF5 dataset "Weather_Quality_Indicator": shape (1000, 1000, 3), type "|u1">
    <HDF5 dataset "Coordinate_System_String": shape (), type "|O">
    <HDF5 dataset "EPSG Code": shape (), type "|O">
    <HDF5 dataset "Map_Info": shape (), type "|O">
    <HDF5 dataset "Proj4": shape (), type "|O">
    <HDF5 dataset "ATCOR_Input_file": shape (), type "|O">
    <HDF5 dataset "ATCOR_Processing_Log": shape (), type "|O">
    <HDF5 dataset "Shadow_Processing_Log": shape (), type "|O">
    <HDF5 dataset "Skyview_Processing_Log": shape (), type "|O">
    <HDF5 dataset "Solar_Azimuth_Angle": shape (), type "<f4">
    <HDF5 dataset "Solar_Zenith_Angle": shape (), type "<f4">
    <HDF5 dataset "ATCOR_Input_file": shape (), type "|O">
    <HDF5 dataset "ATCOR_Processing_Log": shape (), type "|O">
    <HDF5 dataset "Shadow_Processing_Log": shape (), type "|O">
    <HDF5 dataset "Skyview_Processing_Log": shape (), type "|O">
    <HDF5 dataset "Solar_Azimuth_Angle": shape (), type "<f4">
    <HDF5 dataset "Solar_Zenith_Angle": shape (), type "<f4">
    <HDF5 dataset "ATCOR_Input_file": shape (), type "|O">
    <HDF5 dataset "ATCOR_Processing_Log": shape (), type "|O">
    <HDF5 dataset "Shadow_Processing_Log": shape (), type "|O">
    <HDF5 dataset "Skyview_Processing_Log": shape (), type "|O">
    <HDF5 dataset "Solar_Azimuth_Angle": shape (), type "<f4">
    <HDF5 dataset "Solar_Zenith_Angle": shape (), type "<f4">
    <HDF5 dataset "FWHM": shape (426,), type "<f4">
    <HDF5 dataset "Wavelength": shape (426,), type "<f4">
    <HDF5 dataset "to-sensor_azimuth_angle": shape (1000, 1000), type "<f4">
    <HDF5 dataset "to-sensor_zenith_angle": shape (1000, 1000), type "<f4">
    <HDF5 dataset "Reflectance_Data": shape (1000, 1000, 426), type "<i2">
    এখন যেহেতু আমরা এইচডিএফ 5 ফাইলের কাঠামো দেখতে পাচ্ছি, আসুন ভিতরে সঞ্চিত কিছু তথ্য একবার দেখে নিই। আসুন প্রতিবিম্বের ডেটা বের করে শুরু করি, যা নীচে বাসা বাঁধে SERC/Reflectance/Reflectance_Data:
    serc_refl = f['SERC']['Reflectance']
    print(serc_refl)
    <HDF5 group "/SERC/Reflectance" (2 members)>
    
    এইচডিএফ 5 গ্রুপের দুই সদস্য /SERC/Reflectanceহলেন Metadataএবং Reflectance_Data। আসুন প্রতিফলন তথ্যটি ভেরিয়েবল সের্ক_রেফ্লাল অ্যারে হিসাবে সংরক্ষণ করুন:
    serc_reflArray = serc_refl['Reflectance_Data']
    print(serc_reflArray)
    <HDF5 dataset "Reflectance_Data": shape (1000, 1000, 426), type "<i2">
    
    shapeপদ্ধতিটি ব্যবহার করে আমরা এই প্রতিবিম্ব অ্যারের আকারটি বের করতে পারি :
    refl_shape = serc_reflArray.shape
    print('SERC Reflectance Data Dimensions:',refl_shape)
    SERC Reflectance Data Dimensions: (1000, 1000, 426)
    
    এই 3-ডি আকার (1000,1000,426) (y, x, ব্যান্ড) এর সাথে মিলে যায়, যেখানে (x, y) পিক্সেলগুলিতে প্রতিবিম্বের অ্যারের মাত্রা। হাইপারস্পেকট্রাল ডেটা সেটগুলিকে প্রায়শই cubesএই ত্রিমাত্রিক আকারটি প্রতিবিম্বিত করতে বলা হয়।
    নিওন হাইপারস্পেকট্রাল ডেটাতে প্রায় ৪66 বর্ণালী ব্যান্ড থাকে এবং টাইল্ড ডেটার সাথে কাজ করার সময় স্থানিক মাত্রা 1000 x 1000 হয়, যেখানে প্রতিটি পিক্সেল 1 মিটার প্রতিনিধিত্ব করে। এখন আসুন তরঙ্গদৈর্ঘ্যের মানগুলি একবার দেখুন। প্রথমত, আমরা serc_reflযে ভেরিয়েবলটি তৈরি করেছি তা থেকে তরঙ্গদৈর্ঘ্যের তথ্য বের করব :
    #define the wavelengths variable
    wavelengths = serc_refl['Metadata']['Spectral_Data']['Wavelength']
    #View wavelength information and values
    print('wavelengths:',wavelengths)
    wavelengths: <HDF5 dataset "Wavelength": shape (426,), type "<f4">
    
    তারপরে আমরা সর্বনিম্ন এবং সর্বাধিক তরঙ্গদৈর্ঘ্যের মানগুলি দেখতে numpy(হিসাবে আমদানি করা npব্যবহার করতে পারি :
    # Display min & max wavelengths
    print('min wavelength:', np.amin(wavelengths),'nm')
    print('max wavelength:', np.amax(wavelengths),'nm')
    min wavelength: 383.534 nm
    max wavelength: 2511.89 nm
    অবশেষে, আমরা ব্যান্ডের প্রস্থগুলি নির্ধারণ করতে পারি (দুটি সংলগ্ন ব্যান্ডের কেন্দ্রের ব্যান্ডগুলির মধ্যে দূরত্ব)। প্রথম দুটি ব্যান্ড এবং শেষ দুটি ব্যান্ডের জন্য এটি চেষ্টা করি। মনে রাখবেন পাইথন 0-ভিত্তিক সূচক ব্যবহার করে ( [0]অ্যারেতে প্রথম মান উপস্থাপন করে), এবং মনে রাখবেন যে আপনি অ্যারেটির শেষে থেকে মানগুলি বিভক্ত করতে নেগেটিভ সংখ্যাগুলিও ব্যবহার করতে পারেন (অ্যারেতে [-1]সর্বশেষ মানটি উপস্থাপন করে)।
    #show the band widths between the first 2 bands and last 2 bands
    print('band width between first 2 bands =',(wavelengths.value[1]-wavelengths.value[0]),'nm')
    print('band width between last 2 bands =',(wavelengths.value[-1]-wavelengths.value[-2]),'nm')
    band width between first 2 bands = 5.0079 nm
    band width between last 2 bands = 5.00781 nm
    কেন্দ্র তরঙ্গদৈর্ঘ্যের থেকে এই hyperspectral ঘনক্ষেত্র সীমার মধ্যে রেকর্ড করা 383.66 - 2511.94 nm, এবং প্রতিটি ব্যান্ড ~ একটি সীমার জুড়ে 5 nm। এখন আসুন স্থানিক তথ্য আহরণ করুন, যা এর অধীনে সঞ্চিত রয়েছে SERC/Reflectance/Metadata/Coordinate_System/Map_Info:
    serc_mapInfo = serc_refl['Metadata']['Coordinate_System']['Map_Info']
    print('SERC Map Info:',serc_mapInfo.value)
    SERC Map Info: b'UTM,  1.000,  1.000,       368000.00,       4307000.0,       1.0000000,       1.0000000,  18,  North,  WGS-84,  units=Meters, 0'
    
    আউটপুট বোঝা:
    এখানে আমরা প্রতিবিম্ব তথ্য সম্পর্কে স্থানিক তথ্য করতে পারি। নীচে এই মানগুলির প্রতিটিটির অর্থ কী তা ভেঙে দেওয়া হল:
    • UTM - সমন্বয় ব্যবস্থা (ইউনিভার্সাল ট্রান্সভার্স মার্কারেটর)
    • 1.000, 1.000 - পিক্সেল উত্স
    • 368000.000, 4307000.0 - মানচিত্রের উত্সের UTM স্থানাঙ্ক (মিটার), যা চিত্রের উপরের-বাম কোণ (xMin, yMax) বোঝায়।
    • 1.0000000, 1.0000000 - পিক্সেল রেজোলিউশন (মিটার)
    • 18 - ইউটিএম জোন
    • N - ইউটিএম গোলার্ধ (সমস্ত নিওন সাইটের উত্তর)
    • WGS-84 - রেফারেন্স উপবৃত্তাকার
    bইউটিএম এর আগে উপস্থিত বর্ণটি হ'ল এইচডিএফ 5 ফাইলে লেখার সময় ভেরিয়েবল-দৈর্ঘ্যের স্ট্রিং ডেটা বি ইনারি ফর্ম্যাটে সংরক্ষণ করা হয় । আপাতত এটি নিয়ে চিন্তা করবেন না, যেহেতু আমরা আমাদের যে সংখ্যক ডেটা প্রয়োজন তা ভাসমান পয়েন্ট সংখ্যায় রূপান্তর করব। আরও তথ্যের জন্য hdf5 উপর স্ট্রিং পড়তে h5py ডকুমেন্টেশন ।
    Map_Infoএই ডেটাসেটের স্থানিক ব্যাপ্তি নির্ধারণ করতে মেটাডেটা থেকে প্রাসঙ্গিক তথ্য বের করা যাক । এটি করার জন্য, আমরা splitএই স্ট্রিংটিকে পৃথক মানগুলিতে বিভক্ত করার জন্য পদ্ধতিটি ব্যবহার করতে পারি :
    #First convert mapInfo to a string
    mapInfo_string = str(serc_mapInfo.value) #convert to string
    #see what the split method does
    mapInfo_string.split?
    #split the strings using the separator ","
    mapInfo_split = mapInfo_string.split(",")
    print(mapInfo_split)
    ["b'UTM", '  1.000', '  1.000', '       368000.00', '       4307000.0', '       1.0000000', '       1.0000000', '  18', '  North', '  WGS-84', '  units=Meters', " 0'"]
    
    এখন আমরা মানচিত্রের তথ্যের মানগুলি থেকে আমাদের প্রয়োজনীয় স্থানিক তথ্যগুলি বের করতে পারি, উপযুক্ত ডেটা টাইপ (ফ্লোট) এ রূপান্তর করতে পারি এবং এটি এমনভাবে সংরক্ষণ করতে পারি যা আমাদের ডেটা প্লট করতে চাইলে এটি অ্যাক্সেস করতে এবং পরে প্রয়োগ করতে সক্ষম করে:
    #Extract the resolution & convert to floating decimal number
    res = float(mapInfo_split[5]),float(mapInfo_split[6])
    print('Resolution:',res)
    Resolution: (1.0, 1.0)
    
    #Extract the upper left-hand corner coordinates from mapInfo
    xMin = float(mapInfo_split[3])
    yMax = float(mapInfo_split[4])
    #Calculate the xMax and yMin values from the dimensions
    xMax = xMin + (refl_shape[1]*res[0]) #xMax = left edge + (# of columns * x pixel resolution)
    yMin = yMax - (refl_shape[0]*res[1]) #yMin = top edge - (# of rows * y pixel resolution)
    এখন আমরা স্থানিক এক্সটেনশনটিকে টিপল হিসাবে সংজ্ঞায়িত করতে পারি (xMin, xMax, yMin, yMax)। এটি প্লট করার সময় স্থানিক ব্যাপ্তি প্রয়োগের জন্য প্রয়োজনীয় ফর্ম্যাট matplotlib.pyplot
    #Define extent as a tuple:
    serc_ext = (xMin, xMax, yMin, yMax)
    print('serc_ext:',serc_ext)
    print('serc_ext type:',type(serc_ext))
    serc_ext: (368000.0, 369000.0, 4306000.0, 4307000.0)
    serc_ext type: <class 'tuple'>

    অ্যারে থেকে একটি একক ব্যান্ড বের করুন

    হাইপারস্পেকট্রাল কিউবে থাকা সমস্ত ডেটা থাকা কার্যকর হলেও এই সমস্ত তথ্য একবারে কল্পনা করা শক্ত। নীচেরভাবে স্প্লিকিং ব্যবহার করে আমরা কিউব থেকে একটি একক ব্যান্ড (একটি 5nm ব্যান্ড উপস্থাপন করে, একটি তরঙ্গদৈর্ঘ্যের প্রায় অনুমান করে) বের করতে পারি। নোট করুন যে আমাদের প্রতিবিম্বের ডেটা টাইপ করতে হবে float। মনে রাখবেন যে যেহেতু পাইথন সূচীকরণটি 1 এর পরিবর্তে 0 থেকে শুরু হয়, তাই ব্যান্ড 56 বের করতে, আমাদের সূচক 55 ব্যবহার করতে হবে।
    b56 = serc_reflArray[:,:,55].astype(float)
    print('b56 type:',type(b56))
    print('b56 shape:',b56.shape)
    print('Band 56 Reflectance:\n',b56)
    b56 type: <class 'numpy.ndarray'>
    b56 shape: (1000, 1000)
    Band 56 Reflectance:
    [[ 254. 241. 250. ..., 334. 313. 330.]
    [ 253. 260. 624. ..., 281. 311. 291.]
    [ 262. 413. 1050. ..., 295. 349. 280.]
    ...,
    [ 281. 231. 292. ..., 1168. 978. 916.]
    [ 240. 222. 189. ..., 1654. 1728. 1694.]
    [ 319. 329. 317. ..., 1176. 1466. 1582.]]
    এখানে আমরা দেখতে পাচ্ছি যে আমরা তরঙ্গদৈর্ঘ্য ব্যান্ড 56 এর সাথে সম্পর্কিত মাপের প্রতিফলন তথ্যগুলির একটি 2-ডি অ্যারে (1000 x 1000) বের করেছি we আমরা ডেটা ব্যবহার করার আগে, আমাদের এটি একটু পরিষ্কার করতে হবে। নীচে এটি কীভাবে করা যায় তা আমরা দেখাব।

    স্কেল ফ্যাক্টর এবং কোনও ডেটা মান নেই

    এই অ্যারের HDFViewer মধ্যে HDF5 তথ্য নিয়ন Aop প্রতিফলন তথ্য একটি ব্যবহার করে অন্বেষণ থেকে ব্যান্ড 56. রিকল জন্য ছোটো প্রতিফলন প্রতিনিধিত্ব করে Data_Ignore_Valueএর -9999তথ্য (প্রায়ই বলা অনুপস্থিত প্রতিনিধিত্ব করতে NaN), এবং একটি প্রতিফলন Scale_Factorএর 10000.0(নিম্ন স্পষ্টতা ব্যবহার করতে পারেন অর্ডার ডিস্ক স্থান সংরক্ষণ করার জন্য এই পথে).
    নিওন এইচডিএফ 5 ফাইল ফর্ম্যাটের স্ক্রিনশট। সূত্র: ন্যাশনাল ইকোলজিকাল অবজারভেটরি নেটওয়ার্ক
    আমরা নিষ্কাশন করতে Data_Ignore_Valueএবং নীচের Scale_Factorহিসাবে প্রয়োগ করতে পারেন :
    #View and apply scale factor and data ignore value
    scaleFactor = serc_reflArray.attrs['Scale_Factor']
    noDataValue = serc_reflArray.attrs['Data_Ignore_Value']
    print('Scale Factor:',scaleFactor)
    print('Data Ignore Value:',noDataValue)
    b56[b56==int(noDataValue)]=np.nan
    b56 = b56/scaleFactor
    print('Cleaned Band 56 Reflectance:\n',b56)
    Scale Factor: 10000.0
    Data Ignore Value: -9999.0
    Cleaned Band 56 Reflectance:
    [[ 0.0254 0.0241 0.025 ..., 0.0334 0.0313 0.033 ]
    [ 0.0253 0.026 0.0624 ..., 0.0281 0.0311 0.0291]
    [ 0.0262 0.0413 0.105 ..., 0.0295 0.0349 0.028 ]
    ...,
    [ 0.0281 0.0231 0.0292 ..., 0.1168 0.0978 0.0916]
    [ 0.024 0.0222 0.0189 ..., 0.1654 0.1728 0.1694]
    [ 0.0319 0.0329 0.0317 ..., 0.1176 0.1466 0.1582]]

    প্লট একক প্রতিচ্ছবি ব্যান্ড

    এখন আমরা পাইথন প্যাকেজটি ব্যবহার করে এই ব্যান্ডটি প্লট করতে পারি matplotlib.pyplot, যা আমরা পাঠের শুরুতে আমদানি করেছিলাম plt। নোট করুন যে অন্যথায় নির্দিষ্ট না করা থাকলে ডিফল্ট রঙিন মানচিত্র জেট। আপনি নিজেরাই বিভিন্ন রঙের মানচিত্র ব্যবহার করে অন্বেষণ করতে পারেন; অন্যান্য বিকল্পের জন্য ম্যাপ্লটলিব রঙিনম্যাপগুলি দেখুন 
    serc_plot = plt.imshow(b56,extent=serc_ext,cmap='Greys') 
    
    আমরা দেখতে পাচ্ছি যে এই চিত্রটি বেশ ধুয়ে গেছে। এটি কেন তা দেখতে, এটি আমরা ষড়যন্ত্র করছি এমন প্রতিফলন মানগুলির পরিসীমা এবং বন্টনটি দেখতে সহায়তা করে। আমরা একটি হিস্টোগ্রাম তৈরি করে এটি করতে পারি।

    প্লট হিস্টগ্রাম

    matplotlib.pyplot.histফাংশনটি ব্যবহার করে আমরা একটি হিস্টোগ্রাম প্লট করতে পারি । নোট করুন যে কোনও এনএএন মান থাকলে এই ফাংশনটি কাজ করবে না, তাই আমরা নিশ্চিত করতে পারি যে আমরা কেবল নীচের কলটি ব্যবহার করে প্রকৃত ডেটা মানগুলি প্লট করছি। আপনি ডেটাগুলিকে বিভক্ত করতে চান এমন # টি বিনকেও নির্দিষ্ট করতে পারেন।
    plt.hist(b56[~np.isnan(b56)],50); #50 signifies the # of bins
    
    আমরা দেখতে পাচ্ছি যে বেশিরভাগ প্রতিবিম্ব মানগুলি 0 0.4 হয়। চিত্রটিতে আরও বৈপরীত্য প্রদর্শনের জন্য, আমরা রঙিন্যকে ( clim0-0.4 এ সামঞ্জস্য করতে পারি:
    serc_plot = plt.imshow(b56,extent=serc_ext,cmap='Greys',clim=(0,0.4))
    plt.title('SERC Band 56 Reflectance');
    এখানে আপনি দেখতে পারেন যে রঙিন চিত্র প্রদর্শনগুলি বৈশিষ্ট্যগুলি সমন্বয় করা (উদাহরণস্বরূপ রাস্তা, ভবনগুলি) যখন আমরা রঙিন্যাপের সীমাটি প্রতিফলন মানের পুরো পরিসীমাতে সেট করি than

    পাঠ কোড পান: 


  • 0 comments:

    Post a Comment

    New Research

    Attention Mechanism Based Multi Feature Fusion Forest for Hyperspectral Image Classification.

    CBS-GAN: A Band Selection Based Generative Adversarial Net for Hyperspectral Sample Generation.

    Multi-feature Fusion based Deep Forest for Hyperspectral Image Classification.

    ADDRESS

    388 Lumo Rd, Hongshan, Wuhan, Hubei, China

    EMAIL

    contact-m.zamanb@yahoo.com
    mostofa.zaman@cug.edu.cn

    TELEPHONE

    #
    #

    MOBILE

    +8615527370302,
    +8807171546477