trajplot#

class trajplot.Figure(var: str, root_folder, scenario: str = 'RCP 8.5', data_crs=None, coords='all', coords_crs=None, rolling_days: int = 1, period_years: int = 10, annuality='calendar', plot_type: str = None, repres: (None, <class 'str'>) = 'area', cumul: bool = False, relative: bool = False, language: str = 'fr', color='scale', plotsize='wide', filename: str = '', credit: (None, <class 'str'>) = 'auto', showlegend: bool = True, shadow: (None, <class 'str'>) = None, verbose: bool = False)[source]#

Bases: object

Main data available as Figure attributes#

Main variables

Description

self.model_names_list

List of model names.
For example in EXPLORE2 it corresponds to the identifier of the
climatic experiment: ‘Model1’, ‘Model2’, ‘Model3’…, ‘Model17’.

self.original_data

List of the pandas.Dataframes retrieved from the NetCDF data,
for each model (climatic experiments). NetCDF data are converted
into time series by considering the spatial average over the
coords argument (mask).

self.relative_ref

Equivalent to self.original_data, but contains the time
series used as reference (historic) to compute relative
values (if user-chosen).

self.rea_data

Equivalent to self.original_data, but contains the
reanalysis time series, which are added to the plots in
order to provide a historic reference.

self.all_res

List of pd.Dataframes for each period (according to
period_years argument), containing timeseries averaged
over a year (365 days) for each model (climatic experiments)
(one column per model). The year starts on the month defined by
annuality argument.

self.graph_result

Results formated for the plots.
Either in the form of a list of pd.Dataframes, one for each
period, each pd.Dataframe containing the aggregated result
(min, mean, sum…) from self.all_res [in case of
plot_type = 'temporality'].
Or in the form of a single pd.Dataframe containing the
aggregated values for each day [in case of plot_type is
a metric].

Examples#

from watertrajectories_pytools.src.graphics import trajplot as tjp

mask = r"D:- Postdoc- Travaux- Veille- Donnees- Territoire Annecy\masque_zone_etude.shp"

F = tjp.Figure(
    var = 'T',
    root_folder = r"E:\Inputs\Climat",
    scenario = 'rcp8.5',
    coords = mask,
    rolling_days = 30,
    period_years = 10,
    annuality = 3,
    filename = 'Annecy',
    )

for m in mask_dict:
    for scenario in ['SIM2', 'rcp8.5']:
        figweb, _, _ = tjp.temporality(
            var = 'PRETOT', scenario = scenario, root_folder = r"E:\Inputs\Climat",
            coords = mask_dict[m], filename = m,
            period_years = 10, rolling_days = 30, cumul = False, 
            plot_type = 'temporality', annuality = 3, relative = False, 
            language = 'fr', plotsize = 'wide', verbose = True)
        figweb, _, _ = tjp.temporality(
            var = 'DRAIN', scenario = scenario, root_folder = r"E:\Inputs\Climat",
            coords = mask_dict[m], filename = m,
            period_years = 10, rolling_days = 30, cumul = False, 
            plot_type = 'temporality', annuality = 10, relative = False, 
            language = 'fr', plotsize = 'wide', verbose = True)
        figweb, _, _ = tjp.temporality(
            var = 'SWI', scenario = scenario, root_folder = r"E:\Inputs\Climat",
            coords = mask_dict[m], filename = m,
            period_years = 10, rolling_days = 30, cumul = False, 
            plot_type = 'temporality', annuality = 3, relative = False, 
            language = 'fr', plotsize = 'wide', verbose = True)
        figweb, _, _ = tjp.temporality(
            var = 'T', scenario = scenario, root_folder = r"E:\Inputs\Climat",
            coords = mask_dict[m], filename = m,
            period_years = 10, rolling_days = 30, cumul = False, 
            plot_type = 'temporality', annuality = 10, relative = False, 
            language = 'fr', plotsize = 'wide', verbose = True)

Parameters#

varstr

‘PRETOT’ | ‘PRENEI’ | ‘ETP’ | ‘EVAPC’ | ‘RUNOFFC’ | ‘DRAINC’ | ‘T’ | ‘SWI’ | …

scenariostr

‘SIM2’ | ‘historical’ | ‘RCP 4.5’ | ‘RCP 8.5’

root_folderstr, path
Path to the folder containing climatic data.

r”D:- Postdoc- Travaux- Veille- Donnees8- Meteo” (on my PC) r”E:InputsClimat” (on the external harddrive)

data_crsTYPE, optional

DESCRIPTION. The default is None.

coordsTYPE, optional

DESCRIPTION. The default is ‘all’.

