Plotting of water level data from Copernicus Global Land Service¶

  • data source: http://land.copernicus.eu/global/products/wl
  • data to be downloaded by user
  • in script below a river or lake level is expected

https://land.copernicus.vgt.vito.be/PDF/portal/Application.html data downloaded for virtual station downstream zambezi, available in the folder '/available_data'

The sample dataset details are:

  • location [E,N] = [35.5666, -18.0047]
  • name basin = Zambezi
  • name river = Zambeze
  • start observation = 2016-05-02 19:48:00
  • end observation = 2023-11-16 19:49:00
In [1]:
#load library
#----------------------------------------------------
from   sys                 import argv
from   os                  import path
from   json                import load as jload
from   pandas              import DataFrame
from   matplotlib.pyplot   import subplots
from   matplotlib.ticker   import ScalarFormatter

#----------------------------------------------------
In [2]:
name_json_file_in = './available_data/c_gls_WL_202311161949_0000000012677_ALTI_V2.2.0.json'
print("The file name selected is: ", name_json_file_in)
The file name selected is:  ./available_data/c_gls_WL_202311161949_0000000012677_ALTI_V2.2.0.json
In [3]:
#print first couple of lines of the json file
N = 13
with open(name_json_file_in) as f:
    for i in range(0, N):
        print(f.readline(), end = '')
        #print(f.readline())
{
    "type": "Feature",
    "geometry": {
        "type": "Point",
        "coordinates": [
            35.5666,
            -18.0047
        ]
    },
    "properties": {
        "resource": "0000000012677",
        "basin": "Zambezi",
        "river": "Zambeze",
In [4]:
# Load content of GEOjson file with json module
with open(name_json_file_in) as h_json:
    z_table = jload(h_json)
In [5]:
#inspect the full header information available
print (z_table['type'])
print (z_table['geometry'])
print (z_table['properties'])
Feature
{'type': 'Point', 'coordinates': [35.5666, -18.0047]}
{'resource': '0000000012677', 'basin': 'Zambezi', 'river': 'Zambeze', 'comment': 'Timeseries specified by LEGOS and computed by CLS on behalf of CNES and Copernicus Global Land', 'country': 'Mozambique', 'institution': 'LEGOS, CLS, CNES', 'source': 'Derived from satellite altimetry', 'references': 'http://land.copernicus.eu/global/products/wl', 'archive_facility': 'CLS', 'time_coverage_start': '2016-05-02 19:48:00', 'time_coverage_end': '2023-11-16 19:49:00', 'updated': '2023-11-19T00:57:52Z', 'platform': 'SENTINEL3A', 'long_name': 'Lake and River Water Level', 'processing_level': 'LEVEL3B', 'processing_mode': 'Near Real Time', 'status': 'operational', 'copyright': 'Copernicus Service Information 2017', 'contacts': 'Helpdesk: http://land.copernicus.eu/global/contactpage \n Accountable contact: European Commission DG Joint Research Centre copernicuslandproducts@jrc.ec.europa.eu \n Owner contact: European Commission DG Internal Market, Industry, Entrepreneurship and SMEs ENTR-COPERNICUS-ASSETS@ec.europa.eu', 'inspire_theme': 'Hydrography', 'gemet_keywords': 'water level, water management, hydrometry, hydrology, climate, seasonal variation, environmental data, environmental monitoring, monitoring, remote sensing', 'gcmd_keywords': 'TERRESTRIAL HYDROSPHERE, SURFACE WATER', 'iso19115_topic_categories': 'elevation,inlandWaters', 'credit': 'Lake and River Water Level products are generated by the Global Land Service of Copernicus, the Earth Observation Programme of the European Commission and the Theia-land program supported by CNES. The research leading to the current version of the product has received funding from CNES, LEGOS, IRD and CLS.', 'purpose': 'This product is first designed to fit the requirements of the Global Land component of Land Service of Copernicus. It can be also useful for all applications related to the environment monitoring, climate research and hydrology.', 'resource_mimetype': 'application/json', 'water_surface_reference_name': 'EGM2008', 'water_surface_reference_datum_altitude': -9.34, 'missing_value': 9999.999}
In [6]:
#select some header data attributes
print ("location [E,N] =", z_table['geometry']['coordinates'])
print ("name basin =",z_table['properties']['basin'])
label = ''
if 'lake' in z_table['properties']:
    label = z_table['properties']['lake']
    print ("name lake =",label)
elif 'river' in z_table['properties']:
    label = z_table['properties']['river']
    print ("name river =",label)
print ("start observation =",z_table['properties']['time_coverage_start'])
print ("end observation =",z_table['properties']['time_coverage_end'])
location [E,N] = [35.5666, -18.0047]
name basin = Zambezi
name river = Zambeze
start observation = 2016-05-02 19:48:00
end observation = 2023-11-16 19:49:00
In [7]:
#note that a basin input file has been provided, not a river
basin = z_table['properties']['basin']
print(basin)
#river = z_table['properties']['river']
print(label)
location = z_table['geometry']['coordinates']
print(location)
a_list = (location)
#convert elements to string
converted_list = [str(element) for element in a_list]
joined_string = " East, ".join(converted_list)
print(joined_string)
Zambezi
Zambeze
[35.5666, -18.0047]
35.5666 East, -18.0047
In [8]:
# Convert into pandas dataframe
data = DataFrame(z_table['data'])
print(data)
   identifier         time          datetime  \
0       12677  2016.335587  2016/05/02 19:48   
1       12677  2016.409358  2016/05/29 19:48   
2       12677  2016.483128  2016/06/25 19:48   
3       12677  2016.556899  2016/07/22 19:48   
4       12677  2016.630669  2016/08/18 19:48   
..        ...          ...               ...   
83      12677  2023.506372  2023/07/04 19:49   
84      12677  2023.580344  2023/07/31 19:49   
85      12677  2023.654317  2023/08/27 19:49   
86      12677  2023.802262  2023/10/20 19:49   
87      12677  2023.876235  2023/11/16 19:49   

    water_surface_height_above_reference_datum  \
0                                        17.97   
1                                        17.68   
2                                        17.39   
3                                        17.82   
4                                        17.63   
..                                         ...   
83                                       18.18   
84                                       18.04   
85                                       17.75   
86                                       17.70   
87                                       18.09   

    water_surface_height_uncertainty  
0                               0.21  
1                               0.02  
2                               0.02  
3                               0.11  
4                               0.02  
..                               ...  
83                              0.02  
84                              0.01  
85                              0.09  
86                              0.09  
87                              0.05  

[88 rows x 5 columns]
In [9]:
# Plot with matplotlib
from   matplotlib.dates    import DateFormatter
fig, ax = subplots(figsize=(16,9))

ax.errorbar(data['time'], 
            data['water_surface_height_above_reference_datum'], 
            yerr = data['water_surface_height_uncertainty'],
            color = 'darkblue',
            ecolor = 'darkred',
            ls = '-',
            marker = '.',
            alpha = .8,
            label = 'Mean dispersion = %4.2f cm)'%(data['water_surface_height_uncertainty'].mean()*100))


ax.set_xlabel('Time')
ax.xaxis.set_major_formatter(ScalarFormatter(useOffset=False))
ax.set_ylabel('Water Surface Height (m)')
ax.legend(loc = 'best')
ax.grid()

# Set title and labels for axes
#ax.set(title=z_table['properties']['basin'] + "for location retrieved")
ax.set(title="Water Surface Height above Reference Datum for " + basin +" / " + label +  " at " + " " + joined_string +" North")

fig.autofmt_xdate()
In [10]:
# Save plot
name_png_file_out = path.splitext(name_json_file_in)[0]+'.png'
print(name_png_file_out)
fig.savefig(name_png_file_out)
./available_data/c_gls_WL_202311161949_0000000012677_ALTI_V2.2.0.png

The stored figure is available in the folder '/available_data'. Navigate to the folder and double click the png image

In [ ]: