Skip to content

Commit 1f21d33

Browse files
committed
management of floating time
1 parent 6921457 commit 1f21d33

File tree

15 files changed

+86
-46
lines changed

15 files changed

+86
-46
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ and this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0
1010
------------
1111
Changed
1212
^^^^^^^
13+
- Now time will be allow second precision in storage on uint32 from 01/01/1950 to 01/01/2086
14+
new identification will be produce with this type, old file could be still loaded.
15+
If you use old identification to track use `--unraw` option to unpack old time and store in new format.
16+
1317
Fixed
1418
^^^^^
1519
- GridCollection get_next_time_step & get_previous_time_step needed more files to work in the dataset list.

doc/run_tracking.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Example of conf.yaml
2626
2727
# Number of timestep for missing detection
2828
VIRTUAL_LENGTH_MAX: 3
29-
# Minimal time to consider as a full track
29+
# Minimal number of timesteps to consider as a long track
3030
TRACK_DURATION_MIN: 10
3131
3232
To run:
@@ -69,7 +69,7 @@ With yaml you could also select another tracker:
6969
7070
# Number of timesteps for missing detection
7171
VIRTUAL_LENGTH_MAX: 3
72-
# Minimal time to consider as a full track
72+
# Minimal number of timesteps to consider as a long track
7373
TRACK_DURATION_MIN: 10
7474
7575
CLASS:

examples/06_grid_manipulation/pet_okubo_weiss.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
r"""
22
Get Okubo Weis
3-
=====================
3+
==============
44
55
.. math:: OW = S_n^2 + S_s^2 + \omega^2
66

examples/16_network/pet_follow_particle.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ def update(frame):
149149
ax_2nd_f = fig.add_axes([0.52, 0.05, 0.45, 0.45])
150150
ax_1st_b.set_title("Backward advection for each time step")
151151
ax_1st_f.set_title("Forward advection for each time step")
152+
ax_1st_b.set_ylabel("Color -> First target\nLatitude")
153+
ax_2nd_b.set_ylabel("Color -> Secondary target\nLatitude")
154+
ax_2nd_b.set_xlabel("Julian days"), ax_2nd_f.set_xlabel("Julian days")
155+
ax_1st_f.set_yticks([]), ax_2nd_f.set_yticks([])
156+
ax_1st_f.set_xticks([]), ax_1st_b.set_xticks([])
152157

153158

154159
def color_alpha(target, pct, vmin=5, vmax=80):

notebooks/python_module/16_network/pet_follow_particle.ipynb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"cell_type": "markdown",
1616
"metadata": {},
1717
"source": [
18-
"\n# Follow particle\n"
18+
"\nFollow particle\n===============\n"
1919
]
2020
},
2121
{
@@ -55,7 +55,7 @@
5555
"cell_type": "markdown",
5656
"metadata": {},
5757
"source": [
58-
"## Schema\n\n"
58+
"Schema\n------\n\n"
5959
]
6060
},
6161
{
@@ -73,7 +73,7 @@
7373
"cell_type": "markdown",
7474
"metadata": {},
7575
"source": [
76-
"## Animation\nParticle settings\n\n"
76+
"Animation\n---------\nParticle settings\n\n"
7777
]
7878
},
7979
{
@@ -109,7 +109,7 @@
109109
"cell_type": "markdown",
110110
"metadata": {},
111111
"source": [
112-
"### Particle advection\n\n"
112+
"Particle advection\n^^^^^^^^^^^^^^^^^^\n\n"
113113
]
114114
},
115115
{
@@ -131,7 +131,7 @@
131131
},
132132
"outputs": [],
133133
"source": [
134-
"fig = plt.figure(figsize=(10, 10))\nax_1st_b = fig.add_axes([0.05, 0.52, 0.45, 0.45])\nax_2nd_b = fig.add_axes([0.05, 0.05, 0.45, 0.45])\nax_1st_f = fig.add_axes([0.52, 0.52, 0.45, 0.45])\nax_2nd_f = fig.add_axes([0.52, 0.05, 0.45, 0.45])\nax_1st_b.set_title(\"Backward advection for each time step\")\nax_1st_f.set_title(\"Forward advection for each time step\")\n\n\ndef color_alpha(target, pct, vmin=5, vmax=80):\n color = cmap(n.segment[target])\n # We will hide under 5 % and from 80% to 100 % it will be 1\n alpha = (pct - vmin) / (vmax - vmin)\n alpha[alpha < 0] = 0\n alpha[alpha > 1] = 1\n color[:, 3] = alpha\n return color\n\n\nkw = dict(\n name=None, yfield=\"longitude\", event=False, zorder=-100, s=(n.speed_area / 20e6)\n)\nn.scatter_timeline(ax_1st_b, c=color_alpha(i_target_b.T[0], pct_target_b.T[0]), **kw)\nn.scatter_timeline(ax_2nd_b, c=color_alpha(i_target_b.T[1], pct_target_b.T[1]), **kw)\nn.scatter_timeline(ax_1st_f, c=color_alpha(i_target_f.T[0], pct_target_f.T[0]), **kw)\nn.scatter_timeline(ax_2nd_f, c=color_alpha(i_target_f.T[1], pct_target_f.T[1]), **kw)\nfor ax in (ax_1st_b, ax_2nd_b, ax_1st_f, ax_2nd_f):\n n.display_timeline(ax, field=\"longitude\", marker=\"+\", lw=2, markersize=5)\n ax.grid()"
134+
"fig = plt.figure(figsize=(10, 10))\nax_1st_b = fig.add_axes([0.05, 0.52, 0.45, 0.45])\nax_2nd_b = fig.add_axes([0.05, 0.05, 0.45, 0.45])\nax_1st_f = fig.add_axes([0.52, 0.52, 0.45, 0.45])\nax_2nd_f = fig.add_axes([0.52, 0.05, 0.45, 0.45])\nax_1st_b.set_title(\"Backward advection for each time step\")\nax_1st_f.set_title(\"Forward advection for each time step\")\nax_1st_b.set_ylabel(\"Color -> First target\\nLatitude\")\nax_2nd_b.set_ylabel(\"Color -> Secondary target\\nLatitude\")\nax_2nd_b.set_xlabel(\"Julian days\"), ax_2nd_f.set_xlabel(\"Julian days\")\nax_1st_f.set_yticks([]), ax_2nd_f.set_yticks([])\nax_1st_f.set_xticks([]), ax_1st_b.set_xticks([])\n\n\ndef color_alpha(target, pct, vmin=5, vmax=80):\n color = cmap(n.segment[target])\n # We will hide under 5 % and from 80% to 100 % it will be 1\n alpha = (pct - vmin) / (vmax - vmin)\n alpha[alpha < 0] = 0\n alpha[alpha > 1] = 1\n color[:, 3] = alpha\n return color\n\n\nkw = dict(\n name=None, yfield=\"longitude\", event=False, zorder=-100, s=(n.speed_area / 20e6)\n)\nn.scatter_timeline(ax_1st_b, c=color_alpha(i_target_b.T[0], pct_target_b.T[0]), **kw)\nn.scatter_timeline(ax_2nd_b, c=color_alpha(i_target_b.T[1], pct_target_b.T[1]), **kw)\nn.scatter_timeline(ax_1st_f, c=color_alpha(i_target_f.T[0], pct_target_f.T[0]), **kw)\nn.scatter_timeline(ax_2nd_f, c=color_alpha(i_target_f.T[1], pct_target_f.T[1]), **kw)\nfor ax in (ax_1st_b, ax_2nd_b, ax_1st_f, ax_2nd_f):\n n.display_timeline(ax, field=\"longitude\", marker=\"+\", lw=2, markersize=5)\n ax.grid()"
135135
]
136136
}
137137
],
@@ -151,7 +151,7 @@
151151
"name": "python",
152152
"nbconvert_exporter": "python",
153153
"pygments_lexer": "ipython3",
154-
"version": "3.7.9"
154+
"version": "3.7.7"
155155
}
156156
},
157157
"nbformat": 4,

src/py_eddy_tracker/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,17 @@ def parse_args(self, *args, **kwargs):
106106
return opts
107107

108108

109+
TIME_MODELS = ["%Y%m%d", "%Y%m%d%H%M%S", "%Y%m%dT%H%M%S"]
110+
111+
109112
VAR_DESCR = dict(
110113
time=dict(
111114
attr_name="time",
112115
nc_name="time",
113116
old_nc_name=["j1"],
114-
nc_type="int32",
117+
nc_type="float64",
118+
output_type="uint32",
119+
scale_factor=1 / 86400.0,
115120
nc_dims=("obs",),
116121
nc_attr=dict(
117122
standard_name="time",

src/py_eddy_tracker/appli/eddies.py

Lines changed: 24 additions & 16 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 EddyParser
18+
from .. import TIME_MODELS, EddyParser
1919
from ..observations.observation import EddiesObservations, reverse_index
2020
from ..observations.tracking import TrackEddiesObservations
2121
from ..tracking import Correspondances
@@ -223,7 +223,7 @@ def browse_dataset_in(
223223
data_dir,
224224
files_model,
225225
date_regexp,
226-
date_model,
226+
date_model=None,
227227
start_date=None,
228228
end_date=None,
229229
sub_sampling_step=1,
@@ -238,11 +238,7 @@ def browse_dataset_in(
238238
filenames = bytes_(glob(full_path))
239239

240240
dataset_list = empty(
241-
len(filenames),
242-
dtype=[
243-
("filename", "S500"),
244-
("date", "datetime64[D]"),
245-
],
241+
len(filenames), dtype=[("filename", "S500"), ("date", "datetime64[s]")],
246242
)
247243
dataset_list["filename"] = filenames
248244

@@ -268,10 +264,21 @@ def browse_dataset_in(
268264
str_date = result.groups()[0]
269265

270266
if str_date is not None:
271-
item["date"] = datetime.strptime(str_date, date_model).date()
267+
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")
278+
else:
279+
item["date"] = datetime.strptime(str_date, date_model)
272280

273281
dataset_list.sort(order=["date", "filename"])
274-
275282
steps = unique(dataset_list["date"][1:] - dataset_list["date"][:-1])
276283
if len(steps) > 1:
277284
raise Exception("Several days steps in grid dataset %s" % steps)
@@ -304,7 +311,7 @@ def track(
304311
correspondances_only=False,
305312
**kw_c,
306313
):
307-
kw = dict(date_regexp=".*_([0-9]*?).[nz].*", date_model="%Y%m%d")
314+
kw = dict(date_regexp=".*_([0-9]*?).[nz].*")
308315
if isinstance(pattern, list):
309316
kw.update(dict(data_dir=None, files_model=None, files=pattern))
310317
else:
@@ -323,10 +330,9 @@ def track(
323330
c = Correspondances(datasets=datasets["filename"], **kw_c)
324331
c.track()
325332
logger.info("Track finish")
326-
t0, t1 = c.period
327333
kw_save = dict(
328-
date_start=t0,
329-
date_stop=t1,
334+
date_start=datasets["date"][0],
335+
date_stop=datasets["date"][-1],
330336
date_prod=datetime.now(),
331337
path=output_dir,
332338
sign_type=c.current_obs.sign_legend,
@@ -351,11 +357,13 @@ def track(
351357

352358
short_c = c._copy()
353359
short_c.shorter_than(size_max=nb_obs_min)
354-
c.longer_than(size_min=nb_obs_min)
355-
356-
long_track = c.merge(raw_data=raw)
357360
short_track = short_c.merge(raw_data=raw)
358361

362+
if c.longer_than(size_min=nb_obs_min) is False:
363+
long_track = short_track.empty_dataset()
364+
else:
365+
long_track = c.merge(raw_data=raw)
366+
359367
# We flag obs
360368
if c.virtual:
361369
long_track["virtual"][:] = long_track["time"] == 0

src/py_eddy_tracker/appli/grid.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from argparse import Action
66
from datetime import datetime
77

8-
from .. import EddyParser
8+
from .. import TIME_MODELS, EddyParser
99
from ..dataset.grid import RegularGridDataset, UnRegularGridDataset
1010

1111

@@ -121,7 +121,16 @@ def eddy_id(args=None):
121121
cut_wavelength = [0, *cut_wavelength]
122122
inf_bnds, upper_bnds = cut_wavelength
123123

124-
date = datetime.strptime(args.datetime, "%Y%m%d")
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")
125134
kwargs = dict(
126135
step=args.isoline_step,
127136
shape_error=args.fit_errmax,
@@ -150,7 +159,7 @@ def eddy_id(args=None):
150159
sampling_method=args.sampling_method,
151160
**kwargs,
152161
)
153-
out_name = date.strftime("%(path)s/%(sign_type)s_%Y%m%d.nc")
162+
out_name = date.strftime("%(path)s/%(sign_type)s_%Y%m%dT%H%M%S.nc")
154163
a.write_file(path=args.path_out, filename=out_name, zarr_flag=args.zarr)
155164
c.write_file(path=args.path_out, filename=out_name, zarr_flag=args.zarr)
156165

1.14 KB
Binary file not shown.

src/py_eddy_tracker/gui.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,8 @@ def get_infos(self, name, index):
291291
i_first = d.index_from_track[tr]
292292
track = d.obs[i_first : i_first + nb]
293293
nb -= 1
294-
t0 = timedelta(days=int(track[0]["time"])) + datetime(1950, 1, 1)
295-
t1 = timedelta(days=int(track[-1]["time"])) + datetime(1950, 1, 1)
294+
t0 = timedelta(days=track[0]["time"]) + datetime(1950, 1, 1)
295+
t1 = timedelta(days=track[-1]["time"]) + datetime(1950, 1, 1)
296296
txt = f"--{name}--\n"
297297
txt += f" {t0} -> {t1}\n"
298298
txt += f" Tracks : {tr} {now['n']}/{nb} ({now['n'] / nb * 100:.2f} %)\n"

0 commit comments

Comments
 (0)