Skip to content

Commit

Permalink
Remove WeatherStationDataError
Browse files Browse the repository at this point in the history
  • Loading branch information
siiptuo committed Feb 10, 2025
1 parent a573a6d commit 8befa71
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 51 deletions.
7 changes: 0 additions & 7 deletions cloudnetpy/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ def __init__(self, msg: str):
super().__init__(msg)


class WeatherStationDataError(CloudnetException):
"""Internal exception class."""

def __init__(self, msg: str = "Unable to read the file"):
super().__init__(msg)


class ModelDataError(CloudnetException):
"""Internal exception class."""

Expand Down
1 change: 0 additions & 1 deletion cloudnetpy/instruments/rain_e_h3.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def rain_e_h32nc(
UUID of the generated file.
Raises:
WeatherStationDataError : Unable to read the file.
ValidTimeStampError: No valid timestamps found.
"""
rain = RainEH3(site_meta)
Expand Down
74 changes: 35 additions & 39 deletions cloudnetpy/instruments/weather_station.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from cloudnetpy.categorize import atmos_utils
from cloudnetpy.cloudnetarray import CloudnetArray
from cloudnetpy.constants import HPA_TO_PA, MM_H_TO_M_S, SEC_IN_HOUR
from cloudnetpy.exceptions import ValidTimeStampError, WeatherStationDataError
from cloudnetpy.exceptions import ValidTimeStampError
from cloudnetpy.instruments import instruments
from cloudnetpy.instruments.cloudnet_instrument import CSVFile
from cloudnetpy.instruments.toa5 import read_toa5
Expand Down Expand Up @@ -38,48 +38,44 @@ def ws2nc(
UUID of the generated file.
Raises:
WeatherStationDataError : Unable to read the file.
ValidTimeStampError: No valid timestamps found.
"""
if not isinstance(weather_station_file, list):
weather_station_file = [weather_station_file]
try:
ws: WS
if site_meta["name"] == "Palaiseau":
ws = PalaiseauWS(weather_station_file, site_meta)
elif site_meta["name"] == "Bucharest":
ws = BucharestWS(weather_station_file, site_meta)
elif site_meta["name"] == "Granada":
ws = GranadaWS(weather_station_file, site_meta)
elif site_meta["name"] == "Kenttärova":
ws = KenttarovaWS(weather_station_file, site_meta)
elif site_meta["name"] == "Hyytiälä":
ws = HyytialaWS(weather_station_file, site_meta)
elif site_meta["name"] == "Galați":
ws = GalatiWS(weather_station_file, site_meta)
elif site_meta["name"] == "Jülich":
ws = JuelichWS(weather_station_file, site_meta)
elif site_meta["name"] == "Lampedusa":
ws = LampedusaWS(weather_station_file, site_meta)
else:
msg = "Unsupported site"
raise ValueError(msg) # noqa: TRY301
if date is not None:
ws.screen_timestamps(date)
ws.convert_time()
ws.add_date()
ws.add_site_geolocation()
ws.add_data()
ws.convert_temperature_and_humidity()
ws.convert_pressure()
ws.convert_rainfall_rate()
ws.convert_rainfall_amount()
ws.normalize_rainfall_amount()
ws.calculate_rainfall_amount()
attributes = output.add_time_attribute({}, ws.date)
output.update_attributes(ws.data, attributes)
except ValueError as err:
raise WeatherStationDataError from err
ws: WS
if site_meta["name"] == "Palaiseau":
ws = PalaiseauWS(weather_station_file, site_meta)
elif site_meta["name"] == "Bucharest":
ws = BucharestWS(weather_station_file, site_meta)
elif site_meta["name"] == "Granada":
ws = GranadaWS(weather_station_file, site_meta)
elif site_meta["name"] == "Kenttärova":
ws = KenttarovaWS(weather_station_file, site_meta)
elif site_meta["name"] == "Hyytiälä":
ws = HyytialaWS(weather_station_file, site_meta)
elif site_meta["name"] == "Galați":
ws = GalatiWS(weather_station_file, site_meta)
elif site_meta["name"] == "Jülich":
ws = JuelichWS(weather_station_file, site_meta)
elif site_meta["name"] == "Lampedusa":
ws = LampedusaWS(weather_station_file, site_meta)
else:
msg = "Unsupported site"
raise ValueError(msg)
if date is not None:
ws.screen_timestamps(date)
ws.convert_time()
ws.add_date()
ws.add_site_geolocation()
ws.add_data()
ws.convert_temperature_and_humidity()
ws.convert_pressure()
ws.convert_rainfall_rate()
ws.convert_rainfall_amount()
ws.normalize_rainfall_amount()
ws.calculate_rainfall_amount()
attributes = output.add_time_attribute({}, ws.date)
output.update_attributes(ws.data, attributes)
return output.save_level1b(ws, output_file, uuid)


Expand Down
8 changes: 4 additions & 4 deletions tests/unit/test_weather_station.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from cloudnetpy.cloudnetarray import CloudnetArray
import pytest

from cloudnetpy.exceptions import ValidTimeStampError, WeatherStationDataError
from cloudnetpy.exceptions import ValidTimeStampError
from cloudnetpy.instruments import weather_station
from tests.unit.all_products_fun import Check
import numpy as np
Expand Down Expand Up @@ -117,21 +117,21 @@ def test_dimensions(self):
def test_invalid_file():
filename = f"{SCRIPT_PATH}/data/parsivel/norunda.log"
temp_path = TemporaryDirectory().name + "/test.nc"
with pytest.raises(WeatherStationDataError):
with pytest.raises(ValueError):
weather_station.ws2nc(filename, temp_path, SITE_META)


def test_invalid_header():
filename = f"{SCRIPT_PATH}/data/ws/bad-ws.asc"
temp_path = "test.nc"
with pytest.raises(WeatherStationDataError):
with pytest.raises(ValueError):
weather_station.ws2nc(filename, temp_path, SITE_META)


def test_invalid_header2():
filename = f"{SCRIPT_PATH}/data/ws/bad-ws2.asc"
temp_path = "test.nc"
with pytest.raises(WeatherStationDataError):
with pytest.raises(ValueError):
weather_station.ws2nc(filename, temp_path, SITE_META)


Expand Down

0 comments on commit 8befa71

Please sign in to comment.