Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Save time processing netcdf

Reply
Thread Tools

Save time processing netcdf

 
 
vorticitywolfe@gmail.com
Guest
Posts: n/a
 
      03-25-2007
Hello,

I am working with a netcdf file and trying to remove a long string
from it e.g.
"KAST BLAH BLAH BLAH BLAH DATA BLAH DATA BLAH BLAH BLAH BLAH BLAH DATA
BLAH DATA BLAH"

Right now what I have works, but takes a long time to run... I think
this could be cut down to a quick 2 second run, but now takes around 5
minutes primarily because of the problem described below...

Why can't I use something like line 9 to get the entire string (which
returns [0], not
["KAST BLAH BLAH BLAH BLAH DATA BLAH DATA BLAH BLAH BLAH BLAH BLAH
DATA BLAH DATA BLAH"])? Rather I have to loop through it grabbing one
character at a time which drastically increases the processing time
and is very cumbersome.

Any one have any ideas or suggestions?


0 #OPEN NetCDF FILE TO READ
1 allDimNames=file.dimensions.keys()
2 max_string_length=file.dimensions['maxstringLen']
3 variableNames=file.variables.keys()
4 globalAttList=dir(file)
5 globalAttValue=getattr(file,'filePeriod')
6
7#GRABS DATA FROM STRING (2 DIMENSIONAL ARRAY) WITH THE CHARACTERS AS
INDIVIDUAL 8ELEMENTS
9 #YOU CAN'T JUST SPECIFY DATA VALUES DATA[0][0:max_string_length]
10 data=file.variables['rawstring'].getValue()
11 num_stations=data.shape
12 station_id=[str(mz)]
13
14 for m in station_id:
15 station_id=m
16 prec=[]
17 temps=[]
18
19 #Cycles through all of the stations in the file (LARGE ARRAY!!)
20 for k in range(num_stations[0]):
21 #Finds a certain station
22 if data[k][6]=='K' and data[k][7]==station_id[0:1] and data[k]
[8]==station_id[1:2] and 23data[k][9]==station_id[2:3] and data[k]
[15]=='5' or data[k][6]=='K' and data[k][7]==station_id[0:1] and
24data[k][8]==station_id[1:2] and data[k][9]==station_id[2:3] and
data[k][15]=='4':
25
26 #SEPARATES STRING CHARACTER BY CHARACTER ONLY WAY I'VE 27BEEN
ABLE TO FIGURE OUT HOW TO READ ENTIRE STRING INTO A STRING
28 for j in range(max_string_length):
29 prec.append(str(data[k][j]))
30 S= ''.join(prec)
31 # # # ##THEN RIP OFF THE WHITESPACE AT THE RIGHT OF THE
STRING
32 code=S.rstrip("\0")
33

Thanks for any of your help!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Python - modules and netCDF Michele Thornton Python 0 10-06-2008 02:48 PM
Is time.time() < time.time() always true? flamesrock Python 8 11-24-2006 06:51 AM
Problem linking netcdf - Undefined References... lars.uffmann@rwth-aachen.de C++ 5 08-21-2006 03:40 AM
SciPy and NetCDF skilpat@gmail.com Python 9 08-04-2005 08:40 PM
Using Numeric 24.0b2 with Scientific.IO.NetCDF bandw Python 5 07-06-2005 11:04 PM



Advertisments