问题描述:

This question has potentially two parts but maybe only one if the first part can be encapsulated by the second. I am using python with numpy and netCDF4

First:

I have four lists of different variable values (hereafter referred to elevation values) each of which has a length of 28. These four lists are one set of 5 different latitude values of which are one set of the 24 different time values.

So 24 times...each time with 5 latitudes...each latitude with four lists...each list with 28 values.

I want to create an array with the following dimensions (elevation, latitude, time, variable)

In words, I want to be able to specify which of the four lists I access,which index in the list, and specify a specific time and latitude. So an index into this array would look like this:

array(0,1,2,3) where 0 specifies the first index of the the 4th list specified by the 3. 1 specifies the 2nd latitude, and 2 specifies the 3rd time and the output is the value at that point.

I won't include my code for this part since literally the only things of mention are the lists

list1=[...]

list2=[...]

list3=[...]

list4=[...]

How can I do this, is there an easier structure of the array, or is there anything else I a missing?

Second:

I have created a netCDF file with variables with these four dimensions. I need to set those variables to the array structure made above. I have no idea how to do this and the netCDF4 documentation does a 1-d array in a fairly cryptic way. If the arrays can be made directly into the netCDF file bypassing the need to use numpy first, by all means show me how.

Thanks!

网友答案:

After talking to a few people where I work we came up with this solution:

First we made an array of zeroes using the following argument:

array1=np.zeros((28,5,24,4))

Then appended this array by specifying where in the array we wanted to change:

array1[:,0,0,0]=list1

This inserted the values of the list into the first entry in the array.

Next to write the array to a netCDF file, I created a netCDF in the same program I made the array, made a single variable and gave it values like this:

netcdfvariable[:]=array1

Hope that helps anyone who finds this.

相关阅读:
Top