Commit 6b600e4f authored by Benjamin Jakimow's avatar Benjamin Jakimow
Browse files
parent ff7f9c62
...@@ -2750,7 +2750,7 @@ class SpectralLibrary(QgsVectorLayer): ...@@ -2750,7 +2750,7 @@ class SpectralLibrary(QgsVectorLayer):
basename, ext = os.path.splitext(pathOne.name) basename, ext = os.path.splitext(pathOne.name)
assert pathOne.parent.is_dir() assert pathOne.as_posix().startswith('/vsimem/') or pathOne.parent.is_dir(), f'Canot write to {pathOne}'
imageFiles = [] imageFiles = []
for k, profiles in self.groupBySpectralProperties().items(): for k, profiles in self.groupBySpectralProperties().items():
xValues, xUnit, yUnit = k xValues, xUnit, yUnit = k
...@@ -2798,8 +2798,9 @@ class SpectralLibrary(QgsVectorLayer): ...@@ -2798,8 +2798,9 @@ class SpectralLibrary(QgsVectorLayer):
if path is None: if path is None:
path, filter = QFileDialog.getSaveFileName(parent=kwds.get('parent'), path, filter = QFileDialog.getSaveFileName(parent=kwds.get('parent'),
caption='Save Spectral Library', caption='Save Spectral Library',
directory=QgsFileUtils.stringToSafeFilename(self.name()), directory=QgsFileUtils.stringToSafeFilename(self.name()+'.gpkg'),
filter=FILTERS) filter=FILTERS,
initialFilter='Geopackage (*.gpkg)')
if isinstance(path, pathlib.Path): if isinstance(path, pathlib.Path):
path = path.as_posix() path = path.as_posix()
...@@ -2816,7 +2817,8 @@ class SpectralLibrary(QgsVectorLayer): ...@@ -2816,7 +2817,8 @@ class SpectralLibrary(QgsVectorLayer):
elif ext in ['.json', '.geojson', '.geojsonl', '.csv', '.gpkg']: elif ext in ['.json', '.geojson', '.geojsonl', '.csv', '.gpkg']:
return VectorSourceSpectralLibraryIO.write(self, path, **kwds) return VectorSourceSpectralLibraryIO.write(self, path, **kwds)
else:
raise Exception(f'Filetype not supported: {path}')
return [] return []
def spectralValueFields(self) -> typing.List[QgsField]: def spectralValueFields(self) -> typing.List[QgsField]:
......
...@@ -413,9 +413,11 @@ class SpectralProfilePlotDataItem(PlotDataItem): ...@@ -413,9 +413,11 @@ class SpectralProfilePlotDataItem(PlotDataItem):
try: try:
x = self.mXValueConversionFunction(self.mInitialDataX, self) x = self.mXValueConversionFunction(self.mInitialDataX, self)
y = self.mYValueConversionFunction(self.mInitialDataY, self) y = self.mYValueConversionFunction(self.mInitialDataY, self)
if isinstance(x, (list, np.ndarray)) and isinstance(y, (list, np.ndarray)) and len(x) > 0 and len( if isinstance(x, (list, np.ndarray)) and \
isinstance(y, (list, np.ndarray)) and len(x) > 0 and len(
y) > 0: y) > 0:
success = True success = True
except Exception as ex: except Exception as ex:
print(ex) print(ex)
pass pass
...@@ -425,6 +427,8 @@ class SpectralProfilePlotDataItem(PlotDataItem): ...@@ -425,6 +427,8 @@ class SpectralProfilePlotDataItem(PlotDataItem):
if True: if True:
# handle failed removal of NaN # handle failed removal of NaN
# see https://github.com/pyqtgraph/pyqtgraph/issues/1057 # see https://github.com/pyqtgraph/pyqtgraph/issues/1057
# 1. convert to numpy arrays
if not isinstance(y, np.ndarray): if not isinstance(y, np.ndarray):
y = np.asarray(y, dtype=np.float) y = np.asarray(y, dtype=np.float)
if not isinstance(x, np.ndarray): if not isinstance(x, np.ndarray):
...@@ -442,9 +446,18 @@ class SpectralProfilePlotDataItem(PlotDataItem): ...@@ -442,9 +446,18 @@ class SpectralProfilePlotDataItem(PlotDataItem):
y = y[keep] y = y[keep]
x = x[keep] x = x[keep]
connected = connected[keep] connected = connected[keep]
# convert date units to float with decimal year and second precision
if isinstance(x[0], (datetime.datetime, datetime.date, datetime.time, np.datetime64)):
x = convertDateUnit(datetime64(x), 'DecimalYear')
if isinstance(y[0], (datetime.datetime, datetime.date, datetime.time, np.datetime64)):
y = convertDateUnit(datetime64(y), 'DecimalYear')
self.setData(x=x, y=y, connect=connected) self.setData(x=x, y=y, connect=connected)
else: else:
self.setData(x=x, y=y, connect='finite') self.setData(x=x, y=y, connect='finite')
self.setVisible(True) self.setVisible(True)
else: else:
# self.setData(x=[], y=[]) # self.setData(x=[], y=[])
...@@ -1393,7 +1406,7 @@ class SpectralLibraryPlotWidget(pg.PlotWidget): ...@@ -1393,7 +1406,7 @@ class SpectralLibraryPlotWidget(pg.PlotWidget):
self.mNumberOfValueErrorsProfiles += 1 self.mNumberOfValueErrorsProfiles += 1
else: else:
# create a new PDI # create a new PDI
profile = self.speclib().profile(fid, value_field=field_name) profile: SpectralProfile = self.speclib().profile(fid, value_field=field_name)
if not isinstance(profile, SpectralProfile) or profile.isEmpty(): if not isinstance(profile, SpectralProfile) or profile.isEmpty():
self.mNumberOfEmptyProfiles += 1 self.mNumberOfEmptyProfiles += 1
continue continue
......
...@@ -881,8 +881,8 @@ class TestObjects(): ...@@ -881,8 +881,8 @@ class TestObjects():
lyr = dsSrc.GetLayer(0) lyr = dsSrc.GetLayer(0)
assert isinstance(lyr, ogr.Layer) assert isinstance(lyr, ogr.Layer)
assert lyr.GetFeatureCount() > 0 assert lyr.GetFeatureCount() > 0
uri = '{}|{}'.format(dsSrc.GetName(), lyr.GetName()) #uri = '{}|{}'.format(dsSrc.GetName(), lyr.GetName())
uri = dsSrc.GetName()
# dsSrc = None # dsSrc = None
vl = QgsVectorLayer(uri, 'testlayer', 'ogr', lyrOptions) vl = QgsVectorLayer(uri, 'testlayer', 'ogr', lyrOptions)
assert isinstance(vl, QgsVectorLayer) assert isinstance(vl, QgsVectorLayer)
......
...@@ -1552,6 +1552,53 @@ def parseFWHM(dataset) -> typing.Tuple[np.ndarray]: ...@@ -1552,6 +1552,53 @@ def parseFWHM(dataset) -> typing.Tuple[np.ndarray]:
return None return None
def checkWavelength(key: str, values: str, expected: int = 1) -> np.ndarray:
wl: np.ndarray = None
if re.search(r'^wavelengths?$', key, re.I):
# remove trailing / ending { } and whitespace
values = re.sub('[{}]', '', values).strip()
if ',' not in values:
sep = ' '
else:
sep = ','
try:
wl = np.fromstring(values, count=expected, sep=sep)
except ValueError as exV:
pass
except Exception as ex:
pass
return wl
def checkWavelengthUnit(key: str, value: str) -> str:
wlu: str = None
value = value.strip()
if re.search(r'^wavelength[ _]?units?', key, re.I):
# metric length units
wlu = UnitLookup.baseUnit(value)
if wlu is not None:
return wlu
if re.search(r'^Wavenumber$', value, re.I):
wlu = '-'
elif re.search(r'^GHz$', value, re.I):
wlu = 'GHz'
elif re.search(r'^MHz$', value, re.I):
wlu = 'MHz'
# date / time units
elif re.search(r'^(Date|DTG|Date[_ ]?Time[_ ]?Group|Date[_ ]?Stamp|Time[_ ]?Stamp)$', value, re.I):
wlu = 'DateTime'
elif re.search(r'^Decimal[_ ]?Years?$', value, re.I):
wlu = 'DecimalYear'
elif re.search(r'^(Seconds?|s|secs?)$', value, re.I):
wlu = 's'
elif re.search(r'^Index$', value, re.I):
wlu = None
else:
wlu = None
return wlu
def parseWavelength(dataset) -> typing.Tuple[np.ndarray, str]: def parseWavelength(dataset) -> typing.Tuple[np.ndarray, str]:
""" """
Returns the wavelength + wavelength unit of a raster Returns the wavelength + wavelength unit of a raster
...@@ -1561,54 +1608,8 @@ def parseWavelength(dataset) -> typing.Tuple[np.ndarray, str]: ...@@ -1561,54 +1608,8 @@ def parseWavelength(dataset) -> typing.Tuple[np.ndarray, str]:
try: try:
dataset = gdalDataset(dataset) dataset = gdalDataset(dataset)
except: except AssertionError:
pass return None, None
def checkWavelengthUnit(key: str, value: str) -> str:
wlu: str = None
value = value.strip()
if re.search(r'^wavelength[ _]?units?', key, re.I):
# metric length units
wlu = UnitLookup.baseUnit(value)
if wlu is not None:
return wlu
if re.search(r'^Wavenumber$', values, re.I):
wlu = '-'
elif re.search(r'^GHz$', values, re.I):
wlu = 'GHz'
elif re.search(r'^MHz$', values, re.I):
wlu = 'MHz'
# date / time units
elif re.search(r'^(Date|DTG|Date[_ ]?Time[_ ]?Group|Date[_ ]?Stamp|Time[_ ]?Stamp)$', values, re.I):
wlu = 'DateTime'
elif re.search(r'^Decimal[_ ]?Years?$', value, re.I):
wlu = 'DecimalYear'
elif re.search(r'^(Seconds?|s|secs?)$', values, re.I):
wlu = 's'
elif re.search(r'^Index$', values, re.I):
wlu = None
else:
wlu = None
return wlu
def checkWavelength(key: str, values: str, expected:int = 1) -> np.ndarray:
wl: np.ndarray = None
if re.search(r'^wavelengths?$', key, re.I):
# remove trailing / ending { } and whitespace
values = re.sub('[{}]', '', values).strip()
if ',' not in values:
sep = ' '
else:
sep = ','
try:
wl = np.fromstring(values, count=expected, sep=sep)
except ValueError as exV:
pass
except Exception as ex:
pass
return wl
if isinstance(dataset, gdal.Dataset): if isinstance(dataset, gdal.Dataset):
# 1. check on raster level # 1. check on raster level
...@@ -1694,7 +1695,10 @@ def parseWavelength(dataset) -> typing.Tuple[np.ndarray, str]: ...@@ -1694,7 +1695,10 @@ def parseWavelength(dataset) -> typing.Tuple[np.ndarray, str]:
# make decimal-year values leap-year sensitive # make decimal-year values leap-year sensitive
wl = UnitLookup.convertDateUnit(datetime64(wl, dpy=365), 'DecimalYear') wl = UnitLookup.convertDateUnit(datetime64(wl, dpy=365), 'DecimalYear')
return wl, wlu return wl, wlu
else:
return None, None
class Singleton(type): class Singleton(type):
......
...@@ -48,7 +48,7 @@ CI=True ...@@ -48,7 +48,7 @@ CI=True
export CI export CI
find . -name "*.pyc" -exec rm -f {} \; find . -name "*.pyc" -exec rm -f {} \;
export PYTHONPATH="${PYTHONPATH}:$(pwd)" export PYTHONPATH="${PYTHONPATH}:$(pwd):/usr/share/qgis/python/plugins"
# python3 scripts/setup_repository.py # python3 scripts/setup_repository.py
""" """
......
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