Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.12.11
rev: v0.15.1
hooks:
# Run the linter.
- id: ruff-check
args: [--fix]
# Run the formatter.
- id: ruff-format

- repo: local
- repo: https://github.com/allganize/ty-pre-commit
rev: v0.0.17
hooks:
- id: type-check
- id: ty-check
name: Type check
entry: ty check .
language: system
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ requests>=2.32.5
scipy>=1.17.0
tqdm>=4.67.3
wget>=3.2
ty
ruff
4 changes: 2 additions & 2 deletions swvo/io/RBMDataSet/scripts/create_RBSP_line_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ def create_RBSP_line_data(
rbm_data_set_result.line_data_flux[:, e] = np.squeeze(
rbm_data[min_offset_instrument].interp_flux(
target_en_single,
target_al[e],
TargetType.TargetPairs, # ty:ignore[not-subscriptable]
target_al[e], # ty:ignore[not-subscriptable]
TargetType.TargetPairs,
)
)

Expand Down
4 changes: 2 additions & 2 deletions swvo/io/dst/wdc.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(self, data_dir: Optional[Path] = None) -> None:

data_dir = os.environ.get(self.ENV_VAR_NAME) # ty: ignore[invalid-assignment]

self.data_dir: Path = Path(data_dir)
self.data_dir: Path = Path(data_dir) # ty:ignore[invalid-argument-type]
self.data_dir.mkdir(parents=True, exist_ok=True)

logger.info(f"WDC Dst data directory: {self.data_dir}")
Expand Down Expand Up @@ -199,7 +199,7 @@ def _process_single_file(self, file_path: Path, year, month) -> pd.DataFrame:
if len(val) > 4:
val = val[:4] if not val.startswith("9999") else None
try:
dst = float(val)
dst = float(val) # ty:ignore[invalid-argument-type]
except: # noqa: E722
continue
dt = datetime(year, month, day, hour)
Expand Down
2 changes: 1 addition & 1 deletion swvo/io/f10_7/omni.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def read(self, start_time: datetime, end_time: datetime, download: bool = False)
f107_df["file_name"] = data_out["file_name"]

# we return it just every 24 hours
f107_df = f107_df.drop(f107_df[data_out.index.hour % 24 != 0].index, axis=0) # ty: ignore[possibly-missing-attribute]
f107_df = f107_df.drop(f107_df[data_out.index.hour % 24 != 0].index, axis=0) # ty: ignore[unresolved-attribute]
f107_df = f107_df.replace(999.9, np.nan)
f107_df = f107_df.truncate(
before=start_time - timedelta(hours=23.9999),
Expand Down
6 changes: 3 additions & 3 deletions swvo/io/f10_7/swpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __init__(self, data_dir: Optional[Path] = None) -> None:
raise ValueError(msg)
data_dir = os.environ.get(self.ENV_VAR_NAME) # ty: ignore[invalid-assignment]

self.data_dir: Path = Path(data_dir)
self.data_dir: Path = Path(data_dir) # ty:ignore[invalid-argument-type]
self.data_dir.mkdir(parents=True, exist_ok=True)

logger.info(f"SWPC F10.7 data directory: {self.data_dir}")
Expand Down Expand Up @@ -130,7 +130,7 @@ def download_and_process(self) -> None:
logger.debug(f"Updating {file_path}...")

existing_data = pd.read_csv(file_path, parse_dates=["date"])
existing_data["date"] = pd.to_datetime(existing_data["date"]).dt.tz_localize(None) # ty: ignore[unresolved-attribute]
existing_data["date"] = pd.to_datetime(existing_data["date"]).dt.tz_localize(None)
combined_data = pd.concat([existing_data, year_data])
combined_data = combined_data.drop_duplicates(subset=["date"], keep="last")
combined_data = combined_data.sort_values("date")
Expand Down Expand Up @@ -199,7 +199,7 @@ def _process_single_file(self, file_path: Path) -> pd.DataFrame:
skiprows=13,
usecols=[0, 1, 2, 3],
names=["year", "month", "day", "f107"],
)
) # ty:ignore[no-matching-overload]

