:mod:`eggshell.nc.nc_utils` =========================== .. py:module:: eggshell.nc.nc_utils Module Contents --------------- .. data:: LOGGER .. py:class:: CookieNetCDFTransfer(request, opendap_hostnames=[]) .. method:: __enter__(self) .. method:: __exit__(self, exc_type, exc_val, exc_tb) .. function:: aggregations(resource) 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 .. function:: get_auth_cookie(pywps_request) .. function:: opendap_or_download(resource, auth_tkt_cookie={}, output_path=None, max_nbytes=10000000000) 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 .. function:: get_coordinates(resource, variable=None, unrotate=False) 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 .. function:: get_index_lat(resource, variable=None) 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 .. function:: get_variable(resources) Guess main variables in a NetCDF file. (compare nc.ocg_utils.get_variable) :param resources: netCDF4.Dataset :return list: names of main variables Notes ----- 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. .. function:: sort_by_filename(resource, historical_concatination=False) Sort a list of files with CORDEX-conformant file names. :param resource: netCDF file :param historical_concatination: if True (default=False), appropriate historial runs will be sorted to the rcp datasets :return dictionary: {'drs_filename': [list of netCDF files]} .. function:: get_frequency(resource) returns the frequency as set in the metadata (see also metadata.get_frequency) :param resource: NetCDF file :return str: frequency .. function:: get_timerange(resource) returns from/to timestamp of given netcdf file(s). :param resource: list of path(s) to netCDF file(s) :returns netcdf.datetime.datetime: start, end .. function:: get_time(resource) returns all timestamps of given netcdf file as datetime list. :param resource: NetCDF file(s) :return : list of timesteps .. function:: get_values(resource, variable=None) returns the values for a list of files of files belonging to one dataset :param resource: list of files :param variable: variable to be picked from the files (if not set, variable will be detected) :returs numpy.array: values .. function:: drs_filename(resource, skip_timestamp=False, skip_format=False, variable=None, rename_file=False, add_file_path=False) 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) :param 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' :param rename_file: rename the file. (default: False) :returns str: DRS filename .. function:: sort_by_time(resource) Sort a list of files by their time variable. :param resource: File path. :return: Sorted file list.