Skip to content

Commit

Permalink
Add temperature_offset option to wet bulb temperature
Browse files Browse the repository at this point in the history
  • Loading branch information
tukiains committed Aug 1, 2024
1 parent f690f22 commit 2ed1795
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion cloudnetpy/categorize/categorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def generate_categorize(
input_files: dict,
output_file: str,
uuid: str | None = None,
options: dict | None = None,
) -> str:
"""Generates Cloudnet Level 1c categorize file.
Expand All @@ -33,6 +34,7 @@ def generate_categorize(
RPG level 0 files.
output_file: Full path of the output file.
uuid: Set specific UUID for the file.
options: Dictionary containing optional parameters.
Returns:
UUID of the generated file.
Expand Down Expand Up @@ -138,7 +140,7 @@ def _close_all() -> None:
data["disdrometer"] = Disdrometer(input_files["disdrometer"])
except DisdrometerDataError as err:
logging.warning("Unable to use disdrometer: %s", err)
data["model"] = Model(input_files["model"], data["radar"].altitude)
data["model"] = Model(input_files["model"], data["radar"].altitude, options)
time, height = _define_dense_grid()
valid_ind = _interpolate_to_cloudnet_grid()
if not valid_ind:
Expand Down
8 changes: 7 additions & 1 deletion cloudnetpy/categorize/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Model(DataSource):
Args:
model_file: File name of the NWP model file.
alt_site: Altitude of the site above mean sea level (m).
options: Dictionary containing optional parameters.
Attributes:
source_type (str): Model type, e.g. 'gdas1' or 'ecwmf'.
Expand All @@ -41,8 +42,9 @@ class Model(DataSource):
)
fields_sparse = (*fields_dense, "q", "uwind", "vwind")

def __init__(self, model_file: str, alt_site: float):
def __init__(self, model_file: str, alt_site: float, options: dict | None = None):
super().__init__(model_file)
self.options = options
self.source_type = _find_model_type(model_file)
self.model_heights = self._get_model_heights(alt_site)
self.mean_height = _calc_mean_height(self.model_heights)
Expand Down Expand Up @@ -113,7 +115,11 @@ def interpolate_to_grid(
def calc_wet_bulb(self) -> None:
"""Calculates wet-bulb temperature in dense grid."""
wet_bulb_temp = atmos_utils.calc_wet_bulb_temperature(self.data_dense)
offset = (self.options or {}).get("temperature_offset", 0)
wet_bulb_temp += offset
self.append_data(wet_bulb_temp, "Tw", units="K")
if offset:
self.data["Tw"].temperature_correction_applied = offset

def screen_sparse_fields(self) -> None:
"""Removes model fields that we don't want to write in the output."""
Expand Down

0 comments on commit 2ed1795

Please sign in to comment.