<resource schema="dfbsplates" resdir="dfbs">
  <meta name="creationDate">2018-09-08T06:47:55Z</meta>
  <meta name="schema-rank">100</meta>

  <meta name="title">Digitized First Byurakan Survey (DFBS) Plate Scans</meta>

  <meta name="description" format="rst">
    The First Byurakan Survey (FBS) is the largest and the first systematic
    objective prism survey of the extragalactic sky. It covers 17,000 sq.deg.
    in the Northern sky together with a high galactic latitudes region in the
    Southern sky.   This service serves the scanned objective prism images
    and offers SODA-based cutouts.
  </meta>

  <meta name="subject">surveys</meta>
  <meta name="subject">active-galactic-nuclei</meta>
  <meta name="subject">spectroscopy</meta>

  <meta name="creator">Markarian, B.E.; Lipovetski, V.A.; Stepanian, J.A.</meta>
  <meta name="instrument">Byurakan 1m Schmidt</meta>
  <meta name="facility">Byurakan Astrophysical Observatory BAO</meta>

  <meta name="source">2007A&amp;A...464.1177M</meta>
  <meta name="contentLevel">Research</meta>
  <meta name="type">Archive</meta>

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

  <table id="main" onDisk="True" mixin="//siap#pgs" adql="True">
    <meta name="_associatedDatalinkService">
      <meta name="serviceId">dl</meta>
      <meta name="idColumn">publisher_did</meta>
    </meta>

    <mixin
      calibLevel="2"
      collectionName="'DFBS-plates'"
      expTime="exptime"
    >//obscore#publishSIAP</mixin>

    <column name="plate" type="text"
      ucd="meta.id"
      tablehead="Plate id"
      description="Identifier (plate number) for the DFBS plate."
      verbLevel="1"/>
    <column name="exptime"
      unit="s" ucd=""
      tablehead="Exptime"
      description="Exposure time."
      verbLevel="15"/>
     <column name="publisher_did" type="text"
      ucd="meta.ref.url"
      description="Dataset identifier assigned by the publisher."
      verbLevel="15"/>
  </table>

  <coverage>
    <updater mocOrder="3" sourceTable="main"/><spatial>0/1-2 1/0,17-19,22,25-27 2/6,8-10,15,48-49,52-54,58-59,67,85,99,117,120,122-123,126-127,141,143,159,175,191 3/18,21,23,29,31,44-46,48-50,53-55,200-201,205,220-221,227,230,250-251,253-255,261-263,265-267,330-331,334,348-349,351,370,373,375-376,381,383,391,395,465,486,498-499,502-503,542-543,569-571,630-631,635,695,699,757-759,761,763</spatial><temporal>40383 44374</temporal>
  </coverage>

  <data id="import">
    <sources>
      <pattern>data/*.fits</pattern>
    </sources>

    <fitsProdGrammar>
      <rowfilter procDef="//products#define">
        <bind key="table">"\schema.data"</bind>
      </rowfilter>
      <ignoreOn>
        <keyMissing key="WFPDB_ID"/>
      </ignoreOn>
    </fitsProdGrammar>

    <make table="main">
      <rowmaker>
        <apply procDef="//siap#setMeta">
          <bind key="dateObs">parseDate(@DATE_OBS) if "DATE_OBS" in vars else None</bind>
          <bind key="bandpassId">@EMULSION</bind>
          <bind key="pixflags">"C"</bind>
          <bind key="title">"Byurakan %s (%s)"%(@PLATENUM, @EMULSION)</bind>
        </apply>

        <apply procDef="//siap#getBandFromFilter"/>

        <apply procDef="//siap#computePGS"/>

        <map key="plate">re.search(r"fbs(.*)_cor", \srcstem).group(1)</map>
        <map key="exptime">@EXPTIME if "EXPTIME" in vars else None</map>
        <map key="publisher_did">\standardPubDID</map>
      </rowmaker>
    </make>
  </data>

  <service id="i" allowed="form,siap.xml">
    <meta name="description">First Byurakan survey plate scan service</meta>
    <meta name="shortName">DFBS plates</meta>
    <meta name="sia.type">Pointed</meta>
    <meta name="testQuery.pos.ra">28.394</meta>
    <meta name="testQuery.pos.dec">19.222</meta>
    <meta name="testQuery.size.ra">0.1</meta>
    <meta name="testQuery.size.dec">0.1</meta>

    <publish render="siap.xml" sets="ivo_managed"/>
    <publish render="form" sets="local,ivo_managed"/>

    <dbCore queriedTable="main">
      <condDesc original="//siap#protoInput"/>
      <condDesc original="//siap#humanInput"/>
      <condDesc>
        <inputKey original="plate">
            <values fromdb="plate FROM \schema.main ORDER BY plate"/>
        </inputKey>
      </condDesc>
    </dbCore>

    <outputTable>
      <outputField name="dlurl" type="text" select="accref"
        tablehead="Datalink Access"
        description="URL of a datalink document for the dataset
          (cutouts, different formats, etc)">
        <formatter>
          yield T.a(href=getDatalinkMetaLink(
            rd.getById("dl"), data)
            )["Datalink"]
        </formatter>
        <property name="targetType"
          >application/x-votable+xml;content=datalink</property>
        <property name="targetTitle">Datalink</property>
      </outputField>
      <autoCols>*</autoCols>
    </outputTable>
  </service>

  <service id="dl" allowed="dlget,dlmeta">
    <meta name="description">Datalink for Byurakan survey plates</meta>
    <datalinkCore>
      <descriptorGenerator procDef="//soda#fits_genDesc"
          name="genFITSDesc">
        <bind key="accrefPrefix">'dfbs/data'</bind>
        <bind key="qnd">True</bind>
        <code>
          if pubDID.startswith("plate/"):
            # it's a plate number, probably from the spectral service;
            # find the accref from our main table
            plateid = pubDID[6:]
            # there's legacy stuff that keeps the "fbs" in front.
            if plateid.startswith("fbs"):
              plateid = plateid[3:]

            with base.getTableConn() as conn:
              res = list(conn.query("select accref from \schema.main"
                " where plate=%(plate)s",
                {"plate": plateid}))
            if not res:
              raise base.NotFoundError("plate", plateid, "FBS plates")
            pubDID = getStandardPubDID(res[0][0])

          return getFITSDescriptor(pubDID,
              accrefPrefix, cls=descClass, qnd=qnd)
        </code>
      </descriptorGenerator>
      <FEED source="//soda#fits_standardDLFuncs"/>
    </datalinkCore>
  </service>

  <regSuite title="dfbs regression">
    <!-- see http://docs.g-vo.org/DaCHS/ref.html#regression-testing
      for more info on these. -->

    <regTest title="dfbs SIAP serves some data">
      <url POS="214.04753 +46.89315" SIZE="0.1,0.1"
        >i/siap.xml</url>
      <code>
        rows = self.getVOTableRows()
        for row in rows:
          if row["plate"]=='0017':
            break
        else:
          raise AssertionError("plate 0017 not in SIAP result")

        self.assertEqual(row["exptime"], 1200.)
        self.assertEqual(row["bandpassId"], "IIAF bkd")
        self.assertEqual(row["imageTitle"],  'Byurakan fbs0017 (IIAF bkd)')
        self.assertEqual(int(row["centerDelta"]*10), 469)
      </code>
    </regTest>

    <regTest title="dfbs datalink meta returns links">
      <url ID="dfbs/data/fbs0017_cor.fits">dl/dlmeta</url>
      <code>
        bySemantics = dict((row["semantics"], row["access_url"])
          for row in self.getVOTableRows())
        self.assertTrue(
          bySemantics["#preview"].endswith(
            "/getproduct/dfbs/data/fbs0017_cor.fits?preview=True"))
        self.assertTrue(
          bySemantics["#this"].endswith(
            "/getproduct/dfbs/data/fbs0017_cor.fits"))
      </code>
    </regTest>

    <regTest title="fbs datalink cutout works with magic plate id as well.">
      <url ID="plate/fbs0017"
        CIRCLE="214.04 46.89 0.02">dl/dlget</url>
      <code>
        self.assertHasStrings("NAXIS1  =                   94")
        first_data_block = 3
        # this test needs updating when the calibration is fixed
        self.assertEqual(
          self.data[2880*first_data_block:2880*first_data_block+10],
          b"\\x10z\\x10\\xb6\\x114\\x10\\xe9\\x10\\xc9")
      </code>
    </regTest>
  </regSuite>
</resource>

<!-- vi:et:sta:sw=2
-->
