xarray
Skill78 starsChanged 10 months agoMITView on GitHub
N-dimensional labeled arrays for geoscience data. Read/write NetCDF, work with climate and oceanographic datasets, perform multi-dimensional analysis with labeled coordinates. Use when the agent needs to: (1) Read/write NetCDF or Zarr files, (2) Work with multidimensional arrays with labeled dimensions, (3) Analyze climate, ocean, or atmosphere data, (4) Compute temporal aggregations (daily/monthly/annual means), (5) Perform area-weighted statistics, (6) Process large datasets with Dask, (7) Apply CF conventions to scientific data.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- tondevrel/scientific-agent-skillstheir own version, first seen Feb 1, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- tondevrel/scientific-agent-skills★ 22same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository41 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- bouleSkill
- brugesSkill
- devitoSkill
- disbaSkill
- discretizeSkill
- dlisioSkill
- ensaioSkill
- flopySkill
- gemgisSkill
- gempySkill
- geolimeSkill
- geostatspySkill
- gnnwrSkill
- gprpySkill
- harmonicaSkill
- landlabSkill
- lasioSkill
- loopstructuralSkill
- mplstereonetSkill
- mtpySkill
- obspySkill
- pastasSkill
- petropySkill
- poochSkill
- pygimliSkill
- pygmtSkill
- pyleoclimSkill
- pylopsSkill
- pyroliteSkill
- pyvistaSkill
- rockhoundSkill
- scikit-gstatSkill
- segyioSkill
- segysakSkill
- simpegSkill
- striplogSkill
- using-geoscience-skillsSkill
- verdeSkill
- wellySkill
The file
Files
xarray - Multi-Dimensional Geoscience Data
Quick Reference
import xarray as xr
# Read
ds = xr.open_dataset('data.nc')
# Access data
temp = ds['temperature'] # DataArray
values = temp.values # numpy array
df = ds.to_dataframe() # pandas DataFrame
# Structure info
print(ds) # Overview
print(ds.dims) # Dimensions
print(ds.data_vars) # Variables
# Write
ds.to_netcdf('output.nc')Key Classes
| Class | Purpose |
Dataset | Collection of aligned DataArrays (like NetCDF file) |
DataArray | Single variable with labeled dimensions |
Coordinates | Dimension labels (time, lat, lon) |
Essential Operations
Select Data
# By coordinate value
temp_jan = ds['temperature'].sel(time='2020-01-15')
temp_region = ds['temperature'].sel(lat=slice(-30, 30), lon=slice(-60, 60))
# Nearest value
temp_point = ds['temperature'].sel(lat=35.5, lon=-120.3, method='nearest')
# By index
temp_first = ds['temperature'].isel(time=0)Compute Statistics
temp = ds['temperature']
temp_mean_time = temp.mean(dim='time') # Spatial map
temp_mean_space = temp.mean(dim=['lat', 'lon']) # Time series
# Area-weighted mean
import numpy as np
weights = np.cos(np.deg2rad(ds.lat))
temp_weighted = temp.weighted(weights).mean(dim=['lat', 'lon'])GroupBy and Resample
temp = ds['temperature']
# Temporal aggregations
monthly_mean = temp.groupby('time.month').mean()
annual_mean = temp.groupby('time.year').mean()
# Climatology and anomalies
climatology = temp.groupby('time.month').mean('time')
anomalies = temp.groupby('time.month') - climatology
# Resample time series
monthly = temp.resample(time='1M').mean()
rolling_30d = temp.rolling(time=30, center=True).mean()Create New Dataset
import numpy as np
import pandas as pd
times = pd.date_range('2020-01-01', periods=365, freq='D')
lats = np.linspace(-90, 90, 180)
lons = np.linspace(-180, 180, 360)
da = xr.DataArray(
data=np.random.randn(365, 180, 360),
dims=['time', 'lat', 'lon'],
coords={'time': times, 'lat': lats, 'lon': lons},
attrs={'units': 'degC', 'long_name': 'Temperature'}
)
ds = xr.Dataset({'temperature': da})
ds.to_netcdf('output.nc')Masking
temp_warm = temp.where(temp > 20) # Mask by condition
temp_clipped = temp.where(temp > 0, 0) # Replace negative with 0
tropics = (ds.lat > -23.5) & (ds.lat < 23.5)
temp_tropics = temp.where(tropics, drop=True) # Mask by coordinateLarge Datasets (Dask)
# Open with chunking (lazy loading)
ds = xr.open_dataset('large_file.nc', chunks={'time': 100})
ds = xr.open_mfdataset('data_*.nc', chunks='auto')
# Operations are lazy until .compute()
result = ds['temperature'].mean(dim='time').compute()When to Use vs Alternatives
| Tool | Best For | Limitations |
| xarray | Labeled multi-dim arrays, NetCDF/Zarr, Dask integration | Learning curve for newcomers from numpy |
| iris | Met Office climate workflows, UGRID mesh support | Smaller community, UK-centric conventions |
| CDO | Fast command-line climate data operations | Not Python-native, limited custom analysis |
| NCO | Quick NetCDF file manipulation and arithmetic | Command-line only, no visualization |
Use xarray when you need labeled dimension handling, seamless NetCDF/Zarr I/O, groupby/resample operations, or Dask-based parallel processing of large datasets.
Consider alternatives when you need fast one-off command-line operations on NetCDF files (use CDO/NCO), or you work within the Met Office ecosystem with UGRID meshes (use iris).
Common Workflows
Climate data analysis with temporal aggregation
- Open NetCDF dataset with
xr.open_dataset()(usechunks=if large) - Inspect dimensions, coordinates, and variables with
print(ds) - Select region of interest with
.sel(lat=slice(), lon=slice()) - Compute climatology with
.groupby('time.month').mean('time') - Calculate anomalies by subtracting climatology from data
- Compute area-weighted spatial mean using cosine latitude weights
- Resample to desired temporal resolution (monthly, annual)
- Save results to NetCDF with
.to_netcdf()
Common Issues
| Issue | Solution |
| Memory error | Use chunks= for lazy loading |
| Time decoding fails | decode_times=False then manual decode |
| Missing coordinates | Check ds.coords and ds.dims |
| Alignment errors | Check coordinate values match |
References
- I/O Formats - NetCDF, Zarr, and other formats
- Computation - Aggregation and analysis methods
Scripts
- scripts/climate_analysis.py - Climate data analysis
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

