Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
GeoSentinel
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mario Chirinos Colunga
GeoSentinel
Commits
4e5bebc4
Commit
4e5bebc4
authored
May 14, 2018
by
Alfonso Ramire Pedraza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update
parent
ca3d9c27
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
49 deletions
+26
-49
Index.py
geosentinel/Index.py
+26
-49
No files found.
geosentinel/Index.py
View file @
4e5bebc4
...
@@ -6,22 +6,6 @@ Example:
...
@@ -6,22 +6,6 @@ Example:
$ python -m doctest -v Index.py
$ 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
import
os
,
sys
sys
.
path
.
append
(
os
.
path
.
join
(
os
.
path
.
expandvars
(
"
%
userprofile
%
"
),
".snap
\
snap-python"
))
sys
.
path
.
append
(
os
.
path
.
join
(
os
.
path
.
expandvars
(
"
%
userprofile
%
"
),
".snap
\
snap-python"
))
import
snappy
,
numpy
import
snappy
,
numpy
...
@@ -30,14 +14,30 @@ from tools import (tools)
...
@@ -30,14 +14,30 @@ from tools import (tools)
from
readProduct
import
(
readProduct
)
from
readProduct
import
(
readProduct
)
class
Index
(
object
):
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
):
def
__init__
(
self
,
ResolSize
,
IndexType
):
"""The constructor Initialize Sentinel Data.
"""The constructor Initialize Sentinel Data.
Args:
Args:
self: The object pointer.
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:
Returns:
pointer: The object pointer.
pointer: The object pointer.
...
@@ -50,13 +50,18 @@ class Index(object):
...
@@ -50,13 +50,18 @@ class Index(object):
self
.
HashMap
=
jpy
.
get_type
(
'java.util.HashMap'
)
self
.
HashMap
=
jpy
.
get_type
(
'java.util.HashMap'
)
def
Index
(
self
,
product
,
file
):
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
()
width
=
product
.
getSceneRasterWidth
()
height
=
product
.
getSceneRasterHeight
()
height
=
product
.
getSceneRasterHeight
()
product_name
=
product
.
getName
()
product_name
=
product
.
getName
()
# input product red & nir bands
#if (self.Index_Type == "NDVI"):
if
(
self
.
Index_Type
==
self
.
typeNDVI
):
if
(
self
.
Index_Type
==
self
.
typeNDVI
):
print
"Entre NDVI..."
print
"Entre NDVI..."
type
=
self
.
typeNDVI
type
=
self
.
typeNDVI
...
@@ -75,21 +80,15 @@ class Index(object):
...
@@ -75,21 +80,15 @@ class Index(object):
red_band
=
product
.
getBand
(
'B2'
)
red_band
=
product
.
getBand
(
'B2'
)
do_row
=
numpy
.
zeros
(
width
,
dtype
=
numpy
.
float32
)
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
)
output_product
=
Product
(
self
.
Index_Type
,
self
.
Index_Type
,
width
,
height
)
ProductUtils
.
copyGeoCoding
(
product
,
output_product
)
ProductUtils
.
copyGeoCoding
(
product
,
output_product
)
output_band
=
output_product
.
addBand
(
type
,
ProductData
.
TYPE_FLOAT32
)
output_band
=
output_product
.
addBand
(
type
,
ProductData
.
TYPE_FLOAT32
)
# output writer
# Tam = len(image)
fileOut
=
file
[:
-
4
]
+
'_'
+
self
.
Index_Type
+
'.dim'
fileOut
=
file
[:
-
4
]
+
'_'
+
self
.
Index_Type
+
'.dim'
output_product_writer
=
ProductIO
.
getProductWriter
(
'BEAM-DIMAP'
)
output_product_writer
=
ProductIO
.
getProductWriter
(
'BEAM-DIMAP'
)
output_product
.
setProductWriter
(
output_product_writer
)
output_product
.
setProductWriter
(
output_product_writer
)
# output_product.writeHeader(product_name + '.ndvi.dim')
output_product
.
writeHeader
(
fileOut
)
output_product
.
writeHeader
(
fileOut
)
# compute & save ndvi line by line
red_row
=
numpy
.
zeros
(
width
,
dtype
=
numpy
.
float32
)
red_row
=
numpy
.
zeros
(
width
,
dtype
=
numpy
.
float32
)
nir_row
=
numpy
.
zeros
(
width
,
dtype
=
numpy
.
float32
)
nir_row
=
numpy
.
zeros
(
width
,
dtype
=
numpy
.
float32
)
...
@@ -111,25 +110,3 @@ class Index(object):
...
@@ -111,25 +110,3 @@ class Index(object):
output_band
.
writePixels
(
0
,
y
,
width
,
1
,
nbai
)
output_band
.
writePixels
(
0
,
y
,
width
,
1
,
nbai
)
output_product
.
closeIO
()
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment