Skip to content

Commit

Permalink
#143 merge issue128-landsat-metadata into issue143time
Browse files Browse the repository at this point in the history
  • Loading branch information
akorosov committed Jan 22, 2016
2 parents 5363d58 + f8e5d4e commit d0699e8
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions nansat/mappers/mapper_landsat.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
import glob
import tarfile
import warnings
import datetime

from nansat.tools import WrongMapperError
from nansat.tools import WrongMapperError, parse_time
from nansat.tools import gdal, np
from nansat.vrt import VRT

Expand All @@ -19,6 +20,7 @@ class Mapper(VRT):
def __init__(self, fileName, gdalDataset, gdalMetadata,
resolution='low', **kwargs):
''' Create LANDSAT VRT from multiple tif files or single tar.gz file'''
mtlFileName = ''
bandFileNames = []
bandSizes = []
bandDatasets = []
Expand Down Expand Up @@ -47,6 +49,11 @@ def __init__(self, fileName, gdalDataset, gdalMetadata,
bandFileNames.append(sourceFilename)
bandSizes.append(gdalDatasetTmp.RasterXSize)
bandDatasets.append(gdalDatasetTmp)
elif (tarName.endswith('MTL.txt') or
tarName.endswith('MTL.TXT')):
# get mtl file
mtlFileName = tarName

elif ((fname.startswith('L') or fname.startswith('M')) and
(fname.endswith('.tif') or
fname.endswith('.TIF') or
Expand All @@ -65,6 +72,10 @@ def __init__(self, fileName, gdalDataset, gdalMetadata,
bandSizes.append(gdalDatasetTmp.RasterXSize)
bandDatasets.append(gdalDatasetTmp)

# get mtl file
mtlFiles = glob.glob(coreName+'*[mM][tT][lL].[tT][xX][tT]')
if len(mtlFiles) > 0:
mtlFileName = mtlFiles[0]
else:
raise WrongMapperError

Expand Down Expand Up @@ -104,20 +115,14 @@ def __init__(self, fileName, gdalDataset, gdalMetadata,
# add bands with metadata and corresponding values to the empty VRT
self._create_bands(metaDict)

#import ipdb
#ipdb.set_trace()
#t = tarfile.open(fileName)
#for m in t.getmembers():
# if m.name[-4:] == '.TXT' or m.name[-4:] == '.txt':
# f = t.extractfile(m)
# for line in f:


#self.dataset.SetMetadataItem('start_time',
# (parse(gdalMetadata['MPH_SENSING_START']).
# isoformat()))
#self.dataset.SetMetadataItem('stop_time',
# (parse(gdalMetadata['MPH_SENSING_STOP']).
# isoformat()))
#self.dataset.SetMetadataItem('sensor', 'ASAR')
#self.dataset.SetMetadataItem('satellite', 'Envisat')
if len(mtlFileName) > 0:
mtlFileName = os.path.join(os.path.split(bandFileNames[0])[0], mtlFileName)
mtlFileLines = [line.strip() for line in self.read_xml(mtlFileName).split('\n')]
dateString = [line.split('=')[1].strip() for line in mtlFileLines if 'DATE_ACQUIRED' in line][0]
timeStr = [line.split('=')[1].strip() for line in mtlFileLines if 'SCENE_CENTER_TIME' in line][0]
time_start = parse_time(dateString + 'T' + timeStr).isoformat()
time_end = (parse_time(dateString + 'T' + timeStr) +
datetime.timedelta(microseconds=60000000)).isoformat()

self.dataset.SetMetadataItem('time_coverage_start', time_start)
self.dataset.SetMetadataItem('time_coverage_end', time_end)

0 comments on commit d0699e8

Please sign in to comment.