[Kst] branches/work/kst/portto4/kst/src
Barth Netterfield
netterfield at astro.utoronto.ca
Sat Aug 21 04:51:20 CEST 2010
SVN commit 1166136 by netterfield:
Now matrixes can give plots a hint that their axis should be reversed - for
example, if the image is in RA/Dec.
Fits files look at the headers to decide.
Fits files also properly handle inverted or
non-inverted axis.
M +59 -33 datasources/fitsimage/fitsimage.cpp
M +12 -1 libkst/datamatrix.cpp
M +2 -0 libkst/datamatrix.h
M +1 -1 libkst/matrix.cpp
M +6 -0 libkst/matrix.h
M +4 -0 libkstapp/plotrenderitem.cpp
M +15 -0 libkstmath/image.cpp
M +3 -0 libkstmath/image.h
M +3 -0 libkstmath/relation.h
--- branches/work/kst/portto4/kst/src/datasources/fitsimage/fitsimage.cpp #1166135:1166136
@@ -107,12 +107,20 @@
opt.xSize = n_axes[0];
opt.ySize = n_axes[1];
+ char charCDelt1[] = "CDELT1";
+ char charCDelt2[] = "CDELT2";
+ double dx,dy;
+ fits_read_key(*_fitsfileptr, TDOUBLE, charCDelt1, &dx, NULL, &status);
+ fits_read_key(*_fitsfileptr, TDOUBLE, charCDelt2, &dy, NULL, &status);
+
+ if (!status) {
+ opt.invertXHint = (dx<0);
+ opt.invertYHint = (dy<0);
+ }
+
return opt;
}
-//int FitsImageSource::readMatrix(Kst::MatrixData* data, const QString& field, int xStart,
-// int yStart, int xNumSteps, int yNumSteps) {
-
int DataInterfaceFitsImageMatrix::read(const QString& field, DataMatrix::ReadInfo& p) {
long n_axes[2], fpixel[2] = {1, 1};
double nullval = NAN;
@@ -126,6 +134,8 @@
return 0;
}
+ //FIXME: support multiple HDUs
+
fits_get_img_size( *_fitsfileptr, 2, n_axes, &status );
if (status) {
@@ -162,55 +172,71 @@
int ni = p.xNumSteps * p.yNumSteps - 1;
+ // set the suggested matrix transform params: pixel index....
+ double x, y, dx, dy, cx, cy;
+ char charCRVal1[] = "CRVAL1";
+ char charCRVal2[] = "CRVAL2";
+ char charCDelt1[] = "CDELT1";
+ char charCDelt2[] = "CDELT2";
+ char charCRPix1[] = "CRPIX1";
+ char charCRPix2[] = "CRPIX2";
+ fits_read_key(*_fitsfileptr, TDOUBLE, charCRVal1, &x, NULL, &status);
+ fits_read_key(*_fitsfileptr, TDOUBLE, charCRVal2, &y, NULL, &status);
+ fits_read_key(*_fitsfileptr, TDOUBLE, charCDelt1, &dx, NULL, &status);
+ fits_read_key(*_fitsfileptr, TDOUBLE, charCDelt2, &dy, NULL, &status);
+ fits_read_key(*_fitsfileptr, TDOUBLE, charCRPix1, &cx, NULL, &status);
+ fits_read_key(*_fitsfileptr, TDOUBLE, charCRPix2, &cy, NULL, &status);
+
int i = 0;
- if (field==DefaultMatrixName) {
+ if ((dx<0) && (dy>0)) {
for (px = p.xStart; px < x1; px++) {
for (py = y1-1; py >= p.yStart; py--) {
z[ni - i] = buffer[px + py*n_axes[0]];
i++;
}
}
+ } else if ((dx>0) && (dy>0)) {
+ for (px = x1-1; px >= p.xStart; px--) {
+ for (py = y1-1; py >= p.yStart; py--) {
+ z[ni - i] = buffer[px + py*n_axes[0]];
+ i++;
}
-
+ }
+ } else if ((dx>0) && (dy<0)) {
+ for (px = x1-1; px >= p.xStart; px--) {
+ for (py = p.yStart; py < y1; py++) {
+ z[ni - i] = buffer[px + py*n_axes[0]];
+ i++;
+ }
+ }
+ } else if ((dx<0) && (dy<0)) {
+ for (px = p.xStart; px < x1; px++) {
+ for (py = p.yStart; py < y1; py++) {
+ z[ni - i] = buffer[px + py*n_axes[0]];
+ i++;
+ }
+ }
+ }
free(buffer);
-// NOTE: This code results in invalid stepsize / mins. Should be reviewed.
-// temporarily disabled.
-
- // set the suggested matrix transform params: pixel index....
-// double x, y, dx, dy, cx, cy;
-// char charCRVal1[] = "CRVAL1";
-// char charCRVal2[] = "CRVAL2";
-// char charCDelt1[] = "CDELT1";
-// char charCDelt2[] = "CDELT2";
-// char charCRPix1[] = "CRPIX1";
-// char charCRPix2[] = "CRPIX2";
-// fits_read_key(_fptr, TDOUBLE, charCRVal1, &x, NULL, &status);
-// fits_read_key(_fptr, TDOUBLE, charCRVal2, &y, NULL, &status);
-// fits_read_key(_fptr, TDOUBLE, charCDelt1, &dx, NULL, &status);
-// fits_read_key(_fptr, TDOUBLE, charCDelt2, &dy, NULL, &status);
-// fits_read_key(_fptr, TDOUBLE, charCRPix1, &cx, NULL, &status);
-// fits_read_key(_fptr, TDOUBLE, charCRPix2, &cy, NULL, &status);
-//
-// if (status) {
+ if (status) {
p.data->xMin = x0;
p.data->yMin = y0;
p.data->xStepSize = 1;
p.data->yStepSize = 1;
-// } else {
-// dx = fabs(dx);
-// dy = fabs(dy);
-// data->xStepSize = dx;
-// data->yStepSize = dy;
-// data->xMin = x - cx*dx;
-// data->yMin = y - cy*dy;
-// }
+ } else {
+ dx = fabs(dx);
+ dy = fabs(dy);
+ p.data->xStepSize = dx;
+ p.data->yStepSize = dy;
+ p.data->xMin = x - cx*dx;
+ p.data->yMin = y - cy*dy;
+ }
return(i);
}
-
bool DataInterfaceFitsImageMatrix::isValid(const QString& field) const {
return _matrixList.contains( field );
}
--- branches/work/kst/portto4/kst/src/libkst/datamatrix.cpp #1166135:1166136
@@ -38,7 +38,9 @@
DataMatrix::Optional::Optional() :
samplesPerFrame(-1),
xSize(-1),
- ySize(-1)
+ ySize(-1),
+ invertXHint(false),
+ invertYHint(false)
{
}
@@ -337,6 +339,9 @@
int xSize = file()->matrix().optional(_field).xSize;
int ySize = file()->matrix().optional(_field).ySize;
+ _invertXHint = file()->matrix().optional(_field).invertXHint;
+ _invertYHint = file()->matrix().optional(_field).invertYHint;
+
if (_reqXStart < 0) {
// counting from end
realXStart = xSize - _reqNX;
@@ -455,6 +460,8 @@
_minY = minY;
_stepX = stepX;
_stepY = stepY;
+ _invertXHint = false;
+ _invertYHint = false;
_saveable = true;
_editable = true;
@@ -463,6 +470,8 @@
Debug::self()->log(i18n("Data file for matrix %1 was not opened.", Name()), Debug::Warning);
} else {
_samplesPerFrameCache = file()->matrix().optional(_field).samplesPerFrame;
+ _invertXHint = file()->matrix().optional(_field).invertXHint;
+ _invertYHint = file()->matrix().optional(_field).invertYHint;
}
_aveReadBuffer = 0L;
@@ -483,6 +492,8 @@
if (file()) {
_samplesPerFrameCache = file()->matrix().optional(_field).samplesPerFrame;
+ _invertXHint = file()->matrix().optional(_field).invertXHint;
+ _invertYHint = file()->matrix().optional(_field).invertYHint;
}
resizeZ(0);
_NS = 0;
--- branches/work/kst/portto4/kst/src/libkst/datamatrix.h #1166135:1166136
@@ -61,6 +61,8 @@
int samplesPerFrame;
int xSize;
int ySize;
+ bool invertXHint;
+ bool invertYHint;
};
--- branches/work/kst/portto4/kst/src/libkst/matrix.cpp #1166135:1166136
@@ -42,7 +42,7 @@
Matrix::Matrix(ObjectStore *store)
: Primitive(store, 0L), _NS(0), _NRealS(0), _nX(1), _nY(0), _minX(0), _minY(0), _stepX(1), _stepY(1),
- _editable(false), _saveable(false), _z(0L), _zSize(0) {
+ _invertXHint(false), _invertYHint(false), _editable(false), _saveable(false), _z(0L), _zSize(0) {
_initializeShortName();
createScalars(store);
--- branches/work/kst/portto4/kst/src/libkst/matrix.h #1166135:1166136
@@ -130,6 +130,9 @@
int yNumSteps() const { return _nY; }
double xStepSize() const { return _stepX; }
double yStepSize() const { return _stepY; }
+ virtual bool invertXHint() const {return _invertXHint; }
+ virtual bool invertYHint() const {return _invertYHint; }
+
double minX() const { return _minX; }
double minY() const { return _minY; }
@@ -150,6 +153,9 @@
double _minY;
double _stepX;
double _stepY;
+ bool _invertXHint;
+ bool _invertYHint;
+
int _numNew; // number of new samples
QHash<QString, ScalarPtr> _statScalars; // statistics scalars
bool _editable : 1;
--- branches/work/kst/portto4/kst/src/libkstapp/plotrenderitem.cpp #1166135:1166136
@@ -127,9 +127,13 @@
void PlotRenderItem::addRelation(RelationPtr relation) {
if (relation) {
_relationList.append(relation);
+ if (_relationList.count() == 1) {
plotItem()->zoomMaximum();
+ plotItem()->xAxis()->setAxisReversed(relation->invertXHint());
+ plotItem()->yAxis()->setAxisReversed(relation->invertYHint());
}
}
+}
void PlotRenderItem::removeRelation(RelationPtr relation) {
--- branches/work/kst/portto4/kst/src/libkstmath/image.cpp #1166135:1166136
@@ -364,7 +364,22 @@
}
}
+bool Image::invertXHint() const {
+ if (_inputMatrices.contains(THEMATRIX)) {
+ return _inputMatrices[THEMATRIX]->invertXHint();
+ } else {
+ return false;
+ }
+}
+bool Image::invertYHint() const {
+ if (_inputMatrices.contains(THEMATRIX)) {
+ return _inputMatrices[THEMATRIX]->invertYHint();
+ } else {
+ return false;
+ }
+}
+
QString Image::xLabel() const {
if (_inputMatrices.contains(THEMATRIX)) {
return _inputMatrices[THEMATRIX]->xLabel();
--- branches/work/kst/portto4/kst/src/libkstmath/image.h #1166135:1166136
@@ -117,6 +117,9 @@
virtual QString descriptionTip() const;
+ virtual bool invertXHint() const;
+ virtual bool invertYHint() const;
+
protected:
Image(ObjectStore *store);
virtual ~Image();
--- branches/work/kst/portto4/kst/src/libkstmath/relation.h #1166135:1166136
@@ -166,6 +166,9 @@
MatrixMap& inputMatrices() { return _inputMatrices; }
MatrixMap& outputMatrices() { return _outputMatrices; }
+ virtual bool invertXHint() const {return false;}
+ virtual bool invertYHint() const {return false;}
+
protected:
virtual void writeLockInputsAndOutputs() const;
virtual void unlockInputsAndOutputs() const;
More information about the Kst
mailing list