Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check that time is not already a coordinate in CF writer #1987

Merged
merged 7 commits into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/multiscene.rst
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ This will compute one video frame (image) at a time and write it to the MPEG-4
video file. For users with more powerful systems it is possible to use
the ``client`` and ``batch_size`` keyword arguments to compute multiple frames
in parallel using the dask ``distributed`` library (if installed).
See the :doc:`dask distributed <dask:how-to/deploy-dask/single-distributed>` documentation
See the :doc:`dask distributed <dask:deploying-python>` documentation
for information on creating a ``Client`` object. If working on a cluster
you may want to use :doc:`dask jobqueue <jobqueue:index>` to take advantage
of multiple nodes at a time.
Expand Down
10 changes: 10 additions & 0 deletions satpy/etc/readers/slstr_l1b.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ datasets:
standard_name: latitude
units: degree

elevation:
name: elevation
resolution: [500, 1000]
view: [nadir, oblique]
stripe: [a, b, i, f]
file_type: esa_geo
file_key: elevation_{stripe:1s}{view:1s}
standard_name: elevation
units: m

# The channels S1-S3 are available in nadir (default) and oblique view.
S1:
name: S1
Expand Down
4 changes: 2 additions & 2 deletions satpy/modifiers/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class SunZenithCorrector(SunZenithCorrectorBase):
.. code-block:: yaml

sunz_corrected:
compositor: !!python/name:satpy.composites.SunZenithCorrector
modifier: !!python/name:satpy.modifiers.SunZenithCorrector
max_sza: !!null
optional_prerequisites:
- solar_zenith_angle
Expand Down Expand Up @@ -149,7 +149,7 @@ class EffectiveSolarPathLengthCorrector(SunZenithCorrectorBase):
.. code-block:: yaml

effective_solar_pathlength_corrected:
compositor: !!python/name:satpy.composites.EffectiveSolarPathLengthCorrector
modifier: !!python/name:satpy.modifiers.EffectiveSolarPathLengthCorrector
max_sza: !!null
optional_prerequisites:
- solar_zenith_angle
Expand Down
18 changes: 18 additions & 0 deletions satpy/tests/writer_tests/test_cf.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,24 @@ def test_single_time_value(self):
bounds_exp = np.array([[start_time, end_time]], dtype='datetime64[m]')
np.testing.assert_array_equal(f['time_bnds'], bounds_exp)

def test_time_coordinate_on_a_swath(self):
"""Test that time dimension is not added on swath data with time already as a coordinate."""
import xarray as xr

from satpy import Scene
scn = Scene()
test_array = np.array([[1, 2], [3, 4], [5, 6], [7, 8]])
scn['test-array'] = xr.DataArray(test_array,
dims=['y', 'x'],
coords={'time': ('y', np.array(['2018-05-30T10:05:00',
'2018-05-30T10:05:01',
'2018-05-30T10:05:02',
'2018-05-30T10:05:03'], dtype=np.datetime64))})
with TempFile() as filename:
scn.save_datasets(filename=filename, writer='cf')
pnuu marked this conversation as resolved.
Show resolved Hide resolved
with xr.open_dataset(filename, decode_cf=True) as f:
np.testing.assert_array_equal(f['test-array_time'], scn['test-array']['time'])

def test_bounds(self):
"""Test setting time bounds."""
import xarray as xr
Expand Down
2 changes: 1 addition & 1 deletion satpy/writers/cf_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ def _encode_time(new_data, epoch):
new_data['time'].encoding['units'] = epoch
new_data['time'].attrs['standard_name'] = 'time'
new_data['time'].attrs.pop('bounds', None)
if 'time' not in new_data.dims:
if 'time' not in new_data.dims and new_data["time"].size not in new_data.shape:
pnuu marked this conversation as resolved.
Show resolved Hide resolved
new_data = new_data.expand_dims('time')
return new_data

Expand Down