コード例 #1
0
ファイル: plotpseudosection.py プロジェクト: azeezkk/mtpy
 def writeTextFiles(self, save_path=None, ptol=0.10):
     """
     This will write text files for all the phase tensor parameters
     """
     
     if save_path == None:
         try:
             svpath = os.path.dirname(self.mt_lst[0].fn)
         except TypeError:
             raise IOError('Need to input save_path, could not find a path')
     else:
         svpath = save_path
     
     if self.resxy.mean() == 0 :
         self.get_rp_arrays()
         
     header_lst = ['{0:^10}'.format('period(s)')]+\
                  ['{0:^8}'.format(ss) for ss in self.station_lst]+['\n']
     
     fn_dict = {'resxx':self.resxx, 
                'resxy':self.resxy, 
                'resyx':self.resyx,
                'resyy':self.resyy,
                'phasexx':self.phasexx,
                'phasexy':self.phasexy,
                'phaseyx':self.phaseyx,
                'phaseyy':self.phaseyy}
     
     #write the arrays into lines properly formatted
     t1_kwargs = {'spacing':'{0:^10} ', 'value_format':'{0:.2e}', 
                  'append':False, 'add':False}
                  
     tr_kwargs = {'spacing':'{0:^8}', 'value_format':'{0: .2f}', 
                  'append':False, 'add':False}
                  
     tp_kwargs = {'spacing':'{0:^8}', 'value_format':'{0: .2f}', 
                  'append':False, 'add':False}
                  
                  
     for key in fn_dict.keys():
         fid = file(os.path.join(svpath, 'PseudoSection.'+key), 'w')
         fid.write(''.join(header_lst))
         for ii, per in enumerate(self.plot_period):
             if key[0] == 'r':
                 line = [mtpl._make_value_str(per, **t1_kwargs)]+\
                        [mtpl._make_value_str(rr, **tr_kwargs) 
                         for rr in fn_dict[key][ii]]+['\n']
             elif key[0] == 'p':
                 line = [mtpl._make_value_str(per, **t1_kwargs)]+\
                        [mtpl._make_value_str(rr, **tp_kwargs) 
                         for rr in fn_dict[key][ii]]+['\n']
             fid.write(''.join(line))
         fid.close()
     
     print 'Wrote files to: '+\
                     os.path.join(svpath, 'PseudoSection.component')
コード例 #2
0
ファイル: plotpseudosection.py プロジェクト: DSO89/DSO
    def writeTextFiles(self, save_path=None, ptol=0.10):
        """
        This will write text files for all the phase tensor parameters
        """

        if save_path == None:
            try:
                svpath = os.path.dirname(self.mt_list[0].fn)
            except TypeError:
                raise IOError('Need to input save_path, could not find a path')
        else:
            svpath = save_path

        if self.resxy.mean() == 0:
            self.get_rp_arrays()

        header_list = ['{0:^10}'.format('period(s)')]+\
                     ['{0:^8}'.format(ss) for ss in self.station_list]+['\n']

        fn_dict = {
            'resxx': self.resxx,
            'resxy': self.resxy,
            'resyx': self.resyx,
            'resyy': self.resyy,
            'phasexx': self.phasexx,
            'phasexy': self.phasexy,
            'phaseyx': self.phaseyx,
            'phaseyy': self.phaseyy
        }

        #write the arrays into lines properly formatted
        t1_kwargs = {
            'spacing': '{0:^10} ',
            'value_format': '{0:.2e}',
            'append': False,
            'add': False
        }

        tr_kwargs = {
            'spacing': '{0:^8}',
            'value_format': '{0: .2f}',
            'append': False,
            'add': False
        }

        tp_kwargs = {
            'spacing': '{0:^8}',
            'value_format': '{0: .2f}',
            'append': False,
            'add': False
        }

        for key in fn_dict.keys():
            fid = file(os.path.join(svpath, 'PseudoSection.' + key), 'w')
            fid.write(''.join(header_list))
            for ii, per in enumerate(self.plot_period):
                if key[0] == 'r':
                    line = [mtpl._make_value_str(per, **t1_kwargs)]+\
                           [mtpl._make_value_str(rr, **tr_kwargs)
                            for rr in fn_dict[key][ii]]+['\n']
                elif key[0] == 'p':
                    line = [mtpl._make_value_str(per, **t1_kwargs)]+\
                           [mtpl._make_value_str(rr, **tp_kwargs)
                            for rr in fn_dict[key][ii]]+['\n']
                fid.write(''.join(line))
            fid.close()

        print 'Wrote files to: '+\
                        os.path.join(svpath, 'PseudoSection.component')
コード例 #3
0
ファイル: plotstations.py プロジェクト: azeezkk/mtpy
    def write_station_locations(self, save_path=None):
        """
        Write text file containing station locations in map coordinates and 
        relative to ref_point.
        
        Arguments:
        ----------
            **save_path**: string
                           full path to folder to save file, or full path to
                           the file to save to. *default* is None, which uses
                           the directory path of files used to plot.
                           
        Returns:
        ---------
            **fn_save_path**: string    
                              full path to text file
                          
        """
        
        if save_path == None:
            try:
                svpath = os.path.dirname(self.mt_lst.mt_lst[0].fn)
            except TypeError:
                raise IOError('Need to input save_path, could not find a path')
        else:
            svpath = save_path

        if self.map_scale == 'latlon':
            sfmt = '{0: .3f}'
            hdr_lst = ['Station', 'Longitude(deg)', 'Latitude(deg)']
        elif self.map_scale == 'eastnorth':
            sfmt = '{0: .0f}'
            hdr_lst = ['Station', 'Longitude(m)', 'Latitude(m)']
        elif self.map_scale == 'eastnorthkm':
            sfmt = '{0: .0f}'
            hdr_lst = ['Station', 'Longitude(km)', 'Latitude(km)']
            
        try:
            self.mt_lst.map_xarr
        except AttributeError:
            self.mt_lst.get_station_locations(map_scale=self.map_scale,
                                              ref_point=self.ref_point)
                             
        fn_svpath = os.path.join(svpath, 'StationLocations.txt')
        tfid = file(fn_svpath, 'w')
        
        hdr_str = ['{0:15}'.format(hh) for hh in hdr_lst]+['\n']
        
        tfid.write(''.join(hdr_str))
        for ss in self.mt_lst.map_dict.keys():
            tfid.write('{0:15}'.format(ss))
            x = self.mt_lst.map_dict[ss][0]
            y = self.mt_lst.map_dict[ss][1]
            tfid.write('{0:15}'.format(mtpt._make_value_str(x, 
                                       value_format=sfmt, spacing='{0:^15}')))
            tfid.write('{0:15}'.format(mtpt._make_value_str(y, 
                                       value_format=sfmt, spacing='{0:^15}')))
            tfid.write('\n')
            
        tfid.close()
        
        print 'Saved file to: ', fn_svpath