Loading...
Searching...
No Matches
FITSCoordinateUtil.h
Go to the documentation of this file.
//# FITSCoordinateUtil.h: functions to inter-convert between CoordinateSystems and FITS
//# Copyright (C) 1997,1998,1999,2000,2001,2002,2003,2004
//# Associated Universities, Inc. Washington DC, USA.
//#
//# This library is free software; you can redistribute it and/or modify it
//# under the terms of the GNU Library General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or (at your
//# option) any later version.
//#
//# This library is distributed in the hope that it will be useful, but WITHOUT
//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
//# License for more details.
//#
//# You should have received a copy of the GNU Library General Public License
//# along with this library; if not, write to the Free Software Foundation,
//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
//#
//# Correspondence concerning AIPS++ should be addressed as follows:
//# Internet email: casa-feedback@nrao.edu.
//# Postal address: AIPS++ Project Office
//# National Radio Astronomy Observatory
//# 520 Edgemont Road
//# Charlottesville, VA 22903-2475 USA
#ifndef COORDINATES_FITSCOORDINATEUTIL_H
#define COORDINATES_FITSCOORDINATEUTIL_H
#include <casacore/casa/aips.h>
#include <casacore/measures/Measures/MDirection.h>
#include <casacore/measures/Measures/MFrequency.h>
#include <casacore/coordinates/Coordinates/ObsInfo.h>
struct wcsprm;
namespace casacore { //# NAMESPACE CASACORE - BEGIN
class Coordinate;
class CoordinateSystem;
class StokesCoordinate;
class Projection;
class IPosition;
class LogIO;
class Record;
// <summary>
// </summary>
// <use visibility=export>
// <reviewed reviewer="" date="" tests="">
// </reviewed>
//
// <prerequisite>
// <li> <linkto class=Coordinate>CoordinateSystem</linkto>
// </prerequisite>
// <synopsis>
// Helper functions to inter-converft between a CoordinateSystem and FITS
// headers.
// </synopsis>
// <note role=caution>
// </note>
// <example>
// </example>
// <motivation>
// I hate FITS
// </motivation>
//
// <thrown>
// <li> AipsError
// </thrown>
//
// <todo asof="2004/08/23">
// </todo>
//
class FITSCoordinateUtil
{
public:
// Constructor
FITSCoordinateUtil() {;};
// Convert CoordinateSystem to a FITS header. In the record
// the keywords are vectors, it is expected that the actual FITS code will
// split them into scalars and upcase the names. Returns False if one of the
// keywords is already taken.
//
// If writeWCS is True, attempt to write the WCS convention (Greisen and
// Calabretta "Representation of celestial coordinates in FITS") as
// approved in version 3.0 of the FITS standard.
// Use <src>oneRelative=True</src> to convert zero-relative pixel coordinates to
// one-relative FITS coordinates.
//
// prefix gives the prefix for the FITS keywords. E.g.,
// if prefix="c" then crval, cdelt etc.
// if prefix="d" then drval, ddelt etc.
//# Much of the work in to/from fits should be moved to the individual
//# classes.
Bool toFITSHeader(RecordInterface &header,
IPosition &shape,
const CoordinateSystem& cSys,
Bool oneRelative,
Char prefix = 'c', Bool writeWCS=True,
Bool preferVelocity=True,
Bool opticalVelocity=True,
Bool preferWavelength=False,
Bool airWavelength=False) const;
// Probably even if we return False we should set up the best linear
// coordinate that we can. On output, <src>stokesFITSValue</src>
// holds the FITS value of any unofficial Stokes (beam, optical depth,
// spectral index) for the last unofficial value accessed (-1 if none).
// The idea is that if the Stokes axis is of length one and holds an unofficial value,
// you should drop the STokes axis and convert that value to <src>ImageInfo::ImageTypes</src>
// with <src>ImageInfo::imageTypeFromFITSValue</src>. If on input, <src>stokesFITSValue</src>
// is positive, then a warning is issued if any unofficial values are encountered.
// Otherwise no warning is issued.
//# cf comment in toFITS.
//<group>
Bool fromFITSHeader(Int& stokesFITSValue,
CoordinateSystem& coordsys,
RecordInterface& recHeader,
const Vector<String>& header,
const IPosition& shape,
uInt which=0) const;
//</group>
// Helper function to create a FITS style CTYPE vector from the
// axis names from a DirectionCoordinate
static Vector<String> cTypeFromDirection (Bool& isNCP, const Projection& proj,
const Vector<String>& axisNames,
Double refLat, Bool printError);
static Vector<String> cTypeFromDirection (const Projection& proj,
const Vector<String>& axisNames,
Bool printError);
private:
// Generate actual FITS keywords
Bool generateFITSKeywords (LogIO& os, Bool& isNCP,
Double& longPole, Double& latPole,
Vector<Double>& crval,
Vector<Double>& crpix,
Vector<Double>& cdelt,
//# Vector<Double>& crota,
//# Vector<Double>& projp,
Vector<Double>& pvi_ma,
Vector<String>& ctype,
Vector<String>& cunit,
Matrix<Double>& pc,
const CoordinateSystem& cSys,
Int skyCoord, Int longAxis, Int latAxis,
Int specAxis, Int stokesAxis,
Bool writeWCS, Double offset,
const String& sprefix) const;
// Special Stokes processing for conversion to FITS header
Bool toFITSHeaderStokes(Vector<Double>& crval,
Vector<Double>& crpix,
Vector<Double>& cdelt,
LogIO& os,
const CoordinateSystem& coordsys,
Int stokesAxis, Int stokesCoord) const;
// Look for Coordinate type and add to CS
// <group>
Bool addDirectionCoordinate (CoordinateSystem& cSys, Vector<Int>& axes,
const wcsprm& wcs, LogIO& os) const;
Bool addSpectralCoordinate (CoordinateSystem& cSys, Int& axis,
const wcsprm& wcs, const IPosition& shape,
LogIO& os) const;
Bool addStokesCoordinate (CoordinateSystem& cSys, Int& axis, Int& stokesFITSValue,
const wcsprm& wcs, const IPosition& shape,
LogIO& os) const;
Bool addLinearCoordinate (CoordinateSystem& cSys, Vector<Int>& axes,
const wcsprm& wcs, LogIO& os) const;
// </group>
// Decode values from WCS structures which are generated via the wcs FITS parser
// <group>
Bool directionSystemFromWCS (LogIO& os, MDirection::Types& type, String& errMsg,
const wcsprm& wcs) const;
Bool frequencySystemFromWCS (LogIO& os, MFrequency::Types& type, String& errMsg,
const wcsprm& wcs) const;
Bool stokesCoordinateFromWCS (LogIO& os, StokesCoordinate& coord,
Int& stokesFITSValue, String& errMSg,
const wcsprm& wcs, uInt shape, Bool warnStokes) const;
// </group>
// Decode ObsInfo from wcs structure
ObsInfo getObsInfo(LogIO& os, RecordInterface& header, const wcsprm& wcs) const;
// Call wcsset
void setWCS (wcsprm& wcs) const;
// Decode CD cards from FITS file header (Record interface)
Bool getCDFromHeader(Matrix<Double>& cd, uInt n, const RecordInterface& header);
// Decode PC matrix from FITS header (Record interface)
void getPCFromHeader(LogIO& os, Int& rotationAxis, Matrix<Double>& pc,
uInt n, const RecordInterface& header,
const String& sprefix);
// Helper function to convert a wcs structure holding FITS keywords
// into a Record for later consumption.
void cardsToRecord (LogIO& os, RecordInterface& rec, char* pHeader) const;
// Fix up Coordinate for zero increments and the like
// Possibly the wcs FITS parser could do this
void fixCoordinate(Coordinate& c, LogIO& os) const;
// Initialize the wcsprm struct.
// It sets the flag to -1, but furthermore it clears the err pointers
// because wcslib-4.8 (shipped with Ubuntu) sometimes fails to do so.
static void wcsInit (::wcsprm& wcsDest);
};
} //# NAMESPACE CASACORE - END
#endif
casacore::type
casacore::CoordinateSystem
Definition CoordinateSystem.h:215
casacore::Coordinate
Definition Coordinate.h:137
casacore::FITSCoordinateUtil::getObsInfo
ObsInfo getObsInfo(LogIO &os, RecordInterface &header, const wcsprm &wcs) const
Decode ObsInfo from wcs structure.
casacore::FITSCoordinateUtil::wcsInit
static void wcsInit(::wcsprm &wcsDest)
Initialize the wcsprm struct.
casacore::FITSCoordinateUtil::fromFITSHeader
Bool fromFITSHeader(Int &stokesFITSValue, CoordinateSystem &coordsys, RecordInterface &recHeader, const Vector< String > &header, const IPosition &shape, uInt which=0) const
Probably even if we return False we should set up the best linear coordinate that we can.
casacore::FITSCoordinateUtil::fixCoordinate
void fixCoordinate(Coordinate &c, LogIO &os) const
Fix up Coordinate for zero increments and the like Possibly the wcs FITS parser could do this.
casacore::FITSCoordinateUtil::addStokesCoordinate
Bool addStokesCoordinate(CoordinateSystem &cSys, Int &axis, Int &stokesFITSValue, const wcsprm &wcs, const IPosition &shape, LogIO &os) const
casacore::FITSCoordinateUtil::getPCFromHeader
void getPCFromHeader(LogIO &os, Int &rotationAxis, Matrix< Double > &pc, uInt n, const RecordInterface &header, const String &sprefix)
Decode PC matrix from FITS header (Record interface).
casacore::FITSCoordinateUtil::cardsToRecord
void cardsToRecord(LogIO &os, RecordInterface &rec, char *pHeader) const
Helper function to convert a wcs structure holding FITS keywords into a Record for later consumption.
casacore::FITSCoordinateUtil::addDirectionCoordinate
Bool addDirectionCoordinate(CoordinateSystem &cSys, Vector< Int > &axes, const wcsprm &wcs, LogIO &os) const
Look for Coordinate type and add to CS.
casacore::FITSCoordinateUtil::setWCS
void setWCS(wcsprm &wcs) const
Call wcsset.
casacore::FITSCoordinateUtil::toFITSHeader
Bool toFITSHeader(RecordInterface &header, IPosition &shape, const CoordinateSystem &cSys, Bool oneRelative, Char prefix='c', Bool writeWCS=True, Bool preferVelocity=True, Bool opticalVelocity=True, Bool preferWavelength=False, Bool airWavelength=False) const
Convert CoordinateSystem to a FITS header.
casacore::FITSCoordinateUtil::stokesCoordinateFromWCS
Bool stokesCoordinateFromWCS(LogIO &os, StokesCoordinate &coord, Int &stokesFITSValue, String &errMSg, const wcsprm &wcs, uInt shape, Bool warnStokes) const
casacore::FITSCoordinateUtil::addLinearCoordinate
Bool addLinearCoordinate(CoordinateSystem &cSys, Vector< Int > &axes, const wcsprm &wcs, LogIO &os) const
casacore::FITSCoordinateUtil::toFITSHeaderStokes
Bool toFITSHeaderStokes(Vector< Double > &crval, Vector< Double > &crpix, Vector< Double > &cdelt, LogIO &os, const CoordinateSystem &coordsys, Int stokesAxis, Int stokesCoord) const
Special Stokes processing for conversion to FITS header.
casacore::FITSCoordinateUtil::FITSCoordinateUtil
FITSCoordinateUtil()
Constructor.
Definition FITSCoordinateUtil.h:91
casacore::FITSCoordinateUtil::addSpectralCoordinate
Bool addSpectralCoordinate(CoordinateSystem &cSys, Int &axis, const wcsprm &wcs, const IPosition &shape, LogIO &os) const
casacore::FITSCoordinateUtil::generateFITSKeywords
Bool generateFITSKeywords(LogIO &os, Bool &isNCP, Double &longPole, Double &latPole, Vector< Double > &crval, Vector< Double > &crpix, Vector< Double > &cdelt, Vector< Double > &pvi_ma, Vector< String > &ctype, Vector< String > &cunit, Matrix< Double > &pc, const CoordinateSystem &cSys, Int skyCoord, Int longAxis, Int latAxis, Int specAxis, Int stokesAxis, Bool writeWCS, Double offset, const String &sprefix) const
Generate actual FITS keywords.
casacore::FITSCoordinateUtil::frequencySystemFromWCS
Bool frequencySystemFromWCS(LogIO &os, MFrequency::Types &type, String &errMsg, const wcsprm &wcs) const
casacore::FITSCoordinateUtil::cTypeFromDirection
static Vector< String > cTypeFromDirection(const Projection &proj, const Vector< String > &axisNames, Bool printError)
casacore::FITSCoordinateUtil::getCDFromHeader
Bool getCDFromHeader(Matrix< Double > &cd, uInt n, const RecordInterface &header)
Decode CD cards from FITS file header (Record interface).
casacore::FITSCoordinateUtil::cTypeFromDirection
static Vector< String > cTypeFromDirection(Bool &isNCP, const Projection &proj, const Vector< String > &axisNames, Double refLat, Bool printError)
Helper function to create a FITS style CTYPE vector from the axis names from a DirectionCoordinate.
casacore::FITSCoordinateUtil::directionSystemFromWCS
Bool directionSystemFromWCS(LogIO &os, MDirection::Types &type, String &errMsg, const wcsprm &wcs) const
Decode values from WCS structures which are generated via the wcs FITS parser.
casacore::IPosition
Definition IPosition.h:117
casacore::LogIO
Definition LogIO.h:165
casacore::MDirection::Types
Types
Types of known MDirections Warning: The order defines the order in the translation matrix FromTo in ...
Definition MDirection.h:185
casacore::MFrequency::Types
Types
Types of known MFrequencies Warning: The order defines the order in the translation matrix FromTo in...
Definition MFrequency.h:173
casacore::Matrix
Definition Matrix.h:87
casacore::ObsInfo
Definition ObsInfo.h:95
casacore::Projection
Definition Projection.h:94
casacore::StokesCoordinate
Definition StokesCoordinate.h:103
casacore::String
String: the storage and methods of handling collections of characters.
Definition String.h:223
casacore::Vector
Definition Vector.h:82
casacore::Record
Record()
casacore
this file contains all the compiler specific defines
Definition mainpage.dox:28
casacore::False
const Bool False
Definition aipstype.h:42
casacore::ctype
char * ctype(int n) const
Definition hdu.h:360
casacore::offset
int offset(int, int) const
compute a linear offset from array indicies
casacore::uInt
unsigned int uInt
Definition aipstype.h:49
casacore::cdelt
double cdelt(int n) const
Definition hdu.h:364
casacore::shape
IPosition shape(const RecordFieldId &) const
Get the actual shape of this field.
casacore::crpix
double crpix(int n) const
Definition hdu.h:361
casacore::crval
double crval(int n) const
Definition hdu.h:363
casacore::RecordInterface
RecordInterface()
The default constructor creates an empty record with a variable structure.
casacore::Int
int Int
Definition aipstype.h:48
casacore::Bool
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
casacore::True
const Bool True
Definition aipstype.h:41
casacore::Double
double Double
Definition aipstype.h:53
casacore::Char
char Char
Definition aipstype.h:44