file_operation module¶
-
IMTreatment.file_operation.file_operation.
IM7_to_imt
(im7_path, imt_path, kind='SF', compressed=True, **kwargs)[source]¶ Transfome an IM7 (davis) file into a, imt exploitable file.
Parameters: - im7_path (path to file or directory) – Path to the IM7 file(s) , can be path to a single file or path to a directory contening multiples files.
- imt_path (path to file or directory) – Path where to save imt files, has to be the same type of path than ‘im7_path’ (path to file or path to directory)
- kind (string) – Kind of object to store (can be ‘TSF’ for TemporalScalarFields, ‘SSF’ for SpatialScalarFields or ‘SF’ for multiple ScalarField)
- compressed (boolean, optional) – If ‘True’ (default), the file is compressed using gzip.
- kwargs (dict, optional) – Additional arguments for ‘import_from_***()’.
-
IMTreatment.file_operation.file_operation.
VC7_to_imt
(vc7_path, imt_path, kind='VF', compressed=True, **kwargs)[source]¶ Transfome an VC7 (davis) file into a, imt exploitable file.
Parameters: - vc7_path (path to file or directory) – Path to the VC7 file(s) , can be path to a single file or path to a directory contening multiples files.
- imt_path (path to file) – Path where to save imt file.
- kind (string) – Kind of object to store (can be ‘TVF’ for TemporalVectorFields, ‘SVF’ for SpatialVectorFields or ‘VF’ for multiple VectorField)
- compressed (boolean, optional) – If ‘True’ (default), the file is compressed using gzip.
- kwargs (dict, optional) – Additional arguments for ‘import_from_***()’.
-
IMTreatment.file_operation.file_operation.
check_path
(filepath, newfile=False)[source]¶ Normalize and check the validity of the given path to feed importation functions.
-
IMTreatment.file_operation.file_operation.
export_to_file
(obj, filepath, compressed=True, **kw)[source]¶ Write the object in the specified file. Additionnals arguments for the JSON encoder may be set with the **kw argument. If existing, specified file will be truncated. If not, it will be created.
Parameters: - obj – Object to store (common and IMT objects are supported).
- filepath (string) – Path specifiing where to save the object.
- compressed (boolean, optional) – If ‘True’ (default), the file is compressed using gzip.
-
IMTreatment.file_operation.file_operation.
export_to_picture
(SF, filepath)[source]¶ Export a scalar field to a picture file.
Parameters: - SF –
.
- filepath (string) – Path to the picture file.
- SF –
-
IMTreatment.file_operation.file_operation.
export_to_pictures
(SFs, filepath)[source]¶ Export scalar fields to a picture file.
Parameters: - SF –
.
- filename (string) – Path to the picture file. Should include a name for the image (without the extension).
- SF –
-
IMTreatment.file_operation.file_operation.
export_to_video
(SFs, filepath, fps=24, colormap=None)[source]¶ Export scalar fields to a video file.
Parameters: - SF –
.
- filename (string) – Path to the video file.
- SF –
-
IMTreatment.file_operation.file_operation.
export_to_vtk
(obj, filepath, axis=None, **kw)[source]¶ Export the field to a .vtk file, for Mayavi use.
Parameters: - filepath (string) – Path where to write the vtk file.
- axis (tuple of strings) – By default, field axe are set to (x,y), if you want different axis, you have to specified them here. For example, “(‘z’, ‘y’)”, put the x field axis values in vtk z axis, and y field axis in y vtk axis.
- line (boolean (only for Points object)) – If ‘True’, lines between points are writen instead of points.
-
IMTreatment.file_operation.file_operation.
find_file_in_path
(regs, dirpath, ask=False)[source]¶ Search recursively for a folder containing files matching a regular expression, in the given root folder.
Parameters: - exts (list of string) – List of regular expressions
- dirpath (string) – Root path to search from
- ask (bool) – If ‘True’, ask for the wanted folder and return only this one.
Returns: folders – List of folder containings wanted files.
Return type: list of string
-
IMTreatment.file_operation.file_operation.
import_from_IM7
(filename, infos=False)[source]¶ Import a scalar field from a .IM7 file.
Parameters: - filename (string) – Path to the IM7 file.
- infos (boolean, optional) – If ‘True’, also return a dictionary with informations on the im7
-
IMTreatment.file_operation.file_operation.
import_from_IM7s
(fieldspath, kind='TSF', fieldnumbers=None, incr=1)[source]¶ Import scalar fields from .IM7 files. ‘fieldspath’ should be a tuple of path to im7 files. All im7 file present in the folder are imported.
Parameters: - fieldspath (string or tuple of string) –
- kind (string, optional) – Kind of object to create with IM7 files. (can be ‘TSF’ for TemporalScalarFields or ‘SSF’ for SpatialScalarFields).
- fieldnumbers (2x1 tuple of int) – Interval of fields to import, default is all.
- incr (integer) – Incrementation between fields to take. Default is 1, meaning all fields are taken.
-
IMTreatment.file_operation.file_operation.
import_from_VC7
(filename, infos=False, add_fields=False)[source]¶ Import a vector field or a velocity field from a .VC7 file
Parameters: - filename (string) – Path to the file to import.
- infos (boolean, optional) – If ‘True’, also return a dictionary with informations on the im7
- add_fields (boolean, optional) – If ‘True’, also return a tuple containing additional fields contained in the vc7 field (peak ratio, correlation value, …)
-
IMTreatment.file_operation.file_operation.
import_from_VC7s
(fieldspath, kind='TVF', fieldnumbers=None, incr=1, add_fields=False, verbose=False)[source]¶ Import velocity fields from .VC7 files. ‘fieldspath’ should be a tuple of path to vc7 files. All vc7 file present in the folder are imported.
Parameters: - fieldspath (string or tuple of string) – If no ‘.vc7’ are found directly under ‘fieldspath’, present folders are recursively serached for ‘.vc7’ files.
- kind (string, optional) – Kind of object to create with VC7 files. (can be ‘TVF’ or ‘SVF’).
- fieldnumbers (2x1 tuple of int) – Interval of fields to import, default is all.
- incr (integer) – Incrementation between fields to take. Default is 1, meaning all fields are taken.
- add_fields (boolean, optional) – If ‘True’, also return a tuple containing additional fields contained in the vc7 field (peak ratio, correlation value, …).
- Verbose (bool, optional) –
.
-
IMTreatment.file_operation.file_operation.
import_from_file
(filepath, **kw)[source]¶ Load and return an object from the specified file using the JSON format. Additionnals arguments for the JSON decoder may be set with the **kw argument. Such as’encoding’ (to change the file encoding, default=’utf-8’).
Parameters: - filepath (string) – Path specifiing the file to load.
- full_import (boolean) – If ‘True’, everything is charged in memory, else, data are loaded in memory when they are needed.
-
IMTreatment.file_operation.file_operation.
import_from_matlab
(filepath, obj, show_struct=False, **kwargs)[source]¶ Import data from a matlab (.m) file.
Data should be a dictionnary.
Parameters: - filepath (string) – Path of the matlab file
- obj (string in ['ScalarField', 'VectorField', 'Profile',) – ‘Points’] Kind of object to import to.
- show_struct (boolean) – If True, just show the structure of the file (and return it, so you can play with it)
- kwargs – Rest of the keyword arguments should indicate where to find the necessary information in the matlab dictionnary.
Example
With a matlab file containing a dictionnary with the following entries: ‘x’, ‘x_unit’, ‘y’, ‘y_unit’, ‘u’, ‘v’ >>> vf = import_from_matlab(‘data.m’, ‘VectorField’, … axe_x=’x’, axe_y=’y’, … unit_x=’x_unit’, unit_y=’y_unit’, … comp_x=’u’, comp_y=’v’)
-
IMTreatment.file_operation.file_operation.
import_from_picture
(filepath, axe_x=None, axe_y=None, unit_x='', unit_y='', unit_values='', dtype=<class 'float'>)[source]¶ Import a scalar field from a picture file.
Parameters: - filepath (string) – Path to the picture file.
- axe_x –
.
- axe_y –
.
- unit_x –
.
- unit_y –
.
- unit_values –
.
- dtype – Type of the stored values (default to float)
Returns: .
Return type: tmp_sf
-
IMTreatment.file_operation.file_operation.
import_from_pictures
(filepath, axe_x=None, axe_y=None, unit_x='', unit_y='', unit_values='', times=None, unit_times='', dtype=<class 'float'>, fieldnumbers=None, incr=1, verbose=False)[source]¶ Import scalar fields from a bunch of picture files.
Parameters: - filepath (string) – regex matching the files.
- axe_x –
.
- axe_y –
.
- unit_x –
.
- unit_y –
.
- unit_values –
.
- dtype – Type of the stored values (default to float)
- fieldnumbers (2x1 array) – Interval of fields to import, default is all.
- incr (integer) – Increment (incr=2 will load only 1 picture over 2).
Returns: .
Return type: tmp_sf
-
IMTreatment.file_operation.file_operation.
import_from_video
(filepath, dx=1, dy=1, unit_x='', unit_y='', unit_values='', dt=1, unit_times='', dtype=<class 'float'>, frame_inds=None, incr=1, verbose=False)[source]¶ Import scalar fields from a video.
Parameters: - filepath (string) – regex matching the files.
- dx –
.
- dy –
.
- unit_x –
.
- unit_y –
.
- unit_values –
.
- dtype – Type of the stored values (default to float)
- frame_inds (2x1 array) – Interval of fields to import, default is all.
- incr (integer) – Increment (incr=2 will load only 1 picture over 2).
Returns: .
Return type: tmp_sf
-
IMTreatment.file_operation.file_operation.
import_profile_from_ascii
(filepath, x_col=1, y_col=2, unit_x=1 [], unit_y=1 [], **kwargs)[source]¶ Import a Profile object from an ascii file.
Parameters: - y_col (x_col,) – Colonne numbers for the given variables (begining at 1).
- unit_y (unit_x,) – Unities for the given variables.
- **kwargs –
Possibles additional parameters are the same as those used in the numpy function ‘genfromtext()’ : ‘delimiter’ to specify the delimiter between colonnes. ‘skip_header’ to specify the number of colonne to skip at file
begining
-
IMTreatment.file_operation.file_operation.
import_pts_from_ascii
(filepath, x_col=1, y_col=2, v_col=None, unit_x=1 [], unit_y=1 [], unit_v=1 [], **kwargs)[source]¶ Import a Points object from an ascii file.
Parameters: - y_col, v_col (x_col,) – Colonne numbers for the given variables (begining at 1).
- unit_y, unit_v (unit_x,) – Unities for the given variables.
- **kwargs –
Possibles additional parameters are the same as those used in the numpy function ‘genfromtext()’ : ‘delimiter’ to specify the delimiter between colonnes. ‘skip_header’ to specify the number of colonne to skip at file
begining…
-
IMTreatment.file_operation.file_operation.
import_sf_from_ascii
(filepath, x_col=1, y_col=2, vx_col=3, unit_x=1 [], unit_y=1 [], unit_values=1 [], **kwargs)[source]¶ Import a scalarfield from an ascii file.
Parameters: - y_col, vx_col (x_col,) – Colonne numbers for the given variables (begining at 1).
- unit_y, unit_v (unit_x,) – Unities for the given variables.
- **kwargs –
Possibles additional parameters are the same as those used in the numpy function ‘genfromtext()’ : ‘delimiter’ to specify the delimiter between colonnes. ‘skip_header’ to specify the number of colonne to skip at file
begining…
-
IMTreatment.file_operation.file_operation.
import_vf_from_ascii
(filepath, x_col=1, y_col=2, vx_col=3, vy_col=4, unit_x=1 [], unit_y=1 [], unit_values=1 [], **kwargs)[source]¶ Import a vectorfield from an ascii file.
Parameters: - y_col, vx_col, vy_col (x_col,) – Colonne numbers for the given variables (begining at 1).
- unit_y, unit_v (unit_x,) – Unities for the given variables.
- **kwargs –
Possibles additional parameters are the same as those used in the numpy function ‘genfromtext()’ : ‘delimiter’ to specify the delimiter between colonnes. ‘skip_header’ to specify the number of colonne to skip at file
begining…
-
IMTreatment.file_operation.file_operation.
import_vfs_from_ascii
(filepath, kind='TVF', incr=1, interval=None, x_col=1, y_col=2, vx_col=3, vy_col=4, unit_x=1 [], unit_y=1 [], unit_values=1 [], times=[], unit_time=1 [], **kwargs)[source]¶ Import velocityfields from an ascii file.
Parameters: - filepath (string) – Pathname pattern to the ascii files.
- incr (integer, optional) – Increment value between two fields taken.
- interval (2x1 array, optional) – Interval in which take fields.
- y_col, vx_col, vy_col (x_col,) – Colonne numbers for the given variables (begining at 1).
- unit_y, unit_v (unit_x,) – Unities for the given variables.
- times (array of number, optional) – Times of the instantaneous fields.
- unit_time (Unit object, optional) – Time unit, ‘second’ by default.
- **kwargs – Possibles additional parameters are the same as those used in the numpy function ‘genfromtext()’ : ‘delimiter’ to specify the delimiter between colonnes. ‘skip_header’ to specify the number of colonne to skip at file begining
Note
txt files are taken in alpha-numerical order (‘file2.txt’ is taken before ‘file20.txt’). So you should name your files properly.
-
IMTreatment.file_operation.file_operation.
imts_to_imt
(imts_path, imt_path, kind)[source]¶ Concatenate some .imt files to one .imt file.
Parameters: - imts_path (string) – Path to the .imt files
- imt_path (string) – Path to store the new imt file.
- kind (string) – Kind of object for the new imt file (can be ‘TSF’ for TemporalScalarFields, ‘SSF’ for SpatialScalarFields, ‘TVF’ for TemporalVectorFields, ‘SVF’ for SpatialVectorFields)