Deriving the exact grid coordinates (Lat/Lon) of the data cube


#1

Hallo,

after implementing my complete work-flow in R, I will now start translating everything to JULIA. In order to do this, one of my first steps is to extract my reference variables from a dataset that I have offline. At a later stage, I might try to integrate this dataset also in the datacube but for the moment, I would just like to prepare this locally.

So, my strategy to was to first derive the grid coordinates of the datacube and then create my own polygon-shapefile with polygons matching the grid-cells of the data-cube.

One of my earlier attempts was this:

tair = getCubeData(c,variable=“air_temperature_2m”, longitude = (70,108), **
** latitude = (25, 40),)

Data Cube view with the following dimensions
Lon Axis with 152 Elements from 70.125 to 107.875
Lat Axis with 60 Elements from 39.875 to 25.125
Time Axis with 506 Elements from 2001-01-01 to 2011-12-27
Total size: 22.0 MB

z = tair.lonAxis

z

Lon Axis with 152 Elements from 70.125 to 107.875

writecsv(“lon.dat”, z)

MethodError: no method matching start(::ESDL.Cubes.Axes._RangeAxis{Float64,:Lon,StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}})
Closest candidates are:
start(::SimpleVector) at essentials.jl:258
start(::Base.MethodList) at reflection.jl:560
start(::ExponentialBackOff) at error.jl:107

Stacktrace:
[1] #writedlm#18(::Array{Any,1}, ::Function, ::IOStream, ::ESDL.Cubes.Axes._RangeAxis{Float64,:Lon,StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}, ::Char) at ./datafmt.jl:673
[2] #20 at ./datafmt.jl:683 [inlined]
[3] open(::Base.DataFmt.##20#21{Array{Any,1},ESDL.Cubes.Axes._RangeAxis{Float64,:Lon,StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}},Char}, ::String, ::String) at ./iostream.jl:152
[4] #writecsv#23(::Array{Any,1}, ::Function, ::String, ::ESDL.Cubes.Axes._RangeAxis{Float64,:Lon,StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}) at ./datafmt.jl:705
[5] writecsv(::String, ::ESDL.Cubes.Axes._RangeAxis{Float64,:Lon,StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}) at ./datafmt.jl:705
[6] include_string(::String, ::String) at ./loading.jl:522

I wanted to try out some more right now, but at the moment I get an error message right from the start (I used the same code I used before, so I am quite sure that it should not be a problem of my computer or the code):

So again a summary of my questions:

  1. How can I export the Lat/Lon values for the individual grid cells of the data cube to use them offline - plus another question: Are the given Lat/Lon values the centers of the grid, or the upper right corner or … ?

  2. What about the error message appearing right at the start?

Thanks! I will have more question in the next days, while translating my R-project to JULIA.

Best wishes,

Fabian


#2

AH - I just saw the announcement concerning the JULIA kernel and the updated example - I assume this will resolve the problem related to error. So this just leaves the question concerning the Lat/Lon values.

Sorry for not checking announcements before.


#3

I think the simplest way to extract the coordinate values from a cube is to first extract the axis and then extract the values like this:

using ESDL
c = Cube()
d = d = subsetcube(c, variable = ["net_ecosystem_exchange","terrestrial_ecosystem_respiration","gross_primary_productivity"])
time_ax = getAxis("Time",d)
time_ax.values

returns:

1702-element Array{Date,1}:
 1980-01-05
 1980-01-13
 1980-01-21
 1980-01-29
 1980-02-06
 1980-02-14
 1980-02-22
 1980-03-01
 1980-03-09
 1980-03-17
 1980-03-25
 1980-04-02
 1980-04-10
 ⋮         
 2016-10-03
 2016-10-11
 2016-10-19
 2016-10-27
 2016-11-04
 2016-11-12
 2016-11-20
 2016-11-28
 2016-12-06
 2016-12-14
 2016-12-22
 2016-12-30

so I think the missing part was to access the values field of the axis. Hope this helps…


#4

I have now finally found the time to check this and it works fine. Thanks! However, I just saw that the other question was not answered - so I ask again:

Do the Lat/Lon values indicate the center of the pixels or the upper left/lower right corner? This is important for me as I will use the corresponding grid to extract additional values from my own dataset.


#5

ok - I have now found out that the lat/lon values stored in the cube are the coordinates of the center of the grid cells. In case anyone else requires this information.

I found out by exporting a kml-file based on the lat/lon values and additionally a map of one of the variables for the same region.

this resulted in the following:

grid_center