def change_to_composite(observation,
                        algorithm_name='composite',
                        collection=None,
                        features=None):
    """For the case where a SimpleObservation needs to become a
    DerivedObservation."""
    temp = DerivedObservation(
        observation.collection, observation.observation_id,
        Algorithm(algorithm_name), observation.sequence_number,
        observation.intent, observation.type, observation.proposal,
        observation.telescope, observation.instrument, observation.target,
        observation.meta_release, observation.meta_read_groups,
        observation.planes, observation.environment,
        observation.target_position)
    temp.meta_producer = observation.meta_producer
    temp.last_modified = datetime.utcnow()
    temp._id = observation._id
    return temp
Exemple #2
0
 def _update_observation_type(self, observation):
     """For the case where a SimpleObservation needs to become a
     CompositeObservation."""
     return DerivedObservation(
         observation.collection,
         observation.observation_id,
         Algorithm('composite'),
         observation.sequence_number,
         observation.intent,
         observation.type,
         observation.proposal,
         observation.telescope,
         observation.instrument,
         observation.target,
         observation.meta_release,
         observation.meta_read_groups,
         observation.planes,
         observation.environment,
         observation.target_position,
     )
    def visit(self):
        for uri, file_info in self._metadata_reader.file_info.items():
            headers = self._metadata_reader.headers.get(uri)
            telescope_data = Telescope(uri, headers)
            blueprint = ObsBlueprint(instantiated_class=telescope_data)
            telescope_data.accumulate_bp(blueprint)

            if len(headers) == 0:
                parser = GenericParser(blueprint, uri)
            else:
                parser = FitsParser(headers, blueprint, uri)

            if self._dump_config:
                print(f'Blueprint for {uri}: {blueprint}')

            if self._observation is None:
                if blueprint._get('DerivedObservation.members') is None:
                    self._logger.debug('Build a SimpleObservation')
                    self._observation = SimpleObservation(
                        collection=self._storage_name.collection,
                        observation_id=self._storage_name.obs_id,
                        algorithm=Algorithm('exposure'),
                    )
                else:
                    self._logger.debug('Build a DerivedObservation')
                    self._observation = DerivedObservation(
                        collection=self._storage_name.collection,
                        observation_id=self._storage_name.obs_id,
                        algorithm=Algorithm('composite'),
                    )

            parser.augment_observation(
                observation=self._observation,
                artifact_uri=uri,
                product_id=self._storage_name.product_id,
            )

            self._observation = telescope_data.update(self._observation,
                                                      self._storage_name,
                                                      file_info)
        return self._observation
def test_validate_observation():
    obs = SimpleObservation('test_collection', 'test_obs_id',
                            Algorithm('test_name'))
    validate(obs)
    obs = DerivedObservation('test_collection', 'test_obs_id',
                             Algorithm('test_name'),
                             proposal=Proposal('test_proposal'),
                             telescope=Telescope('test_telescope'),
                             instrument=Instrument('test_instrument'),
                             target=Target('test_targets'))
    obs.algorithm.keywords = 'foo'
    obs.proposal.keywords = set('foo=42')
    obs.telescope.keywords = set('foo:42')
    obs.instrument.keywords.add("tick'marks")
    obs.target.keywords = set('has multiple spaces')
    test_plane = Plane('test_plane')
    test_plane.provenance = Provenance('test_provenance')
    test_plane.provenance.keywords.add('pipe|denied')
    obs.planes['test_plane'] = test_plane
    with pytest.raises(AssertionError):
        validate(obs)
