Skip to content

allow to_numpy conversion on typed output? #104

Open
@feefladder

Description

@feefladder

working on #103, solving #87, there were some ffi headaches which made me consider numpy. That's overly complex for the internal Rust part, but it occured to me that converting to numpy on the output would be rather ergonomic and best done in Rust (so in this crate). Currently what's in #103 (will be split in two, this issue is about a third PR, but influences those)

// src/raster_data.rs
pub enum RasterData {
  U8(Vec<u8>),
  U16(Vec<u16>),
  // ..etc
}

impl RasterData {
  fn from_predictor_info(info: PredictorInfo, ..) -> Self
}
// python/src/raster_data.rs
#[pyclass]
struct PyRasterData {
  inner: RasterData
}

#[pymethods]
impl PyRasterData {
  /// Convert this to a numpy array
  /// shape is: (didn't test yet)
  /// [`PlanarConfiguration::Chunky`]: (height, width, channels)
  /// [`PlanarConfiguration::Planar`]: (channels, height, width)
  fn to_numpy(width: u32/usize, height: u32/usize, planar_configuration: PlanarConfiguration) -> NumpyArray {
    // single match statement with trivial conversions to 1-d arrays

    // match on planarconfig and reshape the arrays
  }
}

What's slightly ugly in this api is that those width, height, planar_config are in Tile, but then lost at RasterData, requiring the user to keep those around. So the question is if we want a wrapping DecodedTile struct (maybe only in Python) like:

struct PyDecodedTile {
  data: RasterData,
  width: u32/usize, // whatever it is in Tile or numpy wants, probably usize
  height: u32/usize,
  planar_configuration: PlanarConfiguration
}

or, alternatively, a decode_tile_to_numpy python convenience function that has access to those values anyways - I think that's neat, is the extra dependency and maintenance burden worth it?

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