Exemplo n.º 1
0
    def _create_time_coord(self, timestamp, time_variable_name, data_variables, coord_axis='T', standard_name='time'):
        """
        Create a time coordinate, taking into account the fact that each file may have a different timestamp.
        :param timestamp: Timestamp or list of timestamps for
        :param time_variable_name: Name of the time variable
        :param data_variables: Dictionary containing one or multiple netCDF data variables for each variable name
        :param coord_axis: Axis, default 'T'
        :param standard_name: Coord standard name, default 'time'
        :return: Coordinate
        """
        from cis.data_io.Coord import Coord
        from six.moves import zip_longest

        timestamps = listify(timestamp)
        time_variables = data_variables[time_variable_name]
        time_coords = []
        # Create a coordinate for each separate file to account for differing timestamps
        for file_time_var, timestamp in zip_longest(time_variables, timestamps):
            metadata = get_metadata(file_time_var)
            metadata.standard_name = standard_name
            coord = Coord(file_time_var, metadata, coord_axis)
            coord.convert_to_std_time(timestamp)
            time_coords.append(coord)

        return Coord.from_many_coordinates(time_coords)
Exemplo n.º 2
0
    def _create_coord(self, coord_axis, data_variable_name, data_variables, standard_name):
        """
        Create a coordinate for the co-ordinate list
        :param coord_axis: axis of the coordinate in the coords
        :param data_variable_name: the name of the variable in the data
        :param data_variables: the data variables
        :param standard_name: the standard name it should have
        :return: a coords object
        """
        from cis.data_io.Coord import Coord

        coordinate_data_objects = []
        for d in data_variables[data_variable_name]:
            m = get_metadata(d)
            m.alter_standard_name(standard_name)
            coordinate_data_objects.append(Coord(d, m, coord_axis))
        
        return Coord.from_many_coordinates(coordinate_data_objects)
Exemplo n.º 3
0
    def _create_coord(self, coord_axis, data_variable_name, data_variables, standard_name):
        """
        Create a coordinate for the co-ordinate list
        :param coord_axis: axis of the coordinate in the coords
        :param data_variable_name: the name of the variable in the data
        :param data_variables: the data variables
        :param standard_name: the standard name it should have
        :return: a coords object
        """
        from cis.data_io.Coord import Coord

        coordinate_data_objects = []
        for d in data_variables[data_variable_name]:
            m = get_metadata(d)
            m.standard_name = standard_name
            coordinate_data_objects.append(Coord(d, m, coord_axis))

        return Coord.from_many_coordinates(coordinate_data_objects)
Exemplo n.º 4
0
    def _create_coord(self, coord_axis, data_variable_name, data_variables, standard_name):
        """
        Create a coordinate for the co-ordinate list
        :param coord_axis: axis of the coordinate in the coords
        :param data_variable_name: the name of the variable in the data
        :param data_variables: the data variables
        :param standard_name: the standard name it should have
        :return: a coords object
        """
        from cis.data_io.netcdf import get_metadata
        from cis.data_io.Coord import Coord
        from cf_units import Unit
        import logging

        coordinate_data_objects = []
        for d in data_variables[data_variable_name]:
            data = get_data(d)
            m = get_metadata(d)
            m._name = m._name.lower()
            m.standard_name = standard_name
            if standard_name == 'air_pressure':
                if not isinstance(m.units, Unit):
                    if ',' in m.units:
                        # Try splitting any commas out
                        m.units = m.units.split(',')[0]
                    if ' ' in m.units:
                        # Try splitting any spaces out
                        m.units = m.units.split()[0]
                if str(m.units) == 'mb' or str(m.units) == 'Mb':
                    # Try converting to standard nomencleture
                    m.units = 'mbar'
                if str(m.units) == 'hpa':
                    m.units = 'hPa'

                logging.info("Parsed air pressure units {old}".format(old=m.units))
                logging.info('Converting to hPa')
                if not isinstance(m.units, str):
                    data = m.units.convert(data, 'hPa')
                    m.units = 'hPa'

            coordinate_data_objects.append(Coord(data, m, coord_axis))

        return Coord.from_many_coordinates(coordinate_data_objects)