// based on information in m_casaCS: // - extract axis infos // - set default precisions // - set default sky formatting void CCCoordinateFormatter::parseCasaCS() { /*qDebug() << "CCC nAxes=" << nAxes(); for ( auto & u : m_casaCS->worldAxisUnits() ) { qDebug() << "all units:" << u.c_str(); } for ( auto & u : m_casaCS->worldAxisNames() ) { qDebug() << "all names:" << u.c_str(); }*/ // default precision is 3 m_precisions.resize( nAxes(), 3 ); m_axisInfos.resize( nAxes() ); for ( int i = 0 ; i < nAxes() ; i++ ) { parseCasaCSi( i ); } /*qDebug() << "Parsed axis infos:"; for ( auto & ai : m_axisInfos ) { qDebug() << " lp:" << ai.longLabel().plain() << "lh:" << ai.longLabel().html() << "sp:" << ai.shortLabel().html() << "sh:" << ai.shortLabel().html() << "u:" << ai.unit(); }*/ // set formatting to default setSkyFormatting( SkyFormatting::Default ); } // parseCasaCS
CCCoordinateFormatter::Me & CCCoordinateFormatter::setAxisPrecision( int precision, int axis ) { CARTA_ASSERT( axis >= 0 && axis < nAxes() ); m_precisions[axis] = precision; return * this; }
virtual Me & setAxisPrecision( int precision, int axis ) override { CARTA_ASSERT( axis >= 0 && axis < nAxes() ); m_precisions[axis] = precision; return * this; }
QStringList CCCoordinateFormatter::formatFromPixelCoordinate( const CoordinateFormatterInterface::VD & pix ) { // first convert the pixel coordinates to world coordinates casa::Vector < casa::Double > world; casa::Vector < casa::Double > pixel = pix; m_casaCS->toWorld( world, pix ); // format each axis // QStringList list; // for (unsigned int i = 0; i < m_casaCS->nCoordinates(); i++) { // casa::String units; // casa::String s = m_casaCS->format(units, casa::Coordinate::FIXED, world[i], i); // list.append(QString("%1%2").arg(s.c_str()).arg(units.c_str())); // } // return list; QStringList list; for ( int i = 0 ; i < nAxes() ; i++ ) { list.append( formatWorldValue( i, world[i] ) ); } return list; } // formatFromPixelCoordinate
void CCCoordinateFormatter::parseCasaCSi( int pixelAxis ) { CARTA_ASSERT( 0 <= pixelAxis && pixelAxis < nAxes() ); // find the pixel axes in casacore's coordinate system // coord will be the index of the 'coordinate' // and coord2 will be an index within that index... // warning: casa's coordinates and axes are two completely different things! // e.g. a standard 4D fits file with frequency and stokes has 3 coordinates, but // 4 axes... int coord; // this is the world coordinate int coord2; // this is the index within world coordinate (0 for all but latitude) m_casaCS->findPixelAxis( coord, coord2, pixelAxis ); //qDebug() << pixelAxis << "-->" << coord << "," << coord2; //qDebug() << " " // << casa::Coordinate::typeToString( m_casaCS->coordinate( coord ).type() ).c_str(); AxisInfo & aInfo = m_axisInfos[pixelAxis]; // default will be unknown axis aInfo.setKnownType( AxisInfo::KnownType::OTHER ) .setLongLabel( HtmlString::fromPlain( "Unknown" ) ) .setShortLabel( HtmlString::fromPlain( "Unknown" ) ) .setUnit( "unknown" ); // did we find the world coordinate for this axis in casa core's coordinatesystem? if ( coord >= 0 ) { const auto & cc = m_casaCS->coordinate( coord ); auto skycs = skyCS(); // we handle sky coordinate if ( cc.type() == casa::Coordinate::DIRECTION ) { // is it longitude? if ( coord2 == 0 ) { aInfo.setKnownType( AxisInfo::KnownType::DIRECTION_LON ); // B1950,J200 and ICRS share labels if ( skycs == KnownSkyCS::B1950 || skycs == KnownSkyCS::J2000 || skycs == KnownSkyCS::ICRS ) { aInfo.setLongLabel( HtmlString::fromPlain( "Right ascension" ) ) .setShortLabel( HtmlString( "RA", "α" ) ); } else if ( skycs == KnownSkyCS::Ecliptic ) { aInfo.setLongLabel( HtmlString::fromPlain( "Ecliptic longitude" ) ) //.setShortLabel( HtmlString( "ELon", "l" ) ); .setShortLabel( HtmlString( "ELon", "λ")); } else if ( skycs == KnownSkyCS::Galactic ) { aInfo.setLongLabel( HtmlString::fromPlain( "Galactic longitude" ) ) //.setShortLabel( HtmlString( "GLon", "λ" ) ); .setShortLabel( HtmlString( "GLon", "l")); } else { CARTA_ASSERT( false ); } } // it's latitude then else { aInfo.setKnownType( AxisInfo::KnownType::DIRECTION_LAT ); // B1950,J200 and ICRS share labels if ( skycs == KnownSkyCS::B1950 || skycs == KnownSkyCS::J2000 || skycs == KnownSkyCS::ICRS ) { aInfo.setLongLabel( HtmlString::fromPlain( "Declination" ) ) .setShortLabel( HtmlString( "Dec", "δ" ) ); } else if ( skycs == KnownSkyCS::Ecliptic ) { aInfo.setLongLabel( HtmlString::fromPlain( "Ecliptic latitude" ) ) //.setShortLabel( HtmlString( "ELat", "b" ) ); .setShortLabel( HtmlString( "Elat", "β")); } else if ( skycs == KnownSkyCS::Galactic ) { aInfo.setLongLabel( HtmlString::fromPlain( "Galactic latitude" ) ) //.setShortLabel( HtmlString( "GLat", "β" ) ); .setShortLabel( HtmlString( "GLat", "b")); } else { CARTA_ASSERT( false ); } } m_precisions[pixelAxis] = 3; } else if ( cc.type() == casa::Coordinate::SPECTRAL ) { aInfo.setKnownType( AxisInfo::KnownType::SPECTRAL ) .setLongLabel( HtmlString::fromPlain( "Frequency" ) ) .setShortLabel( HtmlString( "Freq", "Freq" ) ); m_precisions[pixelAxis] = 6; } else if ( cc.type() == casa::Coordinate::STOKES ) { aInfo.setKnownType( AxisInfo::KnownType::STOKES ) .setLongLabel( HtmlString::fromPlain( "Stokes" ) ) .setShortLabel( HtmlString::fromPlain( "Stokes" ) ); } else if ( cc.type() == casa::Coordinate::TABULAR ) { aInfo.setKnownType( AxisInfo::KnownType::TABULAR ); // else if ( cc.type() == casa::Coordinate::QUALITY ) { // aInfo.setKnownType( aInfo.KnownType::QUALITY); // } } else if ( cc.type() == casa::Coordinate::LINEAR ){ aInfo.setKnownType( AxisInfo::KnownType::LINEAR ) .setLongLabel( HtmlString::fromPlain( "Linear")) .setShortLabel( HtmlString::fromPlain( "Linear")); } else { // other types... we copy whatever casacore dishes out aInfo.setKnownType( AxisInfo::KnownType::OTHER ); QString rawAxisLabel = cc.worldAxisNames() ( coord2 ).c_str(); QString shortLabel = rawAxisLabel; aInfo.setLongLabel( HtmlString::fromPlain( rawAxisLabel ) ); aInfo.setShortLabel( HtmlString::fromPlain( shortLabel ) ); } CARTA_ASSERT( cc.worldAxisNames().size() > 0 ); // we always take the unit from casa aInfo.setUnit( cc.worldAxisUnits() ( coord2 ).c_str() ); } else { // this should never happen that casacore didn't find world coordinates for // the given axis... but let's not panic and just leave it a default value } } // parseCasaCSi
CCCoordinateFormatter::Me & CCCoordinateFormatter::setSkyCS( const KnownSkyCS & scs ) { //qDebug() << "setSkyCS" << static_cast < int > ( scs ); // don't even try to set this to unknown if ( scs == KnownSkyCS::Unknown ) { return * this; } // find out where the direction world coordinate lives int which = m_casaCS->directionCoordinateNumber(); if ( which < 0 ) { // this system does not have sky cs, so we are done return * this; // find out which axes correspond to the world coordinate array(longitude/latitude) } auto pixelAxes = m_casaCS->directionAxesNumbers(); CARTA_ASSERT( pixelAxes.size() == 2 ); CARTA_ASSERT( 0 <= pixelAxes[0] && pixelAxes[0] < nAxes() ); CARTA_ASSERT( 0 <= pixelAxes[1] && pixelAxes[1] < nAxes() ); // make a copy of it casa::DirectionCoordinate dirCoordCopy = casa::DirectionCoordinate( m_casaCS->directionCoordinate( which ) ); // change the system in the copy casa::MDirection::Types mdir; switch ( scs ) { case KnownSkyCS::B1950 : mdir = casa::MDirection::B1950; break; case KnownSkyCS::J2000 : mdir = casa::MDirection::J2000; break; case KnownSkyCS::ICRS : mdir = casa::MDirection::ICRS; break; case KnownSkyCS::Ecliptic : mdir = casa::MDirection::ECLIPTIC; break; case KnownSkyCS::Galactic : mdir = casa::MDirection::GALACTIC; break; default : CARTA_ASSERT_ALWAYS_X( false, "Internal error" ); break; } // switch dirCoordCopy.setReferenceConversion( mdir ); if ( ! m_casaCS->replaceCoordinate( dirCoordCopy, which ) ) { qWarning() << "Could not set wcs because replaceCoordinate() failed"; return * this; } // now we need to adjust axisinfos, formatting and precision setSkyFormatting( SkyFormatting::Default ); parseCasaCSi( pixelAxes[0] ); parseCasaCSi( pixelAxes[1] ); // chaning support return * this; } // setSkyCS
const Carta::Lib::AxisInfo & CCCoordinateFormatter::axisInfo( int ind ) const { CARTA_ASSERT( ind >= 0 && ind < nAxes() ); return m_axisInfos[ind]; }
int CCCoordinateFormatter::axisPrecision( int axis ) { CARTA_ASSERT( axis >= 0 && axis < nAxes() ); return m_precisions[axis]; }
virtual int axisPrecision( int axis ) override { CARTA_ASSERT( axis >= 0 && axis < nAxes() ); return m_precisions[axis]; }
virtual const Carta::Lib::AxisInfo & axisInfo( int ind ) const override { CARTA_ASSERT( ind >= 0 && ind < nAxes() ); return m_axisInfos[ind]; }