<jupyter_start><jupyter_text>5. 手動創建DataArray從讀取netCDF檔案的過程中，我們已經理解DataArray的架構，也就是將資料儲存在座標軸的框架中，其中大氣科學資料的儲存格式大多是(time, level, lat, lon)這樣四維的結構。當然，也不一定要是這四個軸，只要是給定了座標軸，我們就可以手動建立DataArray。> *class* xarray.DataArray(data=``, coords=None, dims=None, name=None, attrs=None) - data - Values for this array. Must be an numpy.ndarray, ndarray like, or castable to an ndarray.- dims – Name(s) of the data dimension(s).- coords – Coordinates (tick labels) to use for indexing along each dimension. The following notations are accepted:  - mapping {dimension name: array-like}  - mapping {coord name: DataArray}   - mapping {coord name: Variable}- name – Name of this array.- attrs – Attributes to assign to the new instance.**Example 1: 將每日OLR資料轉化成(year, pentad, lat, lon)格式：** 在探討季內尺度的季內變異時，將資料轉換成pentad單位是很方便的做法，可以過濾掉太高頻天氣尺度的變化。先準備資料：<jupyter_code>import xarray as xr 

olr_ds = xr.open_dataset("data/olr.nc")   
olr_da = olr_ds.olr
olr_noleap = olr_da.sel(time=~((olr_da.time.dt.month == 2) & (olr_da.time.dt.day == 29)))  # 因為處理pentad資料，2/29會使該候多一天，
                                                                                           # 為方便計算先拿掉2/29。

olr_ptd = xr.DataArray( 
                       dims=['year','pentad','lat','lon'],
                       coords=dict(year=range(1998,2018), 
                                   pentad=range(1,74),
                                   lat=olr_da.lat,
                                   lon=olr_da.lon),
                       name='olr')
for yy in olr_ptd.year: 
    for p in olr_ptd.pentad:
        olr_ptd.loc[yy,p,:,:] = (olr_noleap[ int((yy-1998)*365+ (p-1)*5) : int((yy-1998)*365+ (p-1)*5 + 14),:,:  ]
                                            .mean(axis=0))
olr_ptd<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12827822120866592, 'fraction_numerical': 0.02451539338654504, 'mean_word_length': 2.375, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '396766', 'license': 'Unlicense', 'n_tokens_mistral': 777, 'n_tokens_neox': 790, 'n_words': 123, 'path': 'pyaos-wks/docs/_sources/05_da_create.ipynb', 'repo_name': 'wyhtsai/wyhtsai.github.io', 'size': '1754'}