0

I'm in need of some help.

I have some raw data relating to the wild fires in Australia.

The data is reported for a wide range of parameters each corresponding to a small piece (or grid square) of the earths surface. In the raw data the earth is divided up into 6.48 million grid squares defined by their latitude and longitude. As the earth is round the actual area of the grid square changes with latitude and so an area file also contains the corresponding area data. To keep file sizes small we have prefilterred the data so that it just contains results from the region containing Australia. The data are imported as a series of three-dimensional arrays representing date, latitude and longitude. The data include the following:

lat - latitude values in degrees

lon - longitude values in degrees

time - times as a date time object

total_combustion_rate - total combustion rate in kg m-2 s-1

I have imported this npz format into numpy arrays like so:

# import numpy
import numpy as np
data=np.load('australia.npz') # in the same folder as this project
lat = data['arr_0'] # latitude values
lon = data['arr_1'] # longitude values
time = data['arr_2'] # times
total_combustion_rate = data['arr_3'] # in kg m-2 s-1

The array size of total_combustion_rate is: 5425000 with the shape: (31, 350, 500) and of type: float32 The array size of lat is: 350 with the shape: (350,) and of type: float32 The array size of lon is: 500 with the shape: (500,) and of type: float32 The array size of time is: 31 with the shape: (31,) and of type: datetime64[ns]

I need to plot a graph with daily total combustion rate on the Y axis rate for:

Longitude > 141 degrees; latitude between -29 and -40 degrees

with time on the X axis.

Clearly, I need to filter my 3D numpy array of total_combustion_rate which has time, lat and lon in it but I'm totally lost.

Could I get some help/pointers?

1 Answers1

0

You should be able to do the filtering with numpy indexing:

res = total_combustion_rate[:, (lat > -40) & (lat < -29), lon > 141]

Note the single ampersand and parens.

In order to plot combustion against time you'll need to make a choice of how to combine data across lat/long, for example an average:

plt.scatter(time, np.average(res, axis=(1,2))

NOTE: I'm not sure this will work since I don't have access to the data and you haven't posted it. It is better to post a "minimum working example" with toy/example data.

stevemo
  • 947
  • 4
  • 9
  • Actually: I get [this plot](https://i.imgur.com/IWe17KB.png) On the X-axis, it shows the indexes of my data (0-30), but I want the days of January (1-31). Is there anyway I can fix that? Also, it seems to plot using a Seaborn theme despite me using plt.plot(). I have use Seaborn previously in my script though. – suckingalemon Apr 20 '20 at 01:07
  • You may consider converting to a `pandas.DataFrame` ... this is a separate question, [see here](https://stackoverflow.com/questions/20763012/creating-a-pandas-dataframe-from-a-numpy-array-how-do-i-specify-the-index-colum?noredirect=1&lq=1) and [here](https://stackoverflow.com/questions/59113331/is-there-a-way-to-convert-npz-files-to-panda-dataframe). Re: seaborn, [take a look at this post](https://stackoverflow.com/questions/25393936/how-can-i-use-seaborn-without-changing-the-matplotlib-defaults) about reverting to `matplotlib` defaults for older versions of seaborn. – stevemo Apr 20 '20 at 13:09