eggshell.nc.nc_utils

Module Contents

eggshell.nc.nc_utils.LOGGER[source]
class eggshell.nc.nc_utils.CookieNetCDFTransfer(request, opendap_hostnames=[])[source]
__enter__(self)[source]
__exit__(self, exc_type, exc_val, exc_tb)[source]
eggshell.nc.nc_utils.aggregations(resource)[source]

aggregates netcdf files by experiment. Aggregation examples: CORDEX: EUR-11_ICHEC-EC-EARTH_historical_r3i1p1_DMI-HIRHAM5_v1_day CMIP5: We collect for each experiment all files on the time axis: 200101-200512, 200601-201012, … Time axis is sorted by time. :param resource: list of netcdf files :return: dictionary with key=experiment

eggshell.nc.nc_utils.opendap_or_download(resource, auth_tkt_cookie={}, output_path=None, max_nbytes=10000000000)[source]

Check for OPEnDAP support, if not download the resource. :param resource: url of a NetCDF resource :param output_path: where to save the non-OPEnDAP resource :param max_nbytes: maximum file size for download, default: 1 gb :return str: the original url if OPEnDAP is supported or path of saved file

eggshell.nc.nc_utils.get_coordinates(resource, variable=None, unrotate=False)[source]

reads out the coordinates of a variable :param resource: netCDF resource file :param variable: variable name :param unrotate: If True the coordinates will be returned for unrotated pole :returns list, list: latitudes , longitudes

eggshell.nc.nc_utils.get_index_lat(resource, variable=None)[source]

returns the dimension index of the latiude values :param resource: list of path(s) to netCDF file(s) of one Dataset :param variable: variable name :return int: index

eggshell.nc.nc_utils.get_variable(resources)[source]

Guess main variables in a NetCDF file. (compare nc.ocg_utils.get_variable)

Parameters:resources – netCDF4.Dataset
Return list:names of main variables

The main variables are the one with highest dimensionality and size. The time, lon, lat variables and variables that are defined as bounds are automatically ignored.

eggshell.nc.nc_utils.sort_by_filename(resource, historical_concatination=False)[source]

Sort a list of files with CORDEX-conformant file names.

Parameters:
  • resource – netCDF file
  • historical_concatination – if True (default=False), appropriate historial runs will be sorted to the rcp datasets
Return dictionary:
 

{‘drs_filename’: [list of netCDF files]}

eggshell.nc.nc_utils.get_frequency(resource)[source]

returns the frequency as set in the metadata (see also metadata.get_frequency)

Parameters:resource – NetCDF file
Return str:frequency
eggshell.nc.nc_utils.get_timerange(resource)[source]

returns from/to timestamp of given netcdf file(s).

Parameters:resource – list of path(s) to netCDF file(s)
Returns netcdf.datetime.datetime:
 start, end
eggshell.nc.nc_utils.get_time(resource)[source]

returns all timestamps of given netcdf file as datetime list.

Parameters:resource – NetCDF file(s)

:return : list of timesteps

eggshell.nc.nc_utils.get_values(resource, variable=None)[source]

returns the values for a list of files of files belonging to one dataset

Parameters:
  • resource – list of files
  • variable – variable to be picked from the files (if not set, variable will be detected)
Returs numpy.array:
 

values

eggshell.nc.nc_utils.drs_filename(resource, skip_timestamp=False, skip_format=False, variable=None, rename_file=False, add_file_path=False)[source]

generates filename according to the data reference syntax (DRS) based on the metadata in the resource. http://cmip-pcmdi.llnl.gov/cmip5/docs/cmip5_data_reference_syntax.pdf https://pypi.python.org/pypi/drslib :param add_file_path: if add_file_path=True, path to file will be added (default=False) :param resource: netcdf file :param skip_timestamp: if True then from/to timestamp != added to the filename

(default: False)
Parameters:
  • variable – appropriate variable for filename, if not set (default), variable will be determined. For files with more than one data variable, the variable parameter has to be defined (default: ) example: variable=’tas’
  • rename_file – rename the file. (default: False)
Returns str:

DRS filename

eggshell.nc.nc_utils.sort_by_time(resource)[source]

Sort a list of files by their time variable.

Parameters:resource – File path.
Returns:Sorted file list.