HELP! What's wrong here ??? I don't get it!
christian werner
chr_werner at gmx.de
Wed Nov 7 16:25:06 EST 2001
Hello python coders :)
I'm in desperade need for a hint from you guys concerning this junk of code
I produced.
I JUST DON'T GET IT !!!
I'm sorry about the length of this thread, but I figured that the more
detailed I am about my problem, the sooner you might be able to find my stupid
error !!!
Maybe it's easier if I first explain what I intent to do ;):
1.) I try to read a file line by line & transform it into an array (1d)
1.) the IF statement determins, what type od data is given (done by the type
variable)
t = temperature, p = precipitation, r = radiation
2.) I got this one to run for the t and r case, so that's fine (code works
as expected)
basically line 2 - 7 do a read and transform to the data, a3 will be
returned by my
function - that's cool...
3.) for the precipitation I have to substract the previous timestep from the
actual one
(t = t(0) - t(-1)) - I named the previous array pa ;), since I can't
use the data as is
example: a array equals
at t(0) [10, 12, 15, 5, 10, 2, 23, ...]
at t(-1) [5, 7, 10, 4, 10, 1, 21, ...]
than the value for t(0) corrected should look like t(0) - t(-1):
[5, 6, 5, 11, 1, 0, 1, 2, ...]
4.) the main look iterates 24times (1 to 24) representing 24h of a day.
Since hour = 1
has no previous value t(-1) 0 0 t(-1), I assign pa = [0, 0, 0, 0, 0,
...] before the loop
starts (line 0)
then:
-> read line into 1d array
-> reshape to 2d array
-> subtract array of last timestep
-> write corrected array to day-array (a3 called)
If I call the function with type = t or type = r I get the right results...
If I call the function with type = p I get this wired result below:
hour 1: takes first line, substracts 0s' = OK!
a = 1.31 / pa = 0 / a2 = 1.31 / new pa = 1.31
hour 2: a has the same value as in previous timestep, since the function
assigns pa = a in the loop I get '0' for the a2 array
a = 1.31 (again!!! - why?) / pa = 0 / a2 = 1.31 / new pa = 1.31
hour 3: like hour 2
hour 3: like hour 2
etc.
------my code subset -----
0 day = 7 # just any day
0 ln=(day*24)-23 # locate position of 1st line for
hour1 of day
# file contains continous
data:
# hour 1: line1
# hour 2: line2 (...)
# hour 24: line24 (...)
# hour 1: line 25 [day2
starting]
0 pa = zeros((x,y), Float)
1 if (type == 't' or type == 'r'):
2 for hour in range(1,25,1):
3 print hour,
4 line = linecache.getline(file, ln) # read line
5 a = array(map(float, string.split(line))) # map line to 1d
array
6 a = reshape(a, (x,y)) # reshape to 2d
array
7 a3[(hour-1)] = a[:,::-1] # reverse fortran
order of array and
8 # put
into 3d array (day)
9 ln +=1
10 linecache.clearcache()
11
12 elif (type == 'p'):
13 for hour in range(1,25,1):
14 line = linecache.getline(file, ln) # read line
15 a = array(map(float, string.split(line))) # map line to 1d
array
16 a = reshape(a, (x,y)) # reshape to 2d
array
17 a2 = a - pa # a2 =
corrected array
18 pa = a # this
input array a will be
19 # used
in the next iteration as pa
20
21 a3[(hour-1)] = a[:,::-1] # reverse fortran
order off array and
22 # put into
3d array (day)
23 ln += 1
24 linecache.clearcache()
I'm trying to solve this crap for days now and am getting really pissed off
with it... I just don't get it. So please, please,please - where is my error
???
I thinks it either always reads the same line ('p' case) - but why? Is there
a clearcache missing ?
Thanks a lot folks, I really appreciate the help I get from this great list
!!!
cheers,
christian
--
--------------------------
christian werner
Loisachstraße 69
82491 Grainau
+49 (0)8821 727799
Heimatanschrift:
Gartenstraße 15
97737 Gemünden
+49 (0)9351 8435
mobile: 0179 4559242
email: chr_werner at gmx.de
http:\\www.christianw.de
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net
More information about the Python-list
mailing list