gcpy.examples.working_with_files.concatenate_files
This Python script concatenates several individual netCDF files into a single netCDF file using xarray.
Examples
Copy this file to a different folder and navigate to that folder.
In your copy, edit the file names for your use case.
Run the following commands:
$ conda activate gcpy_env
(gcpy_env) $ ./concatentate_files.py
Notes
If you have several individual files with one variable per file, you should consider concatenating them into a single file. This is often more efficient, as opening each netCDF file incurs computational overhead. It is usually faster to read data from a file with multiple variables than to having to open several files with one variable each.
Functions
|
Returns a list of all files in a directory that match one or more substrings. |
|
Main program. |
|
Replaces NaN values with zeroes for each variable within an an xarray Dataset. |
- gcpy.examples.working_with_files.concatenate_files.find_files_in_dir(path, substrs)[source]
Returns a list of all files in a directory that match one or more substrings.
- gcpy.examples.working_with_files.concatenate_files.replace_nans_with_zeroes(dset, verbose=True)[source]
Replaces NaN values with zeroes for each variable within an an xarray Dataset.
- Parameters:
dset (
xarray Dataset) – The input dataset, containing one or more data variables.verbose (
bool, optional) – Set this switch to print out the variable name, as well as the min and max of the variable. This will illustrate the replacement of NaNs with zeroes.