coords_crsTYPE, optional

DESCRIPTION. The default is None.

languageTYPE, optional

DESCRIPTION. The default is ‘fr’.

plotsizeTYPE, optional

DESCRIPTION. The default is ‘wide’.

rolling_daysTYPE, optional

DESCRIPTION. The default is 1.

period_yearsTYPE, optional

DESCRIPTION. The default is 10.

cumulTYPE, optional

DESCRIPTION. The default is False.

plot_typeTYPE

DESCRIPTION.

repres{None, “area” or “bar”}, optional, default None

Only used when plot_type is a metric. Defines the type of graphical representation of the metric plot.

  • "area": curves representing rolling averages

  • "bar": rectangles representing period averages

filenamestr or pathlib.Path

Prefix and extension to add in the file name. Especially usefull to indicate the name of the site.

creditstr, optional, default ‘auto’

To display the acknowledgement for data and conception. If 'auto', the standard info about data source and conception package (geop4th) will be displayed. To remove all mention of credits, pass credit=''.

color‘scale’, ‘discrete’, <colormap> (str) or list of colors, optional, default ‘scale’

Colors for the plots (for now, only for temporality plots)

relativebool

Whether the values should be computed as absolute or relatively to the reference period.

showlegendbool, optional, default True

Whether to display the legend or not.

shadow{None, ‘last’, ‘first’, ‘firstlast’, ‘lastfirst’, ‘all’}, optional, default = None

Whether to display dialy values in grey shadows, and for which period.

annualityint or str
Type of year

‘calendar’ | ‘meteorological’ | ‘meteo’ | ‘hydrological’ | ‘hydro’ 1 | 9 | 10

verbose: bool

Whether or not to display memory diagnotics.

agg_labels = {'decrease': ['decrease', 'diminution'], 'increase': ['increase', 'augmentation'], 'max': ['maximum', 'maximum'], 'mean': ['mean', 'moyenne'], 'min': ['minimum', 'minimum'], 'range': ['range', 'amplitude'], 'sum': ['sum', 'somme']}#
layout(*, plotsize=None, filename=None, credit=None, color=None, language=None, showlegend=None, shadow=None, repres=None, cumul=None)[source]#
load()[source]#

Results#

This method also update the instance attributes all_res and graph_result, which respectively store the whole results and the final results used for the plot.

Warning#

This method can lead to memory size issues. It seems to appear when the garbage collector is not doing its job fast enough in the xarray variable data from C:ProgramDataMiniconda3envscwatenvLibsite-packagesxarraycodingvariables.py.

To solve this, you might just need to open this folder on Windows.

Examples (pipeline)#

>>> import os
>>> mask_folder = r"D:\2- Postdoc\2- Travaux\1- Veille\4- Donnees\15- Territoire Pays Basque"
>>> mask_dict = dict()
>>> mask_dict['cotier'] = os.path.join(mask_folder, r"Sage-cotier-basque.shp")
>>> mask_dict['CAPB'] = os.path.join(mask_folder, r"zone_etude_fusion.shp")
>>> mask_dict['Nive-Nivelle'] = os.path.join(mask_folder, r"Nive-Nivelle.shp")
>>> for var in ['PRETOT', 'DRAIN', 'SWI', 'T']:
>>>     for scenario in ['SIM2', 'rcp8.5']:
>>>         for m in mask_dict:
>>>             F = tjp.Figure(
>>>                 var = var,
>>>                 root_folder = r"E:\Inputs\Climat",
>>>                 scenario = scenario,
>>>                 coords = mask_dict[m],
>>>                 filename = m,
>>>                 rolling_days = 30,
>>>                 period_years = 10,
>>>                 )
>>>             F.plot(plot_type = 'annual_sum')
>>>             F.plot(plot_type = 'annual_sum', period_years = 30)
>>>             F.plot(plot_type = 'annual_sum', period_years = 1)
>>>             F.plot(plot_type = 'annual_scatter', agg_rule = 'sum')
>>>             F.plot(plot_type = '15/11', period_years = 10)
>>>             F.plot(plot_type = '15/05', period_years = 10)
>>>             if var == 'DRAIN':
>>>                 F.plot(plot_type = '> 1.5')
metric_labels = {'annual': ['annual {}', '{} annuelle'], 'date': ['date of {}', 'date de {}']}#
metric_list = ['annual', 'date']#
month_abbrev = {1: 'JAN', 2: 'FEB', 3: 'MAR', 4: 'APR', 5: 'MAY', 6: 'JUN', 7: 'JUL', 8: 'AUG', 9: 'SEP', 10: 'OCT', 11: 'NOV', 12: 'DEC'}#
plot(*, rolling_days=None, period_years=None, annuality=None, plot_type=None, plotsize=None, filename=None, credit=None, color=None, language=None, showlegend=None, shadow=None, repres=None, cumul=None)[source]#
plot_typestr

