
---
title: Dfs2
aliases:
  - ../dfs2.html
---

A dfs2 file is also called a grid series file. Values in a dfs2 file are ‘element based’, i.e. values are defined in the centre of each grid cell. 


```{python}
import mikeio
ds = mikeio.read("../data/gebco_sound.dfs2")
ds
```

## Subset in space

The most convenient way to subset in space is to use the `sel` method, which returns a new (smaller) dataset, which can be further processed or written to disk using the `to_dfs` method. 

```{python}
ds.geometry
```

```{python}
ds_aoi = ds.sel(x=slice(12.5, 13.0), y=slice(55.5, 56.0))
ds_aoi.geometry
```

In order to specify an open-ended subset (i.e. where the end of the subset is the end of the domain), use `None` as the end of the slice. 

```{python}
ds.sel(x=slice(None, 13.0))
```

## Grid2D

The spatial information is available in the `geometry` attribute (accessible from Dfs2, Dataset, and DataArray), which in the case of a dfs2 file is a [`Grid2D`](`mikeio.Grid2D`) geometry. 

```{python}
ds.geometry
```

Grid2D's primary properties and methods are: 

* `x` 
* `nx`
* `dx`
* `y`
* `ny`
* `dy`
* `origin`
* `projection`
* `xy` 
* `bbox`
* `contains()`
* `find_index()`
* `isel()`
* `to_mesh()`

See [API specification](`mikeio.Grid2D`) for details.


## Dfs2 resources

* [Dfs2 | getting-started-with-mikeio](https://dhi.github.io/getting-started-with-mikeio/dfs2.html)
* [Dfs2-Bathymetry](../examples/dfs2/bathy.qmd) - GEBCO NetCDF/xarray to dfs2 
* [Dfs2-GFS](../examples/dfs2/gfs.qmd) - GFS NetCDF/xarray to dfs2
