0

Hello for a project I am working , I need to get the data from a NetCDF file. The file was downloaded from here : https://ads.atmosphere.copernicus.eu/cdsapp#!/dataset/cams-europe-air-quality-forecasts?tab=form.

I have opened the file using python are read it's data, but as it's the first time I am working with this kind of file formats , I have no idea what the data is.

<xarray.Dataset>
Dimensions:    (longitude: 3, latitude: 2, level: 1, time: 72)
Coordinates:
  * longitude  (longitude) float32 21.85 21.95 22.05
  * latitude   (latitude) float32 47.05 46.95
  * level      (level) float32 0.0
  * time       (time) timedelta64[ns] 00:00:00 01:00:00 ... 2 days 23:00:00
Data variables:
    no2_conc   (time, level, latitude, longitude) float32 ...
Attributes:
    title:        NO2 Air Pollutant ANALYSIS at the Surface
    institution:  Data produced by CNRS
    source:       Data from CHIMERE model
    history:      Model CHIMERE ANALYSIS
    ANALYSIS:     Europe, 20210101-20210103+[0H_23H]
    summary:      CHIMERE model hourly ANALYSIS of NO2 concentration at the S...
    project:      MACC-RAQ (http://macc-raq.gmes-atmosphere.eu)

I need to retrieve the NO2 concentrations data ( no2_conc ). It says that it should have this format :

no2_conc   (time, level, latitude, longitude) float32

but when I list the no2_conc dataset I am getting this format :

no2_conc: <class 'numpy.ma.core.MaskedArray'>
no2_conc: [[[[14.050521850585938 13.868622779846191 13.541204452514648]
   [13.683085441589355 13.6248779296875 13.512101173400879]]]


 [[[11.958571434020996 11.823966026306152 11.554755210876465]
   [11.64934253692627 11.685722351074219 11.638428688049316]]]

Python is not my main coding language!

Have you used this type of file before ? If so , could you please , help me understand the format and how can I get the proper (no2_conc) data from it ?

Thank you!

alani
  • 12,573
  • 2
  • 13
  • 23
Collina
  • 33
  • 4
  • 1
    `(time, level, latitude, longitude)` is the shape of the array and `float32` is the type of each data element, but it is being returned in a numpy array. You also have the corresponding axis values in the variables `longitude`, `latitude` etc. What specifically are you wanting to do with the data? – alani Dec 04 '21 at 21:48
  • You also mention that Python is not your main coding language. You haven't said what you normally use, but note that there are interfaces to netCDF data in various languages if you would prefer to use something other than Python. – alani Dec 04 '21 at 21:51
  • Hi, Thank you very much for your quick reply! Well , I understand that part : no2_conc (time, level, latitude, longitude) float32 but for me , it conflicting with it's content : ``` [[[[14.050521850585938 13.868622779846191 13.541204452514648] [13.683085441589355 13.6248779296875 13.512101173400879]]] ``` Which is the time, the level , latitude and longitude ? In a table full of emission pollutant values, I have also 0 values. I need to match data from the NETCdf file to the missing values from my table.Matching based on the datetime (2021-11-24 14:54:00) Thank you! – Collina Dec 04 '21 at 21:54
  • 1
    xarray is not showing you the whole contents when you just do a print, but you can do the array manipulations you need in numpy (check a tutorial for working with numpy arrays), and when you need you can index it to obtain particular data values, e.g. index in the first dimension to select a particular time. The time values themselves are stored in the separate one-dimensional axis variables. – alani Dec 04 '21 at 21:58
  • C# is my main coding language! – Collina Dec 04 '21 at 22:00
  • 1
    More info here on how to index the variable to get the subset you need http://xarray.pydata.org/en/stable/user-guide/indexing.html . And here regarding getting coordinate values (these are in separate variables in the netCDF file but xarray knows that they are the coordinates for the variable, which makes it easier because you can get them via `coords` as explained here) https://stackoverflow.com/questions/43667105/extract-coordinate-values-in-xarray. – alani Dec 04 '21 at 22:05
  • I don't know anything about C# I'm afraid but it seems there is related discussion here if you need: https://stackoverflow.com/questions/60039/c-sharp-netcdf-library . Not one of the languages more commonly used with netCDF data, I guess. – alani Dec 04 '21 at 22:07
  • @collina check out xarray's [getting started](http://xarray.pydata.org/en/stable/getting-started-guide/index.html) guide. You're working with the right library within python, but we'll need a more specific question in order to help. I recommend going through the xarray tutorials and then asking another question once you've narrowed your issue. Good luck! – Michael Delgado Dec 05 '21 at 00:22
  • Hi, I finally found how to process these NETCDF file. I am leaving the the link here, maybe it will help somebody. Link : https://www.youtube.com/watch?v=hrm5RmsVXo0&ab_channel=GeoDeltaLabs => I highly recommend! Thank you very much for your help and quick replies! – Collina Dec 05 '21 at 18:40

0 Answers0