Update

parent dc24c7dd
# -*- coding: utf-8 -*-
# @package JP2ToJPGSubSet Sentinel Files
"""
Example:
$ python -m doctest -v JP2ToJPGSubSet.py
"""
import os,sys,numpy as np
from tools import (tools)
from osgeo import gdal,ogr,osr
class JP2ToJPG_SubSet(object):
""" Class for Sentinel satellites configuration
Test Case
>>> Files = tools("all") #IW_SLC,IW_GRDH,MSIL1C
>>> dir="make/"
>>> platform='Sentinel-2'
>>> list_files=Files.findFilesSentinel(dir,platform,2)#4 for resample_subset.dim
>>> print 'There is/are %d ' % len(list_files) + platform + ' file(s)'
>>> lat1=20.795
>>> lon1=-103.714
>>> lat2=20.165
>>> lon2=-103.086
>>> TypeMerge="RGB"
>>> Convert=JP2ToJPG_SubSet(TypeMerge)
>>> for image in list_files:
... file = dir + "/"+ image
... products = Files.search_band_combination(file,TypeMerge)
... print"Applying Convert JP2 To JPEG and SubSet... ", image
... Convert.Convert_SubSet(lat1, lon1, lon2, lat2, products)
"""
def __init__(self,TypeMerge):
"""The constructor Initialize Sentinel Data.
Args:
self: The object pointer.
TypeMerge (str): RGB
Returns:
pointer: The object pointer.
"""
self.ext=".jpg"
self.SubSet="_SubSet"
self.Type_Merge="_"+TypeMerge
def Convert_SubSet(self, lat1, lon1, lon2, lat2, products):
"""Index Files Sentinel
Args:
self (pointer): The object pointer.
lat1 (float): World Geodetic System 1984.
lon1 (float): World Geodetic System 1984.
lon2 (float): World Geodetic System 1984.
lat2 (float): World Geodetic System 1984.
files (str): local path to image.
"""
for i in products:
outDS=i[:-4]+self.SubSet+self.ext
translate = 'gdal_translate -projwin %s %s %s %s -projwin_srs WGS84 -ot Byte -scale 0 4096 0 255 -of JPEG %s %s' % (lon1, lat1, lon2, lat2, i, outDS)
os.system(translate)
\ No newline at end of file
......@@ -26,16 +26,17 @@ class Merge(object):
>>> Files = tools("all") #IW_SLC,IW_GRDH,MSIL1C
>>> dir="make/"
>>> platform='Sentinel-2'
>>> list_files=Files.findFilesSentinel(dir,platform,4)#4 for resample_subset.dim
>>> list_files=Files.findFilesSentinel(dir,platform,2)#4 for resample_subset.dim
>>> print 'There is/are %d ' % len(list_files) + platform + ' file(s)'
>>> Read=readProduct(dir,platform)
>>> TypeMerge="RGB"
>>> Mergee=Merge("60",TypeMerge)
>>> Mergee=Merge(TypeMerge)
>>> for image in list_files:
... file = dir + image
... print"Applying SubSet... ", image
... products = Files.search_band_combination(file, TypeMerge)
... print"Applying Merge "+TypeMerge+"... ", image
... product=Read.ReadFilesSentinel(file,2)#The flag 2 ReadFiles .dim
... Mergee.merges(product, file)
... Mergee.merges(product, products,file)
"""
def __init__(self,TypeMerge):
......@@ -53,7 +54,6 @@ class Merge(object):
self.looks = jpy.get_type('org.esa.snap.core.datamodel.quicklooks.QuicklookGenerator')
self.File = jpy.get_type('java.io.File')
#def merges(self, product, file):
def merges(self, product, products,file):
"""Index Files Sentinel
......@@ -122,19 +122,3 @@ class Merge(object):
output_dataset.GetRasterBand(3).WriteRaster(0, 0, xsize, ysize, values3)
output_dataset = None
Files = tools("all") #IW_SLC,IW_GRDH,MSIL1C
dir="make/"
platform='Sentinel-2'
list_files=Files.findFilesSentinel(dir,platform,2)#4 for resample_subset.dim
print 'There is/are %d ' % len(list_files) + platform + ' file(s)'
Read=readProduct(dir,platform)
TypeMerge="RGB"
Mergee=Merge(TypeMerge)
for image in list_files:
file = dir + image
products = Files.search_band_combination(file, TypeMerge)
print"Applying Merge "+TypeMerge+"... ", image
product=Read.ReadFilesSentinel(file,2)#The flag 2 ReadFiles .dim
#Mergee.merges(product, file)#for resample_subset.dim
Mergee.merges(product, products,file)#for .SAFE
......@@ -14,7 +14,7 @@ class tools(object):
>>> Files = tools('all')
>>> dir='make'
>>> platform='Sentinel-2'
>>> list_files=Files.findFilesSentinel(dir,platform)
>>> list_files=Files.findFilesSentinel(dir,platform,1)#Find 1=.zip, 2=.SAFE, 3 and 4=.dim
>>> print 'There is/are %d ' % len(list_files) + platform + ' file(s)'
"""
......@@ -60,7 +60,6 @@ class tools(object):
if platform == "Sentinel-1":
nam1=self.namfil1
nam2=self.namfil2
#files = [f for f in files if f.startswith(nam1) and f.endswith(ext) or f.startswith(nam2)]
if platform == "Sentinel-2":
nam1=self.namfil3
nam2=self.namfil4
......
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