예제 #1
0
def _save_cat(file_name, radar, lidar, model, obs, keep_uuid):
    """Creates a categorize netCDF4 file and saves all data into it."""
    def _merge_source():
        # Probably should include mwr and model source if existing
        rootgrp.source = f"radar: {radar.source}\nlidar: {lidar.source}"

    dims = {
        'time': len(radar.time),
        'height': len(radar.height),
        'model_time': len(model.time),
        'model_height': len(model.mean_height)
    }
    rootgrp = output.init_file(file_name, dims, obs, keep_uuid)
    uuid = rootgrp.file_uuid
    output.add_file_type(rootgrp, 'categorize')
    output.copy_global(radar.dataset, rootgrp,
                       ('year', 'month', 'day', 'location'))
    rootgrp.title = f"Categorize file from {radar.location}"
    # Needs to solve how to provide institution
    # rootgrp.institution = f"Data processed at {config.INSTITUTE}"
    rootgrp.references = 'https://doi.org/10.1175/BAMS-88-6-883'
    output.merge_history(rootgrp, 'categorize', radar, lidar)
    _merge_source()
    rootgrp.close()
    return uuid
예제 #2
0
def _save_ceilo(ceilo, output_file, location):
    """Saves the ceilometer netcdf-file."""
    dims = {'time': len(ceilo.time), 'range': len(ceilo.range)}
    rootgrp = output.init_file(output_file, dims, ceilo.data)
    output.add_file_type(rootgrp, 'lidar')
    if hasattr(ceilo, 'dataset'):
        output.copy_variables(ceilo.dataset, rootgrp, ('wavelength', ))
    rootgrp.title = f"Ceilometer file from {location}"
    rootgrp.year, rootgrp.month, rootgrp.day = ceilo.date
    rootgrp.location = location
    rootgrp.history = f"{utils.get_time()} - ceilometer file created"
    rootgrp.source = ceilo.model
    rootgrp.close()
예제 #3
0
def _save_mira(mmclx_file, raw_radar, output_file):
    """Saves the MIRA radar file."""
    dims = {'time': len(raw_radar.time), 'range': len(raw_radar.range)}
    rootgrp = output.init_file(output_file, dims, raw_radar.data)
    fields_from_raw = ('nfft', 'prf', 'nave', 'zrg', 'rg0', 'drg')
    output.copy_variables(netCDF4.Dataset(mmclx_file), rootgrp,
                          fields_from_raw)
    output.add_file_type(rootgrp, 'radar')
    rootgrp.title = f"Radar file from {raw_radar.location}"
    rootgrp.year, rootgrp.month, rootgrp.day = _find_measurement_date(
        raw_radar)
    rootgrp.location = raw_radar.location
    rootgrp.history = f"{utils.get_time()} - radar file created"
    rootgrp.source = raw_radar.source
    rootgrp.close()
예제 #4
0
def _save_ceilo(ceilo: Union[ClCeilo, Ct25k, LufftCeilo], output_file: str,
                location: str, keep_uuid: bool, uuid: Union[str, None]) -> str:
    """Saves the ceilometer netcdf-file."""

    dims = {'time': len(ceilo.time), 'range': len(ceilo.range)}

    rootgrp = output.init_file(output_file, dims, ceilo.data, keep_uuid, uuid)
    uuid = rootgrp.file_uuid
    output.add_file_type(rootgrp, 'lidar')
    rootgrp.title = f"Ceilometer file from {location}"
    rootgrp.year, rootgrp.month, rootgrp.day = ceilo.date
    rootgrp.location = location
    rootgrp.history = f"{utils.get_time()} - ceilometer file created"
    rootgrp.source = ceilo.model
    output.add_references(rootgrp)
    rootgrp.close()
    return uuid
예제 #5
0
def _save_rpg(rpg, output_file):
    """Saves the RPG radar file.

    Notes:

    """

    dims = {
        'time': len(rpg.data['time'][:]),
        'range': len(rpg.data['range'][:]),
        'chirp_sequence': len(rpg.data['chirp_start_indices'][:])
    }

    rootgrp = output.init_file(output_file, dims, rpg.data)
    output.add_file_type(rootgrp, 'radar')
    rootgrp.title = f"Radar file from {rpg.location}"
    rootgrp.year, rootgrp.month, rootgrp.day = rpg.date
    rootgrp.location = rpg.location
    rootgrp.history = f"{utils.get_time()} - radar file created"
    rootgrp.source = rpg.source
    rootgrp.close()
