示例#1
0
def make_collection_context_node(
    time_coordinates_node: NodeBuilder,
    primary_result_summary_node: NodeBuilder,
    investigation_area_node: NodeBuilder,
    observing_system_node: NodeBuilder,
    target_identification_nodes: List[NodeBuilder],
) -> NodeBuilder:
    func = interpret_template("""<Context_Area>
        <NODE name="Time_Coordinates" />
        <NODE name="Primary_Result_Summary" />
        <NODE name="Investigation_Area" />
        <NODE name="Observing_System" />
        <FRAGMENT name="Target_Identification" />
        </Context_Area>""")({
        "Time_Coordinates":
        time_coordinates_node,
        "Primary_Result_Summary":
        primary_result_summary_node,
        "Investigation_Area":
        investigation_area_node,
        "Observing_System":
        observing_system_node,
        "Target_Identification":
        combine_nodes_into_fragment(target_identification_nodes),
    })
    return func
示例#2
0
    def test_interpret_template(self) -> None:
        make_body = interpret_document_template(
            '<doc><NODE name="foo"/></doc>')

        make_template = interpret_template('<foo><NODE name="bar"/></foo>')

        template = make_template({"bar": interpret_text("BAR")})
        body = make_body({"foo": template})

        self.assertEqual('<?xml version="1.0" ?><doc><foo>BAR</foo></doc>',
                         body.toxml())
示例#3
0
def target_identification(
    target_name: str,
    target_type: str,
    alternate_designations: str,
    target_description: str,
    target_lid: str,
    reference_type: str,
) -> NodeBuilder:
    """
    Given the info of target identifications, return a function that takes
    a document and returns a filled-out ``<Target_Identification />``
    XML node, used in product labels.
    """
    alternate_designations_list = []
    if len(alternate_designations) != 0:
        alternate_designations_list = alternate_designations.split("\n")
    alternate_designation_nodes: List[NodeBuilder] = [
        _make_alternate_designation(alternate_designation)
        for alternate_designation in alternate_designations_list
    ]

    description_nodes: List[NodeBuilder] = []
    if len(target_description) != 0:
        # properly align multi line textnodes with 8 spaces
        target_description = " " * 8 + target_description
        target_description = target_description.replace("\n", "\n" + " " * 8)
        description_nodes = [make_description(target_description)]

    func = interpret_template(
        """<Target_Identification>
        <name><NODE name="name"/></name>
        <FRAGMENT name="alternate_designations"/>
        <type><NODE name="type"/></type>
        <FRAGMENT name="description"/>
        <Internal_Reference>
            <lid_reference><NODE name="target_lid"/></lid_reference>
            <reference_type><NODE name="reference_type"/></reference_type>
        </Internal_Reference>
        </Target_Identification>"""
    )(
        {
            "name": target_name,
            "type": target_type,
            "alternate_designations": combine_nodes_into_fragment(
                alternate_designation_nodes
            ),
            "description": combine_nodes_into_fragment(description_nodes),
            "target_lid": target_lid,
            "reference_type": reference_type,
        }
    )
    return func
示例#4
0
from pdart.xml.templates import NodeBuilderTemplate, interpret_template

hst_parameters: NodeBuilderTemplate = interpret_template(
    """<hst:HST_Parameters>
  <NODE name="program_parameters"/>
  <NODE name="instrument_parameters"/>
  <NODE name="pointing_parameters"/>
  <NODE name="tracking_parameters"/>
  <NODE name="exposure_parameters"/>
  <NODE name="wavelength_filter_grating_parameters"/>
  <NODE name="operational_parameters"/>
</hst:HST_Parameters>""")

exposure_parameters: NodeBuilderTemplate = interpret_template(
    """<hst:Exposure_Parameters>
  <hst:exposure_duration unit="s"><NODE name="exposure_duration"/></hst:exposure_duration>
  <hst:exposure_type><NODE name="exposure_type"/></hst:exposure_type>
</hst:Exposure_Parameters>""")

detector_id: NodeBuilderTemplate = interpret_template(
    """<hst:detector_id><NODE name="detector_id"/></hst:detector_id>""")

instrument_parameters: NodeBuilderTemplate = interpret_template(
    """<hst:Instrument_Parameters>
  <hst:instrument_id><NODE name="instrument_id"/></hst:instrument_id>
  <hst:channel_id><NODE name="channel_id"/></hst:channel_id>
  <FRAGMENT name="detector_ids"/>
  <hst:observation_type><NODE name="observation_type"/></hst:observation_type>
</hst:Instrument_Parameters>""")

