Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 or
'ACQUISITION_DATE' in line)][0]
timeStr = [line.split('=')[1].strip()
for line in mtlFileLines
if ('SCENE_CENTER_TIME' in line or
'SCENE_CENTER_SCAN_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)
# set platform
platform = 'LANDSAT'
if fname[2].isdigit():
platform += '-'+fname[2]
ee = pti.get_gcmd_platform(platform)
self.dataset.SetMetadataItem('platform', json.dumps(ee))
# set instrument
instrument = {
'LANDSAT' : 'MSS',
'LANDSAT-1' : 'MSS',
def _set_time_coverage_metadata(self, gdal_metadata):
### GET START TIME from METADATA
time_coverage_start = None
if 'time_coverage_start' in gdal_metadata:
time_coverage_start = parse_time(
gdal_metadata['time_coverage_start'])
### GET END TIME from METADATA
time_coverage_end = None
if 'time_coverage_end' in gdal_metadata:
time_coverage_end = parse_time(
gdal_metadata['time_coverage_end'])
# set time_coverage_start if available
if time_coverage_start is not None:
self.dataset.SetMetadataItem('time_coverage_start',
time_coverage_start.isoformat())
# set time_coverage_end if available
if time_coverage_end is not None:
self.dataset.SetMetadataItem('time_coverage_end',
time_coverage_end.isoformat())
@property
def time_coverage_start(self):
return parse_time(self.get_metadata('time_coverage_start'))
geoTransform = self.dataset.GetGeoTransform()
if len(geoTransform) == 0:
geoTransformStr = geoMetadata.get('GeoTransform',
'(0|1|0|0|0|0|1)')
geoTransform = eval(geoTransformStr.replace('|', ','))
self.dataset.SetGeoTransform(geoTransform)
subMetadata = firstSubDataset.GetMetadata()
### GET START TIME from METADATA
time_coverage_start = None
if 'start_time' in gdalMetadata:
time_coverage_start = parse_time(gdalMetadata['start_time'])
elif 'start_date' in gdalMetadata:
time_coverage_start = parse_time(gdalMetadata['start_date'])
elif 'time_coverage_start' in gdalMetadata:
time_coverage_start = parse_time(
gdalMetadata['time_coverage_start'])
### GET END TIME from METADATA
time_coverage_end = None
if 'stop_time' in gdalMetadata:
time_coverage_end = parse_time(gdalMetadata['stop_time'])
elif 'stop_date' in gdalMetadata:
time_coverage_end = parse_time(gdalMetadata['stop_date'])
elif 'time_coverage_stop' in gdalMetadata:
time_coverage_end = parse_time(
gdalMetadata['time_coverage_stop'])
elif 'end_time' in gdalMetadata:
time_coverage_end = parse_time(gdalMetadata['end_time'])
elif 'end_date' in gdalMetadata:
if 'start_time' in gdalMetadata:
time_coverage_start = parse_time(gdalMetadata['start_time'])
elif 'start_date' in gdalMetadata:
time_coverage_start = parse_time(gdalMetadata['start_date'])
elif 'time_coverage_start' in gdalMetadata:
time_coverage_start = parse_time(
gdalMetadata['time_coverage_start'])
### GET END TIME from METADATA
time_coverage_end = None
if 'stop_time' in gdalMetadata:
time_coverage_end = parse_time(gdalMetadata['stop_time'])
elif 'stop_date' in gdalMetadata:
time_coverage_end = parse_time(gdalMetadata['stop_date'])
elif 'time_coverage_stop' in gdalMetadata:
time_coverage_end = parse_time(
gdalMetadata['time_coverage_stop'])
elif 'end_time' in gdalMetadata:
time_coverage_end = parse_time(gdalMetadata['end_time'])
elif 'end_date' in gdalMetadata:
time_coverage_end = parse_time(gdalMetadata['end_date'])
elif 'time_coverage_end' in gdalMetadata:
time_coverage_end = parse_time(
gdalMetadata['time_coverage_end'])
### GET start time from time variable
if (time_coverage_start is None and 'time#standard_name' in subMetadata and
subMetadata['time#standard_name'] == 'time' and 'time#units' in subMetadata):
# get data from netcdf data
ncFile = Dataset(inputFileName, 'r')
time_var = ncFile.variables['time']
t0 = time_var[0]
def _set_time_coverage_metadata(self, gdal_metadata):
### GET START TIME from METADATA
time_coverage_start = None
if 'time_coverage_start' in gdal_metadata:
time_coverage_start = parse_time(
gdal_metadata['time_coverage_start'])
### GET END TIME from METADATA
time_coverage_end = None
if 'time_coverage_end' in gdal_metadata:
time_coverage_end = parse_time(
gdal_metadata['time_coverage_end'])
# set time_coverage_start if available
if time_coverage_start is not None:
self.dataset.SetMetadataItem('time_coverage_start',
time_coverage_start.isoformat())
# set time_coverage_end if available
if time_coverage_end is not None:
self.dataset.SetMetadataItem('time_coverage_end',
time_coverage_end.isoformat())
def _set_time_coverage_metadata(self, gdal_metadata):
### GET START TIME from METADATA
time_coverage_start = None
if 'time_coverage_start' in gdal_metadata:
time_coverage_start = parse_time(
gdal_metadata['time_coverage_start'])
### GET END TIME from METADATA
time_coverage_end = None
if 'time_coverage_end' in gdal_metadata:
time_coverage_end = parse_time(
gdal_metadata['time_coverage_end'])
# set time_coverage_start if available
if time_coverage_start is not None:
self.dataset.SetMetadataItem('time_coverage_start',
time_coverage_start.isoformat())
# set time_coverage_end if available
if time_coverage_end is not None:
self.dataset.SetMetadataItem('time_coverage_end',
time_coverage_end.isoformat())