Ejemplo n.º 1
0
def generate_classification(categorize_file, output_file):
    """Generates Cloudnet classification product.

    This function reads the initial classification masks from a
    categorize file and creates a more comprehensive classification
    for different atmospheric targets. The results are written in a
    netCDF file.

    Args:
        categorize_file (str): Categorize file name.

        output_file (str): Output file name.

    Examples:
        >>> from cloudnetpy.products import generate_classification
        >>> generate_classification('categorize.nc', 'classification.nc')

    """
    data_handler = DataSource(categorize_file)
    categorize_bits = CategorizeBits(categorize_file)
    classification = _get_target_classification(categorize_bits)
    data_handler.append_data(classification, 'target_classification')
    status = _get_detection_status(categorize_bits)
    data_handler.append_data(status, 'detection_status')
    output.update_attributes(data_handler.data, CLASSIFICATION_ATTRIBUTES)
    output.save_product_file('classification', data_handler, output_file)
    data_handler.close()
Ejemplo n.º 2
0
def generate_classification(categorize_file, output_file, keep_uuid=False):
    """Generates Cloudnet classification product.

    This function reads the initial classification masks from a
    categorize file and creates a more comprehensive classification
    for different atmospheric targets. The results are written in a
    netCDF file.

    Args:
        categorize_file (str): Categorize file name.
        output_file (str): Output file name.
        keep_uuid (bool, optional): If True, keeps the UUID of the old file,
            if that exists. Default is False when new UUID is generated.
    
    Returns:
        str: UUID of the generated file.

    Examples:
        >>> from cloudnetpy.products import generate_classification
        >>> generate_classification('categorize.nc', 'classification.nc')

    """
    data_handler = DataSource(categorize_file)
    categorize_bits = CategorizeBits(categorize_file)
    classification = _get_target_classification(categorize_bits)
    data_handler.append_data(classification, 'target_classification')
    status = _get_detection_status(categorize_bits)
    data_handler.append_data(status, 'detection_status')
    output.update_attributes(data_handler.data, CLASSIFICATION_ATTRIBUTES)
    uuid = output.save_product_file('classification', data_handler,
                                    output_file, keep_uuid)
    data_handler.close()
    return uuid
Ejemplo n.º 3
0
 def __init__(self, categorize_file):
     super().__init__(categorize_file)
     self.lwp = self.getvar('lwp')
     self.lwp_error = self.getvar('lwp_error')
     self.is_rain = self.getvar('is_rain')
     self.dheight = utils.mdiff(self.getvar('height'))
     self.atmosphere = self._get_atmosphere(categorize_file)
     self.categorize_bits = CategorizeBits(categorize_file)
Ejemplo n.º 4
0
 def __init__(self, categorize_file: str):
     super().__init__(categorize_file)
     self.lwp = self.getvar("lwp")
     self.lwp[self.lwp < 0] = 0
     self.lwp_error = self.getvar("lwp_error")
     self.is_rain = get_is_rain(categorize_file)
     self.dheight = utils.mdiff(self.getvar("height"))
     self.atmosphere = self._get_atmosphere(categorize_file)
     self.categorize_bits = CategorizeBits(categorize_file)
Ejemplo n.º 5
0
def generate_classification(categorize_file: str,
                            output_file: str,
                            keep_uuid: bool = False,
                            uuid: Optional[str] = None) -> str:
    """Generates Cloudnet classification product.

    This function reads the initial classification masks from a
    categorize file and creates a more comprehensive classification
    for different atmospheric targets. The results are written in a
    netCDF file.

    Args:
        categorize_file: Categorize file name.
        output_file: Output file name.
        keep_uuid: If True, keeps the UUID of the old file, if that exists. Default is False when new UUID is generated.
        uuid: Set specific UUID for the file.

    Returns:
        str: UUID of the generated file.

    Examples:
        >>> from cloudnetpy.products import generate_classification
        >>> generate_classification('categorize.nc', 'classification.nc')

    """
    product_container = DataSource(categorize_file)
    categorize_bits = CategorizeBits(categorize_file)
    classification = _get_target_classification(categorize_bits)
    product_container.append_data(classification, 'target_classification')
    status = _get_detection_status(categorize_bits)
    product_container.append_data(status, 'detection_status')
    bases, tops = _get_cloud_base_and_top_heights(classification,
                                                  product_container)
    product_container.append_data(bases, 'cloud_base_height_amsl')
    product_container.append_data(tops, 'cloud_top_height_amsl')
    product_container.append_data(bases - product_container.altitude,
                                  'cloud_base_height_agl')
    product_container.append_data(tops - product_container.altitude,
                                  'cloud_top_height_agl')
    date = product_container.get_date()
    attributes = output.add_time_attribute(CLASSIFICATION_ATTRIBUTES, date)
    output.update_attributes(product_container.data, attributes)
    uuid = output.save_product_file('classification', product_container,
                                    output_file, keep_uuid, uuid)
    product_container.close()
    return uuid
Ejemplo n.º 6
0
def _find_valid_fields(nc_file, names):
    """Returns valid field names and corresponding data."""
    valid_names, valid_data = names[:], []
    nc = netCDF4.Dataset(nc_file)
    try:
        bits = CategorizeBits(nc_file)
    except KeyError:
        bits = None
    for name in names:
        if name in nc.variables:
            valid_data.append(nc.variables[name][:])
        elif bits and name in CategorizeBits.category_keys:
            valid_data.append(bits.category_bits[name])
        elif bits and name in CategorizeBits.quality_keys:
            valid_data.append(bits.quality_bits[name])
        else:
            valid_names.remove(name)
    nc.close()
    return valid_data, valid_names
Ejemplo n.º 7
0
def _find_valid_fields(nc_file: str, names: list) -> Tuple[list, list]:
    """Returns valid field names and corresponding data."""
    valid_names, valid_data = names[:], []
    try:
        bits = CategorizeBits(nc_file)
    except KeyError:
        bits = None
    nc = netCDF4.Dataset(nc_file)
    for name in names:
        if name in nc.variables:
            valid_data.append(nc.variables[name][:])
        elif bits and name in CategorizeBits.category_keys:
            valid_data.append(bits.category_bits[name])
        elif bits and name in CategorizeBits.quality_keys:
            valid_data.append(bits.quality_bits[name])
        else:
            valid_names.remove(name)
    nc.close()
    if not valid_names:
        raise ValueError('No fields to be plotted')
    return valid_data, valid_names