[Kst] branches/work/kst/portto4/kst
Barth Netterfield
netterfield at astro.utoronto.ca
Wed Sep 29 19:59:36 CEST 2010
SVN commit 1180993 by netterfield:
Three things:
1) fits image data source can find and export units and quantity metadata.
2) matrixes use units and quantity metadata to determine default X and Y labels.
3) X only and Y only zoom modes shouldn't effect scrolling with the keyboard.
M +1 -1 run-kst
M +53 -2 src/datasources/fitsimage/fitsimage.cpp
M +84 -0 src/libkst/datamatrix.cpp
M +13 -0 src/libkst/datamatrix.h
M +2 -9 src/libkst/datavector.cpp
M +1 -1 src/libkst/matrix.h
M +16 -16 src/libkstapp/plotitem.cpp
--- branches/work/kst/portto4/kst/run-kst #1180992:1180993
@@ -6,4 +6,4 @@
export BUILDDIR=$PWD/build
export LD_LIBRARY_PATH=$BUILDDIR/lib:$LD_LIBRARY_PATH
-$BUILDDIR/bin/kst2 "$@"
+$BUILDDIR/build/bin/kst2 "$@"
--- branches/work/kst/portto4/kst/src/datasources/fitsimage/fitsimage.cpp #1180992:1180993
@@ -66,8 +66,8 @@
void setDataInfo(const QString&, const DataMatrix::DataInfo&) {}
// meta data
- QMap<QString, double> metaScalars(const QString&) { return QMap<QString, double>(); }
- QMap<QString, QString> metaStrings(const QString&) { return QMap<QString, QString>(); }
+ QMap<QString, double> metaScalars(const QString &m);
+ QMap<QString, QString> metaStrings(const QString &m);
// no interface
@@ -150,6 +150,57 @@
return info;
}
+QMap<QString, double> DataInterfaceFitsImageMatrix::metaScalars(const QString &matrix) {
+ qDebug() << "metascalars for " << matrix;
+ QMap<QString, double> M;
+
+ return M;
+}
+
+QMap<QString, QString> DataInterfaceFitsImageMatrix::metaStrings(const QString &matrix) {
+
+ QMap<QString, QString> M;
+ int status = 0;
+ int type;
+ char instr[128];
+
+ M.clear();
+
+ if ( !*_fitsfileptr || !_matrixHash.contains( matrix ) ) {
+ return M;
+ }
+
+ fits_movabs_hdu(*_fitsfileptr, _matrixHash[matrix], &type, &status);
+
+ fits_read_key(*_fitsfileptr, TSTRING, "CTYPE1", instr, NULL, &status);
+ if (!status) {
+ M.insert("x_quantity", QString(instr).trimmed());
+ }
+ status = 0;
+ fits_read_key(*_fitsfileptr, TSTRING, "CTYPE2", instr, NULL, &status);
+ if (!status) {
+ M.insert("y_quantity", QString(instr).trimmed());
+ }
+ status = 0;
+ fits_read_key(*_fitsfileptr, TSTRING, "CRUNIT1", instr, NULL, &status);
+ if (!status) {
+ M.insert("x_units", QString(instr).trimmed());
+ }
+ status = 0;
+ fits_read_key(*_fitsfileptr, TSTRING, "CRUNIT2", instr, NULL, &status);
+ if (!status) {
+ M.insert("y_units", QString(instr).trimmed());
+ }
+ status = 0;
+ fits_read_key(*_fitsfileptr, TSTRING, "BUNIT", instr, NULL, &status);
+ if (!status) {
+ M.insert("z_units", QString(instr).trimmed());
+ }
+ status = 0;
+
+ return M;
+}
+
int DataInterfaceFitsImageMatrix::read(const QString& field, DataMatrix::ReadInfo& p) {
long n_axes[2], fpixel[2] = {1, 1};
double nullval = NAN;
--- branches/work/kst/portto4/kst/src/libkst/datamatrix.cpp #1180992:1180993
@@ -320,6 +320,87 @@
return LLONG_MAX;
}
+void DataMatrix::_resetFieldMetadata() {
+ _resetFieldScalars();
+ _resetFieldStrings();
+}
+
+void DataMatrix::_resetFieldScalars() {
+
+}
+
+void DataMatrix::_resetFieldStrings() {
+ const QMap<QString, QString> meta_strings = file()->matrix().metaStrings(_field);
+
+ QStringList fieldStringKeys = _fieldStrings.keys();
+ // remove field strings that no longer need to exist
+ readLock();
+ for (int i=0; i<fieldStringKeys.count(); i++) {
+ QString key = fieldStringKeys.at(i);
+ if (!meta_strings.contains(key)) {
+ StringPtr sp = _fieldStrings[key];
+ _fieldStrings.remove(key);
+ sp = 0L;
+ }
+ }
+ // find or insert strings, to set their value
+ QMapIterator<QString, QString> it(meta_strings);
+ while (it.hasNext()) {
+ it.next();
+ QString key = it.key();
+ StringPtr sp;
+ if (!_fieldStrings.contains(key)) { // insert a new one
+ _fieldStrings.insert(key, sp = store()->createObject<String>());
+ sp->setProvider(this);
+ sp->setSlaveName(key);
+ sp->_KShared_ref();
+ } else { // find it
+ sp = _fieldStrings[key];
+ }
+ sp->setValue(it.value());
+ }
+ unlock();
+}
+
+QString DataMatrix::xLabel() const {
+ QString label;
+
+ if (_fieldStrings.contains("x_quantity")) {
+ label = _fieldStrings.value("x_quantity")->value();
+ }
+
+ if (!label.isEmpty()) {
+ if (_fieldStrings.contains("x_units")) {
+ QString units = _fieldStrings.value("x_units")->value();
+ if (!units.isEmpty()) {
+ label += " \\[" + units + "\\]";
+ }
+ }
+ }
+
+ return label;
+
+}
+
+QString DataMatrix::yLabel() const {
+ QString label;
+
+ if (_fieldStrings.contains("y_quantity")) {
+ label = _fieldStrings.value("y_quantity")->value();
+ }
+
+ if (!label.isEmpty()) {
+ if (_fieldStrings.contains("y_units")) {
+ QString units = _fieldStrings.value("y_units")->value();
+ if (!units.isEmpty()) {
+ label += " \\[" + units + "\\]";
+ }
+ }
+ }
+
+ return label;
+}
+
void DataMatrix::internalUpdate() {
if (file()) {
file()->writeLock();
@@ -486,6 +567,8 @@
_lastDoSkip = false;;
_lastSkip = 1;
+ _resetFieldMetadata();
+
}
@@ -502,6 +585,7 @@
_NS = 0;
_nX = 1;
_nY = 0;
+ _resetFieldMetadata();
}
--- branches/work/kst/portto4/kst/src/libkst/datamatrix.h #1180992:1180993
@@ -119,6 +119,9 @@
virtual QString propertyString() const;
virtual void internalUpdate();
+
+ virtual QString xLabel() const;
+ virtual QString yLabel() const;
protected:
DataMatrix(ObjectStore *store);
virtual ~DataMatrix();
@@ -131,6 +134,8 @@
virtual QString _automaticDescriptiveName() const;
+ virtual void _resetFieldMetadata();
+
private:
void commonConstructor(DataSourcePtr file, const QString &field,
int reqXStart, int reqYStart, int reqNX, int reqNY,
@@ -140,6 +145,10 @@
void doUpdateSkip(int realXStart, int realYStart);
void doUpdateNoSkip(int realXStart, int realYStart);
+ virtual void _resetFieldScalars();
+ virtual void _resetFieldStrings();
+
+
// values requested; may be different from actual matrix range
int _reqXStart, _reqYStart, _reqNX, _reqNY;
@@ -160,6 +169,10 @@
int _samplesPerFrameCache; // cache the samples per frame of the field in datasource
int readMatrix(MatrixData* data, const QString& matrix, int xStart, int yStart, int xNumSteps, int yNumSteps, int skip);
+
+ QHash<QString, ScalarPtr> _fieldScalars;
+ QHash<QString, StringPtr> _fieldStrings;
+
};
typedef SharedPtr<DataMatrix> DataMatrixPtr;
--- branches/work/kst/portto4/kst/src/libkst/datavector.cpp #1180992:1180993
@@ -2,8 +2,8 @@
datavector.cpp - description
-------------------
begin : Fri Sep 22 2000
- copyright : (C) 2000 by cbn
- email :
+ copyright : (C) 2000-2010 by C. Barth Netterfield
+ email : netterfield at astro.utoronto.ca
***************************************************************************/
/***************************************************************************
@@ -623,12 +623,8 @@
}
void DataVector::_resetFieldStrings() {
- // Note: this does not necessarily preserve order if the
- // datasource or field have been changed. If dynamic
- // fieldScalars are ever wanted, this should be fixed.
const QMap<QString, QString> meta_strings = file()->vector().metaStrings(_field);
-
QStringList fieldStringKeys = _fieldStrings.keys();
// remove field strings that no longer need to exist
readLock();
@@ -663,9 +659,6 @@
void DataVector::_resetFieldScalars() {
- // Note: this does not necessarily preseve order if the
- // datasource or field have been changed. If dynamic
- // fieldScalars are ever wanted, this should be fixed.
const QMap<QString, double> meta_scalars = file()->vector().metaScalars(_field);
--- branches/work/kst/portto4/kst/src/libkst/matrix.h #1180992:1180993
@@ -3,7 +3,7 @@
-------------------
begin : Mon July 19 2004
copyright : (C) 2004 by University of British Columbia
- email :
+ email : netterfield at astro.utoronto.ca
***************************************************************************/
/***************************************************************************
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.cpp #1180992:1180993
@@ -3001,10 +3001,10 @@
void PlotItem::zoomXRight(bool force) {
- if (zoomOnlyMode() == View::ZoomOnlyX) {
- zoomXOut(force);
- return;
- }
+ //if (zoomOnlyMode() == View::ZoomOnlyX) {
+ // zoomXOut(force);
+ // return;
+ //}
#if DEBUG_ZOOM
qDebug() << "zoomXRight" << endl;
#endif
@@ -3019,10 +3019,10 @@
void PlotItem::zoomXLeft(bool force) {
- if (zoomOnlyMode() == View::ZoomOnlyX) {
- zoomXIn(force);
- return;
- }
+ //if (zoomOnlyMode() == View::ZoomOnlyX) {
+ // zoomXIn(force);
+ // return;
+ //}
#if DEBUG_ZOOM
qDebug() << "zoomXLeft" << endl;
#endif
@@ -3159,10 +3159,10 @@
void PlotItem::zoomYUp(bool force) {
- if (zoomOnlyMode() == View::ZoomOnlyY) {
- zoomYOut(force);
- return;
- }
+ //if (zoomOnlyMode() == View::ZoomOnlyY) {
+ // zoomYOut(force);
+ // return;
+ //}
#if DEBUG_ZOOM
qDebug() << "zoomYUp" << endl;
#endif
@@ -3177,10 +3177,10 @@
void PlotItem::zoomYDown(bool force) {
- if (zoomOnlyMode() == View::ZoomOnlyY) {
- zoomYIn(force);
- return;
- }
+ //if (zoomOnlyMode() == View::ZoomOnlyY) {
+ // zoomYIn(force);
+ // return;
+ //}
#if DEBUG_ZOOM
qDebug() << "zoomYDown" << endl;
#endif
More information about the Kst
mailing list