diff --git a/timeseriesviewer/__init__.py b/timeseriesviewer/__init__.py index a5e88c502fdc9fc919a2c18b8be77d4c8854f952..0a11a96de91b2767227335d5be9b6c0259390b0f 100644 --- a/timeseriesviewer/__init__.py +++ b/timeseriesviewer/__init__.py @@ -59,10 +59,19 @@ def file_search(rootdir, wildcard, recursive=False, ignoreCase=False): def findAbsolutePath(file): - if os.path.exists(file): return file + filepath, attr = getFileAndAttributes(file) + + if os.path.exists(filepath): return file possibleRoots = [DIR_EXAMPLES, DIR_REPO, os.getcwd()] for root in possibleRoots: - tmp = jp(root, file) + tmp = jp(root, filepath) if os.path.exists(tmp): - return tmp - return None \ No newline at end of file + return tmp + attr + return None + + +def getFileAndAttributes(file): + dn = os.path.dirname(file) + bn = os.path.basename(file) + bnSplit = bn.split(':') + return os.path.join(dn,bn), ':'.join(bnSplit[1:]) \ No newline at end of file diff --git a/timeseriesviewer/sandbox.py b/timeseriesviewer/sandbox.py index 2de357c53278eda395cd0acec1390613a48afe04..e1d687e6fdf620660356bbc4807c9e8ec2e75a2b 100644 --- a/timeseriesviewer/sandbox.py +++ b/timeseriesviewer/sandbox.py @@ -33,22 +33,51 @@ def sandboxGui(): S.ui.show() S.run() + from timeseriesviewer import file_search + if False: + #load VRTs pointing to Landsat imagery + searchDir = r'O:\SenseCarbonProcessing\BJ_NOC\01_RasterData\02_CuttedVRT' + files = file_search(searchDir, '*BOA.vrt', recursive=True) + S.loadImageFiles(files[0:5]) + return + + if False: + #load Pleiades data + searchDir = r'H:\Pleiades' + #files = file_search(searchDir, 'DIM*.xml', recursive=True) + files = file_search(searchDir, '*.jp2', recursive=True) + S.loadImageFiles(files[0:5]) + + if False: + #load RapidEye + searchDir = r'H:\RapidEye\3A' + files = file_search(searchDir, '*.tif', recursive=True) + files = [f for f in files if not f.endswith('_udm.tif')] + S.loadImageFiles(files[0:5]) + + if True: + #load Sentinel-2 + searchDir = r'H:\Sentinel2' + files = file_search(searchDir, 'S2*.xml', recursive=True) + files = [f+':20m' for f in files] + S.loadImageFiles(files[0:5]) + + if False: - from timeseriesviewer import file_search searchDir = r'H:\LandsatData\Landsat_NovoProgresso' files = file_search(searchDir, '*band4.img', recursive=True) - #searchDir = r'O:\SenseCarbonProcessing\BJ_NOC\01_RasterData\01_UncutVRT' - #files = file_search(searchDir, '*BOA.vrt', recursive=True) - files = files[0:10] S.loadImageFiles(files) return + + if False: files = [r'E:\_EnMAP\temp\temp_bj\landsat\37S\EB\LC81720342015129LGN00\LC81720342015129LGN00_sr.tif'] S.loadImageFiles(files) return - if True: + + if False: from timeseriesviewer import file_search files = file_search(r'E:\_EnMAP\temp\temp_bj\landsat\37S\EB', '*_sr.tif', recursive=True) #files = files[0:15] @@ -63,7 +92,7 @@ def sandboxGui(): S.spatialTemporalVis.MVC.createMapView() S.loadTimeSeries(path=PATH_EXAMPLE_TIMESERIES, n_max=1) return - if True: + if False: S.loadTimeSeries(path=PATH_EXAMPLE_TIMESERIES, n_max=100) return pass @@ -219,15 +248,11 @@ def gdal_qgis_benchmark(): s ="" - -if __name__ == '__main__': - import site, sys - #add site-packages to sys.path as done by enmapboxplugin.py - +def initQgisEnvironment(): + global qgsApp from timeseriesviewer import DIR_SITE_PACKAGES site.addsitedir(DIR_SITE_PACKAGES) - - #prepare QGIS environment + # prepare QGIS environment if sys.platform == 'darwin': PATH_QGS = r'/Applications/QGIS.app/Contents/MacOS' os.environ['GDAL_DATA'] = r'/usr/local/Cellar/gdal/1.11.3_1/share' @@ -235,19 +260,23 @@ if __name__ == '__main__': # assume OSGeo4W startup PATH_QGS = os.environ['QGIS_PREFIX_PATH'] assert os.path.exists(PATH_QGS) - qgsApp = QgsApplication([], True) QApplication.addLibraryPath(r'/Applications/QGIS.app/Contents/PlugIns') QApplication.addLibraryPath(r'/Applications/QGIS.app/Contents/PlugIns/qgis') qgsApp.setPrefixPath(PATH_QGS, True) qgsApp.initQgis() + +if __name__ == '__main__': + import site, sys + #add site-packages to sys.path as done by enmapboxplugin.py + + initQgisEnvironment() + #run tests if False: gdal_qgis_benchmark() if False: sandboxQgisBridge() if True: sandboxGui() - if False: test_component() - #close QGIS qgsApp.exec_() diff --git a/timeseriesviewer/timeseries.py b/timeseriesviewer/timeseries.py index d123df61f00f3fee41a072e4363a233ce8b94621..8f1681f6e274a2ce53c61d3935f93d0d46eacdb3 100644 --- a/timeseriesviewer/timeseries.py +++ b/timeseriesviewer/timeseries.py @@ -49,15 +49,6 @@ def convertMetricUnit(value, u1, u2): return value * 10**(e1-e2) -def verifyVRT(pathVRT): - - ds = gdal.Open(pathVRT) - if ds is None: - return False - s = "" - - return True - def getDS(pathOrDataset): if isinstance(pathOrDataset, gdal.Dataset): @@ -185,9 +176,12 @@ class SensorInstrument(QObject): def verifyInputImage(path, vrtInspection=''): + if path is None or not type(path) in [str, unicode]: + return None - if not os.path.exists(path): - print('{}Image does not exist: '.format(vrtInspection, path)) + path2 = path.split(':')[0] + if not os.path.exists(path2): + print('{}Image does not exist: '.format(vrtInspection, path2)) return False ds = gdal.Open(path) @@ -196,6 +190,9 @@ def verifyInputImage(path, vrtInspection=''): print('{}GDAL unable to open: '.format(vrtInspection, path)) return False + if ds.RasterCount == 0 and len(ds.GetSubDatasets()) > 0: + print('Can not open container {}.\nPlease specify a subdataset'.format(path)) + return False if ds.GetDriver().ShortName == 'VRT': vrtInspection = 'VRT Inspection {}\n'.format(path) nextFiles = set(ds.GetFileList()) - set([path]) @@ -220,6 +217,7 @@ class TimeSeriesDatum(QObject): :param path: :return: """ + p = findAbsolutePath(path) tsd = None if verifyInputImage(p): @@ -465,7 +463,7 @@ class TimeSeries(QObject): TSD.sensor = existingSensors[existingSensors.index(TSD.sensor)] if TSD in self.data: - six.print_('Time series datum already added: {} {}'.format(str(TSD), TSD.pathImg), file=sys.stderr) + six.print_('Time series date-time already added ({} {}). \nPlease use VRTs to mosaic images with same acquisition date-time.'.format(str(TSD), TSD.pathImg), file=sys.stderr) else: self.Sensors[TSD.sensor].append(TSD) #insert sorted @@ -489,6 +487,8 @@ class TimeSeries(QObject): def addFiles(self, files): assert isinstance(files, list) + files = [f for f in files if f is not None] + nMax = len(files) nDone = 0 self.sigLoadingProgress.emit(0,nMax, 'Start loading {} files...'.format(nMax))