Update

parent ca3d9c27
......@@ -6,22 +6,6 @@ Example:
$ python -m doctest -v Index.py
"""
""" Class for Sentinel satellites configuration
Test Case
>>> Files = tools('MSIL1C')
>>> dir="C:\Users\Garantias723\Documents\Poncho\Image_Sentinel"
>>> platform='Sentinel-2'
>>> list_files=Files.findFilesSentinel(dir,platform)
>>> print 'There is/are %d ' % len(list_files) + platform + ' file(s)'
>>> read=readProduct(dir,platform)
>>> for image in list_files:
>>> file = dir + "/" + image
>>> read.ReadfilesSentinel(file)
>>> band_names = product.getBandNames()
>>> print("Bands: %s" % (list(band_names)))
"""
import os,sys
sys.path.append(os.path.join(os.path.expandvars("%userprofile%"),".snap\snap-python"))
import snappy,numpy
......@@ -30,14 +14,30 @@ from tools import (tools)
from readProduct import (readProduct)
class Index(object):
""" Class for Sentinel satellites configuration
Test Case
>>> Files = tools('MSIL1C')
>>> dir="make"
>>> platform='Sentinel-2'
>>> list_files=Files.findFilesSentinel(dir,platform,3)
>>> print 'There is/are %d ' % len(list_files) + platform + ' file(s)'
>>> Read=readProduct(dir,platform)
>>> Ind="NBAI"
>>> Indeex = Index("60", Ind)
>>> for image in list_files:
>>> file = dir + "/" + image
>>> print"Applying Index " + Ind + "... ", image
>>> product=Read.ReadFilesSentinel(file,2)
>>> Indeex.Index(product, file)
"""
def __init__(self,ResolSize,IndexType):
"""The constructor Initialize Sentinel Data.
Args:
self: The object pointer.
folder (str): destination directory.
IndexType (str): # NDVI - Normalized Difference Vegetation Index, NDWI - Normalized Difference Water Index, NBAI - Normalized Built-up Area Index
Returns:
pointer: The object pointer.
......@@ -50,13 +50,18 @@ class Index(object):
self.HashMap = jpy.get_type('java.util.HashMap')
def Index(self,product, file):
"""Index Files Sentinel
Args:
self (pointer): The object pointer.
product (bin): Metadata Sentinel.
file (str): local path to image.
"""
width = product.getSceneRasterWidth()
height = product.getSceneRasterHeight()
product_name = product.getName()
# input product red & nir bands
#if (self.Index_Type == "NDVI"):
if (self.Index_Type == self.typeNDVI):
print"Entre NDVI..."
type=self.typeNDVI
......@@ -75,21 +80,15 @@ class Index(object):
red_band = product.getBand('B2')
do_row = numpy.zeros(width, dtype=numpy.float32)
# output product (ndvi) & new band
# output_product = Product('NDVI', 'NDVI', width, height)
output_product = Product(self.Index_Type, self.Index_Type, width, height)
ProductUtils.copyGeoCoding(product, output_product)
output_band = output_product.addBand(type, ProductData.TYPE_FLOAT32)
# output writer
# Tam = len(image)
fileOut = file[:-4] + '_' + self.Index_Type + '.dim'
output_product_writer = ProductIO.getProductWriter('BEAM-DIMAP')
output_product.setProductWriter(output_product_writer)
# output_product.writeHeader(product_name + '.ndvi.dim')
output_product.writeHeader(fileOut)
# compute & save ndvi line by line
red_row = numpy.zeros(width, dtype=numpy.float32)
nir_row = numpy.zeros(width, dtype=numpy.float32)
......@@ -111,25 +110,3 @@ class Index(object):
output_band.writePixels(0, y, width, 1, nbai)
output_product.closeIO()
\ No newline at end of file
#Applying Index Flag=3 Search .dim files
#Find Sentinel Files
Files = tools("all") #IW_SLC,IW_GRDH,MSIL1C
dir="C:\Users\Garantias723\Documents\Poncho\Image_Sentinel"
platform='Sentinel-2'
list_files=Files.findFilesSentinel(dir,platform,3)
print 'There is/are %d ' % len(list_files) + platform + ' file(s)'
#Read Sentinel Files
Read=readProduct(dir,platform)
#Applying Resampling
Ind="NBAI"
Indeex=Index("60",Ind)
for image in list_files:
file = dir + "\\" + image
print"Applying Index "+Ind+"... ", image
product=Read.ReadFilesSentinel(file,2)#The flag 2 ReadFiles .dim
Indeex.Index(product,file)
#NDVI - Normalized Difference Vegetation Index,
#NDWI - Normalized Difference Water Index,
#NBAI - Normalized Built-up Area Index
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment