From 485eaebb8caa052132785c1ec5a86ccfb0fcd5c8 Mon Sep 17 00:00:00 2001 From: Alho Markku J Date: Thu, 19 Sep 2024 11:15:43 +0300 Subject: [PATCH 1/4] Trial inspect call for emitting warnings --- pyVlsv/vlsvreader.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pyVlsv/vlsvreader.py b/pyVlsv/vlsvreader.py index 64805fed..b0d29bc9 100644 --- a/pyVlsv/vlsvreader.py +++ b/pyVlsv/vlsvreader.py @@ -1716,16 +1716,30 @@ def read_variable_to_cache(self, name, operator="pass"): # Also initialize the fileindex dict at the same go because it is very likely something you want to have for accessing cached values self.__read_fileindex_for_cellid() - def read_variable(self, name, cellids=-1,operator="pass"): + def read_variable(self, name, cellids=-1,operator="pass",sorted=False): ''' Read variables from the open vlsv file. Arguments: :param name: Name of the variable :param cellids: a value of -1 reads all data :param operator: Datareduction operator. "pass" does no operation on data + :param sorted: Return values sorted by CellID (default: file order for vg, 3D array for fsgrid) :returns: numpy array with the data .. seealso:: :func:`read` :func:`read_variable_info` ''' + + import inspect + # print(inspect.stack()) + stck = inspect.stack() + # print(stck[1]) + for i,fr in enumerate(stck): + mod = inspect.getmodule(fr[0]) + print('frame '+str(i)+" module: "+ str(mod)) + + + if(inspect.getmodule(stck[1][0]) is None or (inspect.getmodule(stck[1][0]) is not None and inspect.getmodule(stck[1][0]).__name__ != 'main')): + warnings.warn("Calling read_variable returns data in file layout order. Remember to argsort with CellID or consider using read_variable_info instead!") + cellids = get_data(cellids) # Wrapper, check if requesting an fsgrid variable From 4d992f8d39872fc2f78274984826c195ce7086c3 Mon Sep 17 00:00:00 2001 From: Alho Markku J Date: Thu, 19 Sep 2024 11:17:30 +0300 Subject: [PATCH 2/4] Comment out some prints --- pyVlsv/vlsvreader.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyVlsv/vlsvreader.py b/pyVlsv/vlsvreader.py index b0d29bc9..6b1d5d7b 100644 --- a/pyVlsv/vlsvreader.py +++ b/pyVlsv/vlsvreader.py @@ -1732,9 +1732,9 @@ def read_variable(self, name, cellids=-1,operator="pass",sorted=False): # print(inspect.stack()) stck = inspect.stack() # print(stck[1]) - for i,fr in enumerate(stck): - mod = inspect.getmodule(fr[0]) - print('frame '+str(i)+" module: "+ str(mod)) + # for i,fr in enumerate(stck): + # mod = inspect.getmodule(fr[0]) + # print('frame '+str(i)+" module: "+ str(mod)) if(inspect.getmodule(stck[1][0]) is None or (inspect.getmodule(stck[1][0]) is not None and inspect.getmodule(stck[1][0]).__name__ != 'main')): From 0aa840559c005365abba61cc3169092bc4e8fb9a Mon Sep 17 00:00:00 2001 From: Alho Markku J Date: Fri, 20 Sep 2024 10:56:54 +0300 Subject: [PATCH 3/4] Debugging. inspect.stack() returns None spuriously, while inspect.currentframe returns a proper frame, including f_back. --- pyPlots/plot_colormap3dslice.py | 6 ++++++ pyVlsv/vlsvreader.py | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pyPlots/plot_colormap3dslice.py b/pyPlots/plot_colormap3dslice.py index 77716b5b..30e4a27b 100644 --- a/pyPlots/plot_colormap3dslice.py +++ b/pyPlots/plot_colormap3dslice.py @@ -224,6 +224,8 @@ def exprMA_cust(exprmaps, requestvariables=False): ''' + import inspect + print('inspect.stack from plot_colormap3dslice\n',inspect.stack()) # Verify the location of this watermark image watermarkimage=os.path.join(os.path.dirname(__file__), 'logo_color.png') watermarkimageblack=os.path.join(os.path.dirname(__file__), 'logo_black.png') @@ -431,7 +433,11 @@ def exprMA_cust(exprmaps, requestvariables=False): zsize = int(zsize) [xmin, ymin, zmin, xmax, ymax, zmax] = f.get_spatial_mesh_extent() cellsize = (xmax-xmin)/xsize + print("cellids") + print("inspect.currentframe from plot\n",inspect.currentframe()) + print("inspect.currentframe.f_back from plot\n",inspect.currentframe().f_back) cellids = f.read_variable("CellID") + print("out cellids") # Read the FSgrid mesh try: diff --git a/pyVlsv/vlsvreader.py b/pyVlsv/vlsvreader.py index 6b1d5d7b..3816d8cc 100644 --- a/pyVlsv/vlsvreader.py +++ b/pyVlsv/vlsvreader.py @@ -1731,11 +1731,14 @@ def read_variable(self, name, cellids=-1,operator="pass",sorted=False): import inspect # print(inspect.stack()) stck = inspect.stack() + print("inspect.currentframe from read_variable\n",inspect.currentframe()) + print("inspect.currentframe.f_back from read_variable\n",inspect.currentframe().f_back) # print(stck[1]) # for i,fr in enumerate(stck): # mod = inspect.getmodule(fr[0]) # print('frame '+str(i)+" module: "+ str(mod)) - + print("inspect.stack from read_variable\n", inspect.getmodule(stck)) + if(inspect.getmodule(stck[1][0]) is None or (inspect.getmodule(stck[1][0]) is not None and inspect.getmodule(stck[1][0]).__name__ != 'main')): warnings.warn("Calling read_variable returns data in file layout order. Remember to argsort with CellID or consider using read_variable_info instead!") From 62211aee01236260018b6e0a75ceba38e07fa33b Mon Sep 17 00:00:00 2001 From: Alho Markku J Date: Fri, 20 Sep 2024 14:04:17 +0300 Subject: [PATCH 4/4] main vs __main__ and != vs ==... I thought I had fixed that --- pyPlots/plot_colormap3dslice.py | 6 ------ pyVlsv/vlsvreader.py | 13 ++----------- pytools.py | 2 ++ 3 files changed, 4 insertions(+), 17 deletions(-) diff --git a/pyPlots/plot_colormap3dslice.py b/pyPlots/plot_colormap3dslice.py index 30e4a27b..77716b5b 100644 --- a/pyPlots/plot_colormap3dslice.py +++ b/pyPlots/plot_colormap3dslice.py @@ -224,8 +224,6 @@ def exprMA_cust(exprmaps, requestvariables=False): ''' - import inspect - print('inspect.stack from plot_colormap3dslice\n',inspect.stack()) # Verify the location of this watermark image watermarkimage=os.path.join(os.path.dirname(__file__), 'logo_color.png') watermarkimageblack=os.path.join(os.path.dirname(__file__), 'logo_black.png') @@ -433,11 +431,7 @@ def exprMA_cust(exprmaps, requestvariables=False): zsize = int(zsize) [xmin, ymin, zmin, xmax, ymax, zmax] = f.get_spatial_mesh_extent() cellsize = (xmax-xmin)/xsize - print("cellids") - print("inspect.currentframe from plot\n",inspect.currentframe()) - print("inspect.currentframe.f_back from plot\n",inspect.currentframe().f_back) cellids = f.read_variable("CellID") - print("out cellids") # Read the FSgrid mesh try: diff --git a/pyVlsv/vlsvreader.py b/pyVlsv/vlsvreader.py index 3816d8cc..08c02554 100644 --- a/pyVlsv/vlsvreader.py +++ b/pyVlsv/vlsvreader.py @@ -1729,18 +1729,9 @@ def read_variable(self, name, cellids=-1,operator="pass",sorted=False): ''' import inspect - # print(inspect.stack()) + stck = inspect.stack() - print("inspect.currentframe from read_variable\n",inspect.currentframe()) - print("inspect.currentframe.f_back from read_variable\n",inspect.currentframe().f_back) - # print(stck[1]) - # for i,fr in enumerate(stck): - # mod = inspect.getmodule(fr[0]) - # print('frame '+str(i)+" module: "+ str(mod)) - print("inspect.stack from read_variable\n", inspect.getmodule(stck)) - - - if(inspect.getmodule(stck[1][0]) is None or (inspect.getmodule(stck[1][0]) is not None and inspect.getmodule(stck[1][0]).__name__ != 'main')): + if(inspect.getmodule(stck[1][0]) is None or (inspect.getmodule(stck[1][0]) is not None and inspect.getmodule(stck[1][0]).__name__ == '__main__')): warnings.warn("Calling read_variable returns data in file layout order. Remember to argsort with CellID or consider using read_variable_info instead!") cellids = get_data(cellids) diff --git a/pytools.py b/pytools.py index 8244b2b1..37302e57 100644 --- a/pytools.py +++ b/pytools.py @@ -56,6 +56,8 @@ logging.info('either using csc.taito.fi without loading the mayavi2 module, or by invoking') logging.info('the system python interpeter by calling "./scriptname.py" instead of "python ./scriptname.py"') +logging.getLogger('matplotlib').setLevel(logging.WARNING) + # Run TeX typesetting through the full TeX engine instead of python's own mathtext. Allows # for changing fonts, bold math symbols etc, but may cause trouble on some systems. if not os.getenv('PTNOLATEX'):