<resource schema="pcc">
	<meta name="creationDate">2019-05-28T12:50:01Z</meta>
	<meta name="schema-rank">100</meta>

	<meta name="title">A Catalog of Galaxies in the Direction of the Perseus
	Cluster</meta>

	<meta name="description">
		This is a catalog of 5437 morphologically classified sources in the
		direction of the Perseus galaxy cluster core, among them 496 early-type
		low-mass galaxy candidates. The catalog is primarily based on V-band
		imaging data acquired with the William Herschel Telescope.  Additionally,
		we used archival Subaru multiband imaging data in order to measure aperture
		colors and to perform a morphological classification.  The catalog reaches
		its 50 per cent completeness limit at an absolute V-band luminosity of -12
		mag and a V-band surface brightness of 26 mag arcsec^-2 .

		In addition to the published table, this service also contains cutout
		images of the objects investigated.
	</meta>
		
	<meta name="subject">perseus-cluster</meta>
	<meta name="subject">galaxy-colors</meta>
	<meta name="subject">early-type-galaxies</meta>
	<meta name="subject">dwarf-elliptical-galaxies</meta>

	<meta name="creator">Wittmann, C.; Kotulla, R.; Lisker, T.;
		Grebel, E.K.; Conselice, C.J.; Janz, J.; Penny, S.J.</meta>
	<meta name="instrument">William Herschel Telescope</meta>
	<meta name="instrument">Subaru Hyper Suprimecam</meta>
	<meta name="facility">Observatorio del Roque de los Muchachos</meta>
	<meta name="facility">Subaru telescope</meta>

	<meta name="source">2019ApJS..245...10W</meta>
	<meta name="contentLevel">Research</meta>
	<meta name="type">Catalog</meta>

	<meta name="coverage.waveband">Optical</meta>

	<table id="main" onDisk="True" adql="true" primary="object_name"
			mixin="//scs#q3cindex">

		<mixin>//scs#pgs-pos-index</mixin>

		<meta name="_associatedDatalinkService">
			<meta name="serviceId">stamp</meta>
			<meta name="idColumn">object_name</meta>
		</meta>

		<column name="object_name" type="text"
			ucd="meta.id;meta.main"
			tablehead="Name"
			description="Identifier from Wittman et al (2019)."
			verbLevel="5"/>
		<column name="ra" type="double precision"
			unit="deg" ucd="pos.eq.ra;meta.main"
			tablehead="RA"
			description="ICRS Right Ascension from WHT image"
			verbLevel="1"/>
		<column name="dec" type="double precision"
			unit="deg" ucd="pos.eq.dec;meta.main"
			tablehead="Dec"
			description="ICRS Declination from WHT image"
			verbLevel="1"/>
		<column name="mag" type="double precision"
			unit="mag" ucd="phot.mag;em.opt.V"
			tablehead="Mag"
			description="Integrated V-band apparent magnitude corrected for
				extinction."
			verbLevel="1"/>
		<column name="err_mag"
			unit="mag" ucd="stat.error;phot.mag;em.opt.V"
			tablehead="Err. Mag"
			description="Error in integrated apparent magnitude for sources
				fitted with GALFIT (i.e., pflag = 1 .. 8; NULL otherwise)"
			verbLevel="11"/>
		<column name="r_50"
			unit="arcsec" ucd="phys.angsize"
			tablehead="R_50"
			description="Half-light radius in the V band.."
			verbLevel="1"/>
		<column name="err_r_50"
			unit="arcsec" ucd="stat.error;phys.angsize"
			tablehead="Err. R_50"
			description="Error in half-light radius in the V band."
			verbLevel="11"/>

		<column name="mu50"
			unit="mag.arcsec**-2" ucd="phot.mag.sb"
			tablehead="S.B. in R_50"
			description="Effective V band surface brightness within R_50 corrected
				for extinction"
			verbLevel="15"/>
		<column name="err_mu50"
			unit="mag.arcsec**-2" ucd="stat.error;phot.mag.sb"
			tablehead="Err. S.B."
			description="Error in the effective surface brightness propagated
				from err_mag and err_r_50"
			verbLevel="25"/>

		<column name="sersic_index"
			ucd="stat.fit.param"
			tablehead="Sérsic"
			description="Sérsic index, upper limit constrained to 4 (cf. paper,
				sect. 4.3)"
			verbLevel="15"/>
		<column name="err_sersic_index"
			ucd="stat.error;stat.fit.param"
			tablehead="Err. S.E."
			description="Error in Sérsic index for sources fitted with GALFIT
				with free N parameter (pflag = 1)"
			verbLevel="25"/>
		<column name="b_a"
			ucd="phys.angsize;arith.ratio"
			tablehead="b/a"
			description="Axis ratio in the V band for sources fitted with GALFIT
				(pflag = 1 .. 8)"
			verbLevel="15"/>
		<column name="err_b_a"
			ucd="stat.error;phys.angsize;arith.ratio"
			tablehead="Err. b/a"
			description="Error in axis ratio for sources fitted with GALFIT with
				free B/A parameter (pflag = 1 - 4)"
			verbLevel="25"/>
		<column name="pa"
			unit="deg" ucd="pos.posang"
			tablehead="P.A."
			description="Position Angle for sources fitted with GALFIT and
				b_a &lt; 0.9 [North/Up=0, East/Left=90]; from V band."
			verbLevel="15"/>
		<column name="err_pa"
			unit="deg" ucd="stat.error;pos.posang"
			tablehead="Err. P.A."
			description="Error in position angle."
			verbLevel="15"/>

		<column name="a_v"
			unit="mag" ucd="phys.absorption;em.opt.V"
			tablehead="A_V"
			description="V-band galactic foreground extinction."
			verbLevel="15"/>

		<column name="pflag" type="smallint" required="True"
			ucd="meta.code"
			tablehead="Phot Proc?"
			description="Photometry processing flag (see note)."
			verbLevel="25"
			note="p"/>
		<column name="resflag" type="smallint"
			ucd="meta.code.qual"
			tablehead="Res?"
			description="1 if there were significant residuals after substracting
				GALFIT model, 0 otherwise. This is only given for sources fitted
				with GALFIT (i.e., pflag = 1 .. 8)"
			verbLevel="15">
			<values nullLiteral="-9999"/>
		</column>
		<column name="bgflag" type="smallint" required="True"
			ucd="meta.code"
			tablehead="Bg?"
			description="Background fitted with: ...0: Galfit; ...1: SExtractor with
				BACK_SIZE = 256 pixel background map, ...2: like 1, but BACK_SIZE
				= 32 pixel"
			verbLevel="25"/>

		<LOOP>
			<csvItems>
				name, ucd,             desig, apn, apdef
				g_r, em.opt.V;em.opt.R,g-r,   1,   "(r_aper1 = 1 R50 for sources with R50 > 4 pixels, r_aper1 = 4 pixels for sources with R50 &lt;= 4 pixels)"
				r_z, em.opt.R;em.opt.I,r-z,   1,   "(r_aper1 = 1 R50 for sources with R50 > 4 pixels, r_aper1 = 4 pixels for sources with R50 &lt;= 4 pixels)"
				g_r, em.opt.V;em.opt.R,g-r,   2,   "(only for sources with R50 > 4 pixels, where r_aper2 = 2 R50)"
				r_z, em.opt.R;em.opt.I,r-z,   2,   "(only for sources with R50 > 4 pixels, where r_aper2 = 2 R50)"
			</csvItems>
			<events>
				<column name="\name\+_\apn"
					unit="mag" ucd="phot.color;\ucd"
					tablehead="\desig, Ap \apn"
					description="Subaru \desig for aperture \apn, color corrected for
						extinction.  \apdef"
					verbLevel="15"/>
				<column name="err_\name\+_\apn"
					unit="mag" ucd="phot.color;\ucd"
					tablehead="Err, \desig \apn"
					description="Error in \desig for aperture \apn"
					verbLevel="25"/>
			</events>
		</LOOP>

		<column name="g_r_flag" type="smallint"
			ucd="meta.code.qual"
			tablehead="g-r?"
			description="1 if g-r photometry possibly comtaminated through bleeding
				trails of bright stars within 3 arcsec, 0 otherwise"
			verbLevel="25">
			<values nullLiteral="-1"/>
		</column>
		<column name="r_z_flag" type="smallint"
			ucd="meta.code.qual"
			tablehead="r-z?"
			description="1 if r-z photometry possibly comtaminated through bleeding
				trails of bright stars within 3 arcsec, 0 otherwise"
			verbLevel="25">
			<values nullLiteral="-1"/>
		</column>
		<column name="a_g"
			unit="mag" ucd="phys.absorption;em.opt.V"
			tablehead="A_g"
			description="g-band galactic foreground extinction."
			verbLevel="25"/>
		<column name="a_r"
			unit="mag" ucd="phys.absorption;em.opt.R"
			tablehead="A_r"
			description="r-band galactic foreground extinction."
			verbLevel="25"/>
		<column name="a_z"
			unit="mag" ucd="phys.absorption;em.opt.I"
			tablehead="A_z"
			description="z-band galactic foreground extinction."
			verbLevel="25"/>

		<column name="morphology" type="text"
			ucd="src.class"
			tablehead="Morphology"
			description="Morphological classification"
			verbLevel="1"/>
		<column name="nucleation" type="text"
			ucd="src.class"
			tablehead="Nucleation"
			description="Remark on nucleation"
			verbLevel="1"/>
		<column name="cutout_link" type="text"
			ucd="meta.ref.url"
			tablehead="Image"
			description="Link to a FITS cutout for this source from an r-band
				mosaic.  See datalink for additional retrieval options."
			displayHint="type=url" verbLevel="1"/>

		<meta name="note" tag="p">
			The photometry processing flag means:

			:1: Galfit:
			    Sérsic fit with free parameters
			:2: Galfit:
			    Sérsic fit with free parameters but constrained N = 4
			:3:
			    Galfit: Sérsic fit with fixed N (derived from Petrosian
			    concentration r_90/r_50, see Wittmann et al. 2019, Sect. 4.3)
			:4:
			    Galfit: Sérsic fit with fixed N and position
			:5:
			    Galfit: Sérsic fit with fixed N and B/A = 0.1
			:6:
			    Galfit: Sérsic fit with fixed N, R50 = 0.5 pixel, and B/A = 1
			:7:
			    Galfit: Sérsic fit with fixed N, position, and B/A = 0.1
			:8:
			    Galfit: Sérsic fit with fixed N, position, R50 = 0.5 pixel,
			    and B/A = 1
			:9: Petrosian photometry
		</meta>
	</table>

	<coverage>
		<updater sourceTable="main"/><spatial>6/1700-1701</spatial>
	</coverage>

	<data id="import">
		<sources pattern="data/table6.dat"/>

		<reGrammar>
			<commentPat>(?m)^#.*$</commentPat>
			<!-- I need to remove the extra column for the cutout link here -->
			<names>\reSub{,cutout_link}{}{\colNames{main}}</names>
		</reGrammar>

		<make table="main">
			<rowmaker idmaps="*">
				<map key="morphology">{
					1: "Likely dE/ETGcluster candidate",
					11: "Possible dE/ETGcluster candidate",
					2: "Likely background ETG or unresolved source",
					3: "Cluster or background LTG",
					4: "Cluster or background galaxy with possibly weak substructure",
					5: "Likely cluster or background edge-on disk galaxy",
					6: "Likely merging system",
					-9999: ""}[int(@morphology)]
				</map>
				<map key="nucleation">{
					1: "Nucleated",
					2: "Non-nucleated",
					3: "Unsure about nucleation",
					4: "Bulge or Bright central source",
					-9999: ""}[int(@nucleation)]
				</map>

				<LOOP listItems="err_mag err_r_50 err_mu50 err_sersic_index
					b_a err_b_a pa err_pa
					g_r_1 err_g_r_1 r_z_1 err_r_z_1
					g_r_2 err_g_r_2 r_z_2 err_r_z_2 a_g a_r a_z">
					<events>
						<map key="\item" nullExpr="-9999.0"/>
					</events>
				</LOOP>

				<LOOP listItems="resflag g_r_flag r_z_flag">
					<events>
						<map key="\item" nullExpr="-9999"/>
					</events>
				</LOOP>

				<map key="cutout_link"
					>'\internallink{pcc/q/stamp/dlget}?ID='+@object_name</map>
			</rowmaker>
		</make>
	</data>

	<service id="stamp" allowed="dlmeta,dlget,static">
		<meta name="title">Perseus Cluster Cutouts</meta>
		<meta name="description">This is a datalink service for cutouts
			over Ralf Kotullas Perseus Cluster mosaic.  Full images in
			different Subaru bands are available as related data.
		</meta>
		<property key="staticData">data</property>
		
		<datalinkCore>
			<descriptorGenerator procDef="//soda#fits_genDesc" name="genFITSDesc">
				<setup>
					<par key="mainPubDID"
						>('ivo://dc.g-vo.org/pcc/q/stamp?'
						'perseus_subaru_hsc_r_fullres.fits.fits')</par>
				</setup>
				<bind key="accrefPrefix">'pcc/data'</bind>
				<code>
					# This is funky in that we always operate on the
					# same file (data/perseus_r_fullres.fits) when doing
					# cutouts and take the parameters to do that from the
					# identifier by doing a table lookup.
					# In particular, the #this must be a cutout URL that we generate
					# here and take from the descriptor in the meta maker below.

					desc = FITSProductDescriptor(
						pubDID=mainPubDID,
						accref='pcc/data/perseus_subaru_hsc_r_fullres.fits',
						accessPath=os.path.join(
							base.getConfig("inputsDir"),
							'pcc/data/perseus_subaru_hsc_r_fullres.fits'),
						mime="application/fits")
					desc.suppressAutoLinks = True
				
					if pubDID!=mainPubDID:
						with base.getTableConn() as conn:
							res = list(conn.query("SELECT ra, dec, r_50"
								" FROM pcc.main"
								" WHERE object_name=%(id)s",
								{"id": pubDID}))
						if not res:
							return None
						ra, dec, size = res[0]

						soda.ensureSkyWCS(desc)
						soda.addPolygonSlices(desc,
							pgsphere.SCircle.fromDALI([ra, dec, size/3600.*2]).asPoly(),
							"CIRCLE")

						desc.thisURL = '\internallink{pcc/q/stamp/dlget}?ID='+pubDID

					return desc
				</code>
			</descriptorGenerator>

			<FEED source="//soda#fits_standardDLFuncs"/>

			<metaMaker semantics="#counterpart">
				<code>
					yield descriptor.makeLinkFromFile(
						"data/perseus_WHT_PFIP_V.fits",
						description="Perseus cluster mosaic in WHT PFIP V-band (~ 0.25"
							" arcsec/pix).",
						semantics="#progenitor",
						contentQualifier="#image")
					yield descriptor.makeLinkFromFile(
						"data/perseus_subaru_hsc_r_fullres.fits",
						description="Perseus cluster mosaic in Subaru HSC r-band (~ 0.15"
							" arcsec/pix)",
						contentQualifier="#image")
					yield descriptor.makeLinkFromFile("data/perseus_subaru_hsc_r.fits",
						description="Perseus cluster mosaic in Subaru HSC r-band (~ 0.25"
						" arcsec/pix)",
						contentQualifier="#image")
					yield descriptor.makeLinkFromFile("data/perseus_subaru_hsc_g.fits",
						description="Perseus cluster mosaic in Subaru HSC g-band (~ 0.25"
						" arcsec/pix)",
						contentQualifier="#image")
					yield descriptor.makeLinkFromFile("data/perseus_subaru_hsc_z.fits",
						description="Perseus cluster mosaic in Subaru HSC z-band (~ 0.25)"
						" arcsec/pix)",
						contentQualifier="#image")

					if hasattr(descriptor, "thisURL"):
						yield descriptor.makeLink(descriptor.thisURL,
							semantics="#this",
							description="Cutout for this object.",
							contentType="application/fits",
							contentQualifier="#image")
				</code>
			</metaMaker>
		</datalinkCore>
	</service>

	<service id="cone" allowed="form,scs.xml">
		<publish render="scs.xml" sets="ivo_managed"/>
		<publish render="form" sets="local,ivo_managed"/>
		<meta name="shortName">pcc cone</meta>
		<meta name="testQuery">
			<meta name="ra">49.5958</meta>
			<meta name="dec">41.2689</meta>
			<meta name="sr">0.001</meta>
		</meta>
		<scsCore queriedTable="main">
			<FEED source="//scs#coreDescs"/>
			<condDesc buildFrom="mag"/>
			<condDesc buildFrom="r_50"/>
			<condDesc buildFrom="mu50"/>
			<condDesc buildFrom="sersic_index"/>
		</scsCore>
	</service>

	<regSuite title="PCC regression">
			<regTest title="PCC cone search is reasonable.">
				<url RA="49.5958" DEC="41.2689" SR="0.001" mag="15 16" VERB="3"
					>cone/scs.xml</url>
				<code>
					rows = self.getVOTableRows()
					self.assertEqual(len(rows), 1)
					row = rows[0]
					self.assertAlmostEqual(row["mag"], 15.03)
					self.assertEqual(row["err_sersic_index"], None)
					self.assertTrue(row["cutout_link"].endswith(
						"/pcc/q/stamp/dlget?ID=PCC-2146"))
				</code>
			</regTest>

		<regTest title="PCC FITS cutout works">
			<url httpHonorRedirects="True">/pcc/q/stamp/dlget?ID=PCC-2146</url>
			<code>
				self.assertHasStrings(
					"NAXIS2  =                  171",
					"FILTER  = 'HSC-r   '",
					"Nu9")
				self.assertHeader("content-type", "application/fits")
			</code>
		</regTest>

		<regTest title="PCC datalink metadata looks about right" tags="bigserver">
			<url httpHonorRedirects="True">/pcc/q/stamp/dlmeta?ID=PCC-2146</url>
			<code>
				for row in self.getVOTableRows():
					if row["semantics"]=='#progenitor':
						self.assertTrue(row["access_url"].endswith(
							"pcc/q/stamp/static/perseus_WHT_PFIP_V.fits"))
						break
				else:
					raise AssertionError("No #progenitor link?")
			</code>
		</regTest>
	</regSuite>
</resource>
