zapata.lib module

zapata.lib.name_notebook(newname)[source]

Change name to Jupyterlab instance

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.remove_values_from_list(the_list, val)[source]

Remove value val from list the_list

zapata.lib.makename(var, lev, yy, mm, dd)[source]

Utility to create names for ERA5 files.

zapata.lib.makemm(var, lev, yy, mm)[source]

Utility to create names for ERA5 numpy files

zapata.lib.makefilename(dir, var, lev, yy, mm, ext)[source]

Generalize file name creation

zapata.lib.adddir(name, dir)[source]

Add dir directory name to name file

zapata.lib.makedir(fndir)[source]

Create Directory fndir

zapata.lib.movefile(oldfile, newdir)[source]

Move file from oldfile to newdir

zapata.lib.copyfile(oldfile, newdir)[source]

Copy file from oldfile to newdir

zapata.lib.chop(a, epsilon=1e-10)[source]

Eliminate real small complex number converting to real

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.build_preprocess(months, time_dim, weighted, avg_per_file, user_pp)[source]
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

zapata.lib.write_txt_file(data: ndarray, file_path: str) None[source]

Write a numpy array to a text file.

Parameters:
  • data -- Numpy array to be written to the file.

  • file_path -- Path where the text file will be saved.

Return type:

None

zapata.lib.optimize_for_macos()[source]

Apply macOS-specific optimizations.