Dfs0 - CMEMS in-situ data

Copernicus Marine provides access to a wide range of model and in-situ data. In this example we will look at how to access the in-situ data and convert it to a MIKE IO dataset.

import pandas as pd
import xarray as xr
import mikeio
fino = xr.open_dataset("../../data/NO_TS_MO_FINO1_202209.nc")
fino
<xarray.Dataset> Size: 3MB
Dimensions:      (TIME: 2879, LATITUDE: 2879, LONGITUDE: 2879, DEPTH: 7,
                  POSITION: 2879)
Coordinates:
  * TIME         (TIME) datetime64[ns] 23kB 2022-09-01 ... 2022-09-30T23:31:5...
  * LATITUDE     (LATITUDE) float32 12kB 54.0 54.0 54.0 54.0 ... 54.0 54.0 54.0
  * LONGITUDE    (LONGITUDE) float32 12kB 6.583 6.583 6.583 ... 6.583 6.583
    DEPH         (TIME, DEPTH) float32 81kB ...
Dimensions without coordinates: DEPTH, POSITION
Data variables: (12/22)
    DEPH_QC      (TIME, DEPTH) float32 81kB ...
    TIME_QC      (TIME) float32 12kB ...
    POSITION_QC  (POSITION) float32 12kB ...
    TEMP         (TIME, DEPTH) float64 161kB ...
    TEMP_QC      (TIME, DEPTH) float32 81kB ...
    VHM0         (TIME, DEPTH) float64 161kB ...
    ...           ...
    VTPK_DM      (TIME, DEPTH) object 161kB ...
    VTZA         (TIME, DEPTH) float64 161kB ...
    VTZA_QC      (TIME, DEPTH) float32 81kB ...
    VPED         (TIME, DEPTH) float64 161kB ...
    VPED_QC      (TIME, DEPTH) float32 81kB ...
    VPED_DM      (TIME, DEPTH) object 161kB ...
Attributes: (12/46)
    platform_code:                  FINO1
    platform_name:                  
    data_mode:                      M
    title:                          NWS - NRT in situ Observations
    summary:                        Oceanographic data from North West Shelf
    naming_authority:               Copernicus Marine In Situ
    ...                             ...
    doi:                            
    pi_name:                        
    qc_manual:                      OceanSITES User's Manual v1.2
    date_update:                    2022-10-07T05:39:40Z
    history:                        2022-10-01T18:04:25Z : Creation; 2022-10-...
    wmo_inst_type:                  

CMEMS in-situ data is provided in a standardised format.

Find out which variables we are interested in to extract:

data = [
    {
        "name": fino[var].name,
        "standard_name": fino[var].standard_name,
        "units": fino[var].units,
    }
    for var in fino.data_vars
    if hasattr(fino[var], "units")
]

pd.DataFrame(data)
name standard_name units
0 TEMP sea_water_temperature degrees_C
1 VHM0 sea_surface_wave_significant_height m
2 VZMX sea_surface_wave_maximum_height m
3 VTM02 sea_surface_wave_mean_period_from_variance_spe... s
4 VTPK sea_surface_wave_period_at_variance_spectral_d... s
5 VTZA sea_surface_wave_mean_period s
6 VPED sea_surface_wave_from_direction_at_variance_sp... degree

The data have a DEPTH dimension, even though variables are only measured at a single level and doesn’t vary in time although the format allows for it.

I.e. temperature (TEMP) is available at level 1 (0.5 m)

fino.DEPH.plot.line(x="TIME")

fino['TEMP'].plot.line("-^",x='TIME')

fino['VHM0'].plot.line("-^",x='TIME')

Wave data are only available at the surface.

fino[['VHM0','VTZA','VPED']].isel(DEPTH=0)
<xarray.Dataset> Size: 104kB
Dimensions:  (TIME: 2879)
Coordinates:
  * TIME     (TIME) datetime64[ns] 23kB 2022-09-01 ... 2022-09-30T23:31:59.99...
    DEPH     (TIME) float32 12kB ...
Data variables:
    VHM0     (TIME) float64 23kB ...
    VTZA     (TIME) float64 23kB ...
    VPED     (TIME) float64 23kB ...
Attributes: (12/46)
    platform_code:                  FINO1
    platform_name:                  
    data_mode:                      M
    title:                          NWS - NRT in situ Observations
    summary:                        Oceanographic data from North West Shelf
    naming_authority:               Copernicus Marine In Situ
    ...                             ...
    doi:                            
    pi_name:                        
    qc_manual:                      OceanSITES User's Manual v1.2
    date_update:                    2022-10-07T05:39:40Z
    history:                        2022-10-01T18:04:25Z : Creation; 2022-10-...
    wmo_inst_type:                  
df = fino[['VHM0','VTZA','VPED']].isel(DEPTH=0).to_dataframe()

The data are stored on the concurrent timesteps.

df[['VHM0','VTZA','VPED']].head()
VHM0 VTZA VPED
TIME
2022-09-01 00:00:00 NaN 4.12 NaN
2022-09-01 00:02:00 1.11 NaN 2.800000
2022-09-01 00:30:00 NaN 4.18 NaN
2022-09-01 00:32:00 1.09 NaN 353.000017
2022-09-01 01:00:00 NaN 4.00 NaN
df[['VHM0','VTZA']].plot(style='+')

Convert the wave height data to a mikeio dataset.

ds = mikeio.from_pandas(
    df[["VHM0"]].dropna(), items=mikeio.ItemInfo(mikeio.EUMType.Significant_wave_height)
)
ds
<mikeio.Dataset>
dims: (time:1439)
time: 2022-09-01 00:02:00 - 2022-09-30 23:31:59.999999744 (1439 non-equidistant records)
geometry: GeometryUndefined()
items:
  0:  VHM0 <Significant wave height> (meter)

Store the results in Dfs0 format.

ds.to_dfs("FINO1_VHM0.dfs0")

Read the file again to check…

ds = mikeio.read("FINO1_VHM0.dfs0")
ds
<mikeio.Dataset>
dims: (time:1439)
time: 2022-09-01 00:02:00 - 2022-09-30 23:32:00 (1439 non-equidistant records)
geometry: GeometryUndefined()
items:
  0:  VHM0 <Significant wave height> (meter)