operational_parameters: NodeBuilderTemplate = interpret_template(
示例#5
0
"""
from typing import Any, List, Dict

from pdart.xml.templates import (
    combine_nodes_into_fragment,
    FragBuilder,
    NodeBuilder,
    NodeBuilderTemplate,
    interpret_template,
)

_primary_result_summary: NodeBuilderTemplate = interpret_template(
    """<Primary_Result_Summary>
      <purpose>Science</purpose>
      <processing_level><NODE name="processing_level"/></processing_level>
      <description><NODE name="description"/></description>
      <Science_Facets>
        <FRAGMENT name="wavelength_range"/>
        <discipline_name>Ring-Moon Systems</discipline_name>
      </Science_Facets>
    </Primary_Result_Summary>""")
"""
An interpreted fragment template to create an ``<Primary_Result_Summary />``
XML element.
"""

_make_wavelength_range_node: NodeBuilderTemplate = interpret_template(
    """<wavelength_range><NODE name="wavelength_range"/></wavelength_range>""")


def _make_wavelength_range(wavelength_range: str) -> FragBuilder:
    return _make_wavelength_range_node({"wavelength_range": wavelength_range})
示例#6
0
"""
Templates to create a ``<Time_Coordinates />`` XML node for product
labels.
"""

from pdart.xml.templates import NodeBuilderTemplate, interpret_template

time_coordinates: NodeBuilderTemplate = interpret_template(
    """<Time_Coordinates>
      <start_date_time><NODE name="start_date_time"/></start_date_time>
      <stop_date_time><NODE name="stop_date_time"/></stop_date_time>
    </Time_Coordinates>""")
"""
An interpreted node builder template to create an ``<Time_Coordinates />``
XML element.
"""


def _remove_trailing_decimal(num_str: str) -> str:
    """
    Given a num_string, remove any trailing zeros and then any trailing
    decimal point and return it.
    """
    # remove any trailing zeros
    while num_str[-1] == "0":
        num_str = num_str[:-1]
    # remove any trailing decimal point
    if num_str[-1] == ".":
        num_str = num_str[:-1]
    return num_str
示例#7
0
"""
Templates to create an ``<Investigation_Area />`` XML element.
Roll-up: One <Investigation_Area /> for bundle, data colleciton, and data.
Reference type can be difference for bundle, data collection, and data.
"""
from typing import Any, Dict

from pdart.xml.templates import NodeBuilder, NodeBuilderTemplate, interpret_template

_investigation_area: NodeBuilderTemplate = interpret_template(
    """<Investigation_Area>
      <name><NODE name="Investigation_Area_name" /></name>
      <type>Individual Investigation</type>
      <Internal_Reference>
        <lidvid_reference><NODE name="investigation_lidvid" />\
</lidvid_reference>
        <reference_type><NODE name="reference_type" />_to_investigation\
</reference_type>
      </Internal_Reference>
    </Investigation_Area>""")
"""
An interpreted fragment template to create an ``<Investigation_Area />``
XML element.
"""


def investigation_area(
    Investigation_Area_name: str,
    investigation_lidvid: str,
    reference_type: str,
) -> NodeBuilder:
示例#8
0
AXIS_NAME_TABLE: Dict[int, str] = {1: "Line", 2: "Sample", 3: "Band"}

BITPIX_TABLE: Dict[int, str] = {
    # TODO Verify these
    8: "UnsignedByte",
    16: "SignedMSB2",
    32: "SignedMSB4",
    64: "SignedMSB8",
    -32: "IEEE754MSBSingle",
    -64: "IEEE754MSBDouble",
}

axis_array: NodeBuilderTemplate = interpret_template("""<Axis_Array>
<axis_name><NODE name="axis_name"/></axis_name>
<elements><NODE name="elements"/></elements>
<sequence_number><NODE name="sequence_number"/></sequence_number>
</Axis_Array>""")
"""
An interpreted node template to create an ``<Axis_Array />``
XML element.
"""

header_contents: NodeBuilderTemplate = interpret_template("""<Header>
<local_identifier><NODE name="local_identifier"/></local_identifier>
<offset unit="byte"><NODE name="offset"/></offset>
<object_length unit="byte"><NODE name="object_length"/></object_length>
<parsing_standard_id>FITS 3.0</parsing_standard_id>
<description><NODE name="description"/></description>
</Header>""")
"""
示例#9
0
"""
Functionality to create a ``<Citation_Information />`` XML element.
"""

from pdart.citations import Citation_Information
from pdart.xml.templates import NodeBuilder, NodeBuilderTemplate, interpret_template

PUBLICATION_YEAR = 2021

_collection_citation_information: NodeBuilderTemplate = interpret_template(
    """<Citation_Information>
<author_list><NODE name="author_list" /></author_list>
<publication_year><NODE name="publication_year" /></publication_year>
<description><NODE name="description" /></description>
</Citation_Information>""")
"""
An interpreted template to create a ``<Citation_Information
/>`` XML element.
"""

_bundle_citation_information: NodeBuilderTemplate = interpret_template(
    """<Citation_Information>
<author_list><NODE name="author_list" /></author_list>
<publication_year><NODE name="publication_year" /></publication_year>
<doi><NODE name="doi" /></doi>
<description><NODE name="description" /></description>
</Citation_Information>""")
"""
An interpreted template to create a ``<Citation_Information
/>`` XML element.
"""
示例#10
0
"""Templates to create a label for a collection."""
from typing import List

from pdart.labels.namespaces import COLLECTION_NAMESPACES, PDS4_XML_MODEL
from pdart.xml.pds4_version import INFORMATION_MODEL_VERSION
from pdart.xml.templates import (
    DocTemplate,
    NodeBuilder,
    NodeBuilderTemplate,
    interpret_document_template,
    interpret_template,
    combine_nodes_into_fragment,
)

make_context_collection_title: NodeBuilderTemplate = interpret_template("""
    <title>Context collection of <NODE name="instrument"/> observations \
obtained from HST Observing Program <NODE name="proposal_id"/>.</title>
    """)

make_document_collection_title: NodeBuilderTemplate = interpret_template("""
    <title>Document collection of <NODE name="instrument"/> observations \
obtained from HST Observing Program <NODE name="proposal_id"/>.</title>
    """)

make_schema_collection_title: NodeBuilderTemplate = interpret_template("""
    <title>Schema collection of <NODE name="instrument"/> observations \
obtained from HST Observing Program <NODE name="proposal_id"/>.</title>
    """)

make_other_collection_title: NodeBuilderTemplate = interpret_template("""
    <title><NODE name="collection_title"/></title>
    """)
示例#11
0
from pdart.labels.namespaces import BUNDLE_NAMESPACES, PDS4_XML_MODEL
from pdart.xml.pds4_version import INFORMATION_MODEL_VERSION
from pdart.xml.templates import (
    DocTemplate,
    NodeBuilderTemplate,
    NodeBuilder,
    FragBuilder,
    interpret_document_template,
    interpret_template,
    combine_nodes_into_fragment,
)

_make_internal_ref_node: NodeBuilderTemplate = interpret_template(
    """<Internal_Reference>
            <lid_reference><NODE name="ref_lid"/></lid_reference>
            <reference_type><NODE name="ref_type"/></reference_type>
      </Internal_Reference>""")


def make_internal_ref(ref_lid: str, ref_type: str) -> FragBuilder:
    return _make_internal_ref_node({
        "ref_lid": ref_lid,
        "ref_type": ref_type,
    })


_make_description_node: NodeBuilderTemplate = interpret_template(
    """<description>
<NODE name="description"/>
    </description>""")
示例#12
0
    <NODE name="Citation_Information" />
    <Modification_History>
      <Modification_Detail>
        <modification_date><NODE name="mod_date" /></modification_date>
        <version_id>1.0</version_id>
        <description>Initial PDS4 version</description>
      </Modification_Detail>
    </Modification_History>
  </Identification_Area>
  <FRAGMENT name="Context_Area" />
  <NODE name="Reference_List" />
  <Bundle>
    <bundle_type>Archive</bundle_type>
  </Bundle>
  <FRAGMENT name="Bundle_Member_Entries"/>
</Product_Bundle>""")
"""
An interpreted document template to create a bundle label.
"""

make_bundle_entry_member: NodeBuilderTemplate = interpret_template(
    """<Bundle_Member_Entry>
    <lidvid_reference><NODE name="collection_lidvid"/></lidvid_reference>
    <member_status>Primary</member_status>
    <reference_type><NODE name="ref_type"/></reference_type>
</Bundle_Member_Entry>""")
"""
An interpreted fragment template to create a ``<Bundle_Member_Entry
/>`` XML element.
"""
示例#13
0
# ----------------
# making <Citation_Information>
# ----------------
def _make_proposal_description(proposal_id: int, proposal_title: str,
                               pi_name: str, publication_year: str) -> str:
    """
    Return a string the describes the proposal.
    """
    return ("This document provides a summary of the observation "
            f"plan for HST proposal {proposal_id}, {proposal_title}, "
            f"PI {pi_name}, {publication_year}.")


_citation_information_template: NodeBuilderTemplate = interpret_template(
    """<Citation_Information>
<author_list><NODE name="author_list" /></author_list>
<publication_year><NODE name="publication_year" /></publication_year>
<description><NODE name="description" /></description>
</Citation_Information>""")


def make_doc_citation_information(info: Citation_Information) -> NodeBuilder:
    return _citation_information_template({
        "author_list": info.author_list,
        "publication_year": info.publication_year,
        "description": info.description,
    })


def make_doc_citation_information2(bundle_db: BundleDB, bundle_lid: str,
                                   proposal_id: int) -> NodeBuilder:
    """
示例#14
0
There can be multiple instruments for a bundle, but only one instrument for
data collection and data.
"""

from pdart.xml.templates import NodeBuilder, NodeBuilderTemplate, interpret_template

_observing_system: NodeBuilderTemplate = interpret_template(
    """<Observing_System>
      <name><NODE name="name"/></name>
      <Observing_System_Component>
        <name>Hubble Space Telescope</name>
        <type>Host</type>
        <Internal_Reference>
          <lid_reference>urn:nasa:pds:context:instrument_host:spacecraft.hst</lid_reference>
          <reference_type>is_instrument_host</reference_type>
        </Internal_Reference>
      </Observing_System_Component>
      <Observing_System_Component>
        <name><NODE name="component_name"/></name>
        <type>Instrument</type>
        <Internal_Reference>
          <lid_reference><NODE name="instrument_lid"/></lid_reference>
          <reference_type>is_instrument</reference_type>
        </Internal_Reference>
      </Observing_System_Component>
    </Observing_System>""")
"""
An interpreted fragment template to create an ``<Observing_System />``
XML element.
"""

acs_observing_system: NodeBuilder = _observing_system({
示例#15
0
from typing import Dict, List

from pdart.labels.namespaces import COLLECTION_NAMESPACES, PDS4_XML_MODEL
from pdart.xml.pds4_version import INFORMATION_MODEL_VERSION
from pdart.xml.templates import (
    DocTemplate,
    interpret_document_template,
    combine_nodes_into_fragment,
    FragBuilder,
    interpret_template,
    NodeBuilder,
    NodeBuilderTemplate,
)

_make_alternate_designation_node: NodeBuilderTemplate = interpret_template(
    """<alternate_designation><NODE name="alternate_designation"/></alternate_designation>"""
)


def _make_alternate_designation(alternate_designation: str) -> FragBuilder:
    return _make_alternate_designation_node(
        {"alternate_designation": alternate_designation}
    )


_make_description_node: NodeBuilderTemplate = interpret_template(
    """<description>
<NODE name="description"/>
    </description>"""
)
示例#16
0
Templates to create an ``<Reference_List />`` XML element.
Reference_List exists in data product, data collection and bundle labels.
"""
from typing import List

from pdart.xml.templates import (
    NodeBuilder,
    NodeBuilderTemplate,
    FragBuilder,
    combine_nodes_into_fragment,
    interpret_template,
)

_make_doc_internal_ref_node: NodeBuilderTemplate = interpret_template(
    """<Internal_Reference>
            <lid_reference><NODE name="ref_lid"/></lid_reference>
            <reference_type><NODE name="ref_type"/></reference_type>
            <comment><NODE name="comment"/></comment>
      </Internal_Reference>""")


def _make_doc_internal_ref(ref_lid: str, ref_type: str,
                           comment: str) -> FragBuilder:
    return _make_doc_internal_ref_node({
        "ref_lid": ref_lid,
        "ref_type": ref_type,
        "comment": comment,
    })


def get_hst_data_hand_book_lid(instrument: str) -> str:
    return f"urn:nasa:pds:hst-support:document:{instrument}-dhb"