pyradtran.clouds.CloudGenerator#
- class pyradtran.clouds.CloudGenerator[source]#
Bases:
objectFactory for
CloudLayersequences.All methods are static — no instantiation needed. Choose a source method according to your input data:
from_simple_parameters()— uniform slab from a few numbers.from_era5_dataset()— vertically resolved layers from ERA5.
See also
CloudFileWriterPersist layers to libRadtran
.datfiles.
- static from_era5_dataset(ds: Dataset, time: datetime | None = None, lat: float | None = None, lon: float | None = None, cloud_variables: Dict[str, str] | None = None, altitude_levels_km: ndarray | None = None, lwc_threshold: float = 1e-06, iwc_threshold: float = 1e-06, default_r_eff_water: float = 10.0, default_r_eff_ice: float = 30.0, pressure_levels: str | None = None, geopotential_var: str | None = None) List[CloudLayer][source]#
Extract cloud layers from an ERA5
xarray.Dataset.The method selects a single profile (time, lat, lon), converts LWC / IWC from kg kg⁻¹ to g m⁻³, and returns one
CloudLayerper model level that exceeds the water- content thresholds.- Parameters:
ds (xarray.Dataset) – ERA5 dataset containing, at minimum, cloud water content on pressure levels.
time (datetime, optional) – Time step to select. Defaults to the first available.
lat (float, optional) – Coordinates for nearest-neighbour selection. If either is None the spatial mean is used.
lon (float, optional) – Coordinates for nearest-neighbour selection. If either is None the spatial mean is used.
cloud_variables (dict of str, optional) – Mapping
{'lwc': 'clwc', 'iwc': 'ciwc', 'cc': 'cc', 'temp': 't', 'z': 'z'}that connects internal keys to dataset variable names.altitude_levels_km (numpy.ndarray, optional) – Pre-computed altitude grid. When None, altitudes are derived from geopotential height or the hypsometric equation.
lwc_threshold (float, default
1e-6) – Minimum liquid water content (g m⁻³) to retain.iwc_threshold (float, default
1e-6) – Minimum ice water content (g m⁻³) to retain.default_r_eff_water (float, default
10.0) – Effective radius for liquid droplets (µm).default_r_eff_ice (float, default
30.0) – Effective radius for ice crystals (µm).pressure_levels (str, optional) – Name of the pressure coordinate. Auto-detected when None.
geopotential_var (str, optional) – Name of the geopotential variable. Auto-detected when None.
- Returns:
One layer per model level with significant cloud content, sorted from lowest to highest altitude.
- Return type:
list of CloudLayer
- Raises:
ValueError – If no pressure coordinate can be found.
KeyError – If a required cloud variable is missing from ds.
Examples
>>> import xarray as xr >>> ds = xr.open_dataset("era5_cloud.nc") >>> layers = CloudGenerator.from_era5_dataset( ... ds, lat=78.0, lon=15.0, default_r_eff_water=8.0 ... )
See also
generate_cloud_file_from_era5One-step convenience wrapper.
- static from_simple_parameters(z_base_km: float, z_top_km: float, lwc_g_m3: float = 0.1, iwc_g_m3: float = 0.0, r_eff_um: float = 10.0, cloud_fraction: float = 1.0, n_layers: int = 1) List[CloudLayer][source]#
Create uniform cloud layers from basic parameters.
The altitude range z_base_km … z_top_km is split into n_layers sub-layers, each receiving the same microphysical values.
- Parameters:
z_base_km (float) – Cloud base altitude (km above sea level).
z_top_km (float) – Cloud top altitude (km above sea level).
lwc_g_m3 (float, default
0.1) – Liquid water content (g m⁻³).iwc_g_m3 (float, default
0.0) – Ice water content (g m⁻³).r_eff_um (float, default
10.0) – Effective droplet / crystal radius (µm).cloud_fraction (float, default
1.0) – Cloud fraction (0–1).n_layers (int, default
1) – Number of sub-layers to create.
- Returns:
Layers ordered from bottom to top.
- Return type:
list of CloudLayer
- Raises:
ValueError – If n_layers < 1 or z_base_km >= z_top_km.
Examples
>>> layers = CloudGenerator.from_simple_parameters( ... z_base_km=1.0, z_top_km=2.0, lwc_g_m3=0.3, n_layers=5 ... ) >>> len(layers) 5
See also
CloudFileWriter.write_water_cloud_fileWrite layers to disk.