0

I try to get data from netCDF format with xarray

I have code like this,

import numpy as np
import pandas as pd
import xarray as xr
import sys, json
import base64

ds = xr.open_dataset('/home/misdan/Documents/Data/Angin/wind_1992.nc')
da = ds['u10'].sel(time='1992-02',latitude=6.0, longitude=95.20,method='nearest').data

print('--------------------------')
print('hasilnya adalah : ')
print(da)

The result is like this

hasilnya adalah : 
[-2.2909293]

how i can get the value from the result without [], like this

hasilnya adalah : 
-2.2909293

the data is like this

<xarray.DataArray 'u10' (time: 1)>
array([-2.290929], dtype=float32)
Coordinates:
    longitude  float32 95.25
    latitude   float32 6.0
  * time       (time) datetime64[ns] 1992-02-01
Attributes:
    units:      m s**-1
    long_name:  10 metre U wind component
6
  • Same way you get data from any other array: da[0] Commented Aug 24, 2018 at 2:32
  • but i get like this, z = da[0] IndexError: too many indices for array Commented Aug 24, 2018 at 3:10
  • What is the output of type(da)? Commented Aug 24, 2018 at 3:15
  • <xarray.DataArray 'u10' (time: 1)> array([-2.290929], dtype=float32) Coordinates: longitude float32 95.25 latitude float32 6.0 * time (time) datetime64[ns] 1992-02-01 Attributes: units: m s**-1 long_name: 10 metre U wind component Commented Aug 24, 2018 at 3:25
  • the data is like this Commented Aug 24, 2018 at 3:25

1 Answer 1

2

print(da[0]) will print the first item in the da list, which is what you are looking for.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.