|
6 | 6 | """
|
7 | 7 |
|
8 | 8 | from abc import abstractmethod
|
| 9 | +from datetime import timedelta |
9 | 10 | import pyproj
|
10 | 11 | import numpy as np
|
11 | 12 | import xarray as xr
|
@@ -63,6 +64,44 @@ def __init__(self, ds, obsdim, timedim):
|
63 | 64 | self.obsdim = obsdim
|
64 | 65 | self.timedim = timedim
|
65 | 66 |
|
| 67 | + def num_timesteps(self): |
| 68 | + if self.timedim in self.ds.sizes: |
| 69 | + timedim = self.timedim |
| 70 | + else: |
| 71 | + logger.warning(f'self.timedim ({self.timedim}) is not an existing dimension! Using instead "obs".') |
| 72 | + timedim = 'obs' |
| 73 | + return self.ds.sizes[timedim] |
| 74 | + |
| 75 | + def num_trajectories(self): |
| 76 | + return self.ds.sizes['trajectory'] |
| 77 | + |
| 78 | + def __repr__(self): |
| 79 | + output = '=======================\n' |
| 80 | + output += 'TrajAn info:\n' |
| 81 | + output += '------------\n' |
| 82 | + output += f'{self.num_trajectories()} trajectories\n' |
| 83 | + output += f'{self.num_timesteps()} timesteps\n' |
| 84 | + try: |
| 85 | + timestep = self.timestep() |
| 86 | + timestep = timedelta(seconds=int(timestep)) |
| 87 | + except: |
| 88 | + timestep = '[self.timestep returns error]' # TODO |
| 89 | + output += f'Timestep: {timestep}\n' |
| 90 | + start_time = self.ds.time.min().data |
| 91 | + end_time = self.ds.time.max().data |
| 92 | + output += f'Time coverage: {start_time} - {end_time}\n' |
| 93 | + output += f'Longitude span: {self.tx.min().data} to {self.tx.max().data}\n' |
| 94 | + output += f'Latitude span: {self.ty.min().data} to {self.ty.max().data}\n' |
| 95 | + output += 'Variables:\n' |
| 96 | + for var in self.ds.variables: |
| 97 | + if var not in ['trajectory', 'obs']: |
| 98 | + output += f' {var}' |
| 99 | + if 'standard_name' in self.ds[var].attrs: |
| 100 | + output += f' [{self.ds[var].standard_name}]' |
| 101 | + output += '\n' |
| 102 | + output += '=======================\n' |
| 103 | + return output |
| 104 | + |
66 | 105 | @property
|
67 | 106 | def plot(self) -> Plot:
|
68 | 107 | """
|
|
0 commit comments