Commit 397fd234 authored by Camilla Dodge Koslowsky Harris's avatar Camilla Dodge Koslowsky Harris
Browse files

various tweaks to satisfy the linter and starting to remove pandas things

parent 5644e875
...@@ -20,6 +20,9 @@ __all__ = [ ...@@ -20,6 +20,9 @@ __all__ = [
__author__ = 'Camilla D. K. Harris' __author__ = 'Camilla D. K. Harris'
__email__ = 'cdha@umich.edu' __email__ = 'cdha@umich.edu'
import os
import re
import numpy as np import numpy as np
import tecplot import tecplot
...@@ -110,20 +113,20 @@ def _save_hdf5(): ...@@ -110,20 +113,20 @@ def _save_hdf5():
""" """
def _save_ascii(): def _save_csv():
"""Save the aux data and a subset of the variables in plain-text format. """Save the aux data and a subset of the variables in plain-text format.
""" """
def tecplot_interpolate( def tecplot_interpolate(
tecplot_plt_file_path:str tecplot_plt_file_path: str
,geometry:str , geometry: str
,write_as:str , write_as: str
,filename:str=None , filename: str = None
,tecplot_equation_file_path:str=None , tecplot_equation_file_path: str = None
,tecplot_variable_pattern:str=None , tecplot_variable_pattern: str = None
,verbose:bool=False , verbose: bool = False
,**kwargs , **kwargs
): ):
"""Interpolates Tecplot binary data onto various geometries. """Interpolates Tecplot binary data onto various geometries.
...@@ -132,7 +135,7 @@ def tecplot_interpolate( ...@@ -132,7 +135,7 @@ def tecplot_interpolate(
geometry (str): Type of geometry for interpolation. Supported geometries geometry (str): Type of geometry for interpolation. Supported geometries
are 'shell', 'line', 'rectprism', or 'trajectory'. are 'shell', 'line', 'rectprism', or 'trajectory'.
write_as (str): Type of file to write to. Supported options are 'hdf5', write_as (str): Type of file to write to. Supported options are 'hdf5',
'ascii', 'tecplot_ascii', and 'tecplot_plt'. 'csv', 'tecplot_ascii', and 'tecplot_plt'.
filename (str): (Optional) Name of the file to write to. Defaults to a filename (str): (Optional) Name of the file to write to. Defaults to a
concatenation of the tecplot file name and the geometry type. concatenation of the tecplot file name and the geometry type.
tecplot_equation_file_path (str): (Optional) Path to an equation file to tecplot_equation_file_path (str): (Optional) Path to an equation file to
...@@ -160,7 +163,7 @@ def tecplot_interpolate( ...@@ -160,7 +163,7 @@ def tecplot_interpolate(
center (array-like): Argument for the 'rectprism' geometry. Contains the center (array-like): Argument for the 'rectprism' geometry. Contains the
X, Y, and Z positions of the center of the rectangular prism. X, Y, and Z positions of the center of the rectangular prism.
Defaults to (0,0,0). Defaults to (0,0,0).
halfwidth (array-like): Argument for the 'rectprism' geometry. Contains halfwidths (array-like): Argument for the 'rectprism' geometry. Contains
the half widths of the rectangular prism in the X, Y, and Z the half widths of the rectangular prism in the X, Y, and Z
directions. Required. directions. Required.
npoints (array-like): Argument for the 'rectprism' geometry. Contains npoints (array-like): Argument for the 'rectprism' geometry. Contains
...@@ -208,16 +211,17 @@ def tecplot_interpolate( ...@@ -208,16 +211,17 @@ def tecplot_interpolate(
if verbose: if verbose:
print('Adding defaults') print('Adding defaults')
if 'shell' in geometry_params['kind']: if 'shell' in geometry_params['kind']:
geometry_params['center'] = geometry_params.get('center',(0.0,0.0,0.0)) geometry_params['center'] = geometry_params.get('center', (0.0,0.0,0.0))
geometry_params['npolar'] = geometry_params.get('npolar',181) geometry_params['npoints'] = geometry_params.get('npoints', (359,181))
geometry_params['nazimuth'] = geometry_params.get('nazimuth',359) elif 'rectprism' in geometry_params['kind']:
geometry_params['center'] = geometry_params.get('center', (0.0,0.0,0.0))
## check that we support the geometry ## check that we support the geometry
geometry_param_names = { geometry_param_names = {
'shell':('radius',) 'shell': ('radius',)
,'line':('r1','r2','npoints') , 'line': ('r1', 'r2', 'npoints')
,'rectprism':('center','halfwidth','npoints') , 'rectprism': ('halfwidths', 'npoints')
,'trajectory':('trajectory_data','trajectory_format') , 'trajectory': ('trajectory_data', 'trajectory_format')
} }
if geometry_params['kind'] not in geometry_param_names: if geometry_params['kind'] not in geometry_param_names:
raise ValueError(f'Geometry {geometry_params["kind"]} not supported!') raise ValueError(f'Geometry {geometry_params["kind"]} not supported!')
...@@ -232,10 +236,9 @@ def tecplot_interpolate( ...@@ -232,10 +236,9 @@ def tecplot_interpolate(
## check that we support the file type to save as ## check that we support the file type to save as
file_types = ( file_types = (
'hdf5' 'hdf5'
,'pandas_ascii' , 'csv'
,'pandas_hdf5' , 'tecplot_ascii'
,'tecplot_ascii' , 'tecplot_plt'
,'tecplot_plt'
) )
if write_as not in file_types: if write_as not in file_types:
raise ValueError(f'File type {write_as} not supported!') raise ValueError(f'File type {write_as} not supported!')
...@@ -243,15 +246,15 @@ def tecplot_interpolate( ...@@ -243,15 +246,15 @@ def tecplot_interpolate(
## describe the interpolation we're about to do on the data ## describe the interpolation we're about to do on the data
if verbose: if verbose:
print('Geometry to be interpolated:') print('Geometry to be interpolated:')
for key,value in geometry_params.items(): for key, value in geometry_params.items():
print(f'\t{key}: {value.__repr__()}') print(f'\t{key}: {value.__repr__()}')
## check whether we are using equations ## check whether we are using equations
## check that the equations file is there ## check that the equations file is there
use_equations = not (tecplot_equation_file_path is None) use_equations = not tecplot_equation_file_path is None
if use_equations: if use_equations:
f = open(tecplot_equation_file_path,'r') equations_file = open(tecplot_equation_file_path, 'r')
f.close() equations_file.close()
if verbose: if verbose:
print('Applying equations from file:') print('Applying equations from file:')
print(tecplot_equation_file_path) print(tecplot_equation_file_path)
...@@ -281,24 +284,24 @@ def tecplot_interpolate( ...@@ -281,24 +284,24 @@ def tecplot_interpolate(
## apply equations ## apply equations
if verbose: if verbose:
print('Applying equations to data') print('Applying equations to data')
tecplot_apply_equations(tecplot_equation_file_path) apply_equations(tecplot_equation_file_path)
if verbose: if verbose:
print('Variables after equations:') print('Variables after equations:')
print(batsrus.variable_names) print(batsrus.variable_names)
## create geometry zone ## create geometry zone
if 'shell' in geometry_params['kind']: if 'shell' in geometry_params['kind']:
geometry_points = shell_geometry(geometry_params) geometry_points = _shell_geometry(geometry_params)
elif 'line' in geometry_params['kind']: elif 'line' in geometry_params['kind']:
geometry_points = line_geometry(geometry_params) geometry_points = _line_geometry(geometry_params)
elif 'rectprism' in geometry_params['kind']: elif 'rectprism' in geometry_params['kind']:
geometry_points = rectprism_geometry(geometry_params) geometry_points = _rectprism_geometry(geometry_params)
elif 'trajectory' in geometry_params['kind']: elif 'trajectory' in geometry_params['kind']:
geometry_points = trajectory_geometry(geometry_params) geometry_points = _trajectory_geometry(geometry_params)
source_zone = list(batsrus.zones()) source_zone = list(batsrus.zones())
new_zone = batsrus.add_ordered_zone('geometry',geometry_points['npoints']) new_zone = batsrus.add_ordered_zone('geometry', geometry_points['npoints'])
for i,d in zip((0,1,2),('X','Y','Z')): for i, d in zip((0, 1, 2), ('X', 'Y', 'Z')):
new_zone.values(i)[:] = geometry_points[d][:] new_zone.values(i)[:] = geometry_points[d][:]
## interpolate variables on to the geometry ## interpolate variables on to the geometry
...@@ -310,8 +313,8 @@ def tecplot_interpolate( ...@@ -310,8 +313,8 @@ def tecplot_interpolate(
print(var.name) print(var.name)
tecplot.data.operate.interpolate_linear( tecplot.data.operate.interpolate_linear(
destination_zone=new_zone destination_zone=new_zone
,source_zones=source_zone , source_zones=source_zone
,variables=variables , variables=variables
) )
## add variables for shell and trajectory cases ## add variables for shell and trajectory cases
if 'shell' in geometry_params['kind']: if 'shell' in geometry_params['kind']:
...@@ -339,19 +342,17 @@ def tecplot_interpolate( ...@@ -339,19 +342,17 @@ def tecplot_interpolate(
if verbose: if verbose:
print(f'Writing {filename}') print(f'Writing {filename}')
if 'hdf5' in write_as: if 'hdf5' in write_as:
save_hdf5() _save_hdf5()
elif 'pandas_ascii' in write_as: elif 'csv' in write_as:
save_pandas_ascii(filename,batsrus,variables) _save_csv()
elif 'pandas_hdf5' in write_as:
save_pandas_hdf5()
elif 'tecplot_ascii' in write_as: elif 'tecplot_ascii' in write_as:
tecplot.data.save_tecplot_ascii( tecplot.data.save_tecplot_ascii(
filename filename
,zones=new_zone , zones=new_zone
,use_point_format='True' , use_point_format='True'
) )
elif 'tecplot_plt' in write_as: elif 'tecplot_plt' in write_as:
tecplot.data.save_tecplot_plt( tecplot.data.save_tecplot_plt(
filename filename
,zones=new_zone , zones=new_zone
) )
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment