Beispiel #1
0
 def _make_area_from_coords(self, coords):
     """Create an appropriate area with the given *coords*."""
     if len(coords) == 2:
         lon_sn = coords[0].attrs.get('standard_name')
         lat_sn = coords[1].attrs.get('standard_name')
         if lon_sn == 'longitude' and lat_sn == 'latitude':
             key = None
             try:
                 key = (coords[0].data.name, coords[1].data.name)
                 sdef = self.coords_cache.get(key)
             except AttributeError:
                 sdef = None
             if sdef is None:
                 sdef = SwathDefinition(*coords)
                 if key is not None:
                     self.coords_cache[key] = sdef
             sensor_str = '_'.join(self.info['sensors'])
             shape_str = '_'.join(map(str, coords[0].shape))
             sdef.name = "{}_{}_{}_{}".format(sensor_str, shape_str,
                                              coords[0].attrs['name'],
                                              coords[1].attrs['name'])
             return sdef
         else:
             raise ValueError(
                 'Coordinates info object missing standard_name key: ' +
                 str(coords))
     elif len(coords) != 0:
         raise NameError("Don't know what to do with coordinates " +
                         str(coords))
Beispiel #2
0
 def _make_area_from_coords(self, coords):
     """Create an appropriate area with the given *coords*."""
     if len(coords) == 2:
         lon_sn = coords[0].attrs.get('standard_name')
         lat_sn = coords[1].attrs.get('standard_name')
         if lon_sn == 'longitude' and lat_sn == 'latitude':
             key = None
             try:
                 key = (coords[0].data.name, coords[1].data.name)
                 sdef = self.coords_cache.get(key)
             except AttributeError:
                 sdef = None
             if sdef is None:
                 sdef = SwathDefinition(*coords)
                 if key is not None:
                     self.coords_cache[key] = sdef
             sensor_str = '_'.join(self.info['sensors'])
             shape_str = '_'.join(map(str, coords[0].shape))
             sdef.name = "{}_{}_{}_{}".format(sensor_str, shape_str,
                                              coords[0].attrs['name'],
                                              coords[1].attrs['name'])
             return sdef
         else:
             raise ValueError(
                 'Coordinates info object missing standard_name key: ' +
                 str(coords))
     elif len(coords) != 0:
         raise NameError("Don't know what to do with coordinates " + str(
             coords))
Beispiel #3
0
    def combine_info(self, all_infos):
        """Combine metadata for multiple datasets.

        When loading data from multiple files it can be non-trivial to combine
        things like start_time, end_time, start_orbit, end_orbit, etc.

        By default this method will produce a dictionary containing all values
        that were equal across **all** provided info dictionaries.

        Additionally it performs the logical comparisons to produce the
        following if they exist:

         - start_time
         - end_time
         - start_orbit
         - end_orbit
         - satellite_altitude
         - satellite_latitude
         - satellite_longitude
         - orbital_parameters

         Also, concatenate the areas.

        """
        combined_info = combine_metadata(*all_infos)

        new_dict = self._combine(all_infos, min, 'start_time', 'start_orbit')
        new_dict.update(self._combine(all_infos, max, 'end_time', 'end_orbit'))
        new_dict.update(self._combine(all_infos, np.mean,
                                      'satellite_longitude',
                                      'satellite_latitude',
                                      'satellite_altitude'))

        # Average orbital parameters
        orb_params = [info.get('orbital_parameters', {}) for info in all_infos]
        if all(orb_params):
            # Collect all available keys
            orb_params_comb = {}
            for d in orb_params:
                orb_params_comb.update(d)

            # Average known keys
            keys = ['projection_longitude', 'projection_latitude', 'projection_altitude',
                    'satellite_nominal_longitude', 'satellite_nominal_latitude',
                    'satellite_actual_longitude', 'satellite_actual_latitude', 'satellite_actual_altitude',
                    'nadir_longitude', 'nadir_latitude']
            orb_params_comb.update(self._combine(orb_params, np.mean, *keys))
            new_dict['orbital_parameters'] = orb_params_comb

        try:
            area = SwathDefinition(lons=np.ma.vstack([info['area'].lons for info in all_infos]),
                                   lats=np.ma.vstack([info['area'].lats for info in all_infos]))
            area.name = '_'.join([info['area'].name for info in all_infos])
            combined_info['area'] = area
        except KeyError:
            pass

        new_dict.update(combined_info)
        return new_dict
Beispiel #4
0
 def _make_area_from_coords(self, coords):
     """Create an apropriate area with the given *coords*."""
     if (len(coords) == 2
             and coords[0].info.get('standard_name') == 'longitude'
             and coords[1].info.get('standard_name') == 'latitude'):
         from pyresample.geometry import SwathDefinition
         sdef = SwathDefinition(*coords)
         sensor_str = sdef.name = '_'.join(self.info['sensors'])
         shape_str = '_'.join(map(str, coords[0].shape))
         sdef.name = "{}_{}_{}_{}".format(sensor_str, shape_str,
                                          coords[0].info['name'],
                                          coords[1].info['name'])
         return sdef
     elif len(coords) != 0:
         raise NameError("Don't know what to do with coordinates " +
                         str(coords))
Beispiel #5
0
    def get_dataset(self, key, info):
        """Load a dataset
        """

        logger.debug('Reading %s.', key.name)

        if key.name in chans_dict:
            m_data = self.read_dataset(key, info)
        else:
            m_data = self.read_geo(key, info)
        m_data.info.update(info)
        if self.lons is None or self.lats is None:
            self.lons, self.lats = self.navigate(key)
        m_area_def = SwathDefinition(
            np.ma.masked_where(m_data.mask, self.lons, copy=False),
            np.ma.masked_where(m_data.mask, self.lats, copy=False))
        m_area_def.name = 'yo'
        m_data.info['area'] = m_area_def
        return m_data
Beispiel #6
0
    def combine_info(self, all_infos):
        """Combine metadata for multiple datasets.

        When loading data from multiple files it can be non-trivial to combine
        things like start_time, end_time, start_orbit, end_orbit, etc.

        By default this method will produce a dictionary containing all values
        that were equal across **all** provided info dictionaries.

        Additionally it performs the logical comparisons to produce the
        following if they exist:

         - start_time
         - end_time
         - start_orbit
         - end_orbit

         Also, concatenate the areas.

        """
        combined_info = combine_info(*all_infos)
        if 'start_time' not in combined_info and 'start_time' in all_infos[0]:
            combined_info['start_time'] = min(i['start_time']
                                              for i in all_infos)
        if 'end_time' not in combined_info and 'end_time' in all_infos[0]:
            combined_info['end_time'] = max(i['end_time'] for i in all_infos)
        if 'start_orbit' not in combined_info and 'start_orbit' in all_infos[0]:
            combined_info['start_orbit'] = min(i['start_orbit']
                                               for i in all_infos)
        if 'end_orbit' not in combined_info and 'end_orbit' in all_infos[0]:
            combined_info['end_orbit'] = max(i['end_orbit'] for i in all_infos)

        try:
            area = SwathDefinition(
                lons=np.ma.vstack([info['area'].lons for info in all_infos]),
                lats=np.ma.vstack([info['area'].lats for info in all_infos]))
            area.name = '_'.join([info['area'].name for info in all_infos])
            combined_info['area'] = area
        except KeyError:
            pass

        return combined_info
Beispiel #7
0
    def combine_info(self, all_infos):
        """Combine metadata for multiple datasets.

        When loading data from multiple files it can be non-trivial to combine
        things like start_time, end_time, start_orbit, end_orbit, etc.

        By default this method will produce a dictionary containing all values
        that were equal across **all** provided info dictionaries.

        Additionally it performs the logical comparisons to produce the
        following if they exist:

         - start_time
         - end_time
         - start_orbit
         - end_orbit
         - satellite_altitude
         - satellite_latitude
         - satellite_longitude

         Also, concatenate the areas.

        """
        combined_info = combine_metadata(*all_infos)

        new_dict = self._combine(all_infos, min, 'start_time', 'start_orbit')
        new_dict.update(self._combine(all_infos, max, 'end_time', 'end_orbit'))
        new_dict.update(
            self._combine(all_infos, np.mean, 'satellite_longitude',
                          'satellite_latitude', 'satellite_altitude'))

        try:
            area = SwathDefinition(
                lons=np.ma.vstack([info['area'].lons for info in all_infos]),
                lats=np.ma.vstack([info['area'].lats for info in all_infos]))
            area.name = '_'.join([info['area'].name for info in all_infos])
            combined_info['area'] = area
        except KeyError:
            pass

        new_dict.update(combined_info)
        return new_dict
Beispiel #8
0
 def _make_area_from_coords(self, coords):
     """Create an apropriate area with the given *coords*."""
     if len(coords) == 2:
         lon_sn = coords[0].info.get('standard_name')
         lat_sn = coords[1].info.get('standard_name')
         if lon_sn == 'longitude' and lat_sn == 'latitude':
             sdef = SwathDefinition(*coords)
             sensor_str = sdef.name = '_'.join(self.info['sensors'])
             shape_str = '_'.join(map(str, coords[0].shape))
             sdef.name = "{}_{}_{}_{}".format(sensor_str, shape_str,
                                              coords[0].info['name'],
                                              coords[1].info['name'])
             return sdef
         else:
             raise ValueError(
                 'Coordinates info object missing standard_name key: ' +
                 str(coords))
     elif len(coords) != 0:
         raise NameError("Don't know what to do with coordinates " +
                         str(coords))