‘temporality’ | ‘annual_sum’

None.

>>> F = tjp.Figure(
>>>     var = 'DRAINC',
>>>     root_folder = r"E:\Inputs\Climat",
>>>     scenario = 'rcp8.5',
>>>     coords = r"C:
ile.shp”,
>>>     rolling_days = 30,
>>>     annuality = 10,
>>>     filename = 'myCatchment',
>>>     )
>>> F.plot(plot_type = '> 1.5', period_years = 10)
>>> F.plot(plot_type = 'annual_sum')
>>> F.plot(plot_type = 'annual_sum', period_years = 30)
>>> F.plot(plot_type = 'annual_scatter', period_years = 1)
>>> F.plot(plot_type = '15/11', period_years = 10)
static timeseries(*, data_type, var, scenario, season, domain='Pays-Basque', data_crs=None, coords='all', coords_crs=None, language='fr', plotsize='wide', rolling_window=1, plot_type='2series')[source]#

Examples#

import climatic_plot as tjp

tjp.timeseries(data_type = “Indicateurs DRIAS-Eau 2024 SWIAV”,

scenario = ‘historical’, season = ‘JJA’, domain = ‘Pays Basque’, rolling_window = 10, plot_type = ‘2series’)

# —- Original and rolled series for SWIAV for season in [‘JJA’, ‘SON’, ‘DJF’, ‘MAM’]:

for scenario in [‘historical’, ‘rcp45’, ‘rcp85’]:
for domain in [‘Pays Basque’, ‘Annecy’]:
tjp.timeseries(data_type = “Indicateurs DRIAS-Eau 2024”,

var = ‘SWIAV’, scenario = scenario, season = season, domain = domain, rolling_window = 10, plot_type = ‘2series’)

# —- Same for SSWI for season in [‘JJA’, ‘SON’, ‘DJF’, ‘MAM’]:

for scenario in [‘rcp45’, ‘rcp85’]:
for domain in [‘Pays Basque’, ‘Annecy’]:
tjp.timeseries(data_type = “Indicateurs DRIAS-Eau 2024”,

var = ‘SSWI’, scenario = scenario, season = season, domain = domain, rolling_window = 10, plot_type = ‘2series’)

# —- All different colors with SIM2 tjp.timeseries(data_type = “Indicateurs DRIAS-Eau 2024”,

var = ‘SWIAV’, scenario = ‘historical’, season = ‘JJA’, domain = ‘Pays Basque’, rolling_window = 10, plot_type = ‘all with sim2’)

# —- Narratifs for season in [‘JJA’, ‘SON’, ‘DJF’, ‘MAM’]:

for domain in [‘Pays Basque’, ‘Annecy’]:
tjp.timeseries(data_type = “Indicateurs DRIAS-Eau 2024”,

var = ‘SWIAV’, scenario = ‘rcp85’, season = season, domain = domain, rolling_window = 10, plot_type = ‘narratifs’)

Parameters#

  • : TYPE

    DESCRIPTION.

root_folderTYPE

DESCRIPTION.

scenariostr

‘historical’ | ‘rcp45’ | ‘rcp85’

seasonstr

‘DJF’ | ‘MAM’ | ‘JJA’ | ‘SON’ | ‘NDJFMA’ | ‘MAMJJASO’ | ‘JJASO’ | ‘SONDJFM’

data_typeTYPE

DESCRIPTION.

data_crsTYPE, optional

DESCRIPTION. The default is None.

coordsTYPE, optional

DESCRIPTION. The default is ‘all’.

coords_crsTYPE, optional

DESCRIPTION. The default is None.

languageTYPE, optional

DESCRIPTION. The default is ‘fr’.

plotsizeTYPE, optional

DESCRIPTION. The default is ‘wide’.

rolling_windowTYPE, optional

DESCRIPTION. The default is 10.

plot_typeTYPE, optional

DESCRIPTION. The default is ‘2series’.

: TYPE

DESCRIPTION.

Returns#

None.

update(*, var=None, root_folder=None, scenario=None, data_crs=None, coords=None, coords_crs=None, relative=None, rolling_days=None, period_years=None, annuality=None, plot_type=None, repres=None, cumul=None, language=None, plotsize=None, color=None, filename=None, credit=None, showlegend=None, shadow=None, verbose=None)[source]#
classmethod update_verbose(verbose: bool)[source]#
verbose: bool = False#