def xml(self, project_name):
     r'''
     Actually generate the required XML. This method calls two
     other methods, which may be overridden: xml_prefix() and
     xml_suffix().
     '''
     xml_string = self.xml_prefix(project_name)
     if self.children:
         childlist_format = '\n<children>%s\n</children>'
         child_format     = '\n  <item index="%d">\n%s\n  </item>'
         children = [child_format % (index, indent(child.xml(project_name), 4))
                     for index, child in enumerate(self.children)]
         xml_string += indent(childlist_format % '\n'.join(children), 2)
     xml_string += self.xml_suffix(project_name)
     return xml_string
示例#2
0
    def xml(self, project_name=None, child_id=None, parent_label=None):
        r'''
        '''
        def lower_case(bool):
            return repr(bool).lower()
            
        incoherent_stokes = self.incoherent_stokes_data is not None
        coherent_stokes = self.coherent_stokes_data is not None
        flyseye = False
        if coherent_stokes:
            flyseye = self.tied_array_beams.flyseye

            
        output = '''<correlatedData>'''+lower_case(self.correlated_data)+'''</correlatedData>
<filteredData>'''+lower_case(self.filtered_data)+'''</filteredData>
<beamformedData>'''+lower_case(self.beamformed_data)+'''</beamformedData>
<coherentStokesData>'''+lower_case(coherent_stokes)+'''</coherentStokesData>
<incoherentStokesData>'''+lower_case(incoherent_stokes)+'''</incoherentStokesData>'''
        if self.correlated_data:
            output += '''
<integrationInterval>'''+str(self.integration_time_seconds)+'''</integrationInterval>'''
        output += '''
<channelsPerSubband>'''+str(self.channels_per_subband)+'''</channelsPerSubband>
<pencilBeams>
  <flyseye>'''+lower_case(flyseye)+'''</flyseye>
  <pencilBeamList/>
</pencilBeams>''' + self.tied_array_beams.xml()+'''
<stokes>
  <integrateChannels>'''+lower_case(self.stokes_integrate_channels)+'''</integrateChannels>'''

        # If number_collapsed_channels is not set, default to
        # correlator settings.
        if self.incoherent_stokes_data:
            if self.incoherent_stokes_data.number_collapsed_channels is None:
                    self.incoherent_stokes_data.number_collapsed_channels = self.channels_per_subband
            output += '\n'+indent(self.incoherent_stokes_data.xml(), 2)
        if self.coherent_stokes_data:
            if self.coherent_stokes_data.number_collapsed_channels is None:
                    self.coherent_stokes_data.number_collapsed_channels = self.channels_per_subband

            output += '\n'+indent(self.coherent_stokes_data.xml(), 2)

        output += '''
</stokes>
<bypassPff>'''+lower_case(self.bypass_pff)+'''</bypassPff>
<enableSuperterp>'''+lower_case(self.enable_superterp)+'''</enableSuperterp>
'''
        return output
 def xml(self, project_name):
     r'''
     Actually generate the required XML. This method calls two
     other methods, which may be overridden: xml_prefix() and
     xml_suffix().
     '''
     xml_string = self.xml_prefix(project_name)
     if self.children:
         childlist_format = '\n<children>%s\n</children>'
         child_format = '\n  <item index="%d">\n%s\n  </item>'
         children = [
             child_format % (index, indent(child.xml(project_name), 4))
             for index, child in enumerate(self.children)
         ]
         xml_string += indent(childlist_format % '\n'.join(children), 2)
     xml_string += self.xml_suffix(project_name)
     return xml_string