예제 #6
0
def _save_cat(full_path: str, data_obs: dict, cloudnet_arrays: dict,
              keep_uuid: bool, uuid: Union[str, None]) -> str:
    """Creates a categorize netCDF4 file and saves all data into it."""

    dims = {
        'time': len(data_obs['radar'].time),
        'height': len(data_obs['radar'].height),
        'model_time': len(data_obs['model'].time),
        'model_height': len(data_obs['model'].mean_height)
    }

    file_type = 'categorize'
    nc = output.init_file(full_path, dims, cloudnet_arrays, keep_uuid, uuid)
    uuid = nc.file_uuid
    output.add_file_type(nc, file_type)
    output.copy_global(data_obs['radar'].dataset, nc,
                       ('year', 'month', 'day', 'location'))
    nc.title = f"{file_type.capitalize()} file from {data_obs['radar'].location}"
    nc.source_file_uuids = output.get_source_uuids(*data_obs.values())
    output.add_references(nc, file_type)
    output.merge_history(nc, file_type, data_obs['radar'], data_obs['lidar'])
    nc.close()
    return uuid
예제 #7
0
def save_disdrometer(
    disdrometer: Union[Parsivel, Thies], output_file: str, uuid: Union[str, None]
) -> str:
    """Saves disdrometer file."""
    dims = {
        "time": len(disdrometer.data["time"][:]),
        "diameter": disdrometer.n_diameter,
        "velocity": disdrometer.n_velocity,
        "nv": 2,
    }
    file_type = "disdrometer"
    rootgrp = output.init_file(output_file, dims, disdrometer.data, uuid)
    file_uuid = rootgrp.file_uuid
    rootgrp.cloudnet_file_type = file_type
    rootgrp.title = f"{file_type.capitalize()} file from {disdrometer.site_meta['name']}"
    rootgrp.year, rootgrp.month, rootgrp.day = disdrometer.date
    rootgrp.location = disdrometer.site_meta["name"]
    rootgrp.history = f"{utils.get_time()} - {file_type} file created"
    rootgrp.source = disdrometer.source
    if disdrometer.sensor_id is not None:
        rootgrp.sensor_id = disdrometer.sensor_id
    rootgrp.references = output.get_references()
    rootgrp.close()
    return file_uuid
예제 #8
0
def _save_cat(full_path: str, data_obs: dict, cloudnet_arrays: dict,
              uuid: Union[str, None]) -> str:
    """Creates a categorize netCDF4 file and saves all data into it."""

    dims = {
        "time": len(data_obs["radar"].time),
        "height": len(data_obs["radar"].height),
        "model_time": len(data_obs["model"].time),
        "model_height": len(data_obs["model"].mean_height),
    }

    file_type = "categorize"
    nc = output.init_file(full_path, dims, cloudnet_arrays, uuid)
    uuid_out = nc.file_uuid
    nc.cloudnet_file_type = file_type
    output.copy_global(data_obs["radar"].dataset, nc,
                       ("year", "month", "day", "location"))
    nc.title = f"Cloud categorization products from {data_obs['radar'].location}"
    nc.source_file_uuids = output.get_source_uuids(*data_obs.values())
    nc.references = output.get_references(file_type)
    output.add_source_instruments(nc, data_obs)
    output.merge_history(nc, file_type, data_obs)
    nc.close()
    return uuid_out
예제 #9
0
def save_rpg(rpg: Rpg, output_file: str, valid_files: list, keep_uuid: bool,
             uuid: Union[str, None]) -> Tuple[str, list]:
    """Saves the RPG radar / mwr file."""

    dims = {'time': len(rpg.data['time'][:])}

    if 'fmcw' in rpg.source.lower():
        dims['range'] = len(rpg.data['range'][:])
        dims['chirp_sequence'] = len(rpg.data['chirp_start_indices'][:])
        file_type = 'radar'
    else:
        file_type = 'mwr'

    rootgrp = output.init_file(output_file, dims, rpg.data, keep_uuid, uuid)
    file_uuid = rootgrp.file_uuid
    output.add_file_type(rootgrp, file_type)
    rootgrp.title = f"{file_type.capitalize()} file from {rpg.location}"
    rootgrp.year, rootgrp.month, rootgrp.day = rpg.date
    rootgrp.location = rpg.location
    rootgrp.history = f"{utils.get_time()} - {file_type} file created"
    rootgrp.source = rpg.source
    output.add_references(rootgrp)
    rootgrp.close()
    return file_uuid, valid_files