Esempio n. 1
0
def get_archive_info(archive_id):
    if archive_id:
        for v in blueskyconfig.get('archives').values():
            if archive_id in v:
                archive_info = v[archive_id]
                return dict(archive_info, id=archive_id,
                    **(blueskyconfig.get('domains')[archive_info['domain_id']]))
        raise InvalidArchiveError(archive_id)
Esempio n. 2
0
 def _fill_in_defaults(self):
     # fill config with defaults
     hysplit_defaults = blueskyconfig.get('hysplit')
     hysplit_defaults.update(
         blueskyconfig.get('hysplit_met_specific').get(
             self._archive_info['domain_id'], {}))
     for k in hysplit_defaults:
         # use MPI and NCPUS defaults even if request specifies them
         if k in ('MPI', 'NCPUS') or k not in self._hysplit_config:
             self._hysplit_config[k] = hysplit_defaults[k]
Esempio n. 3
0
 def _process_config(self):
     """Gets user-supplied hysplit config, or initializes if necessary
     """
     # validate
     self._hysplit_config = self._input_data['config']['dispersion'].get(
         'hysplit') or {}
     restrictions = blueskyconfig.get('hysplit_settings_restrictions')
     for k in self._hysplit_config:
         if k in restrictions:
             if 'max' in restrictions[k] and (self._hysplit_config[k] >
                                              restrictions[k]['max']):
                 self._handle_error(
                     400, "{} ({}) can't be greater than {} ".format(
                         k, self._hysplit_config[k],
                         restrictions[k]['max']))
             if 'min' in restrictions[k] and (self._hysplit_config[k] <
                                              restrictions[k]['min']):
                 self._handle_error(
                     400, "{} ({}) can't be less than {} ".format(
                         k, self._hysplit_config[k],
                         restrictions[k]['min']))
Esempio n. 4
0
    def _process_options(self):
        """Parses hysplit query string options, makes sure they
        don't conflict with each other or with hysplit config settings
        in the input data, and translates them to hysplit config settings.
        """
        # get query_parameters
        speed = self._hysplit_query_params.get('dispersion_speed')
        res = self._hysplit_query_params.get('grid_resolution')
        num_par = self._hysplit_query_params.get('number_of_particles')

        self._grid_resolution_factor = 1.0
        if any([k is not None for k in (speed, res, num_par)]):
            if (speed or num_par) and 'NUMPAR' in self._hysplit_config:
                self._handle_error(
                    400, ErrorMessages.NUMPAR_CONFLICTS_WITH_OTHER_OPTIONS)

            if (speed or res) and any([
                    self._hysplit_config.get(k)
                    for k in ('grid', 'USER_DEFINED_GRID', 'compute_grid')
            ]):
                self._handle_error(
                    400, ErrorMessages.GRID_CONFLICTS_WITH_OTHER_OPTIONS)

            if speed is not None:
                if res is not None or num_par is not None:
                    self._handle_error(
                        400, ErrorMessages.
                        DISPERSION_SPEED_CONFLICTS_WITH_OTHER_OPTIONS)
                speed = speed.lower()
                speed_options = blueskyconfig.get('hysplit_options',
                                                  'dispersion_speed')
                if speed not in speed_options:
                    self._handle_error(
                        400,
                        ErrorMessages.INVALID_DISPERSION_SPEED.format(speed))
                self._hysplit_config['NUMPAR'] = speed_options[speed]['numpar']
                self._grid_resolution_factor = speed_options[speed][
                    'grid_resolution_factor']

            else:
                if num_par is not None:
                    num_par_options = blueskyconfig.get(
                        'hysplit_options', 'number_of_particles')
                    if num_par not in num_par_options:
                        self._handle_error(
                            400,
                            ErrorMessages.INVALID_NUMBER_OF_PARTICLES.format(
                                num_par))
                    self._hysplit_config['NUMPAR'] = num_par_options[num_par]

                if res is not None:
                    res_options = blueskyconfig.get('hysplit_options',
                                                    'grid_resolution')
                    if res not in res_options:
                        self._handle_error(
                            400,
                            ErrorMessages.INVALID_GRID_RESOLUTION.format(res))
                    self._grid_resolution_factor = res_options[res]

        else:
            if len([
                    v for v in [
                        k in self._hysplit_config
                        for k in ('grid', 'USER_DEFINED_GRID', 'compute_grid')
                    ] if v
            ]) > 1:
                self._handle_error(400,
                                   ErrorMessages.TOO_MANY_GRID_SPECIFICATIONS)

        self._grid_size_factor = 1.0
        size = self._hysplit_query_params.get('grid_size')
        if size is not None:
            if size <= 0 or size > 1:
                self._handle_error(
                    400, "grid_size ({}) must be > 0 and <= 100".format(size))
            self._grid_size_factor = size
Esempio n. 5
0
import ssl
from urllib.parse import urlparse

import motor
import tornado.log
import blueskyconfig

__all__ = [
    "DOMAINS",
    "BoundaryNotDefinedError",
    "InvalidArchiveError",
    "UnavailableArchiveError",
    "MetArchiveDB"
]

DOMAINS = blueskyconfig.get('domains')
ARCHIVES = blueskyconfig.get('archives')

class BoundaryNotDefinedError(ValueError):
    pass
class ArchiveNotDefinedError(ValueError):
    pass
class InvalidArchiveError(ValueError):
    pass
class UnavailableArchiveError(ValueError):
    pass


ONE_DAY = datetime.timedelta(days=1)

##
Esempio n. 6
0
 def ARCHIVES(self):
     return blueskyconfig.get('archives')
Esempio n. 7
0
 def DOMAINS(self):
     return blueskyconfig.get('domains')
Esempio n. 8
0
    def get(self, api_version, domain_id=None):
        if domain_id:
            if domain_id not in met.db.DOMAINS:
                self._raise_error(404, "Domain does not exist")
            else:
                self.write({'domain': self._marshall(domain_id)})
        else:
            self.write(
                {'domains': [self._marshall(d) for d in met.db.DOMAINS]})


##
## Archives
##

ARCHIVES = blueskyconfig.get('archives')


class MetArchiveBaseHander(RequestHandlerBase):
    def __init__(self, *args, **kwargs):
        super(MetArchiveBaseHander, self).__init__(*args, **kwargs)
        self.met_archives_db = met.db.MetArchiveDB(
            self.settings['mongodb_url'])


class MetArchivesInfo(MetArchiveBaseHander):
    async def _marshall(self, archive_group, archive_id):
        r = dict(ARCHIVES[archive_group][archive_id],
                 id=archive_id,
                 group=archive_group)
        availability = await self.met_archives_db.get_availability(archive_id)
Esempio n. 9
0
def validate_archive_id(archive_id):
    if archive_id:
        for v in blueskyconfig.get('archives').values():
            if archive_id in v:
                return archive_id
        raise InvalidArchiveError(archive_id)