ILAMB.Regions.Regions.addRegionNetCDF4

Regions.addRegionNetCDF4(filename)[source]

Add regions found in a netCDF4 file.

This routine will search the target filename’s variables for 2-dimensional datasets which contain indices representing distinct non-overlapping regions. Each unique non-masked index found in this dataset will be added to the global list of regions along with a mask representing the region. The names of the regions are taken from a required attribute in the variable called ‘labels’. This attribute should point to a variable which is a string array labeling each index found in the two-dimensional dataset.

For example, the following header represents a dataset encoded to represent 50 of the world’s largest river basins. The ‘basin_index’ variable contains integer indices 0 through 49 where index 0 is labeled by the 0th label found in the ‘label’ variable:

dimensions:
      lat = 360 ;
      lon = 720 ;
      n = 50 ;
variables:
      string label(n) ;
              label:long_name = "basin labels" ;
      float lat(lat) ;
              lat:long_name = "latitude" ;
              lat:units = "degrees_north" ;
      float lon(lon) ;
              lon:long_name = "longitude" ;
              lon:units = "degrees_east" ;
      int basin_index(lat, lon) ;
              basin_index:labels = "label" ;
Parameters

filename (str) – the full path of the netCDF4 file containing the regions

Returns

regions – a list of the keys of the regions added.

Return type

list of str