zapata.lib module¶
- zapata.lib.get_values_from_dict(input_dict, keys)[source]¶
Get values from dictionary input_dict for keys in keys
- Parameters:
input_dict -- Dictionary
keys -- List of keys
- Return type:
List of values
- zapata.lib.year2date(years, i)[source]¶
Transform index i in string date yy/mm.
Rounding requires the small shift Years are obtained from np.arange(1979,2018, 1/12)
- zapata.lib.date2year(years, date)[source]¶
Transform index date ['Jan' '1989' ] in index i.
Years are from np.arange(1979,2018, 1/12)
- zapata.lib.putna(left, right, xar, scalar=None)[source]¶
Put NaN in xarray according if they are laying in the interval left,right
- Parameters:
left,right -- Extremes of the interval where the values must be NaN
xar -- Xarray
scalar -- If set all entries not satisfying the condition are put equal to scalar
- Return type:
Modified array
- zapata.lib.go_to(dir)[source]¶
Set Working directory
- Parameters:
dir -- Target directory relative to users' root directory
- Yields:
Change working directory
- zapata.lib.long_string(lon, cent_lon=0)[source]¶
Get nice formatted longitude string
- Parameters:
lon -- Longitude
cent_lon -- Central longitude for projection used
- Yields:
string in nice format
- zapata.lib.lat_string(lat)[source]¶
Get nice formatted latitude string
- Parameters:
lat -- Latitude
- Yields:
string in nice format
- zapata.lib.get_environment_info(option)[source]¶
Get information about the Python environment
- Parameters:
option -- String Options are: 'interpreter': Get the path of the Python interpreter 'version': Get the Python version 'packages': Get the list of installed packages
- Return type:
Information about the Python environment
- zapata.lib.get_ocean_GLORS(year: int | str, var: str, outfile: str, *, pool: ~concurrent.futures.thread.ThreadPoolExecutor = <concurrent.futures.thread.ThreadPoolExecutor object>)[source]¶
Asynchronously download GLORS reanalysis for year into outfile.
- Parameters:
year (int or str) -- Year to fetch (e.g. 1993). Converted to str internally.
var (str) -- Variable to fetch, e.g. 'sea_water_potential_temperature'.
outfile (str) -- Path to write the NetCDF file.
pool (ThreadPoolExecutor, optional) -- Executor that runs the blocking retrieval. Defaults to a module-level pool so every call shares the same threads.
- Returns:
Future whose .result() blocks until the file is fully written.
- Return type:
concurrent.futures.Future
- zapata.lib.write_netcdf(ds, file)[source]¶
Write a NetCDF file with the given filename.
- Parameters:
file -- Name of the NetCDF file to be written.
- Return type:
None
- zapata.lib.seasonal_average(files: Sequence[str], seasons: Mapping[str, Iterable[int]], *, time_dim: str = 'time', weighted: bool = True, avg_per_file: bool = False, user_preprocess: Callable[[Dataset], Dataset] | None = None, **open_kwargs) Dict[str, Dataset] [source]¶
- zapata.lib.select_files_by_years(YEARS, file_template='GLORS_YEARS_T_44_{year}.nc', directory='.')[source]¶
Selects files based on the years provided, checks their existence in the specified directory, and returns a list of selected file paths along with a sorted list of years for which files were found.
- Parameters:
YEARS (list) (List of years to check.)
file_template (str) (Template for the file name, e.g., "GLORS_YEARS_T_44_{year}.nc".)
directory (str) (Directory path where the files are stored.)
- Returns:
tuple --
selected_files (list): List of file paths found.
sorted_found_years (list): Sorted list of years for which the files were found.
- Return type:
A tuple containing:
- zapata.lib.read_txt_file(file_path: str) ndarray [source]¶
Read a text file and return its content as a numpy array. :Parameters: file_path -- Path to the text file to be read.
- Returns:
Numpy array containing the data from the text file.
- Return type:
numpy.ndarray