|
60 | 60 | # =============================================================================
|
61 | 61 | # Imports
|
62 | 62 | # =============================================================================
|
| 63 | +from pathlib import Path |
63 | 64 | import copy
|
64 | 65 | from typing import Optional, Union
|
65 | 66 |
|
@@ -197,6 +198,38 @@ def df(self, value):
|
197 | 198 | self._set_datetime_columns(self._add_columns(value)), inplace=False
|
198 | 199 | )
|
199 | 200 |
|
| 201 | + def _has_df(self): |
| 202 | + """ |
| 203 | + check to see if dataframe is set |
| 204 | + """ |
| 205 | + if self._df is not None: |
| 206 | + if not self._df.empty: |
| 207 | + return True |
| 208 | + return False |
| 209 | + return False |
| 210 | + |
| 211 | + def _df_has_local_station_id(self): |
| 212 | + """ |
| 213 | + Check to make sure the dataframe has the local station id |
| 214 | +
|
| 215 | + :return: DESCRIPTION |
| 216 | + :rtype: bool |
| 217 | +
|
| 218 | + """ |
| 219 | + if self._has_df(): |
| 220 | + return (self._df.station == self.local_station_id).any() |
| 221 | + |
| 222 | + def _df_has_remote_station_id(self): |
| 223 | + """ |
| 224 | + Check to make sure the dataframe has the local station id |
| 225 | +
|
| 226 | + :return: DESCRIPTION |
| 227 | + :rtype: bool |
| 228 | +
|
| 229 | + """ |
| 230 | + if self._has_df(): |
| 231 | + return (self._df.station == self.remote_station_id).any() |
| 232 | + |
200 | 233 | def _set_datetime_columns(self, df):
|
201 | 234 | """
|
202 | 235 | be sure to set start and end to be date time objects
|
@@ -241,6 +274,119 @@ def _add_columns(self, df):
|
241 | 274 | )
|
242 | 275 | return df
|
243 | 276 |
|
| 277 | + @property |
| 278 | + def local_station_id(self): |
| 279 | + return self._local_station_id |
| 280 | + |
| 281 | + @local_station_id.setter |
| 282 | + def local_station_id(self, value): |
| 283 | + if value is None: |
| 284 | + self._local_station_id = None |
| 285 | + else: |
| 286 | + try: |
| 287 | + self._local_station_id = str(value) |
| 288 | + except ValueError: |
| 289 | + raise ValueError( |
| 290 | + f"Bad type {type(value)}. " |
| 291 | + "Cannot convert local_station_id value to string." |
| 292 | + ) |
| 293 | + if self._has_df(): |
| 294 | + if not self._df_has_local_station_id(): |
| 295 | + raise NameError( |
| 296 | + f"Could not find {self._local_station_id} in dataframe" |
| 297 | + ) |
| 298 | + |
| 299 | + @property |
| 300 | + def local_mth5_path(self): |
| 301 | + """ |
| 302 | +
|
| 303 | + :return: Local station MTH5 path, a property extracted from the dataframe |
| 304 | + :rtype: Path |
| 305 | +
|
| 306 | + """ |
| 307 | + if self._has_df(): |
| 308 | + return Path( |
| 309 | + self._df.loc[ |
| 310 | + self._df.station == self.local_station_id, "mth5_path" |
| 311 | + ].unique()[0] |
| 312 | + ) |
| 313 | + else: |
| 314 | + return None |
| 315 | + |
| 316 | + # @local_mth5_path.setter |
| 317 | + # def local_mth5_path(self, value): |
| 318 | + # self._local_mth5_path = self.set_path(value) |
| 319 | + |
| 320 | + def has_local_mth5(self): |
| 321 | + """test if local mth5 exists""" |
| 322 | + if self.local_mth5_path is None: |
| 323 | + return False |
| 324 | + else: |
| 325 | + return self.local_mth5_path.exists() |
| 326 | + |
| 327 | + @property |
| 328 | + def remote_station_id(self): |
| 329 | + return self._remote_station_id |
| 330 | + |
| 331 | + @remote_station_id.setter |
| 332 | + def remote_station_id(self, value): |
| 333 | + if value is None: |
| 334 | + self._remote_station_id = None |
| 335 | + else: |
| 336 | + try: |
| 337 | + self._remote_station_id = str(value) |
| 338 | + except ValueError: |
| 339 | + raise ValueError( |
| 340 | + f"Bad type {type(value)}. " |
| 341 | + "Cannot convert remote_station_id value to string." |
| 342 | + ) |
| 343 | + if self._has_df(): |
| 344 | + if not self._df_has_remote_station_id(): |
| 345 | + raise NameError( |
| 346 | + f"Could not find {self._remote_station_id} in dataframe" |
| 347 | + ) |
| 348 | + |
| 349 | + @property |
| 350 | + def remote_mth5_path(self): |
| 351 | + """ |
| 352 | +
|
| 353 | + :return: remote station MTH5 path, a property extracted from the dataframe |
| 354 | + :rtype: Path |
| 355 | +
|
| 356 | + """ |
| 357 | + if self._has_df() and self.remote_station_id is not None: |
| 358 | + return Path( |
| 359 | + self._df.loc[ |
| 360 | + self._df.station == self.remote_station_id, "mth5_path" |
| 361 | + ].unique()[0] |
| 362 | + ) |
| 363 | + else: |
| 364 | + return None |
| 365 | + |
| 366 | + # @remote_mth5_path.setter |
| 367 | + # def remote_mth5_path(self, value): |
| 368 | + # self._remote_mth5_path = self.set_path(value) |
| 369 | + |
| 370 | + def has_remote_mth5(self): |
| 371 | + """test if remote mth5 exists""" |
| 372 | + if self.remote_mth5_path is None: |
| 373 | + return False |
| 374 | + else: |
| 375 | + return self.remote_mth5_path.exists() |
| 376 | + |
| 377 | + @classmethod |
| 378 | + def set_path(self, value): |
| 379 | + return_path = None |
| 380 | + if value is not None: |
| 381 | + if isinstance(value, (str, Path)): |
| 382 | + return_path = Path(value) |
| 383 | + if not return_path.exists(): |
| 384 | + raise IOError(f"Cannot find file: {return_path}") |
| 385 | + else: |
| 386 | + raise ValueError(f"Cannot convert type{type(value)} to Path") |
| 387 | + |
| 388 | + return return_path |
| 389 | + |
244 | 390 | def from_run_summary(
|
245 | 391 | self,
|
246 | 392 | run_summary: RunSummary,
|
|
0 commit comments