0

how are you doing?

I have been working on this for quite a while now, but I am not able to proceed any further. I was given .nc Files with Cloud Based Altitudes (CBA are measurements to indicate the height of clods for a particular area).

For now I am not even able to extract Data for a single Coordinate. This Data contains the area shown in this picture, from the top left to the bottom right:

Area contained in Data

Here is a screenshot of the data I am working with:

enter image description here

Sorry that I can not provide more Data than that, but I don't want to get in trouble.

The cba value is the information I want to extract. So let's say I have a set of coordinates (longitude/latitude) of an area I am interested in, how would I be able to get the appropriate cba values?

I don't need a specific solution, but a direction so I can continue on my own.

For additional information this is how the .cba and .cba.values look:

enter image description here

I have been working with data like that before, but not this nested, so I have absolutely no idea how I can even approach that. Is there a module/package in python which would allow me to easily handle this, so when I put in coordinates for an area it would directly give me the corresponding cba-values?

I hope that is enough information to go on and you can help me, I would really appreciate it.

Regards

1 Answer 1

2

The package you are using (xarray) is already perfectly suited for this task.

dObj is an xarray.Dataset object, each contained variable (such as dObj['cba']) is an xarray.DataArray object.

You can access the data at a given set of coordinates like this:

lat = ...
lon = ...
dObj['cbd'].sel(y=lat, x=lon, method='nearest')

method='nearest' is needed as your coordinate array is unlikely to contain the requested floating point values exactly.

If you instead want to select a range of latitudes and longitudes you can do that as follows:

lat_min, lat_max = (...)
lon_min, lon_max = (...)
dObj['cbd'].sel(y=slice(lat_min, lat_max), x=slice(lon_min, lon_max))

For more information about dealing with xarray objects, have a look at the very comprehensive documentation: http://xarray.pydata.org/en/stable/index.html

Sign up to request clarification or add additional context in comments.

5 Comments

Holy shit, thank you SOOOOOO MUCH. This is EXACTLY what I needed. Oh man I have been working with python for quite a while now, but there is so much I don't yet know and understand. Thank you again.
Hey Jhansen, I have a follow up question. Is it possible to find out which coordinates have been selected when using this function -> dObj['cbd'].sel(y=lat, x=lon, method='nearest') I would like to check some things and need to know how far they are apart and which coordinates have been used.
@Medhusalem Sure, once you have selected the subset you can simply access the .coords attribute of the DataArray to check the x and y coordinate arrays: dObj['cbd'].sel(..).coords.
Ah thank you very much for the answer, I have just figure out that this approach "dObj['cbd'].sel(y=lat, x=lon, method='nearest')" will not really work out for me. Since y and x coordinates are some weird UTM Format. What I really need are the informations contained in the variables longitude and latitude but since they are 2Dimensional, when I use: dObj['cbd'].sel(latitude=lat, longitude=lon, method='nearest') I get an error ValueError: dimensions or multi-index levels ['latitude', 'longitude'] do not exist. It is really starting to get frustrating...
Yes, if you want to select by latitude and longitude but your data is in a different projection then you either have to convert your lat and lon values into the data CRS before using .sel(), or reproject the entire dataset into EPSG:4326 (i.e. lat-lon coordinates)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.