Getting started#
Note
Feel free to click through the individual tutorials, some of them are already finished!
Warning
This “Getting started” tutorial will give a brief general overview and then link to the specific tutorials on each major concept. It is still work-in-progress and will be finalized as the other more specific tutorials mature.
1. The xsnowDataset data model#
Unlike data models that treat each single snow profile as a standalone object, xsnow organizes data on a labeled grid. That means one dataset can hold:
multiple locations,
multiple times,
multiple slope/aspect configurations per location and time,
multiple realizations (e.g. different weather forcings, ensemble members), and
each full stratigraphy (layered snow profile) underneath those.
Formally, the core dimensions are:
locationWhere is this profile? We typically attach geographic metadata as coordinates on this dimension (e.g.latitude,longitude,easting,northing,altitude).timeWhen is this profile valid? Note:timeis timezone-naive and reflects whatever the data source used. How to handle time zones correctly is covered in Handling timezones.slopeSame physical location and time, but different terrain orientation. xsnow attaches the coordinatesinclination(degrees from horizontal)azimuth(degrees from north; e.g., 180° = south)
If you only have one slope/aspect, the dimension length is 1.
realizationParallel “versions” of the snowpack for the same(location, time, slope)— for example:different weather inputs (multi model, or ensemble model members),
different physical parametrizations,
observed vs. modeled,
different land cover classes, etc.
If you don’t use this dimension, it’s still present but length 1.
layerThe vertical snow stratigraphy. Variables defined alonglayerdescribe per-layer properties: density, grain size, temperature, etc. There is also a vertical coordinate variable likez(zero at the snow surface, positive upward, negative downward).
Those five dimensions give you a consistent, rectangular grid. On top of them, we store two broad kinds of variables:
Kind of variable |
Typical dims |
|---|---|
Profile-level / scalar per profile |
|
Layer-level / stratigraphy variable |
|
Example:
HS(total snow height) is profile-level and therefore does not have alayerdimension.densityis a layer property and therefore it does have thelayerdimension.
Why this structure?
You can run fully vectorized analysis and statistics across large subsets of the data.
For example: “Give me all weak layers with poor stability on north-facing slopes after a certain date” becomes a straightforward selection and filter on the dataset—no manual loops, no filename parsing, no ad hoc per-station scripts.The entire dataset can be serialized to (and restored from) NetCDF efficiently, lazily, and it can be subset on parsing.
By adopting this data model,
xsnowcan directly leverage the high-performancexarrayecosystem.
This not only gives us convenient labeled indexing, resampling, and computation, but also sets upxsnowfor future-friendly storage formats like zarr / geozarr, which are increasingly used for scalable, cloud-native geoscience data.
An xsnowDataset feels like an xarray.Dataset
While xsnow introduces its own class, xsnowDataset, we’ve taken meticulous care to make an xsnowDataset behave and feel just like an xarray.Dataset.
Full compatibility:
Any method you can call on anxarray.Datasetcan also be called on anxsnowDataset.Underlying xarray object:
EveryxsnowDatasetcontains a regularxarray.Datasetholding the actual data, accessible via the attributeds.data.
If you want to explicitly export to a purexarray.Dataset, simply call:ds.to_xarray()
Automatic method forwarding:
Any attribute or method that’s not part ofxsnowDatasetis automatically forwarded to the underlyingxarray.Dataset.
For example:ds.info() # under the hood calls ds.data.info() ds['density'] # under the hood calls ds.data['density']
Helpful auto-complete organization:
Python’s tab completion works seamlessly and is structured to help you explore:ds. # + TAB: shows xsnow-native methods and coordinates ds.data. # + TAB: shows all xarray.Dataset methods available on ds as well
This design keeps the workflow intuitive: you get all the power of xarray, plus the specialized snow science functionality of xsnow.
Warning
More coming soon!