@@ -494,46 +494,47 @@ def assign_coords(self, coords=None, **coords_kwargs):
494
494
495
495
Convert `Dataset` longitude coordinates from 0-359 to -180-179:
496
496
497
- >>> np.random.seed(0)
497
+ >>> temperature = np.linspace(20, 32, num=16).reshape(2, 2, 4)
498
+ >>> precipitation = 2 * np.identity(4).reshape(2, 2, 4)
498
499
>>> ds = xr.Dataset(
499
500
... data_vars=dict(
500
- ... temperature=(["x", "y", "time"], 15 + 8 * np.random.randn(2, 2, 3) ),
501
- ... precipitation=(["x", "y", "time"], 10 * np.random.rand(2, 2, 3) ),
501
+ ... temperature=(["x", "y", "time"], temperature ),
502
+ ... precipitation=(["x", "y", "time"], precipitation ),
502
503
... ),
503
504
... coords=dict(
504
505
... lon=(["x", "y"], [[260.17, 260.68], [260.21, 260.77]]),
505
506
... lat=(["x", "y"], [[42.25, 42.21], [42.63, 42.59]]),
506
- ... time= pd.date_range("2014-09-06", periods=3 ),
507
- ... reference_time= pd.Timestamp("2014-09-05")
507
+ ... time = pd.date_range("2014-09-06", periods=4 ),
508
+ ... reference_time = pd.Timestamp("2014-09-05")
508
509
... ),
509
510
... attrs=dict(description="Weather-related data"),
510
511
... )
511
512
>>> ds
512
513
<xarray.Dataset>
513
- Dimensions: (x: 2, y: 2, time: 3 )
514
+ Dimensions: (x: 2, y: 2, time: 4 )
514
515
Coordinates:
515
516
lon (x, y) float64 260.2 260.7 260.2 260.8
516
517
lat (x, y) float64 42.25 42.21 42.63 42.59
517
- * time (time) datetime64[ns] 2014-09-06 2014-09-07 2014-09-08
518
+ * time (time) datetime64[ns] 2014-09-06 2014-09-07 ... 2014-09-09
518
519
reference_time datetime64[ns] 2014-09-05
519
520
Dimensions without coordinates: x, y
520
521
Data variables:
521
- temperature (x, y, time) float64 29.11 18.2 22.83 ... 18.28 16.15 26.63
522
- precipitation (x, y, time) float64 5.68 9.256 0.7104 ... 7.992 4.615 7.805
522
+ temperature (x, y, time) float64 20.0 20.8 21.6 22.4 ... 30.4 31.2 32.0
523
+ precipitation (x, y, time) float64 2.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 2.0
523
524
Attributes:
524
- description: Temperature data
525
+ description: Weather-related data
525
526
>>> ds.assign_coords(lon=(((ds.lon + 180) % 360) - 180))
526
527
<xarray.Dataset>
527
- Dimensions: (x: 2, y: 2, time: 3 )
528
+ Dimensions: (x: 2, y: 2, time: 4 )
528
529
Coordinates:
529
530
lon (x, y) float64 -99.83 -99.32 -99.79 -99.23
530
531
lat (x, y) float64 42.25 42.21 42.63 42.59
531
- * time (time) datetime64[ns] 2014-09-06 2014-09-07 2014-09-08
532
+ * time (time) datetime64[ns] 2014-09-06 2014-09-07 ... 2014-09-09
532
533
reference_time datetime64[ns] 2014-09-05
533
534
Dimensions without coordinates: x, y
534
535
Data variables:
535
- temperature (x, y, time) float64 29.11 18.2 22.83 ... 18.28 16.15 26.63
536
- precipitation (x, y, time) float64 5.68 9.256 0.7104 ... 7.992 4.615 7.805
536
+ temperature (x, y, time) float64 20.0 20.8 21.6 22.4 ... 30.4 31.2 32.0
537
+ precipitation (x, y, time) float64 2.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 2.0
537
538
Attributes:
538
539
description: Weather-related data
539
540
0 commit comments