Пример #1
0
# Read time info
start_time = datetime.strptime(time_info['start_time'].strftime('%Y%m%d'),
                               '%Y%m%d')
end_time = datetime.strptime(time_info['end_time'].strftime('%Y%m%d'),
                             '%Y%m%d')

# Read space info
space_info = config['space']
if not 'boundary_type' in space_info:
    min_lat = space_info['min_lat']
    max_lat = space_info['max_lat']
    min_lon = space_info['min_lon']
    max_lon = space_info['max_lon']
else:
    min_lat, max_lat, min_lon, max_lon = utils.CORDEX_boundary(
        space_info['boundary_type'][6:].replace(" ", "").lower())

# Additional arguments for the DatasetLoader
extra_opts = {
    'min_lat': min_lat,
    'max_lat': max_lat,
    'min_lon': min_lon,
    'max_lon': max_lon,
    'start_time': start_time,
    'end_time': end_time,
    'username': None,
    'password': None
}

# Get the dataset loader options
obs_data_info = config['datasets']['reference']
Пример #2
0
    def __init__(self,
                 boundary_type='rectangular',
                 us_states=None,
                 countries=None,
                 user_mask_file=None,
                 mask_variable_name=None,
                 longitude_name=None,
                 latitude_name=None,
                 lat_min=-90,
                 lat_max=90,
                 lon_min=-180,
                 lon_max=180,
                 start=None,
                 end=None):
        '''Default Bounds constructor
        :param boundary_type: The type of spatial subset boundary.
        :type boundary_type: :mod:`string'


        :param lat_min: The minimum latitude bound.
        :type lat_min: :class:`float`

        :param lat_min: The minimum latitude bound.
        :type lat_min: :class:`float`

        :param lat_max: The maximum latitude bound.
        :type lat_max: :class:`float`

        :param lon_min: The minimum longitude bound.
        :type lon_min: :class:`float`

        :param lon_max: The maximum longitude bound.
        :type lon_max: :class:`float`

        :param start: An optional datetime object for the starting
                      datetime bound.
        :type start: :class:`datetime.datetime`

        :param end: An optional datetime object for the ending datetime bound.
        :type end: :class:`datetime.datetime`

        :raises: ValueError
        '''
        self.boundary_type = boundary_type
        if start:
            self._start = start
        else:
            self._start = None

        if end:
            self._end = end
        else:
            self._end = None

        if boundary_type == 'us_states':
            self.masked_regions = utils.shapefile_boundary(
                boundary_type, us_states)
        if boundary_type == 'countries':
            self.masked_regions = utils.shapefile_boundary(
                boundary_type, countries)
        if boundary_type == 'user':
            file_object = netCDF4.Dataset(user_mask_file)
            self.mask_variable = file_object.variables[mask_variable_name][:]
            mask_longitude = file_object.variables[longitude_name][:]
            mask_latitude = file_object.variables[latitude_name][:]
            if mask_longitude.ndim == 1 and mask_latitude.ndim == 1:
                self.mask_longitude, self.mask_latitude = numpy.meshgrid(
                    mask_longitude, mask_latitude)
            elif mask_longitude.ndim == 2 and mask_latitude.ndim == 2:
                self.mask_longitude = mask_longitude
                self.mask_latitude = mask_latitude
        if boundary_type == 'rectangular':
            if not (-90 <= float(lat_min) <=
                    90) or float(lat_min) > float(lat_max):
                error = "Attempted to set lat_min to invalid value: %s" % (
                    lat_min)
                logger.error(error)
                raise ValueError(error)
            if not (-90 <= float(lat_max) <= 90):
                error = "Attempted to set lat_max to invalid value: %s" % (
                    lat_max)
                logger.error(error)
                raise ValueError(error)
            if not (-180 <= float(lon_min) <=
                    180) or float(lon_min) > float(lon_max):
                error = "Attempted to set lon_min to invalid value: %s" % (
                    lon_min)
                logger.error(error)
                raise ValueError(error)
            if not (-180 <= float(lon_max) <= 180):
                error = "Attempted to set lat_max to invalid value: %s" % (
                    lon_max)
                logger.error(error)
                raise ValueError(error)

            self.lat_min = float(lat_min)
            self.lat_max = float(lat_max)
            self.lon_min = float(lon_min)
            self.lon_max = float(lon_max)
        if boundary_type[:6].upper() == 'CORDEX':
            self.lat_min, self.lat_max, self.lon_min, self.lon_max = utils.CORDEX_boundary(
                boundary_type[6:].replace(" ", "").lower())
Пример #3
0
else:
    # These values will be determined after datasets are loaded
    start_time, end_time = None, None

# Read space info
space_info = config['space']
if not 'boundary_type' in space_info:
    min_lat = space_info['min_lat']
    max_lat = space_info['max_lat']
    min_lon = space_info['min_lon']
    max_lon = space_info['max_lon']
else:
    domain = space_info['boundary_type']
    if domain.startswith('CORDEX '):
        domain = domain.replace('CORDEX ', '').lower()
    min_lat, max_lat, min_lon, max_lon = utils.CORDEX_boundary(domain)

# Additional arguments for the DatasetLoader
extra_opts = {
    'min_lat': min_lat,
    'max_lat': max_lat,
    'min_lon': min_lon,
    'max_lon': max_lon,
    'start_time': start_time,
    'end_time': end_time,
    'username': None,
    'password': None
}

# Get the dataset loader options
data_info = config['datasets']
Пример #4
0
    def __init__(self, boundary_type='rectangular',
                 us_states=None, countries=None,
                 user_mask_file=None, mask_variable_name=None,
                 longitude_name=None, latitude_name=None,
                 lat_min=-90, lat_max=90, lon_min=-180, lon_max=180,
                 start=None, end=None):
        """Default Bounds constructor
        :param boundary_type: The type of spatial subset boundary.
        :type boundary_type: :mod:`string`


        :param lat_min: The minimum latitude bound.
        :type lat_min: :class:`float`

        :param lat_min: The minimum latitude bound.
        :type lat_min: :class:`float`

        :param lat_max: The maximum latitude bound.
        :type lat_max: :class:`float`

        :param lon_min: The minimum longitude bound.
        :type lon_min: :class:`float`

        :param lon_max: The maximum longitude bound.
        :type lon_max: :class:`float`

        :param start: An optional datetime object for the starting
                      datetime bound.
        :type start: :class:`datetime.datetime`

        :param end: An optional datetime object for the ending datetime bound.
        :type end: :class:`datetime.datetime`

        :raises: ValueError
        """

        self.boundary_type = boundary_type

        self._start = None
        self._end = None
        self.lat_min = None
        self.lat_max = None
        self.lon_min = None
        self.lon_max = None

        if start and self._validate_start(start):
            self._start = start

        if end and self._validate_end(end):
            self._end = end

        if boundary_type == 'us_states':

            self.masked_regions = utils.shapefile_boundary(boundary_type, us_states)

        if boundary_type == 'countries':

            self.masked_regions = utils.shapefile_boundary(boundary_type, countries)

        if boundary_type == 'user':

            file_object = netCDF4.Dataset(user_mask_file)
            self.mask_variable = file_object.variables[mask_variable_name][:]
            mask_longitude = file_object.variables[longitude_name][:]
            mask_latitude = file_object.variables[latitude_name][:]
            if mask_longitude.ndim == 1 and mask_latitude.ndim == 1:
                self.mask_longitude, self.mask_latitude = \
                    numpy.meshgrid(mask_longitude, mask_latitude)
            elif mask_longitude.ndim == 2 and mask_latitude.ndim == 2:
                self.mask_longitude = mask_longitude
                self.mask_latitude = mask_latitude

        if boundary_type == 'rectangular':

            if self._validate_lat_lon(lat_max=lat_max, lat_min=lat_min, lon_max=lon_max, lon_min=lon_min):
                self.lat_min = float(lat_min)
                self.lat_max = float(lat_max)
                self.lon_min = float(lon_min)
                self.lon_max = float(lon_max)

        if boundary_type[:6].upper() == 'CORDEX':

            lat_min, lat_max, lon_min, lon_max = \
                utils.CORDEX_boundary(boundary_type[6:].replace(" ", "").lower())

            if self._validate_lat_lon(lat_max=lat_max, lat_min=lat_min, lon_max=lon_max, lon_min=lon_min):
                self.lat_min = float(lat_min)
                self.lat_max = float(lat_max)
                self.lon_min = float(lon_min)
                self.lon_max = float(lon_max)