Skip to content

Commit 43c2616

Browse files
committed
Add documentation and create method to detect time format
1 parent 2b1eb7f commit 43c2616

File tree

5 files changed

+29
-27
lines changed

5 files changed

+29
-27
lines changed

src/py_eddy_tracker/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import logging
2424
from argparse import ArgumentParser
25+
from datetime import datetime
2526

2627
import zarr
2728

@@ -109,6 +110,15 @@ def parse_args(self, *args, **kwargs):
109110
TIME_MODELS = ["%Y%m%d", "%Y%m%d%H%M%S", "%Y%m%dT%H%M%S"]
110111

111112

113+
def identify_time(str_date):
114+
for model in TIME_MODELS:
115+
try:
116+
return datetime.strptime(str_date, model)
117+
except ValueError:
118+
pass
119+
raise Exception("No time model found")
120+
121+
112122
VAR_DESCR = dict(
113123
time=dict(
114124
attr_name="time",

src/py_eddy_tracker/appli/eddies.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from numpy import bincount, bytes_, empty, in1d, unique
1616
from yaml import safe_load
1717

18-
from .. import TIME_MODELS, EddyParser
18+
from .. import EddyParser, identify_time
1919
from ..observations.observation import EddiesObservations, reverse_index
2020
from ..observations.tracking import TrackEddiesObservations
2121
from ..tracking import Correspondances
@@ -163,7 +163,12 @@ def eddies_tracking():
163163
parser.add_argument(
164164
"--zarr", action="store_true", help="Output will be wrote in zarr"
165165
)
166-
parser.add_argument("--unraw", action="store_true", help="Load unraw data")
166+
parser.add_argument(
167+
"--unraw",
168+
action="store_true",
169+
help="Load unraw data, use only for netcdf."
170+
"If unraw is active, netcdf is loaded without apply scalefactor and add_offset.",
171+
)
167172
parser.add_argument(
168173
"--blank_period",
169174
type=int,
@@ -265,16 +270,7 @@ def browse_dataset_in(
265270

266271
if str_date is not None:
267272
if date_model is None:
268-
model_found = False
269-
for model in TIME_MODELS:
270-
try:
271-
item["date"] = datetime.strptime(str_date, model)
272-
model_found = True
273-
break
274-
except ValueError:
275-
pass
276-
if not model_found:
277-
raise Exception("No time model found")
273+
item["date"] = identify_time(str_date)
278274
else:
279275
item["date"] = datetime.strptime(str_date, date_model)
280276

src/py_eddy_tracker/appli/grid.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
All entry point to manipulate grid
44
"""
55
from argparse import Action
6-
from datetime import datetime
76

8-
from .. import TIME_MODELS, EddyParser
7+
from .. import EddyParser, identify_time
98
from ..dataset.grid import RegularGridDataset, UnRegularGridDataset
109

1110

@@ -121,16 +120,7 @@ def eddy_id(args=None):
121120
cut_wavelength = [0, *cut_wavelength]
122121
inf_bnds, upper_bnds = cut_wavelength
123122

124-
model_found = False
125-
for model in TIME_MODELS:
126-
try:
127-
date = datetime.strptime(args.datetime, model)
128-
model_found = True
129-
break
130-
except ValueError:
131-
pass
132-
if not model_found:
133-
raise Exception("No time model found")
123+
date = identify_time(args.datetime)
134124
kwargs = dict(
135125
step=args.isoline_step,
136126
shape_error=args.fit_errmax,

src/py_eddy_tracker/observations/observation.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
poly_indexs,
7070
reduce_size,
7171
vertice_overlap,
72-
winding_number_poly
72+
winding_number_poly,
7373
)
7474

7575
logger = logging.getLogger("pet")
@@ -1326,7 +1326,12 @@ def solve_conflict(cost):
13261326

13271327
@staticmethod
13281328
def solve_simultaneous(cost):
1329-
"""Write something (TODO)"""
1329+
"""Deduce link from cost matrix.
1330+
1331+
:param array(float) cost: Cost for each available link
1332+
:return: return a boolean mask array, True for each valid couple
1333+
:rtype: array(bool)
1334+
"""
13301335
mask = ~cost.mask
13311336
if mask.size == 0:
13321337
return mask

src/scripts/EddyTranslate

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ def id_parser():
1616
)
1717
parser.add_argument("filename_in")
1818
parser.add_argument("filename_out")
19-
parser.add_argument("--unraw", action="store_true", help="Load unraw data")
19+
parser.add_argument("--unraw", action="store_true", help="Load unraw data, use only for netcdf."
20+
"If unraw is active, netcdf is loaded without apply scalefactor and add_offset.")
2021
return parser
2122

2223

0 commit comments

Comments
 (0)