Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

WIP: New cube type#181

Merged
meggart merged 46 commits intomasterJuliaDataCubes/EarthDataLab.jl:masterfrom
NewCubeTypeJuliaDataCubes/EarthDataLab.jl:NewCubeTypeCopy head branch name to clipboard
Dec 7, 2020
Merged

WIP: New cube type#181
meggart merged 46 commits intomasterJuliaDataCubes/EarthDataLab.jl:masterfrom
NewCubeTypeJuliaDataCubes/EarthDataLab.jl:NewCubeTypeCopy head branch name to clipboard

Conversation

@meggart
Copy link
Copy Markdown
Member

@meggart meggart commented Feb 18, 2020

This is work in progress and prepares ESDL to be used in a wider context and on a variety of input formats. Here, we removed the different data cube types that existed so far and only provide a single ESDLArray on which Cube operations can happen. This data type contains the field data which can be any AbstractArray including Julia Arrays or DiskArrays. All lazy operations that existed so far, like permutedims, views, concatenation will happen on the data level now and not create an extra Cube type.

The current unit tests are passing, but experience says that this package is unfortunately under-tested, so there will still be bugs to find (and unit-tests to be added). @felixcremer maybe you want to give this branch a try and report what works and what doesn't for you?

@meggart
Copy link
Copy Markdown
Member Author

meggart commented Feb 18, 2020

Just forgot to mention we need the permute_reshape branch of DiskArrays.jl

@felixcremer
Copy link
Copy Markdown
Member

I can try this tomorrow.

@felixcremer
Copy link
Copy Markdown
Member

If I try cubefromshape, I get the following error:

