In [1]:
Copied!
# install required packages
# !pip install prismatools
# install required packages
# !pip install prismatools
In [2]:
Copied!
from prismatools.prisma import (
read_prismaL2D,
write_prismaL2D,
extract_prisma,
write_prismaL2BC,
)
from prismatools.prisma import (
read_prismaL2D,
write_prismaL2D,
extract_prisma,
write_prismaL2BC,
)
Register and obtain the PRISMA datasets from the ASI PRISMA portal
Once you have downloaded a dataset, replace the filepath which we will use in this notebook.
In [3]:
Copied!
file = "/path/to/prisma.he5" # example: r"..\..\data\PRS_L2D_STD_20240429095823_20240429095827_0001.he5"
file = "/path/to/prisma.he5" # example: r"..\..\data\PRS_L2D_STD_20240429095823_20240429095827_0001.he5"
01. Read PRISMA hyperspectral and panchromatic data as xarray.Dataset¶
In [4]:
Copied!
# # Reads hyperspectral cube from a file path
# ds = read_prismaL2D(file)
# ds
# # Reads hyperspectral cube from a file path
# ds = read_prismaL2D(file)
# ds
In [5]:
Copied!
# # Reads a hyperspectral cube from a file path and selects only the bands corresponding to the specified wavelengths
# ds_sel = read_prismaL2D(file, wavelengths=[490, 560, 670, 1300, 2200], method="nearest")
# ds_sel
# # Reads a hyperspectral cube from a file path and selects only the bands corresponding to the specified wavelengths
# ds_sel = read_prismaL2D(file, wavelengths=[490, 560, 670, 1300, 2200], method="nearest")
# ds_sel
In [6]:
Copied!
# # Reads panchromatic data from a file path
# ds_pan = read_prismaL2D(file, panchromatic=True)
# ds_pan
# # Reads panchromatic data from a file path
# ds_pan = read_prismaL2D(file, panchromatic=True)
# ds_pan
In [7]:
Copied!
# # Extracts data from PRISMA dataset
# res = extract_prisma(dataset=ds, lat=41.4468, lon=15.4646)
# res.values
# # Extracts data from PRISMA dataset
# res = extract_prisma(dataset=ds, lat=41.4468, lon=15.4646)
# res.values
In [8]:
Copied!
# extracted_values = []
# points = [
# [41.4468, 15.4646],
# [41.4500, 15.4700],
# [41.4400, 15.4600]
# ]
# for lat, lon in points:
# res = extract_prisma(ds, lat=lat, lon=lon)
# extracted_values.append(res.values)
# extracted_values[0]
# extracted_values = []
# points = [
# [41.4468, 15.4646],
# [41.4500, 15.4700],
# [41.4400, 15.4600]
# ]
# for lat, lon in points:
# res = extract_prisma(ds, lat=lat, lon=lon)
# extracted_values.append(res.values)
# extracted_values[0]
02. Write PRISMA hyperspectral and panchromatic data as georeferenced image¶
In [9]:
Copied!
out_path = "path/to/outfile.tif" # example: r'..\..\..\out_test\your_output.tif'
out_path = "path/to/outfile.tif" # example: r'..\..\..\out_test\your_output.tif'
In [10]:
Copied!
# # case1a: write Panchromatic data from path (panchromatic=True)
# write_prismaL2D(file, output=out_path+"\img_pan.tif", panchromatic=True)
# # case1b: write Hyperspectral data from path (panchromatic=False)
# write_prismaL2D(file, output=out_path+"\img_cube.tif")
# # case1a: write Panchromatic data from path (panchromatic=True)
# write_prismaL2D(file, output=out_path+"\img_pan.tif", panchromatic=True)
# # case1b: write Hyperspectral data from path (panchromatic=False)
# write_prismaL2D(file, output=out_path+"\img_cube.tif")
In [11]:
Copied!
# # case2a: write Panchromatic data from xarray.Dataset
# write_prismaL2D(ds_pan, output=out_path+"\img_pan_ds.tif") # no need to set "panchromatic=True", just provide xr.Dataset with panchromatic data
# # case2b: write Hyperspectral data from xarray.Dataset
# write_prismaL2D(ds, output=out_path+"\img_cube_ds.tif")
# # case2a: write Panchromatic data from xarray.Dataset
# write_prismaL2D(ds_pan, output=out_path+"\img_pan_ds.tif") # no need to set "panchromatic=True", just provide xr.Dataset with panchromatic data
# # case2b: write Hyperspectral data from xarray.Dataset
# write_prismaL2D(ds, output=out_path+"\img_cube_ds.tif")
In [12]:
Copied!
# # case3: chose other output formats, e.g. ENVI format
# # panchromatic
# write_prismaL2D(file, output=out_path+"\img_pan_ds.dat", panchromatic=False)
# # hyperspectral
# write_prismaL2D(file, output=out_path+"\img_cube_ds.dat", panchromatic=True)
# # case3: chose other output formats, e.g. ENVI format
# # panchromatic
# write_prismaL2D(file, output=out_path+"\img_pan_ds.dat", panchromatic=False)
# # hyperspectral
# write_prismaL2D(file, output=out_path+"\img_cube_ds.dat", panchromatic=True)
03. Write PRISMA L2B and L2C data¶
In addition to PRISMA L2D (surface reflectance) data, you can also work with L2B and L2C products, which might be useful depending on your application.
- L2B data
In [13]:
Copied!
# path to L2B data
file = "/path/to/prismaL2B.he5" # example: r"..\..\data\PRS_L2B_STD_20240429095823_20240429095827_0001.he5"
# path to L2B data
file = "/path/to/prismaL2B.he5" # example: r"..\..\data\PRS_L2B_STD_20240429095823_20240429095827_0001.he5"
In [14]:
Copied!
# # hyperspectral
# write_prismaL2BC(file, output=out_path+'\imgCube_L2B_hyp.tif', product_type='PRS_L2B', panchromatic=False)
# write_prismaL2BC(file,
# output=out_path+'\imgCube_L2B_hyp_sel.tif',
# product_type='PRS_L2B',
# wavelengths=[650, 550, 450, 900],
# method='nearest',
# panchromatic=False)
# # panchromatic
# write_prismaL2BC(file, output=out_path+'\imgCube_L2B_pan.tif', product_type='PRS_L2B', panchromatic=True)
# # hyperspectral
# write_prismaL2BC(file, output=out_path+'\imgCube_L2B_hyp.tif', product_type='PRS_L2B', panchromatic=False)
# write_prismaL2BC(file,
# output=out_path+'\imgCube_L2B_hyp_sel.tif',
# product_type='PRS_L2B',
# wavelengths=[650, 550, 450, 900],
# method='nearest',
# panchromatic=False)
# # panchromatic
# write_prismaL2BC(file, output=out_path+'\imgCube_L2B_pan.tif', product_type='PRS_L2B', panchromatic=True)
- L2C data
In [15]:
Copied!
# path to L2C data
file = "/path/to/prismaL2C.he5" # example: r"..\..\data\PRS_L2C_STD_20240429095823_20240429095827_0001.he5"
# path to L2C data
file = "/path/to/prismaL2C.he5" # example: r"..\..\data\PRS_L2C_STD_20240429095823_20240429095827_0001.he5"
In [16]:
Copied!
# # hyperspectral
# write_prismaL2BC(file, output=out_path+'\imgCube_L2C_hyp.tif', product_type='PRS_L2C', panchromatic=False)
# write_prismaL2BC(file,
# output=out_path+'\imgCube_L2C_hyp_sel.tif',
# product_type='PRS_L2C',
# wavelengths=[650, 550, 450, 900],
# method='nearest',
# panchromatic=False)
# # panchromatic
# write_prismaL2BC(file, output=out_path+'\imgCube_L2C_pan.tif', product_type='PRS_L2C', panchromatic=True)
# # hyperspectral
# write_prismaL2BC(file, output=out_path+'\imgCube_L2C_hyp.tif', product_type='PRS_L2C', panchromatic=False)
# write_prismaL2BC(file,
# output=out_path+'\imgCube_L2C_hyp_sel.tif',
# product_type='PRS_L2C',
# wavelengths=[650, 550, 450, 900],
# method='nearest',
# panchromatic=False)
# # panchromatic
# write_prismaL2BC(file, output=out_path+'\imgCube_L2C_pan.tif', product_type='PRS_L2C', panchromatic=True)