예제 #1
0
    def __init__(self, parent, **kwargs):
        self._REQ_KEY_SETS = [[QUANTITY.VALUE], [QUANTITY.SOURCE]]

        super().__init__(parent, **kwargs)

        # Aliases not added if in DISTINCT_FROM
        if self._key == parent._KEYS.ALIAS:
            value = parent.catalog.clean_entry_name(self[QUANTITY.VALUE])
            for df in parent.get(parent._KEYS.DISTINCT_FROM, []):
                if value == df[QUANTITY.VALUE]:
                    raise CatDictError("Alias '{}' in '{}'\' '{}' list".format(
                        value, parent[parent._KEYS.NAME],
                        parent._KEYS.DISTINCT_FROM))

        # Check that value exists
        if (not self[QUANTITY.VALUE] or self[QUANTITY.VALUE] == '--'
                or self[QUANTITY.VALUE] == '-'):
            raise CatDictError(
                "Value '{}' is empty, not adding to '{}'".format(
                    self[QUANTITY.VALUE], parent[parent._KEYS.NAME]))

        if not parent._clean_quantity(self):
            raise CatDictError(
                "Value '{}' did not survive cleaning process, not adding to "
                " '{}'.".format(self[QUANTITY.VALUE],
                                parent[parent._KEYS.NAME]))

        # Check that quantity value matches type after cleaning
        if (isinstance(self._key, Key) and self._key.type == KEY_TYPES.NUMERIC
                and not is_number(self[QUANTITY.VALUE])):
            raise CatDictError(
                "Value '{}' is not numeric, not adding to '{}'".format(
                    self[QUANTITY.VALUE], parent[parent._KEYS.NAME]))
예제 #2
0
파일: entry.py 프로젝트: sPaMFouR/astrocats
 def _check_cat_dict_source(self, cat_dict_class, key_in_self, **kwargs):
     """Check that a source exists and that a quantity isn't erroneous."""
     # Make sure that a source is given
     source = kwargs.get(cat_dict_class._KEYS.SOURCE, None)
     if source is None:
         raise CatDictError(
             "{}: `source` must be provided!".format(self[self._KEYS.NAME]),
             warn=True)
     # Check that source is a list of integers
     for x in source.split(','):
         if not is_integer(x):
             raise CatDictError(
                 "{}: `source` is comma-delimited list of "
                 " integers!".format(self[self._KEYS.NAME]),
                 warn=True)
     # If this source/data is erroneous, skip it
     if self.is_erroneous(key_in_self, source):
         self._log.info("This source is erroneous, skipping")
         return None
     # If this source/data is private, skip it
     if (self.catalog.args is not None and not self.catalog.args.private and
             self.is_private(key_in_self, source)):
         self._log.info("This source is private, skipping")
         return None
     return source
    def __init__(self, parent, **kwargs):
        """Initialize."""
        self._REQ_KEY_SETS = [[PHOTOMETRY.SOURCE, PHOTOMETRY.MODEL],
                              [PHOTOMETRY.TIME, PHOTOMETRY.HOST],
                              [
                                  PHOTOMETRY.MAGNITUDE, PHOTOMETRY.FLUX,
                                  PHOTOMETRY.UNABSORBED_FLUX,
                                  PHOTOMETRY.FLUX_DENSITY,
                                  PHOTOMETRY.COUNT_RATE, PHOTOMETRY.LUMINOSITY
                              ]]
        # Note: `_check()` is called at end of `super().__init__`
        super(Photometry, self).__init__(parent, **kwargs)

        # If `BAND` is given, but any of `bandmetaf_keys` is not, try to infer
        if self._KEYS.BAND in self:
            sband = self[self._KEYS.BAND]
            bandmetaf_keys = [
                self._KEYS.INSTRUMENT, self._KEYS.TELESCOPE, self._KEYS.SYSTEM
            ]

            for bmf in bandmetaf_keys:
                if bmf not in self:
                    temp = bandmetaf(sband, bmf)
                    if temp is not None:
                        self[bmf] = temp

        # Convert dates to MJD
        timestrs = [str(x) for x in listify(self.get(self._KEYS.TIME, ''))]
        for ti, timestr in enumerate(timestrs):
            if (any(x in timestr for x in ['-', '/'])
                    and not timestr.startswith('-')):
                timestrs[ti] = timestr.replace('/', '-')
                try:
                    timestrs[ti] = str(
                        astrotime(timestrs[ti], format='isot').mjd)
                except Exception:
                    raise CatDictError('Unable to convert date to MJD.')
            elif timestr:  # Make sure time is string
                timestrs[ti] = timestr
        if len(timestrs) > 0 and timestrs[0] != '':
            self[self._KEYS.
                 TIME] = timestrs if len(timestrs) > 1 else timestrs[0]

        # Time unit is necessary for maximum time determination
        if self._KEYS.U_TIME not in self and self._KEYS.TIME in self:
            self._log.info('`{}` not found in photometry, assuming '
                           ' MJD.'.format(self._KEYS.U_TIME))
            self[self._KEYS.U_TIME] = 'MJD'

        if (self._KEYS.U_COUNT_RATE not in self
                and self._KEYS.COUNT_RATE in self):
            self._log.info('`{}` not found in photometry, assuming '
                           ' s^-1.'.format(self._KEYS.U_COUNT_RATE))
            self[self._KEYS.U_COUNT_RATE] = 's^-1'

        return
예제 #4
0
    def __init__(self, parent, **kwargs):
        """Initialize `Quantity` object."""
        self._REQ_KEY_SETS = [[CORRELATION.VALUE], [CORRELATION.QUANTITY]]

        super(Correlation, self).__init__(parent, **kwargs)

        # Check that value exists
        if (not self[CORRELATION.VALUE] or self[CORRELATION.VALUE] == '--'
                or self[CORRELATION.VALUE] == '-'):
            raise CatDictError(
                "Value '{}' is empty, not adding to '{}'".format(
                    self[CORRELATION.VALUE], parent[parent._KEYS.NAME]))