1414from os .path import basename , dirname , normpath , splitext
1515from tempfile import mkdtemp , mkstemp
1616import subprocess as sp
17+ import warnings
1718
1819from pkg_resources import resource_filename
1920
2324from .prv import PRV , get_prv_header_info
2425from . import config
2526
27+ from pypop .utils .exceptions import ExtraePRVNoOnOffEventsError
28+
2629floatmatch = re .compile (r"[0-9,]+\.[0-9]+" )
2730keymatch = re .compile (r"@.*@" )
2831tabmatch = re .compile (r"\t+" )
@@ -111,13 +114,14 @@ def chop_prv_to_roi(prv_file, outfile=None):
111114 if outfile :
112115 workdir = dirname (normpath (outfile ))
113116 else :
114- tgtname = ".chop" .join (splitext (basename (prv_file )))
117+ if prv_file .endswith (".gz" ):
118+ tgtname = ".chop" .join (splitext (basename (prv_file [:- 3 ])))
119+ else :
120+ tgtname = ".chop" .join (splitext (basename (prv_file )))
121+
115122 # Make sure config._tmpdir_path exists before using it
116123 if config ._tmpdir_path :
117- try :
118- os .makedirs (config ._tmpdir_path , exist_ok = True )
119- except OSError as err :
120- print ("FATAL: {}" .format (err ))
124+ os .makedirs (config ._tmpdir_path , exist_ok = True )
121125 workdir = mkdtemp (dir = config ._tmpdir_path )
122126 outfile = os .path .join (workdir , tgtname )
123127
@@ -189,7 +193,7 @@ def chop_prv_to_roi(prv_file, outfile=None):
189193
190194
191195def _get_roi_times (roi_prv ):
192- """ Extract ROi timing information from a filtered trace
196+ """ Extract ROI timing information from a filtered trace
193197
194198 Expects a trace containing only Extrae On/Off events and returns tuple of
195199 earliest and latest time
@@ -211,7 +215,7 @@ def _get_roi_times(roi_prv):
211215 ontime , offtime = (ons ["time" ].min (), 1 + offs ["time" ].max ())
212216
213217 if ontime is numpy .nan or offtime is numpy .nan :
214- raise ValueError ( "Unable to locate valid ON-OFF bracket in trace" )
218+ raise ExtraePRVNoOnOffEventsError ( "No valid Extrae ON-OFF bracket in trace" )
215219
216220 return ontime , offtime
217221
@@ -389,12 +393,10 @@ def run_paramedir(tracefile, paramedir_config, outfile=None, variables=None):
389393
390394 # Make sure config._tmpdir_path exists before using it
391395 if config ._tmpdir_path :
392- try :
393- os .makedirs (config ._tmpdir_path , exist_ok = True )
394- except OSError as err :
395- print ("FATAL: {}" .format (err ))
396-
397- tmpdir = mkdtemp (dir = config ._tmpdir_path )
396+ os .makedirs (config ._tmpdir_path , exist_ok = True )
397+ tmpdir = mkdtemp (dir = config ._tmpdir_path )
398+ else :
399+ tmpdir = mkdtemp ()
398400
399401 # If variables is none, still sub with empty dict
400402 variables = variables if variables else {}
@@ -476,7 +478,7 @@ def _split_countline(countline, bins):
476478 extra_strings = len (count_strings ) - num_values
477479
478480 if extra_strings > 1 :
479- print (
481+ warnings . warn (
480482 "Warning, got more label strings ({}) than expected (1)"
481483 "" .format (extra_strings )
482484 )
0 commit comments