示例#4
0
    def xml_prefix(self, project_name):
        obs_name = self.children[0].target_source.name + ' ' + self.antenna_set
        if self.name:
            obs_name = self.name

        now = ephem.Observer().date

        start_date = self.start_date
        end_date = ephem.Date(
            ephem.Date(self.start_date) + ephem.second *
            (self.duration_seconds)).tuple()
        rounded_start_date = start_date[:-1] + (int(round(start_date[-1])), )
        rounded_end_date = end_date[:-1] + (int(round(end_date[-1])), )
        now = now.tuple()[:-1] + (int(round(now.tuple()[-1])), )
        topology = self.label()
        check_mom_topology(topology)

        observation_str = '''<lofar:observation>
  <name>''' + obs_name + '''</name>
  <description>''' + obs_name + '''</description>
  <topology>''' + topology + '''</topology>
  <currentStatus>
    <mom2:''' + self.initial_status + '''Status/>
  </currentStatus>
  <lofar:observationAttributes>
    <name>''' + obs_name + '''</name>
    <projectName>''' + project_name + '''</projectName>
    <instrument>''' + self.backend.instrument_name() + '''</instrument>
    <defaultTemplate>''' + self.backend.default_template + '''</defaultTemplate>
    <tbbPiggybackAllowed>''' + str(
            self.allow_tbb).lower() + '''</tbbPiggybackAllowed>
    <aartfaacPiggybackAllowed>''' + str(
                self.allow_aartfaac).lower() + '''</aartfaacPiggybackAllowed>
    <userSpecification>
      <antenna>''' + mom_antenna_name_from_mac_name(
                    self.antenna_set) + '''</antenna>
      <clock mode=\"''' + str(self.clock_mhz) + ''' MHz\"/>
      <instrumentFilter>''' + mom_frequency_range(
                        self.frequency_range,
                        self.clock_mhz) + '''</instrumentFilter>
''' + indent(self.backend.xml(), 6) + '''      <stationSet>Custom</stationSet>
      <stations>
        ''' + '\n        '.join([
                            '<station name=\"' + n + '\" />'
                            for n in self.stations
                        ]) + '''
      </stations>
      <timeFrame>UT</timeFrame>
      <startTime>''' + mom_timestamp(*rounded_start_date) + '''</startTime>
      <endTime>''' + mom_timestamp(*rounded_end_date) + '''</endTime>
      <duration>''' + mom_duration(
                            seconds=self.duration_seconds) + '''</duration>
      <numberOfBitsPerSample>''' + str(
                                self.bit_mode) + '''</numberOfBitsPerSample>
    </userSpecification>
    <systemSpecification/>
  </lofar:observationAttributes>'''
        return observation_str
