pypago.pyio¶
Functions/classes dedicated to inputs/outputs using PyPAGO
Functions
check_ncvar_exist (filename, varname) |
Determines whether a variable exists in a NetCDF file |
correct_file_arch (filename) |
This function corrects the architecture of .pygo files that contains any pago_obj instances. |
count_dim (filename, varname) |
Counts the number of elements of a netcdf file along a given dimension. |
count_ndim (filename, varname) |
Counts the number of dimensions of a variable |
load (filename) |
Loads a file and reads its content. |
modify_meshfile (filename) |
Masks the vertical scale factors e3t, e3v and e3u on solid points. |
read_bg_file (finname) |
Reads a background netcdf file (bathy for instance). |
read_time (filename, time_varname) |
Reads the time variable of a NetCDF time. |
readnc (filename, varname[, start, end, stride]) |
Reads a variable from a NetCDF file. |
readnc_dtype (filename, variable) |
Reads the precision of a variable within a file. |
readnc_wrap (filename, var, start, end, nlon) |
Reads a variable from a NetCDF file, with the possibility to do some kind of shiftgrid. |
save (dictio, filename) |
Function that saves a variable object into a file. |
-
_readnc_span
(ncfile, varname, start, end, stride)[source]¶ Function which is called if we are to read the variable var from the f file, with start, end and stride which are not None
Parameters: - ncfile (netCDF4.Dataset) – netcdf file
- varname (str) – name of the variable to read
- start (numpy.array) – array that contains the start indexes
- end (numpy.array) – array that contains the end indexes
- stride (numpy.array) – array that contains the stride indexes
-
check_ncvar_exist
(filename, varname)[source]¶ Determines whether a variable exists in a NetCDF file
Parameters: Returns: True if the variable is in the file, else False
Return type:
-
correct_file_arch
(filename)[source]¶ This function corrects the architecture of .pygo files that contains any pago_obj instances. It reads the pickle file as a text file and virtually replace the module associated with the pago_obj by the pypago.io one. A new file is created, which has the same absolute path as the input, but with _new suffix added
Parameters: filename (str) – The name of the .pygo file to modify
-
count_dim
(filename, varname)[source]¶ Counts the number of elements of a netcdf file along a given dimension.
Parameters: Return type: Returns: Number of dimensions
-
count_ndim
(filename, varname)[source]¶ Counts the number of dimensions of a variable
Parameters: Return type: Returns: Number of dimensions
-
load
(filename)[source]¶ Loads a file and reads its content. The file must have been saved with the
pypago.io.save()
function. It uses thepickle.load()
function.Parameters: filename (str) – the name of the file ( .pygo
)Returns: The content of the file Return type: list
,dict
orpypago.pypago_misc.pago_obj
-
modify_meshfile
(filename)[source]¶ Masks the vertical scale factors e3t, e3v and e3u on solid points. This is useful when using partial steps, since it allows to properly mask the solid points along the sections staircases, instead of masking where the current velocity is zero.
Parameters: filename (str) – Name of the mesh file which contains the scale factors to modify
-
read_bg_file
(finname)[source]¶ Reads a background netcdf file (bathy for instance).
It takes as an input the name of a NetCDF file, which must contain three variables:
- A variable that has the same name as the first dimension (lat for instance, 1D or 2D)
- A variable that has the same name as the second dimension (lon for instance, 1D or 2D)
- And a third variable, whose name differs from the dimension names (bathy for instance, must be 2D)
It is used in the
pypago.guis.gui_sections_edition
module.Changed in version 20150813.
Parameters: finname (str) – name of the background file
-
read_time
(filename, time_varname)[source]¶ Reads the time variable of a NetCDF time. If the time variable contains a ‘units’ attribute, then a list of py:class:datetime.datetime is returned. Else, a list of floats is returned.
Parameters:
-
readnc
(filename, varname, start=None, end=None, stride=None)[source]¶ Reads a variable from a NetCDF file. Additional arguments allow to read only a part of the variable. If start and end are None, all the file is read. If they are defined, the stride variable is also read. If it is None, it is set to 1 along each dimension.
Parameters: Returns: the array that contains the variable
Return type: numpy.array
-
readnc_dtype
(filename, variable)[source]¶ Reads the precision of a variable within a file. Allows to determine whether the file is in 16 bits (hence with possible issues in the calculations).
Parameters:
-
readnc_wrap
(filename, var, start, end, nlon)[source]¶ Reads a variable from a NetCDF file, with the possibility to do some kind of shiftgrid. It uses the
pypago.io.readnc()
function.Parameters: - filename (str) – name of the NetCDF file
- var (str) – name of the variable to read
- start (list) – list that contains the first index to read for each dimension.
- end (list) – list that contains the last index to read for each dimension.
- nlon (list) – number of longitudes contained in the file (last
dimension in the
.nc
file)
Returns: the array that contains the variable
Return type: numpy.array
-
save
(dictio, filename)[source]¶ Function that saves a variable object into a file. It uses the
pickle.dump()
functionParameters: Returns: none