Commit 6b600e4f authored by Benjamin Jakimow's avatar Benjamin Jakimow
Browse files
parent ff7f9c62
......@@ -2750,7 +2750,7 @@ class SpectralLibrary(QgsVectorLayer):
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 = []
for k, profiles in self.groupBySpectralProperties().items():
xValues, xUnit, yUnit = k
......@@ -2798,8 +2798,9 @@ class SpectralLibrary(QgsVectorLayer):
if path is None:
path, filter = QFileDialog.getSaveFileName(parent=kwds.get('parent'),
caption='Save Spectral Library',
directory=QgsFileUtils.stringToSafeFilename(self.name()),
filter=FILTERS)
directory=QgsFileUtils.stringToSafeFilename(self.name()+'.gpkg'),
filter=FILTERS,
initialFilter='Geopackage (*.gpkg)')
if isinstance(path, pathlib.Path):
path = path.as_posix()
......@@ -2816,7 +2817,8 @@ class SpectralLibrary(QgsVectorLayer):
elif ext in ['.json', '.geojson', '.geojsonl', '.csv', '.gpkg']:
return VectorSourceSpectralLibraryIO.write(self, path, **kwds)
else:
raise Exception(f'Filetype not supported: {path}')
return []
def spectralValueFields(self) -> typing.List[QgsField]:
......
......@@ -413,9 +413,11 @@ class SpectralProfilePlotDataItem(PlotDataItem):
try:
x = self.mXValueConversionFunction(self.mInitialDataX, 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:
success = True
except Exception as ex:
print(ex)
pass
......@@ -425,6 +427,8 @@ class SpectralProfilePlotDataItem(PlotDataItem):
if True:
# handle failed removal of NaN
# see https://github.com/pyqtgraph/pyqtgraph/issues/1057
# 1. convert to numpy arrays
if not isinstance(y, np.ndarray):
y = np.asarray(y, dtype=np.float)
if not isinstance(x, np.ndarray):
......@@ -442,9 +446,18 @@ class SpectralProfilePlotDataItem(PlotDataItem):
y = y[keep]
x = x[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)
else:
self.setData(x=x, y=y, connect='finite')
self.setVisible(True)
else:
# self.setData(x=[], y=[])
......@@ -1393,7 +1406,7 @@ class SpectralLibraryPlotWidget(pg.PlotWidget):
self.mNumberOfValueErrorsProfiles += 1
else:
# 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():
self.mNumberOfEmptyProfiles += 1
continue
......
......@@ -881,8 +881,8 @@ class TestObjects():
lyr = dsSrc.GetLayer(0)
assert isinstance(lyr, ogr.Layer)
assert lyr.GetFeatureCount() > 0
uri = '{}|{}'.format(dsSrc.GetName(), lyr.GetName())
#uri = '{}|{}'.format(dsSrc.GetName(), lyr.GetName())
uri = dsSrc.GetName()
# dsSrc = None
vl = QgsVectorLayer(uri, 'testlayer', 'ogr', lyrOptions)
assert isinstance(vl, QgsVectorLayer)
......
......@@ -1552,19 +1552,24 @@ def parseFWHM(dataset) -> typing.Tuple[np.ndarray]:
return None
def parseWavelength(dataset) -> typing.Tuple[np.ndarray, str]:
"""
Returns the wavelength + wavelength unit of a raster
:param dataset:
:return: (wl, wl_u) or (None, None), if not existing
"""
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:
dataset = gdalDataset(dataset)
except:
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:
def checkWavelengthUnit(key: str, value: str) -> str:
wlu: str = None
value = value.strip()
if re.search(r'^wavelength[ _]?units?', key, re.I):
......@@ -1574,41 +1579,37 @@ def parseWavelength(dataset) -> typing.Tuple[np.ndarray, str]:
if wlu is not None:
return wlu
if re.search(r'^Wavenumber$', values, re.I):
if re.search(r'^Wavenumber$', value, re.I):
wlu = '-'
elif re.search(r'^GHz$', values, re.I):
elif re.search(r'^GHz$', value, re.I):
wlu = 'GHz'
elif re.search(r'^MHz$', values, re.I):
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)$', values, re.I):
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?)$', values, re.I):
elif re.search(r'^(Seconds?|s|secs?)$', value, re.I):
wlu = 's'
elif re.search(r'^Index$', values, re.I):
elif re.search(r'^Index$', value, 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 = ','
def parseWavelength(dataset) -> typing.Tuple[np.ndarray, str]:
"""
Returns the wavelength + wavelength unit of a raster
:param dataset:
:return: (wl, wl_u) or (None, None), if not existing
"""
try:
wl = np.fromstring(values, count=expected, sep=sep)
except ValueError as exV:
pass
except Exception as ex:
pass
return wl
dataset = gdalDataset(dataset)
except AssertionError:
return None, None
if isinstance(dataset, gdal.Dataset):
# 1. check on raster level
......@@ -1695,6 +1696,9 @@ def parseWavelength(dataset) -> typing.Tuple[np.ndarray, str]:
wl = UnitLookup.convertDateUnit(datetime64(wl, dpy=365), 'DecimalYear')
return wl, wlu
else:
return None, None
class Singleton(type):
......
......@@ -48,7 +48,7 @@ CI=True
export CI
find . -name "*.pyc" -exec rm -f {} \;
export PYTHONPATH="${PYTHONPATH}:$(pwd)"
export PYTHONPATH="${PYTHONPATH}:$(pwd):/usr/share/qgis/python/plugins"
# 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