示例#5
0
def xml(items, project='2015LOFAROBS_new', description=None):
    """
    Format a list of *items* as an XML string that can be
    uploaded to a MoM project with name *project*.
    """
    return """<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<lofar:project xmlns:lofar=\"http://www.astron.nl/MoM2-Lofar\"
    xmlns:mom2=\"http://www.astron.nl/MoM2\"
    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.astron.nl/MoM2-Lofar http://lofar.astron.nl:8080/mom3/schemas/LofarMoM2.xsd http://www.astron.nl/MoM2 http://lofar.astron.nl:8080/mom3/schemas/MoM2.xsd \">
    <version>1.16</version>
    <name>"""+project+"""</name>
    <description>"""+ (description or project) +"""</description>
    <children>
      <item>\n"""+'      </item>\n      <item>'.join([indent(item.xml(project), 8)
                                                    for child_id, item in enumerate(items)])+"""
示例#6
0
    def xml_prefix(self, project_name):
        obs_name = self.children[0].target_source.name+' '+self.antenna_set
        if self.name:
            obs_name = self.name

        now = ephem.Observer().date

        start_date = self.start_date
        end_date = ephem.Date(ephem.Date(self.start_date) + ephem.second*(self.duration_seconds)).tuple()
        rounded_start_date = start_date[:-1]+(int(round(start_date[-1])),)
        rounded_end_date   = end_date[:-1]+(int(round(end_date[-1])),)
        now = now.tuple()[:-1] + (int(round(now.tuple()[-1])),)
        topology = self.label()
        check_mom_topology(topology)
        
        observation_str = '''<lofar:observation>
  <name>'''+obs_name+'''</name>
  <description>'''+obs_name+'''</description>
  <topology>'''+topology+'''</topology>
  <currentStatus>
    <mom2:'''+self.initial_status+'''Status/>
  </currentStatus>
  <lofar:observationAttributes>
    <name>'''+obs_name+'''</name>
    <projectName>'''+project_name+'''</projectName>
    <instrument>'''+self.backend.instrument_name()+'''</instrument>
    <defaultTemplate>'''+self.backend.default_template+'''</defaultTemplate>
    <tbbPiggybackAllowed>'''+str(self.allow_tbb).lower()+'''</tbbPiggybackAllowed>
    <aartfaacPiggybackAllowed>'''+str(self.allow_aartfaac).lower()+'''</aartfaacPiggybackAllowed>
    <userSpecification>
      <antenna>'''+mom_antenna_name_from_mac_name(self.antenna_set)+'''</antenna>
      <clock mode=\"'''+str(self.clock_mhz)+''' MHz\"/>
      <instrumentFilter>'''+mom_frequency_range(self.frequency_range, self.clock_mhz)+'''</instrumentFilter>
'''+indent(self.backend.xml(), 6)+'''      <stationSet>Custom</stationSet>
      <stations>
        '''+'\n        '.join(['<station name=\"'+n+'\" />' for n in self.stations])+'''
      </stations>
      <timeFrame>UT</timeFrame>
      <startTime>'''+mom_timestamp(*rounded_start_date)+'''</startTime>
      <endTime>'''+mom_timestamp(*rounded_end_date)+'''</endTime>
      <duration>'''+mom_duration(seconds = self.duration_seconds)+'''</duration>
      <numberOfBitsPerSample>'''+str(self.bit_mode)+'''</numberOfBitsPerSample>
    </userSpecification>
    <systemSpecification/>
  </lofar:observationAttributes>'''
        return observation_str
示例#7
0
    def xml_prefix(self, project_name, current_date = None):
        backend    = self.parent.backend
        obs_name   = self.target_source.name
        if self.parent.name:
            obs_name = self.parent.name

        duration_s = 0
        if self.duration_s is not None:
            duration_s = int(round(self.duration_s))

        tied_array_beams = ''
        if backend.need_beam_observation() or self.tied_array_beams:
            if self.tied_array_beams is None:
                self.tied_array_beams = backend.tied_array_beams
            tied_array_beams = indent(
                self.tied_array_beams.xml(project_name),
                amount = 4)


        result_data_products = self.xml_result_data_products(backend,
                                                             self.storage_cluster,
                                                             self.storage_partition)
        
        sub_bands     = parse_subband_list(self.subband_spec)
        bandwidth_mhz = len(sub_bands)*(self.parent.clock_mhz/1024.0)
        mean_sub_band = sum(sub_bands)/float(len(sub_bands))
        central_frequency_mhz = mean_sub_band*(self.parent.clock_mhz/1024.0)
        if self.parent.frequency_range == 'HBA_LOW':
            central_frequency_mhz += self.parent.clock_mhz/2.0
        if self.parent.frequency_range in ['HBA_MID', 'HBA_HIGH']:
            central_frequency_mhz += self.parent.clock_mhz

        parameters = {
            'backend_measurement_type' : backend.measurement_type(),
            'name'                     : self.target_source.name,
            'description'              : obs_name,
            'topology'                 : self.label(),
            'backend_attributes'       : backend.measurement_attributes(),
            'measurement_type'         : self.measurement_type,
            'target_name'              : self.target_source.name,
            'ra_deg'                   : self.target_source.ra_deg(),
            'dec_deg'                  : self.target_source.dec_deg(),
            'reference_frame'          : self.target_source.reference_frame,
            'mom_duration'             : mom_duration(seconds = duration_s),
            'bandwidth_mhz'            : bandwidth_mhz,
            'central_frequency_mhz'    : central_frequency_mhz,
            'subband_spec'             : self.subband_spec,
            'tied_array_beams'         : tied_array_beams,
            'result_data_products'     : result_data_products,
            'initial_status'           : self.parent.initial_status,
        }
        prefix_format = '''<lofar:measurement xsi:type=\"%(backend_measurement_type)s\">
<name>%(name)s</name>
<description>%(description)s</description>
<topology>%(topology)s</topology>
<currentStatus>
  <mom2:%(initial_status)sStatus/>
</currentStatus>
<lofar:%(backend_attributes)s>
  <measurementType>%(measurement_type)s</measurementType>
  <specification>
    <targetName>%(target_name)s</targetName>
    <ra>%(ra_deg)r</ra>
    <dec>%(dec_deg)r</dec>
    <equinox>%(reference_frame)s</equinox>
    <duration>%(mom_duration)s</duration>
    <subbandsSpecification>
      <bandWidth unit=\"MHz\">%(bandwidth_mhz).4f</bandWidth>
      <centralFrequency unit=\"MHz\">%(central_frequency_mhz).4f</centralFrequency>
      <contiguous>false</contiguous>
      <subbands>%(subband_spec)s</subbands>
    </subbandsSpecification>%(tied_array_beams)s
  </specification>
</lofar:%(backend_attributes)s>%(result_data_products)s'''

        return prefix_format % parameters
示例#8
0
    def xml_prefix(self, project_name = None):
        template ='''<lofar:pipeline xsi:type="lofar:AveragingPipelineType">
  <topology>%(label)s</topology>
  <predecessor_topology>%(predecessor)s</predecessor_topology>
  <name>%(name)s</name>
  <description>%(name)s: "%(default_template)s"</description>
  <processingCluster>
    <name>%(processing_cluster)s</name>
    <partition>%(processing_partition)s</partition>
    <numberOfTasks>%(processing_nr_nodes)s</numberOfTasks>
    <numberOfCoresPerTask>%(processing_nr_cores)s</numberOfCoresPerTask>
  </processingCluster>
  <currentStatus>
    <mom2:%(initial_status)sStatus/>
  </currentStatus>
  <averagingPipelineAttributes>
    <defaultTemplate>%(default_template)s</defaultTemplate>
    <duration>%(duration)s</duration>
    <startTime>%(start_time)s</startTime>
    <endTime></endTime>%(ndppp)s
    <flaggingStrategy>%(flagging_strategy)s</flaggingStrategy>
  </averagingPipelineAttributes>
  <usedDataProducts>%(used_data_products)s
  </usedDataProducts>
  <resultDataProducts>
    <item>
      <lofar:uvDataProduct>
        <name>%(label)s</name>
        <topology>%(label)s</topology>
        <status>no_data</status>
        <storageCluster>
          <name>%(storage_cluster)s</name>
          <partition>%(storage_partition)s</partition>
        </storageCluster>
      </lofar:uvDataProduct>
    </item>
  </resultDataProducts>
'''
        used_data_product_template = '''\n<item>
  <lofar:uvDataProduct topology="%(name)s">
    <name>%(name)s</name>
  </lofar:uvDataProduct>
</item>'''
        args = {
            'label'       : self.label() + '.uv.dps',
            'predecessor' : self.predecessor(),
            'name'        : self.name,
            'default_template' : self.default_template,
            'duration'    : '',
            'start_time'  : '',
            'flagging_strategy': self.flagging_strategy,
            'ndppp'       : indent(self.ndppp.xml(), 4),
            'used_data_products' : '',
            'initial_status': self.initial_status,
            'processing_cluster': self.processing_cluster,
            'processing_partition': self.processing_partition,
            'processing_nr_nodes': self.processing_nr_nodes,
            'processing_nr_cores': self.processing_nr_cores,
            'storage_cluster': self.storage_cluster,
            'storage_partition': self.storage_partition
        }
        if self.duration_s is not None:
            args['duration'] = mom_duration(seconds = self.duration_s)
        if self.start_date is not None:
            start_date = ephem.Date(self.start_date).tuple()
            rounded_start_date = start_date[:-1]+(int(round(start_date[-1])),)
            args['start_time'] = mom_timestamp(*rounded_start_date)
        if self.input_data is None:
            raise ValueError('AveragingPipeline.input_data is None!')
        if self.flagging_strategy is None:
            args['flagging_strategy'] = self.input_data[0].parent.antenna_set[0:3].upper()+'default'
        elif self.flagging_strategy in ['HBAdefault', 'LBAdefault']:
            args['flagging_strategy'] = self.flagging_strategy
        else:
            raise ValueError('lofarobsxml.AverigingPipeline: unknown flagging strategy %r' %
                             self.flagging_strategy)
        args['used_data_products'] = indent(
            '\n'.join([
                used_data_product_template % {'name' : sap.data_products_label()} #TODO this needs a proper fix as the topology for the observation has changed
                for sap in self.input_data]),
            4)
        return template % args
示例#9
0
    def xml_prefix(self, project_name=None):
        template = '''<lofar:pipeline xsi:type="lofar:AveragingPipelineType">
  <topology>%(label)s</topology>
  <predecessor_topology>%(predecessor)s</predecessor_topology>
  <name>%(name)s</name>
  <description>%(name)s: "%(default_template)s"</description>
  <processingCluster>
    <name>%(processing_cluster)s</name>
    <partition>%(processing_partition)s</partition>
    <numberOfTasks>%(processing_nr_nodes)s</numberOfTasks>
    <numberOfCoresPerTask>%(processing_nr_cores)s</numberOfCoresPerTask>
  </processingCluster>
  <currentStatus>
    <mom2:%(initial_status)sStatus/>
  </currentStatus>
  <averagingPipelineAttributes>
    <defaultTemplate>%(default_template)s</defaultTemplate>
    <duration>%(duration)s</duration>
    <startTime>%(start_time)s</startTime>
    <endTime></endTime>%(ndppp)s
    <flaggingStrategy>%(flagging_strategy)s</flaggingStrategy>
  </averagingPipelineAttributes>
  <usedDataProducts>%(used_data_products)s
  </usedDataProducts>
  <resultDataProducts>
    <item>
      <lofar:uvDataProduct>
        <name>%(label)s</name>
        <topology>%(label)s</topology>
        <status>no_data</status>
        <storageCluster>
          <name>%(storage_cluster)s</name>
          <partition>%(storage_partition)s</partition>
        </storageCluster>
      </lofar:uvDataProduct>
    </item>
  </resultDataProducts>
'''
        used_data_product_template = '''\n<item>
  <lofar:uvDataProduct topology="%(name)s">
    <name>%(name)s</name>
  </lofar:uvDataProduct>
</item>'''
        args = {
            'label': self.label() + '.uv.dps',
            'predecessor': self.predecessor(),
            'name': self.name,
            'default_template': self.default_template,
            'duration': '',
            'start_time': '',
            'flagging_strategy': self.flagging_strategy,
            'ndppp': indent(self.ndppp.xml(), 4),
            'used_data_products': '',
            'initial_status': self.initial_status,
            'processing_cluster': self.processing_cluster,
            'processing_partition': self.processing_partition,
            'processing_nr_nodes': self.processing_nr_nodes,
            'processing_nr_cores': self.processing_nr_cores,
            'storage_cluster': self.storage_cluster,
            'storage_partition': self.storage_partition
        }
        if self.duration_s is not None:
            args['duration'] = mom_duration(seconds=self.duration_s)
        if self.start_date is not None:
            start_date = ephem.Date(self.start_date).tuple()
            rounded_start_date = start_date[:-1] + (int(round(
                start_date[-1])), )
            args['start_time'] = mom_timestamp(*rounded_start_date)
        if self.input_data is None:
            raise ValueError('AveragingPipeline.input_data is None!')
        if self.flagging_strategy is None:
            args['flagging_strategy'] = self.input_data[0].parent.antenna_set[
                0:3].upper() + 'default'
        elif self.flagging_strategy in ['HBAdefault', 'LBAdefault']:
            args['flagging_strategy'] = self.flagging_strategy
        else:
            raise ValueError(
                'lofarobsxml.AverigingPipeline: unknown flagging strategy %r' %
                self.flagging_strategy)
        args['used_data_products'] = indent(
            '\n'.join([
                used_data_product_template % {
                    'name': sap.data_products_label()
                }  #TODO this needs a proper fix as the topology for the observation has changed
                for sap in self.input_data
            ]),
            4)
        return template % args
示例#10
0
    def xml_prefix(self, project_name, current_date=None):
        backend = self.parent.backend
        obs_name = self.target_source.name
        if self.parent.name:
            obs_name = self.parent.name

        duration_s = 0
        if self.duration_s is not None:
            duration_s = int(round(self.duration_s))

        tied_array_beams = ''
        if backend.need_beam_observation() or self.tied_array_beams:
            if self.tied_array_beams is None:
                self.tied_array_beams = backend.tied_array_beams
            tied_array_beams = indent(self.tied_array_beams.xml(project_name),
                                      amount=4)

        result_data_products = self.xml_result_data_products(
            backend, self.storage_cluster, self.storage_partition)

        sub_bands = parse_subband_list(self.subband_spec)
        if len(sub_bands) == 0:
            raise ('Empty subband list %r' % self.subband_spec)
        bandwidth_mhz = len(sub_bands) * (self.parent.clock_mhz / 1024.0)
        mean_sub_band = sum(sub_bands) / float(len(sub_bands))
        central_frequency_mhz = mean_sub_band * (self.parent.clock_mhz /
                                                 1024.0)
        if self.parent.frequency_range == 'HBA_LOW':
            central_frequency_mhz += self.parent.clock_mhz / 2.0
        if self.parent.frequency_range in ['HBA_MID', 'HBA_HIGH']:
            central_frequency_mhz += self.parent.clock_mhz

        parameters = {
            'backend_measurement_type': backend.measurement_type(),
            'name': self.target_source.name,
            'description': obs_name,
            'topology': self.label(),
            'backend_attributes': backend.measurement_attributes(),
            'measurement_type': self.measurement_type,
            'target_name': self.target_source.name,
            'ra_deg': self.target_source.ra_deg(),
            'dec_deg': self.target_source.dec_deg(),
            'reference_frame': self.target_source.reference_frame,
            'mom_duration': mom_duration(seconds=duration_s),
            'bandwidth_mhz': bandwidth_mhz,
            'central_frequency_mhz': central_frequency_mhz,
            'subband_spec': self.subband_spec,
            'tied_array_beams': tied_array_beams,
            'result_data_products': result_data_products,
            'initial_status': self.parent.initial_status,
        }
        prefix_format = '''<lofar:measurement xsi:type=\"%(backend_measurement_type)s\">
<name>%(name)s</name>
<description>%(description)s</description>
<topology>%(topology)s</topology>
<currentStatus>
  <mom2:%(initial_status)sStatus/>
</currentStatus>
<lofar:%(backend_attributes)s>
  <measurementType>%(measurement_type)s</measurementType>
  <specification>
    <targetName>%(target_name)s</targetName>
    <ra>%(ra_deg)r</ra>
    <dec>%(dec_deg)r</dec>
    <equinox>%(reference_frame)s</equinox>
    <duration>%(mom_duration)s</duration>
    <subbandsSpecification>
      <bandWidth unit=\"MHz\">%(bandwidth_mhz).4f</bandWidth>
      <centralFrequency unit=\"MHz\">%(central_frequency_mhz).4f</centralFrequency>
      <contiguous>false</contiguous>
      <subbands>%(subband_spec)s</subbands>
    </subbandsSpecification>%(tied_array_beams)s
  </specification>
</lofar:%(backend_attributes)s>%(result_data_products)s'''

        return prefix_format % parameters