julia> oldcube=cubefromshape(oldpath, trend_emd)
ERROR: MethodError: no method matching rasterizepoly!(::Array{Int32,2}, ::Array{Union{Missing, Shapefile.Polygon},1}, ::NamedTuple{(:left, :right, :top, :bottom),NTuple{4,Float64}})
Closest candidates are:
  rasterizepoly!(::Any, ::Array{#s86,1} where #s86<:GeoInterface.AbstractMultiPolygon, ::Any) at /home/crem_fe/.julia/packages/ESDL/lS3UG/src/Proc/Shapes.jl:137
  rasterizepoly!(::Any, ::Array{T<:GeoInterface.AbstractPoint,1}, ::Any; value, wrap) where T<:GeoInterface.AbstractPoint at /home/crem_fe/.julia/packages/ESDL/lS3UG/src/Proc/Shapes.jl:144
  rasterizepoly!(::Any, ::Shapefile.Polygon, ::Any; value) at /home/crem_fe/.julia/packages/ESDL/lS3UG/src/Proc/Shapes.jl:181
Stacktrace:
 [1] #rasterize!#27(::NamedTuple{(:left, :right, :top, :bottom),NTuple{4,Float64}}, ::Nothing, ::typeof(ESDL.Proc.rasterize!), ::Array{Int32,2}, ::String) at /home/crem_fe/.julia/packages/ESDL/lS3UG/src/Proc/Shapes.jl:130
 [2] (::getfield(ESDL.Proc, Symbol("#kw##rasterize!")))(::NamedTuple{(:bb,),Tuple{NamedTuple{(:left, :right, :top, :bottom),NTuple{4,Float64}}}}, ::typeof(ESDL.Proc.rasterize!), ::Array{Int32,2}, ::String) at ./none:0
 [3] #cubefromshape_single#20(::Nothing, ::Type, ::typeof(ESDL.Proc.cubefromshape_single), ::String, ::RangeAxis{Float64,:Lon,StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}, ::RangeAxis{Float64,:Lat,StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}) at /home/crem_fe/.julia/packages/ESDL/lS3UG/src/Proc/Shapes.jl:85
 [4] cubefromshape_single(::String, ::RangeAxis{Float64,:Lon,StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}, ::RangeAxis{Float64,:Lat,StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}) at /home/crem_fe/.julia/packages/ESDL/lS3UG/src/Proc/Shapes.jl:81
 [5] #cubefromshape#22(::Nothing, ::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(cubefromshape), ::String, ::Vararg{Any,N} where N) at /home/crem_fe/.julia/packages/ESDL/lS3UG/src/Proc/Shapes.jl:106
 [6] cubefromshape at /home/crem_fe/.julia/packages/ESDL/lS3UG/src/Proc/Shapes.jl:105 [inlined]
 [7] #cubefromshape#21 at /home/crem_fe/.julia/packages/ESDL/lS3UG/src/Proc/Shapes.jl:103 [inlined]
 [8] cubefromshape(::String, ::ESDL.Cubes.ConcatCube{Union{Missing, Float32},3}) at /home/crem_fe/.julia/packages/ESDL/lS3UG/src/Proc/Shapes.jl:103
 [9] top-level scope at REPL[19]:1

I can load a cube and I can subset it.
I am going to test actual computations next week.

@felixcremer
Copy link
Copy Markdown
Member

I just made a few tests and my normal computations work.

@meggart
Copy link
Copy Markdown
Member Author

meggart commented Feb 24, 2020

I will have a look at what happens in cubefromshape

@felixcremer
Copy link
Copy Markdown
Member

Exporting the data into netcdf goes through, but the resulting netcdf file is not readable in QGIS, therefore, I can't check, whether the computations are doing what I expect.

@meggart
Copy link
Copy Markdown
Member Author

meggart commented Mar 4, 2020

@felixcremer the cubefromshape bug should be fixed now. What is the exact reason that you can not read the data in QGIS, which metadata is missing?

@felixcremer
Copy link
Copy Markdown
Member

Thanks, the cubefrom shape is fixed.
I have no idea, what is missing in the netcdf. I only get an

Invalid Data Source: /home/crem_fe/Daten/newcube_test.nc is not a valid or recognized data source.

and also opening it with gdalinfo doesn't work. I don't know enough about netcdf internals to debug this.
You can find the file I generated for a month under the following link:
https://upload.uni-jena.de/data/5e61194eef7363.49610469/newcube_test.nc

Comment thread src/Proc/CubeIO.jl Outdated
import ..Cubes.ESDLZarr: ZArrayCube
using Base.Iterators: Iterators, product
using Zarr: ZArray, NoCompressor
using NetCDF: ncwrite, NcDim, NcVar, ncread, create, nccreate, ncputatt
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add NetCDF after the : so that we can use NetCDF.close later on, we need to do it like that, so that it doesn't name clash with Base.close

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

Comment thread src/Proc/CubeIO.jl Outdated
cont_loop = Dict(ii=>axname(ax_cont[ii]) for ii in isplit:length(ax_cont))
mapCube(writefun,r,length(ax_cont),cont_loop,filename,indims=incubes,include_loopvars=true,ispar=false,max_cache=5e8,
nthreads=[1])
NetCDF.close(file)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should be restored, because this caused the problems with the exported NetCDF files.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depends on your NetCDF branch. I was testing on this meggart/NetCDF.jl#119 , but I agree that we should call sync here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure, whether I tested the right branches, but using the finalizer branch of NetCDF doesn't solve the opening problem of the exported nc files.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, this is strange. Does a call to NetCDF.sync() help in this case?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling sync(file) doesn't help. the _close function is called six times in my example, but the file is only readable in QGIS when I close julia.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will do some more experiments to find out what is happening. I just realize there is a mixture high-level and low-level access going on here, which might be bad. WIll change this

@felixcremer
Copy link
Copy Markdown
Member

If I try to export cubes with two categorical axes, this fails on this branch but works on master.
This is both on the finalizer branch of NetCDF and also on the recent release.
This is the stacktrace:

ERROR: MethodError: no method matching push!(::Array{NetCDF.NcVar,2}, ::NetCDF.NcVar{Float64,1,6})
Closest candidates are:
  push!(::Any, ::Any, ::Any) at abstractarray.jl:2159
  push!(::Any, ::Any, ::Any, ::Any...) at abstractarray.jl:2160
  push!(::Array{Any,1}, ::Any) at array.jl:875
  ...
Stacktrace:
 [1] #create#40(::Dict{Any,Any}, ::UInt16, ::Bool, ::typeof(NetCDF.create), ::String, ::Array{NetCDF.NcVar,2}) at /home/crem_fe/.julia/dev/NetCDF/src/NetCDF.jl:804
 [2] create(::String, ::Array{NetCDF.NcVar,2}) at /home/crem_fe/.julia/dev/NetCDF/src/NetCDF.jl:768
 [3] #exportcube#14(::Dict{String,Int64}, ::Dict{String,Any}, ::typeof(exportcube), ::ESDL.Cubes.ESDLArray{Union{Missing, Float32},4,ESDL.Cubes.DiskArrayStack{Union{Missing, Float32},4,Zarr.ZArray{Union{Missing, Float32},3,Zarr.NoCompressor,Zarr.DirectoryStore},1},Array{CubeAxis,1}}, ::String) at /home/crem_fe/.julia/dev/ESDL/src/Proc/CubeIO.jl:91
 [4] exportcube(::ESDL.Cubes.ESDLArray{Union{Missing, Float32},4,ESDL.Cubes.DiskArrayStack{Union{Missing, Float32},4,Zarr.ZArray{Union{Missing, Float32},3,Zarr.NoCompressor,Zarr.DirectoryStore},1},Array{CubeAxis,1}}, ::String) at /home/crem_fe/.julia/dev/ESDL/src/Proc/CubeIO.jl:81
 [5] top-level scope at REPL[5]:1

You can find an example cube here:
https://upload.uni-jena.de/data/5e67fbadeed588.73983617/hidalgo_stats.zip

Copy link
Copy Markdown
Member

@felixcremer felixcremer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you have a look at the saving problems with multiple categorical axes?

Comment thread Project.toml Outdated
Comment thread src/Cubes/Cubes.jl Outdated
Comment thread src/Cubes/Cubes.jl Outdated
Comment thread src/Cubes/Cubes.jl Outdated
Comment thread src/Cubes/Cubes.jl Outdated
Comment thread src/Cubes/Cubes.jl Outdated
common_offset(a::DiskArrays.GridChunks) = a.offset
function common_offset(a)
ntuple(ndims(a)) do idim
otherdims = setdiff(1:ndims(a),idim)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we combine this with the start of the common_size function into one helper function?

Comment thread src/Cubes/TransformedCubes.jl Outdated
isempty(newperm) ? subscube : permutedims(subscube,(newperm...,))

function Base.map(op, incubes::AbstractCubeData...)
axlist=copy(caxes(incubes[1]))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the copy here? This is not going to be changed in the following code?

Comment thread src/Cubes/TransformedCubes.jl Outdated
Comment thread src/Proc/CubeIO.jl Outdated
cont_loop = Dict(ii=>axname(ax_cont[ii]) for ii in isplit:length(ax_cont))
mapCube(writefun,r,length(ax_cont),cont_loop,filename,indims=incubes,include_loopvars=true,ispar=false,max_cache=5e8,
nthreads=[1])
NetCDF.close(file)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure, whether I tested the right branches, but using the finalizer branch of NetCDF doesn't solve the opening problem of the exported nc files.

Comment thread src/Cubes/TransformedCubes.jl Outdated
Felix Cremer and others added 27 commits April 6, 2020 13:26
This doesn't solve the test failure because some readblock! method is
still missing.
I also changed the import Zarr to using Zarr: ... and sorted the imports
into types and functions which are sorted alphabetically.
Wrap is a keyword which is projection specific and which gives the
projection value at which the projection wraps into itself.
The default values fail for non Lat Lon projections.
Therefore, this makes the keyword available in the cubefromshape
interface.
This is an intermediate solution, because it would be better to have the
projection as a metadata information of a cube, so that we could use
this to set the wrapping values.
This reverts commit 6e778a2.
Unfortunately, this pull request was not yet ready.
I should have indicated that more clearly.
I am reverting this for now and then I am going to push a tidied up
version of the PR.
Clone is the keyword from the old package manger.
* Removed a lot of files

* move some files

* break more things

* Clean up Proc module

* Many fixes to get dataset creation running again

* savecube to netcdf works

* more improvements

* Commit many more changes

* Separate out API

* some test fixes

* switch to YAXArrayBase

* read variables in a typed way

* add ESDLArray export

* Fixes to remap

* remove NetCDF and Zarr dependency

* delete some unused stuff

* Do not permute cubes by default

* Add concatenations

* Fixes to findaxis

* Tests pass again

* Try to fix chunking

* dont depend on reexport

* remove reexport dep

* dont forgegt using it

* update test

* Allow NamedTuples

* minor changes

* Finalsplit (#220)

* Delete almost everything

* More updates

* Old tests for ESDL pass

* More changes

* Fix bugs in ESDL

* Some fixes

* Fix some warnings

* tests should pass
* Removed a lot of files

* move some files

* break more things

* Clean up Proc module

* Many fixes to get dataset creation running again

* savecube to netcdf works

* more improvements

* Commit many more changes

* Separate out API

* some test fixes

* switch to YAXArrayBase

* read variables in a typed way

* add ESDLArray export

* Fixes to remap

* remove NetCDF and Zarr dependency

* delete some unused stuff

* Do not permute cubes by default

* Add concatenations

* Fixes to findaxis

* Tests pass again

* Try to fix chunking

* dont depend on reexport

* remove reexport dep

* dont forgegt using it

* update test

* Allow NamedTuples

* minor changes

* Finalsplit (#220)

* Delete almost everything

* More updates

* Old tests for ESDL pass

* More changes

* Fix bugs in ESDL

* Some fixes

* Fix some warnings

* tests should pass
@meggart meggart merged commit decc64b into master Dec 7, 2020
@meggart meggart deleted the NewCubeType branch March 17, 2021 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.