コード例 #1
0
 def get_members(self):
     members = caom_util.TypedSet(
         observation.ObservationURI, observation.ObservationURI("caom:foo/bar"))
     return members
コード例 #2
0
 def get_inputs(self):
     return caom_util.TypedSet(plane.PlaneURI,
                               plane.PlaneURI("caom:foo/bar/plane1"),
                               plane.PlaneURI("caom:foo/bar/plane2"))
コード例 #3
0
def _build_observation(args):
    config = mc.Config()
    config.get_executors()

    existing = None
    if args.in_obs_xml:
        existing = mc.read_obs_from_file(args.in_obs_xml.name)

    drao_name, drao_dir = _get_name(args)
    json_fqn = f'{drao_dir}/{drao_name.obs_id}.json'
    logging.error(f'Looking for metadata in {json_fqn}')
    if not os.path.exists(json_fqn):
        raise mc.CadcException(
            f'Could not find {json_fqn}. Cannot continue without it.')

    with open(json_fqn) as f:
        js = f.read()

    # get the skeleton of the CAOM2 observation
    jsonpickle.handlers.register(TypedOrderedDict, TypedOrderedDictHandler)
    jsonpickle.handlers.register(datetime, DateTimeHandler)
    obs = jsonpickle.decode(js)

    # add the bits of the CAOM2 observation that are required for a
    # structure that's acceptable to /ams - this mostly amounts to
    # ensuring that attributes have been defined on the 'un-pickled'

    _set_common(obs, existing)

    if obs._proposal is not None:
        if not hasattr(obs._proposal, '_project'):
            obs._proposal._project = None
        if not hasattr(obs._proposal, '_name'):
            obs._proposal._name = None
        if not hasattr(obs._proposal, '_keywords'):
            obs._proposal._keywords = set()
        if not hasattr(obs._proposal, '_title'):
            obs._proposal._title = None
    if obs._target is not None:
        if not hasattr(obs._target, '_target_type'):
            obs._target._target_type = None
        if not hasattr(obs._target, '_standard'):
            obs._target._standard = None
        if not hasattr(obs._target, '_redshift'):
            obs._target._redshift = None
        if not hasattr(obs._target, '_moving'):
            obs._target._moving = None
        if not hasattr(obs._target, '_target_id'):
            obs._target._target_id = None
        obs._target._keywords = set()
    obs._requirements = None
    if obs._telescope is not None:
        obs._telescope._keywords = set()
    if obs._instrument is not None:
        obs._instrument._keywords = set()
    obs._environment = None

    if not hasattr(obs, '_meta_read_groups'):
        obs._meta_read_groups = None

    for plane in obs.planes.values():
        if existing is not None:
            _set_common(plane, existing.planes[plane.product_id])
        else:
            _set_common(plane, None)
        plane._acc_meta_checksum = None

        if not hasattr(plane, '_data_read_groups'):
            plane._data_read_groups = None
        if not hasattr(plane, '_meta_read_groups'):
            plane._meta_read_groups = None

        plane._metrics = None
        plane._quality = None
        if plane._provenance is not None:
            plane._provenance._keywords = set()
            plane._provenance._inputs = TypedSet(PlaneURI, )
            if not hasattr(plane._provenance, '_run_id'):
                plane._provenance._run_id = None
            # plane._provenance._last_executed = None
        if hasattr(plane, '_position'):
            if plane._position is not None:
                plane._position._dimension = None
                plane._position._resolution = None
                plane._position._sample_size = None

            if not hasattr(plane._position, '_resolution_bounds'):
                plane._position._resolution_bounds = None
        else:
            plane._position = None
        if hasattr(plane, '_energy'):
            if plane._energy is not None:
                if not hasattr(plane._energy, '_sample_size'):
                    plane._energy._sample_size = None
                if not hasattr(plane._energy, '_bandpass_name'):
                    plane._energy._bandpass_name = None
                if not hasattr(plane._energy, '_transition'):
                    plane._energy._transition = None
                if not hasattr(plane._energy, '_resolving_power'):
                    plane._energy._resolving_power = None
                if not hasattr(plane._energy, '_resolving_power_bounds'):
                    plane._energy._resolving_power_bounds = None

                if hasattr(plane._energy, '_em_band'):
                    plane._energy.energy_bands = caom_util.TypedSet(EnergyBand)
                    plane._energy.energy_bands.add(plane._energy._em_band)
        else:
            plane._energy = None
        if not hasattr(plane, '_polarization'):
            plane._polarization = None
        if hasattr(plane, '_time'):
            if plane._time is not None:
                if not hasattr(plane._time, '_resolution'):
                    plane._time._resolution = None
                if not hasattr(plane._time, '_resolution_bounds'):
                    plane._time._resolution_bounds = None
        else:
            plane._time = None
        if not hasattr(plane, '_position'):
            plane._position = None
        if not hasattr(plane, '_custom'):
            plane._custom = None

        for artifact in plane.artifacts.values():
            if existing is not None:
                _set_common(
                    artifact,
                    existing.planes[plane.product_id].artifacts[artifact.uri])
            else:
                _set_common(artifact, None)
            artifact._acc_meta_checksum = None
            artifact.parts = TypedOrderedDict(Part, )
            if not hasattr(artifact, '_content_release'):
                artifact._content_release = None
            if not hasattr(artifact, '_content_read_groups'):
                artifact._content_read_groups = None

    if args.out_obs_xml:
        mc.write_obs_to_file(obs, args.out_obs_xml)
    else:
        raise mc.CadcException(f'No where to write for {obs.observation_id}')
    return 0