Utilities API
FM2PROF includes a set of utilities to analyse its output.
Compare1D2D
Bases: ModelOutputReader
Utility to compare the results of a 1D and 2D model through visualisation and statistical post-processing.
Note
If 2D and 1D netCDF input files are provided, they will first be
converted to csv files. Once csv files are present, the original
netCDF files are no longer used. In that case, the arguments
to path_1d
and path_2d
should be None
.
Example usage
Parameters:
Name | Type | Description | Default |
---|---|---|---|
project |
Project
|
|
required |
path_1d |
Union[Path, str] | None
|
path to SOBEK dimr directory |
None
|
path_2d |
Union[Path, str] | None
|
path to his nc file |
None
|
routes |
List[List[str]] | None
|
list of branch abbreviations, e.g. ['NR', 'LK'] |
None
|
start_time |
Union[None, datetime]
|
start time for plotting and analytics. Use this to crop the time to prevent initalisation from affecting statistics. |
None
|
stop_time |
Union[None, datetime]
|
stop time for plotting and analytics. |
None
|
style |
str
|
|
'sito'
|
Source code in fm2prof\utils.py
eval()
does a bunch
Source code in fm2prof\utils.py
figure_at_station(station, func='time', savefig=True)
Creates a figure with the timeseries at a single observation station.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
station |
str
|
name of station. use |
required |
func |
str
|
use |
'time'
|
savefig |
bool
|
if True, saves to png. If False, returned FigureOutput |
True
|
Source code in fm2prof\utils.py
1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 |
|
figure_compare_discharge_at_stations(stations, title='no_title', savefig=True)
Like Compare1D2D.figure_at_station
, but compares discharge
distribution over two stations.
Example usage:
Figures are saved to[Compare1D2D.output_path]/figures/discharge
Example output:
.. figure:: figures_utils/discharge/example.png
Example output figure
Source code in fm2prof\utils.py
1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 |
|
figure_longitudinal(route, stat='time', savefig=True, label='', add_to_fig=None)
Creates a figure along a route
. Content of figure depends
on stat
. Figures are saved to [Compare1D2D.output_path]/figures/longitudinal
Example output:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
route |
List[str]
|
List of branches (e.g. ['NK', 'LK']) |
required |
stat |
str
|
what type of longitudinal plot to make. Options are: - time - last25 - max13 |
'time'
|
savefig |
bool
|
if true, figure is saved to png file. If false, |
True
|
add_to_fig |
FigureOutput | None
|
if |
None
|
Source code in fm2prof\utils.py
2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 |
|
figure_longitudinal_rating_curve(route)
Create a figure along a route with lines at various dicharges. To to this, rating curves are generated at each point by digitizing the model output.
Figures are saved to [Compare1D2D.output_path]/figures/longitudinal
Example output:
.. figure:: figures_utils/longitudinal/example_rating_curve.png
example output figure
Source code in fm2prof\utils.py
2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 |
|
get_route(route)
returns a sorted list of stations along a route, with rkms
Source code in fm2prof\utils.py
heatmap_rating_curve(route)
Create a 2D heatmap along a route. The horizontal axis uses the digitized rating curves to match the two models
Figures are saved to [Compare1D2D.output_path]/figures/heatmap
Example output:
.. figure:: figures_utils/heatmaps/example_rating_curve.png
example output figure
Source code in fm2prof\utils.py
heatmap_time(route)
Create a 2D heatmap along a route. The horizontal axis uses timemarks to match the 1D and 2D models
Figures are saved to [Compare1D2D.output_path]/figures/heatmap
Example output:
.. figure:: figures_utils/heatmaps/example_time_series.png
example output figure
Source code in fm2prof\utils.py
statistics_to_file(file_path='error_statistics')
Creates and output a file `error_statistics.csv', which is a comma-seperated file with the following columns:
,bias,rkm,branch,is_lmw,std,mae
with for each station:
- bias = bias, mean error
- rkm = river kilometer of the station
- branch = name of 1D branch on which the station lies
- is_lmw = if "LMW" is in the name of station, True.
- std = standard deviation of the rror
- mae = mean absolute error of the error