/// <summary> /// Constructor with data to init variables and the name of the passband /// </summary> /// <param name="row">Field info from query (DataRow)</param> /// <param name="band">Passband name (string)</param> public Band(DataRow row, string band) { if ("ugriz".IndexOf(band.ToLower()) < 0) { throw new ApplicationException("Parameter 'band' is invalid! Should be one of u,g,r,i or z..."); } this.filter = band; this.node = (double)row["node"]; this.incl = (double)row["incl"]; string postfix = "_" + band; //this.a = (double)row["a"+postfix]; //this.b = (double)row["b"+postfix]; //this.c = (double)row["c"+postfix]; //this.d = (double)row["d"+postfix]; //this.e = (double)row["e"+postfix]; //this.f = (double)row["f"+postfix]; // this Convert is used because only dr8 gives problem it has float values // otherwise simple (double) cast works for all others this.a = Convert.ToDouble(row["a" + postfix]); this.b = Convert.ToDouble(row["b" + postfix]); this.c = Convert.ToDouble(row["c" + postfix]); this.d = Convert.ToDouble(row["d" + postfix]); this.e = Convert.ToDouble(row["e" + postfix]); this.f = Convert.ToDouble(row["f" + postfix]); this.pixperdeg = 9088; this.wcs = this.Wcs(); }
/// <summary> /// Get WCS at any pixel in the image /// </summary> /// <param name="crpix1">pixel coord 1 (double)</param> /// <param name="crpix2">pixel coord 2 (double)</param> /// <returns>WCS</returns> public WCS Wcs(double crpix1, double crpix2) { SdssCoord[] corner; center = CoordsAtPix(crpix1, crpix2); corner = CornerCoords(); double mu, nu, ra, dec; // build linear eqns and solve for affine transform double mumu = 0, nunu = 0, munu = 0, ramu = 0, ranu = 0, decmu = 0, decnu = 0; for (int i = 0; i < corner.Length; i++) { mu = corner[i].mu - center.mu; nu = corner[i].nu - center.nu; ra = corner[i].ra - center.ra; dec = corner[i].dec - center.dec; // increment mumu += mu * mu; munu += mu * nu; nunu += nu * nu; ramu += ra * mu; ranu += ra * nu; decmu += dec * mu; decnu += dec * nu; } double p, q, s, r; SolveSym2D(mumu, munu, nunu, ramu, ranu, out p, out q); SolveSym2D(mumu, munu, nunu, decmu, decnu, out s, out r); WCS wcs = new WCS(); wcs.EPOCH = "J2000"; wcs.CTYPE2 = "DEC--TAN"; wcs.CTYPE1 = "RA---TAN"; wcs.CUNIT1 = "deg"; wcs.CUNIT2 = "deg"; wcs.NAXIS1 = this.npix1; wcs.NAXIS2 = this.npix2; wcs.CRPIX1 = crpix1 + 0.5; // different SDSS vs FITS convention (Steve Kent) wcs.CRPIX2 = crpix2 + 0.5; // -"- wcs.CRVAL1 = center.ra; wcs.CRVAL2 = center.dec; wcs.CD1_1 = p * b + q * e; wcs.CD1_2 = s * b + r * e; wcs.CD2_1 = p * c + q * f; wcs.CD2_2 = s * c + r * f; // john's suggestions for a fix double scale = Math.Cos(center.dec * Math.PI / 180); wcs.CD1_1 *= scale; wcs.CD1_2 *= scale; return(wcs); }