Skip to content

Is there a way to retrieve type from file? #290

@alex-s-gardner

Description

@alex-s-gardner

I realize that reading from a netcdf is not not type-stable:
https://juliageo.org/NCDatasets.jl/stable/performance/#performance_tips

When using NCDatasets I typically identify the variable type by asserting an incorrect type and letting typeassert correct me as to what the true type is:

My workflow looks like this:

  using NCDatasets
  using Downloads
  path2nc = "https://people.sc.fsu.edu/~jburkardt/data/netcdf/part.nc"
  path2nc = Downloads.download(path2nc)
  ds = NCDataset(path2nc)
  
  B = ds["Tetrahedron_Vertex"][:,:]:: Array{Float64, 2};
  ERROR: TypeError: in typeassert, expected Matrix{Float64}, got a value of type Matrix{Int32}
  Stacktrace:
   [1] macro expansion
     @ ./timing.jl:689 [inlined]
    B = ds["Tetrahedron_Vertex"][:,:]::Matrix{Int32}

The type assertion error is returned instantly where as loading a large NC file without typeassetion can take a very long time.

Having to manually assert the type is rather cumbersome for more generic code.

This makes me think that there must be a way to quickly retrieve the type from the file before reading, if non is provided by the user. I'm sure this has been explored and I'm just wondering what the reasons are for no implementing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions