From cfc15ad82288bc7010196d413af05f26a176fc74 Mon Sep 17 00:00:00 2001 From: augustinm Date: Fri, 20 Sep 2024 11:56:49 +0200 Subject: [PATCH] write time as days --- aprofiles/io/write_profiles.py | 12 ++++++------ docs/changelog.rst | 6 ++++++ pyproject.toml | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/aprofiles/io/write_profiles.py b/aprofiles/io/write_profiles.py index 309780b..d214688 100644 --- a/aprofiles/io/write_profiles.py +++ b/aprofiles/io/write_profiles.py @@ -19,11 +19,11 @@ def write(profiles, base_dir, verbose): - verbose (bool): Verbose mode. Defaults to False. """ - def _convert_time_after_epoch(ds, resolution='ms'): - time_attrs = ds["time"].attrs - ds = ds.assign_coords(time=ds.time.data.astype(f"datetime64[{resolution}]").astype(int)) - ds["time"] = ds["time"].assign_attrs(time_attrs) - ds["time"].attrs['units'] = 'milliseconds since 1970-01-01T00:00:00' + def _convert_time_after_epoch(ds): + ds = ds.assign_coords(time=ds.time.data.astype(f"datetime64[ms]").astype(f'float32')) + # milliseconds to days + ds['time'] = ds['time'] / (1000 * 60 * 60 * 24) + ds["time"].attrs['units'] = 'days since 1970-01-01T00:00:00' return ds def _classify_scene(ds): @@ -131,7 +131,7 @@ def _classify_retrieval_scene(ds): ds_towrite = ds_towrite.drop(nodim_var) # converts time - ds_towrite = _convert_time_after_epoch(ds_towrite, resolution='ms') + ds_towrite = _convert_time_after_epoch(ds_towrite) # add altitude direction ds_towrite["altitude"] = ds_towrite["altitude"].assign_attrs({ diff --git a/docs/changelog.rst b/docs/changelog.rst index d153f5f..cb8b1fe 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -4,6 +4,12 @@ Changelog .. image:: _static/images/history-solid.svg :class: awesome-svg +0.6.5 +^^^^^^^ +Sep 20, 2024 + +- Work on CF compliance (write time as days). + 0.6.4 ^^^^^^^ Sep 16, 2024 diff --git a/pyproject.toml b/pyproject.toml index 5e9f2ab..252e0ce 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "aprofiles" -version = "0.6.4" +version = "0.6.5" description = "Analysis of atmospheric profilers measurements" authors = ["augustinm "] license = "GPL-3.0"