Save time processing netcdf

Discussion in 'Python' started by vorticitywolfe@gmail.com, Mar 25, 2007.

  1. Guest

    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!
    , Mar 25, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bandw
    Replies:
    5
    Views:
    598
    bandw
    Jul 7, 2005
  2. SciPy and NetCDF

    , Jul 26, 2005, in forum: Python
    Replies:
    9
    Views:
    1,437
    Scott Kilpatrick
    Aug 4, 2005
  3. Replies:
    5
    Views:
    2,792
    Lars Uffmann
    Aug 21, 2006
  4. Michele Thornton

    Python - modules and netCDF

    Michele Thornton, Oct 6, 2008, in forum: Python
    Replies:
    0
    Views:
    505
    Michele Thornton
    Oct 6, 2008
  5. Sudheer Joseph

    python netcdf

    Sudheer Joseph, Jun 6, 2013, in forum: Python
    Replies:
    2
    Views:
    112
    Sudheer Joseph
    Jun 6, 2013
Loading...

Share This Page