data["date"] = pd.to_datetime(data[["year", "month", "day"]].assign(hour=0))
data = data[["date", "f107"]]
Expand Down
6 changes: 3 additions & 3 deletions swvo/io/hp/ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __init__(self, index: str, data_dir: Optional[Path] = None) -> None:

data_dir = os.environ.get(self.ENV_VAR_NAME) # ty: ignore[invalid-assignment]

self.data_dir: Path = Path(data_dir)
self.data_dir: Path = Path(data_dir) # ty:ignore[invalid-argument-type]

logger.info(f"{self.index.upper()} Ensemble data directory: {self.data_dir}")

Expand Down Expand Up @@ -178,7 +178,7 @@ def read_with_horizon(self, start_time: datetime, end_time: datetime, horizon: N
if end_time is not None:
end_time = enforce_utc_timezone(end_time)

if not (0 <= horizon <= 72): # ty: ignore[unsupported-operator]
if not (0 <= horizon <= 72):
raise ValueError("Horizon must be between 0 and 72 hours")

if self.index == "hp30":
Expand All @@ -187,7 +187,7 @@ def read_with_horizon(self, start_time: datetime, end_time: datetime, horizon: N
raise ValueError("Horizon for hp30 must be in 0.5 hour increments")
elif self.index == "hp60":
freq = "1h"
if horizon % 1 != 0: # ty: ignore[unsupported-operator]
if horizon % 1 != 0:
raise ValueError("Horizon for hp60 must be in 1 hour increments")

align_start_to_hp_hr = start_time.replace(hour=start_time.hour, minute=0, second=0, microsecond=0)
Expand Down
4 changes: 2 additions & 2 deletions swvo/io/hp/gfz.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __init__(self, index: str, data_dir: Optional[Path] = None) -> None:

data_dir = os.environ.get(self.ENV_VAR_NAME) # ty: ignore[invalid-assignment]

self.data_dir: Path = Path(data_dir)
self.data_dir: Path = Path(data_dir) # ty:ignore[invalid-argument-type]
self.data_dir.mkdir(parents=True, exist_ok=True)
self.index_number: int = index[2:]

Expand Down Expand Up @@ -161,7 +161,7 @@ def _download(self, temporary_dir: Path, start_time: datetime, end_time: datetim
with open(output_file, "w") as f:
json.dump(data, f)

except requests.exceptions.RequestException as e: # ty: ignore[unresolved-attribute]
except requests.exceptions.RequestException as e:
logger.error(f"API request failed: {e}")
raise

Expand Down
2 changes: 1 addition & 1 deletion swvo/io/kp/ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(self, data_dir: Optional[Path] = None) -> None:

data_dir = os.environ.get(self.ENV_VAR_NAME) # ty: ignore[invalid-assignment]

self.data_dir: Path = Path(data_dir)
self.data_dir: Path = Path(data_dir) # ty:ignore[invalid-argument-type]

logger.info(f"Kp Ensemble data directory: {self.data_dir}")

Expand Down
2 changes: 1 addition & 1 deletion swvo/io/kp/niemegk.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __init__(self, data_dir: Optional[Path] = None) -> None:

data_dir = os.environ.get(self.ENV_VAR_NAME) # ty: ignore[invalid-assignment]

self.data_dir: Path = Path(data_dir)
self.data_dir: Path = Path(data_dir) # ty:ignore[invalid-argument-type]
self.data_dir.mkdir(parents=True, exist_ok=True)

logger.info(f"Kp Niemegk data directory: {self.data_dir}")
Expand Down
2 changes: 1 addition & 1 deletion swvo/io/kp/omni.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def read(self, start_time: datetime, end_time: datetime, download: bool = False)
kp_df["kp"] = data_out["kp"]
kp_df["file_name"] = data_out["file_name"]
# we return it just every 3 hours
kp_df = kp_df.drop(kp_df[data_out.index.hour % 3 != 0].index, axis=0) # ty: ignore[possibly-missing-attribute]
kp_df = kp_df.drop(kp_df[data_out.index.hour % 3 != 0].index, axis=0) # ty: ignore[unresolved-attribute]
kp_df = kp_df.truncate(
before=start_time - timedelta(hours=2.9999),
after=end_time + timedelta(hours=2.9999),
Expand Down
6 changes: 3 additions & 3 deletions swvo/io/kp/swpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __init__(self, data_dir: Optional[Path] = None) -> None:

data_dir = os.environ.get(self.ENV_VAR_NAME) # ty: ignore[invalid-assignment]

self.data_dir: Path = Path(data_dir)
self.data_dir: Path = Path(data_dir) # ty:ignore[invalid-argument-type]
self.data_dir.mkdir(parents=True, exist_ok=True)

logger.info(f"Kp SWPC data directory: {self.data_dir}")
Expand Down Expand Up @@ -253,7 +253,7 @@ def _process_single_file(self, temporary_dir: Path) -> pd.DataFrame:
lines = f.readlines()
for line in lines:
if ":Issued:" in line:
year = int(re.search(r"(\d{4})", line).group(1)) # ty: ignore[possibly-missing-attribute]
year = int(re.search(r"(\d{4})", line).group(1)) # ty: ignore[unresolved-attribute]
break

for i, line in enumerate(lines):
Expand Down Expand Up @@ -286,7 +286,7 @@ def _process_single_file(self, temporary_dir: Path) -> pd.DataFrame:
kp.append(kp_data[j][i])

time_in = [timestamp[0]] * 24
df = pd.DataFrame({"t_forecast": timestamp}, index=time_in)
df = pd.DataFrame({"t_forecast": timestamp}, index=time_in) # ty:ignore[invalid-argument-type]
df["kp"] = kp

df.loc[round(df["kp"] % 1, 2) == 0.67, "kp"] = round(df.loc[round(df["kp"] % 1, 2) == 0.67, "kp"]) + 2 / 3
Expand Down
4 changes: 2 additions & 2 deletions swvo/io/omni/omni_high_res.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(self, data_dir: Optional[Path] = None) -> None:

data_dir = os.environ.get(self.ENV_VAR_NAME) # ty: ignore[invalid-assignment]

self.data_dir: Path = Path(data_dir)
self.data_dir: Path = Path(data_dir) # ty:ignore[invalid-argument-type]
self.data_dir.mkdir(parents=True, exist_ok=True)

logger.info(f"OMNI high resolution data directory: {self.data_dir}")
Expand Down Expand Up @@ -296,7 +296,7 @@ def _process_single_month(self, data: list[str]) -> pd.DataFrame:
logger.error(msg)
raise ValueError(msg)

df = pd.DataFrame([line.split() for line in data_lines], columns=columns)
df = pd.DataFrame([line.split() for line in data_lines], columns=columns) # ty:ignore[invalid-argument-type]
df = df.apply(pd.to_numeric)

df["timestamp"] = df["YYYY"].map(str).apply(lambda x: x + "-01-01 ") + df["HR"].map(str).apply(
Expand Down
2 changes: 1 addition & 1 deletion swvo/io/omni/omni_low_res.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def __init__(self, data_dir: Optional[Path] = None) -> None:

data_dir = os.environ.get(self.ENV_VAR_NAME) # ty: ignore[invalid-assignment]

self.data_dir: Path = Path(data_dir)
self.data_dir: Path = Path(data_dir) # ty:ignore[invalid-argument-type]
self.data_dir.mkdir(parents=True, exist_ok=True)

logger.info(f"OMNI Low Res data directory: {self.data_dir}")
Expand Down
4 changes: 2 additions & 2 deletions swvo/io/solar_wind/ace.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __init__(self, data_dir: Optional[Path] = None) -> None:

data_dir = os.environ.get(self.ENV_VAR_NAME) # ty: ignore[invalid-assignment]

self.data_dir: Path = Path(data_dir)
self.data_dir: Path = Path(data_dir) # ty:ignore[invalid-argument-type]
self.data_dir.mkdir(parents=True, exist_ok=True)

logger.info(f"ACE data directory: {self.data_dir}")
Expand Down Expand Up @@ -107,7 +107,7 @@ def download_and_process(self, request_time: datetime) -> None:
logger.debug("Processing file ...")
processed_df = self._process_single_file(temporary_dir)

unique_dates = np.unique(processed_df.index.date) # ty: ignore[possibly-missing-attribute]
unique_dates = np.unique(processed_df.index.date) # ty: ignore[unresolved-attribute]

for date in unique_dates:
file_path = self.data_dir / date.strftime("%Y/%m") / f"ACE_SW_NOWCAST_{date.strftime('%Y%m%d')}.csv"
Expand Down
4 changes: 2 additions & 2 deletions swvo/io/solar_wind/dscovr.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(self, data_dir: Optional[Path] = None) -> None:

data_dir = os.environ.get(self.ENV_VAR_NAME) # ty: ignore[invalid-assignment]

self.data_dir: Path = Path(data_dir)
self.data_dir: Path = Path(data_dir) # ty:ignore[invalid-argument-type]
self.data_dir.mkdir(parents=True, exist_ok=True)

logger.info(f"DSCOVR data directory: {self.data_dir}")
Expand Down Expand Up @@ -103,7 +103,7 @@ def download_and_process(self, request_time: datetime) -> None:
logger.debug("Processing file ...")
processed_df = self._process_single_file(temporary_dir)

unique_dates = np.unique(processed_df.index.date) # ty: ignore[possibly-missing-attribute]
unique_dates = np.unique(processed_df.index.date) # ty: ignore[unresolved-attribute]

for date in unique_dates:
file_path = self.data_dir / date.strftime("%Y/%m") / f"DSCOVR_SW_NOWCAST_{date.strftime('%Y%m%d')}.csv"
Expand Down
6 changes: 3 additions & 3 deletions swvo/io/solar_wind/swift.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __init__(self, data_dir: Optional[Path] = None) -> None:

data_dir = os.environ.get(self.ENV_VAR_NAME) # ty: ignore[invalid-assignment]

self.data_dir: Path = Path(data_dir)
self.data_dir: Path = Path(data_dir) # ty:ignore[invalid-argument-type]

logger.info(f"SWIFT ensemble data directory: {self.data_dir}")

Expand Down Expand Up @@ -212,7 +212,7 @@ def _read_single_file(self, file_name, use_old_column_names=False) -> pd.DataFra
"uz": uz,
"pdyn": pdyn,
},
index=time,
index=time, # ty:ignore[invalid-argument-type]
)
else:
df = pd.DataFrame(
Expand All @@ -226,7 +226,7 @@ def _read_single_file(self, file_name, use_old_column_names=False) -> pd.DataFra
"bz_gsm": bz,
"pdyn": pdyn,
},
index=time,
index=time, # ty:ignore[invalid-argument-type]
)

df["file_name"] = file_name
Expand Down
2 changes: 1 addition & 1 deletion swvo/io/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def sw_mag_propagation(sw_data: pd.DataFrame) -> pd.DataFrame:
Data frame with propagated solar wind data, indexed by time.
"""

sw_data["t"] = [t.timestamp() for t in sw_data.index.to_pydatetime()] # ty: ignore[possibly-missing-attribute]
sw_data["t"] = [t.timestamp() for t in sw_data.index.to_pydatetime()] # ty: ignore[unresolved-attribute]
sw_data = sw_data.dropna(how="any")

distance = 1.5e6
Expand Down
Loading