Exemple #5
0
def _build_obs(override, db_content, fqn, index, almaca_name, md_name):

    obs_date = db_content['Observation date'][index]
    if obs_date is None:
        raise mc.CadcException('No observation date for {}'.format(fqn))
    else:
        obs_date = time.Time(obs_date).to_datetime()

    # of_site('alma')
    # 2225015.30883296, -5440016.41799762, -2481631.27428014
    #
    size = db_content['Array'][index]
    telescope = Telescope(name="ALMA-{}".format(size),
                          geo_location_x=2225142.18,
                          geo_location_y=-5440307.37,
                          geo_location_z=-2481029.852)

    instrument = Instrument(name=_get_band_name(override))

    # HK - 14-08-19
    # target: this should be the science target / science fieldname and
    # not the calibrator fieldname, as it is presently (i.e., should be
    # J1851+0035, not J1924-2914).  Or, we may need to continue to leave
    # that field blank at this level.  A single calibrated measurement set
    # may contain multiple science target names, which would not be
    # properly captured at this level.  [For the raw data, the target
    # field is left blank]
    target = Target(name=override.get('field'),
                    standard=False,
                    moving=False,
                    target_type=TargetType.OBJECT)

    # HK - 07-02-20
    # Since we've changed what the base level observation is and can now list
    # a target name in the 'Derived Observation' base plane, I believe that
    # means we can also include that target's position under targetPosition.
    # You've already pulled this info out for the subsequent levels of the
    # hierarchy under 'position', so it's presumably fairly straightforward to
    # include the same info here.
    result_ra, result_dec = _get_ra_dec(md_name)
    point = Point(result_ra, result_dec)
    target_position = TargetPosition(
        coordinates=point,
        coordsys='ICRS',  # from listobs output
        equinox=2000.0)  # a guess by google

    # db_content as votable:
    # >>> t.colnames
    # ['Project_code', 'Source_name', 'RA', 'Dec', 'Galactic_longitude',
    # 'Galactic_latitude', 'Band', 'Spatial_resolution',
    # 'Frequency_resolution', 'Array', 'Mosaic', 'Integration',
    # 'Release_date', 'Frequency_support', 'Velocity_resolution',
    # 'Pol_products', 'Observation_date', 'PI_name', 'SB_name',
    # 'Proposal_authors', 'Line_sensitivity__10_km_s_',
    # 'Continuum_sensitivity', 'PWV', 'Group_ous_id', 'Member_ous_id',
    # 'Asdm_uid', 'Project_title', 'Project_type', 'Scan_intent',
    # 'Field_of_view', 'Largest_angular_scale', 'QA2_Status', 'COUNT',
    # 'Science_keyword', 'Scientific_category', 'ASA_PROJECT_CODE']
    #
    # db_content.colnames as html:
    #
    # ['Project code', 'Source name', 'RA', 'Dec', 'Galactic longitude',
    # 'Galactic latitude', 'Band', 'Spatial resolution',
    # 'Frequency resolution', 'Array', 'Mosaic', 'Integration',
    # 'Release date', 'Frequency support', 'Velocity resolution',
    # 'Pol products', 'Observation date', 'PI name', 'SB name',
    # 'Proposal authors', 'Line sensitivity (10 km/s)',
    # 'Continuum sensitivity', 'PWV', 'Group ous id', 'Member ous id',
    # 'Asdm uid', 'Project title', 'Project type', 'Scan intent',
    # 'Field of view', 'Largest angular scale', 'QA2 Status', 'COUNT',
    # 'Science keyword', 'Scientific category', 'ASA_PROJECT_CODE']

    # HK - 14-08-19
    # can we include the project code, and not just the observation UID
    # somewhere in here?  For the raw data, it looks like the project
    # code was included as 'proposal: ID', whereas for the calibrated
    # measurement set, proposal: ID is now set to the UID and the project
    # code (2016.1.00010.S) is not captured anywhere.  Could the 'project'
    # field, currently set as 'null' be used for this?
    proposal = Proposal(id=db_content['Project code'][index],
                        project=override.get('project'),
                        pi_name=db_content['PI name'][index],
                        title=db_content['Project title'][index])

    keywords = db_content['Science keyword'][index]
    if keywords is not None:
        proposal.keywords = set(keywords.split())

    environment = Environment()
    environment.tau = db_content['PWV'][index] / 0.935 + 0.35
    environment.wavelength_tau = 350 * units.um.to(units.meter)

    intent = (ObservationIntentType.SCIENCE
              if almaca_name.intent is ProductType.SCIENCE else
              ObservationIntentType.CALIBRATION)

    algorithm = Algorithm(name='single band split')
    #
    # PD, SG 15-08-19
    # make it a composite, algorithm name something like
    # 'target splitting'
    #
    observation = DerivedObservation(collection=ARCHIVE,
                                     observation_id=almaca_name.obs_id,
                                     sequence_number=None,
                                     intent=intent,
                                     type="OBJECT",
                                     proposal=proposal,
                                     telescope=telescope,
                                     instrument=instrument,
                                     target=target,
                                     meta_release=obs_date,
                                     algorithm=algorithm,
                                     environment=environment,
                                     target_position=target_position)
    observation.members.add(
        ObservationURI(
            mc.CaomName.make_obs_uri_from_obs_id('ALMA', 'A001_X88b_X23')))
    return observation