diva.graphs package

Submodules

diva.graphs.graph_generator module

class diva.graphs.graph_generator.GraphTexts(graph_type: str, title: str, x_axis_title: str, under_x_axis_title1, under_x_axis_title2, y_axis_title: str, tips, langage)[source]

Bases: object

A class to manage the textual content of a graph, including titles and axis labels, with the ability to translate the text into English.

Attributes

titlestr

The title of the graph.

x_axis_titlestr

The title of the x-axis.

under_x_axis_title1str

The first subtitle or description below the x-axis.

under_x_axis_title2str

The second subtitle or description below the x-axis.

y_axis_titlestr

The title of the y-axis.

tipsstr

Additional tips or instructions related to the graph.

langagestr

The language in which the graph texts are written.

textual_content()[source]

Retrieve all textual content of the graph as a list.

Returns

list

A list containing the title, axis titles, subtitles, and tips for the graph.

translate()[source]

Translate the textual content of the graph from English if the language is not English.

Returns

GraphTexts

A new GraphTexts object with the translated content, or the original object if the language is English.

class diva.graphs.graph_generator.IGraphGenerator(params, langage, user_type)[source]

Bases: object

property NB_PARAM_ELM
property aggreg_type
property climate_variable
property comparison_loc
property comparison_time
property context
property cross_tenses
property data
property delta_time
property delta_time_multi
property endtime
abstract generate()[source]
get_collection()[source]
property graph_context
property graph_type
property heatmap_not_supported
initialise_data_collection()[source]
property langage
property list_not_found_loc
property location
property out_of_bounds
property params
property params_after_processing
process_params()[source]

Processes input parameters for graph generation: - Determines the variable name, path to data, and unit based on the climate variable. - Sets start and end times as Python datetime objects and handles out-of-bounds dates. - Processes location information and checks for validity. - Determines the aggregation type.

Returns

None

property shapefile_europe
property shapefile_europe_cities
property starttime
property time_out_of_bounds

diva.graphs.service_graph_generation module

class diva.graphs.service_graph_generation.ServiceGeneratePlotlyGraph(params, langage, user_type)[source]

Bases: IGraphGenerator

add_tense_data(df)[source]
checks()[source]

Perform validation checks on the graph generation parameters, including location and time bounds.

Returns

bool

True if there are any errors in the parameters; otherwise, False.

property colors
property colors_gray
compute_diff_ref(x, y, ref, mode)[source]

Compute the difference between observed values and a reference period, returning the anomalies based on the specified mode.

This function calculates the anomaly of values relative to a given reference period. It supports both ‘simple’ and ‘multi’ modes of calculation: - In ‘simple’ mode, it computes anomalies for a single reference dataset. - In ‘multi’ mode, it computes anomalies across multiple reference datasets.

Parameters

xlist

List of dates corresponding to the observed values.

ylist

List of observed values for each date.

reflist

Reference values used to compute the anomalies.

modestr

Calculation mode (‘simple’ for single reference, ‘multi’ for multiple references).

Returns

list

A list of computed anomalies, with each anomaly representing the difference between observed values and reference values: - If aggregation is yearly (‘YS’), returns yearly anomalies. - If aggregation is monthly (‘MS’), returns monthly anomalies.

generate(show=False)[source]

Generates a graph based on the provided parameters and graph type.

The method handles various conditions: - Bounds and errors related to time and location. - Generates the appropriate type of graph (e.g., line chart, bar chart, histogram) based on the parameters. - Handles comparisons based on time and location if specified.

Parameters

showbool, optional

Whether to display the generated graph in test mode. Default is False.

Returns

None

generate_barplot(comparison_type='single')[source]

Display the bar chart with average data. comparison_type:

  • “single”: 1 location, 1 period

  • “location”: Comparison of locations

  • “time”: Comparison of times

  • “location_time”: Comparison of both location and time

generate_boxplot(comparison_type='single')[source]
generate_distribution(comparison_type='single')[source]
generate_lineplot(comparison_type='single')[source]

Generate a line chart for raw data with options to compare locations, times, or both.

Args:

compare_loc (bool): Whether to compare multiple locations. compare_time (bool): Whether to compare multiple time periods.

generate_lineplot_mean(comparison_type='single')[source]

Display the line chart with average data and min/max corridor. comparison_type:

  • “single”: 1 location, 1 period

  • “location”: Comparison of locations

  • “time”: Comparison of times

  • “location_time”: Comparison of both location and time

generate_map(comparison_type=None)[source]

Generate a map visualization using the data collected in the DataCollection.

Creates a chart using Altair, encoding latitude and longitude, and coloring points based on the variable of interest. The resulting figure is stored in the fig attribute.

generate_rainbow(comparison_type='single')[source]
generate_warming_stripes(comparison_type='single')[source]
get_data_source()[source]
get_interp_colors_anomaly(years)[source]
get_mean_val_on_ref_period()[source]

Calculate the average values of the dataset over a specified reference period (1971-2000).

This function generates a DataCollection for the specified reference period, extracts the required data, and computes average values based on the aggregation type (yearly, monthly, or daily). The function returns a list of means corresponding to each aggregation level.

Returns

list

A list of mean values for each aggregation type within the reference period: - If the aggregation type is yearly, the list contains mean values per year. - If monthly, the list contains mean values per month across years. - If daily, the list contains mean values for each day across years.

get_xy_pos_note_under_graph()[source]

Determine the position of notes below the graph based on graph type and aggregation type.

Returns

tuple

A tuple containing the x and y positions for the note.

graph_elm_for_translate(cat, lang)[source]

Translate graph elements based on category and language.

Parameters

catstr

The category of the graph element to translate.

langstr

The target language for the translation.

Returns

str

The translated graph element based on the provided category and language.

matching_case()[source]

Determines and generates the appropriate plot based on the comparison settings and graph type.

This function checks whether time or location comparisons are enabled, and then selects the appropriate plot generation method based on the current graph_type. It handles different plot types including line charts (with various subtypes depending on the time delta and aggregation type), bar charts, and histograms.

Returns

None

Module contents