3D numpy array woes and extracting data
I am assuming numpy is imported under the name np, and all arrays are numpy arrays.
You have to start by summing total_combustion_rate along the time dimension. This way, you will get a 2-D array for which each entry represents an integrated value over time for each location of your dataset.
total_combustion_rate.sum(axis=0)
Now, this array is the exact place where you can look for 0 values. The idea is to determine where the non-zero entries are so that you can use their index to probe into area_array and get the relevant areas you need. A masked array makes the task extremely easy as it will "hide" these entries you do not want, meaning the ones that sum up to 0.
np.ma.MaskedArray(area_array, total_combustion_rate.sum(axis=0) == 0)
When you have the masked array, all you need to do is to compare the sum of the un-masked areas to the sum of all areas. Again, this is achieved effortlessly.
(np.ma.MaskedArray(area_array, total_combustion_rate.sum(axis=0) == 0).sum()
 / area_array.sum())
All in one (long) line. :)
I have some data concerning the 2020 Australian bush fires I'm trying to work with.
I have some data in numpy arrays: lat (for latitude), lon (for longitude), and time.
The array size of lat is: 350 with the shape: (350,)
The array size of lon is: 500 with the shape: (500,)
The array size of time is: 31 with the shape: (31,) - this makes sense as it's days of the month in Jan 2020.
I have another array, total_combustion_rate:
The array size of total_combustion_rate is: 5425000 with the shape: (31, 350, 500) - so it's made up of days in the month, lat and lon values.
I have a final array called area_array:
The array size of area_array is: 175000 with the shape: (350, 500). It contains the area of each grid square in km2.
I have been asked to work out what percentage of Australia experienced fire during January 2020.
I'm unsure how to go about this problem though.
There are a lot of values in total_combustion_rate that are zero. Getting rid of them should just leave me with entries that mean there is a fire of some description burning in each grid square. I can see that I need to then sum the same lon and lat values in area_array that have a value that isn't zero in total_combustion_rate and that should give me the total area of grid squares that were on fire.
Converting to a percentage should then just be: (total on fire / total area contained in area_array) * 100.
I'm totally lost on how I'd go about doing this though as I get a bit confused with 3D numpy arrays. Can anyone help?