xtrdet.utils package

Submodules

xtrdet.utils.data_extract module

xtrdet.utils.data_extract.adjust_coordinates(lon, lat, ngrids_relax_zone=0, ngrids_exten_zone=0)

Adjust coordinates to get valid values for analysis, e.g., discard values over extention/relaxation zones

Parameters:
  • lon (2-dimension array, float) – Longitudes

  • lat (2-dimension array, float) – Latitudes

  • ngrids_relax_zone (integer) – Number of grids used for relaxation zone

  • ngrids_exten_zone (integer) – Number of grids used for extention zone

Returns:

Adjusted longitudes and latitudes to get valid values for analyis

Return type:

2-dimension array, float

xtrdet.utils.data_extract.get_data_over_target_domain(var_ld, lon_ld, lat_ld, coordinates_of_detection_area)

Extract data from a larger domain over a smaller target domain

Parameters:
  • var_ld (3-dimension array (time, lat, lon), float) – Variable for large domain

  • lat_ld (2-dimension array (lat, lon), float) – Latitudes for large domain

  • lon_sd (2-dimension array (lat, lon), float) – Longitudes for small domain

  • coordinates_of_detection_area (dictionary, string) –

Returns:

var, lat and lon over target domain

Return type:

array

xtrdet.utils.data_extract.get_data_over_target_period(varin)

Extract data from a longer period over a shorter target period (to complete)

Parameters:
  • lon_ld (2-dimension array, float) – Longitudes for large domain

  • lat_ld (2-dimension array, float) – Latitudes for large domain

  • lon_sd (2-dimension array, float) – Longitudes for small domain

  • lat_sd (2-dimension array, float) – Latitudes for small domain

Returns:

The index for large domain corresponding to the small domain

Return type:

integer

xtrdet.utils.file_writer module

class xtrdet.utils.file_writer.FileWriter(file_out)

Bases: object

Reads a file

write_nc(nc_file_2D, nc_var_to_read, nc_vars_to_write, var_2D)
write_txt(var_dict)

xtrdet.utils.ini_reader module

Config reader module

Creates and return a dictionary built from a config file.

Created: Autumn 2016 Authors: David Lindstedt & Petter Lind

xtrdet.utils.ini_reader.get_config_dict(ini_file)

Create a dictionary from then input config file. PARAMETERS: config (.ini) file RETURNS : Dictionary

xtrdet.utils.ncdump module

xtrdet.utils.ncdump.ncdump(nc_fid, verb=True)

ncdump outputs dimensions, variables and their attribute information. The information is similar to that of NCAR’s ncdump utility. ncdump requires a valid instance of Dataset.

Parameters

nc_fid: netCDF4.Dataset

A netCDF4 dateset object

verb: Boolean

whether or not nc_attrs, nc_dims, and nc_vars are printed

Returns

nc_attrs: list

A Python list of the NetCDF file global attributes

nc_dims: list

A Python list of the NetCDF file dimensions

nc_vars: list

A Python list of the NetCDF file variables

xtrdet.utils.open_data module

xtrdet.utils.iresampling module

class xtrdet.utils.resampling.Resampling(resample_frequency, resample_method)

Bases: object

Resample data with chosen time frequency and resample method.

change_resample_frequency(frequency)
change_resample_method(method)
get_time_frequency(frequency)
resample(data)

xtrdet.utils.spatial_masking module

xtrdet.utils.statistics module

class xtrdet.utils.statistics.Statistics(var_ref)

Bases: object

extreme_statistics(threshold_for_extreme)

Calculate weather statistics.

Parameters:

threshold_for_extreme (2-D array) – The threshold for extreme (N-th percentile (e.g. N = 95)) over each grid

Returns:

statistics for extremes detected: extremes_filtered (3-d array), number_of_extreme_grids (1-d array), accumulated_extreme_values (1-d array)

Return type:

dictionary

extreme_threshold(threshold_method, pctl_threshold)

Calculate the threshold values over each pixel for extreme.

Parameters:
  • threshold_method – Options for different methods to calculate threshold values

  • pctl_threshold (integer) – Pre-defined N-th percentile (e.g. N = 95) for the entire chosen (sub)domain and time period

Returns:

thresholds for triggering extremes

Return type:

array

extreme_triggering(filter_method, statistics_for_extremes, perc_of_time_periods)

Extreme triggering by different statistics.

Parameters:
  • filter_method (string) – percentile or number

  • statistics_for_extremes (array) – statistics of weather

  • perc_of_time_periods (integer) – Percentage (e.g. 10%) of the days with the largest cr_sum as the potential events of interest (extreme events) to downscale them

Returns:

time_period_of_extreme_triggered, time period with extremes

Return type:

1-D array (time)

extreme_warning(statistics_for_extremes)

Issue extreme warning with different warning levels.

Parameters:

statistics_for_extremes (dictionary) – statistics of weather

Returns:

extreme_warning_levels

Return type:

1-D array (string)

Module contents