Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

xarray get number of lat lon

# To extract coordinates values from a datatable using xarray

import xarray as xr
import numpy as np
import pandas as pd

# This sectin creates a dummy data
years=range(1982,1986)
time = pd.date_range('14/1/' + str(years_arr[0]) + ' 12:00:00', periods=len(years_arr), freq=pd.DateOffset(years=1))
lon = range(20,24)
lat = range(10,14)
arr1 = xr.DataArray(data, coords=[time, lat, lon], dims=['time', 'latitude', 'longitude'])

# This section performs the extraction
# extract coordinate value of the lon
arr1.coords['lon'] 			# gives you longitude as a xarray.DataArray, and
arr1.coords['lon'].values 	# gives you the values as a numpy array.

# extract all coordinates (time, lat, lon) values
time, lat, lon = arr1.indexes.values()
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #xarray #number #lat #lon
ADD COMMENT
Topic
Name
8+3 =