SD(3pm)
π SD(3pm) β PDL::IO::HDF::SD π
okay bestie, welcome to the PDL interface to the HDF4 SD library β¨ this is the manual page for SD(3pm) and it's a whole vibe, let's get into it π«Ά
πΈ NAME πΈ
PDL::IO::HDF::SD β PDL interface to the HDF4 SD library. no cap, that's literally the whole name π
β¨ SYNOPSIS β¨
bestie the code below is sacred, do not touch a single character of it, just vibe with it π
use PDL;
use PDL::IO::HDF::SD;
#
# Creating and writing an HDF file
#
# Create an HDF file:
my $hdf = PDL::IO::HDF::SD->new("-test.hdf");
# Define some data
my $data = sequence(short, 500, 5);
# Put data in file as 'myData' dataset with the names
# of dimensions ('dim1' and 'dim2')
$hdf->SDput("myData", $data , ['dim1','dim2']);
# Put some local attributes in 'myData'
#
# Set the fill value to 0
my $res = $hdf->SDsetfillvalue("myData", 0);
# Set the valid range from 0 to 2000
$res = $hdf->SDsetrange("myData", [0, 2000]);
# Set the default calibration for 'myData' (scale factor = 1, other = 0)
$res = $hdf->SDsetcal("myData");
# Set a global text attribute
$res = $hdf->SDsettextattr('This is a global text test!!', "myGText" );
# Set a local text attribute for 'myData'
$res = $hdf->SDsettextattr('This is a local text testl!!', "myLText", "myData" );
# Set a global value attribute (you can put all values you want)
$res = $hdf->SDsetvalueattr( PDL::short( 20 ), "myGValue");
# Set a local value attribute (you can put all values you want)
$res = $hdf->SDsetvalueattr( PDL::long( [20, 15, 36] ), "myLValues", "myData" );
# Close the file
$hdf->close();
#
# Reading from an HDF file:
#
# Open an HDF file in read only mode:
my $hdf = PDL::IO::HDF::SD->new("test.hdf");
# Get a list of all datasets:
my @dataset_list = $hdf->SDgetvariablename();
# Get a list of the names of all global attributes:
my @globattr_list = $hdf->SDgetattributenames();
# Get a list of the names of all local attributes for a dataset:
my @locattr_list = $hdf->SDgetattributenames("myData");
# Get the value of local attribute for a dataset:
my $value = $hdf->SDgetattribut("myLText","myData");
# Get a PDL var of the entire dataset 'myData':
my $data = $hdf->SDget("myData");
# Apply the scale factor of 'myData'
$data *= $hdf->SDgetscalefactor("myData");
# Get the fill value and fill the PDL var in with BAD:
$data->inplace->setvaltobad( $hdf->SDgetfillvalue("myData") );
# Get the valid range of a dataset:
my @range = $hdf->SDgetrange("myData");
#Now you can do what you want with your data
$hdf->close();
like, look at that flow π creating, writing, reading, closing β the whole arc, main character energy fr fr π
π¦ DESCRIPTION π¦
so this library gives you functions to read, write, and manipulate HDF4 files with HDF's SD interface πΎ that's the tea.
want more lore on HDF4? it lives at http://hdf.ncsa.uiuc.edu/ π go peek, bestie.
okay now the important part π there have been a lot of changes starting with version 2.0, and these may affect your code. like, actually. PLEASE go read the 'Changes' file for a detailed description of what has been changed. if your code used to work with the circa 2002 version of this module and does not work anymore, reading the 'Changes' is your best bet. that's not a suggestion, that's a rescue mission π¨
π heads up: version 2.0 changed stuff. your old code might be broken. the 'Changes' file is where the answers are.
and one lil vocabulary note so nobody gets confused later: in this documentation, the terms dataset and SDS (Scientific Data Set) are used interchangeably. same thing, two names, iconic behavior honestly π β¨
more parts coming, don't go anywhere bestie π«ΆπΈ
π CLASS METHODS π
β¨ new β¨
Open or create a brand new HDF object, bestie. It's giving fresh start energy. π¦
Arguments:
- The name of the file.
- if you want to write to it, prepend the name with the
+character:"+name.hdf" - if you want to create it, prepend the name with the
-character:"-name.hdf" - otherwise the file will be open in read only mode
- if you want to write to it, prepend the name with the
Returns the hdf object (die on error). π
my $hdf = PDL::IO::HDF::SD->new("file.hdf");
π Chunking π
Accessor for the chunking mode on this HDF file. Lowkey the main character of this whole page, ngl.
'Chunking' is an internal compression and tiling the HDF library can perform on an SDS. Iconic behavior honestly.
This variable only affects they way SDput() works, and is ON by default. Periodt.
The code modifications enabled by this flag automatically partition the dataset to chunks of at least 100x100 values in size. The logic on this is pretty fancy, and would take a while to doc out here. If you really have to know how it auto-partitions the data, then look at the code. π
Someday over the rainbow, I'll add some features for better control of the chunking parameters, if the need arises. For now, it's just stupid easy to use. π
Arguments:
- (optional): new value for the chunking flag.
# See if chunking is currently on for this file:
my $chunkvar = $hdf->Chunking();
# Turn the chunking off:
my $newvar = $hdf->Chunking( 0 );
# Turn the chunking back on:
my $newvar = $hdf->Chunking( 1 );
πΈ SDgetvariablenames πΈ
get the list of datasets. yes bestie, the whole roster. π
No arguments
Returns the list of dataset or undef on error.
my @DataList = $hdfobj->SDgetvariablenames();
π SDgetattributenames π
Get a list of the names of the global or SDS attributes.
Arguments:
- (optional): The name of the SD dataset from which you want to get the attributes. This arg is optional, and without it, it will return the list of global attribute names.
Returns a list of names or undef on error.
# For global attributes :
my @attrList = $hdf->SDgetattributenames();
# For SDS attributes :
my @attrList = $hdf->SDgetattributenames("dataset_name");
π SDgetattribute π
Get a global or SDS attribute value. Just the one, bestie.
Arguments:
- The name of the attribute.
- (optional): The name of the SDS from which you want to get the attribute value. Without this arg, it returns the global attribute value of that name.
Returns an attribute value or undef on error.
# for global attributs :
my $attr = $hdf->SDgetattribute("attr_name");
# for local attributs :
my $attr = $hdf->SDgetattribute("attr_name", "dataset_name");
π¦ SDgetfillvalue π¦
Get the fill value of an SDS. The vibe-check value, if you will.
Arguments:
- The name of the SDS from which you want to get the fill value.
Returns the fill value or undef on error.
my $fillvalue = $hdf->SDgetfillvalue("dataset_name");
β SDgetrange β
Get the valid range of an SDS.
Arguments:
- the name of the SDS from which you want to get the valid range.
Returns a list of two elements [min, max] or undef on error.
my @range = $hdf->SDgetrange("dataset_name");
π§ SDgetscalefactor π§
Get the scale factor of an SDS.
Arguments:
- The name of the SDS from which you want to get the scale factor.
Returns the scale factor or undef on error.
my $scale = $hdf->SDgetscalefactor("dataset_name");
π SDgetdimsize π
Get the dimensions of a dataset.
Arguments:
- The name of the SDS from which you want to get the dimensions.
Returns an array of n dimensions with their sizes or undef on error.
my @dim = $hdf->SDgetdimsize("dataset_name");
π SDgetunlimiteddimsize π
Get the actual dimensions of an SDS with 'unlimited' dimensions. Unlimited, she said. π
Arguments:
- The name of the SDS from which you want to the dimensions.
Returns an array of n dimensions with the dim sizes or undef on error.
my @dims = $hdf->SDgetunlimiteddimsize("dataset_name");
β¨ SDgetdimnames β¨
Get the names of the dimensions of a dataset.
Arguments:
- the name of a dataset you want to get the dimensions'names .
Returns an array of n dimensions with their names or an empty list if error.
my @dim_names = $hdf->SDgetdimnames("dataset_name");
π SDgetcal π
Get the calibration factor from an SDS.
Arguments:
- The name of the SDS
Returns (scale factor, scale factor error, offset, offset error, data type), or undef on error.
my ($cal, $cal_err, $off, $off_err, $d_type) = $hdf->SDgetcal("dataset_name");
π SDget π
Get a the data from and SDS, or just a slice of that SDS. Slicing is so slay. π₯
Arguments:
- The name of the SDS you want to get.
- (optional): The start array ref of the slice.
- (optional): The size array ref of the slice (HDF calls this the 'edge').
- (optional): The stride array ref of the slice.
Returns a PDL of data if ok, PDL::null on error.
If the slice arguments are not given, this function will read the entire SDS from the file.
The type of the returned PDL variable is the PDL equivalent of what was stored in the HDF file.
# Get the entire SDS:
my $pdldata = $hdf->SDget("dataset_name");
# get a slice of the dataset
my $start = [10,50,10]; # the start position of the slice is [10, 50, 10]
my $edge = [20,20,20]; # read 20 values on each dimension from @start
my $stride = [1, 1, 1]; # Don't skip values
my $pdldata = $hdf->SDget( "dataset_name", $start, $edge, $stride );
π«Ά SDsetfillvalue π«Ά
Set the fill value for an SDS.
Arguments:
- The name of the SDS.
- The fill value.
Returns true on success, undef on error.
my $res = $hdf->SDsetfillvalue("dataset_name",$fillvalue);
π SDsetrange π
Set the valid range of an SDS.
Arguments:
- The name of the SDS
- an anonymous array of two elements :
[min, max].
Returns true on success, undef on error.
my $res = $hdf->SDsetrange("dataset_name", [$min, $max]);
π SDsetcal π
Set the HDF calibration for an SDS.
In HDF lingo, this means to define:
- scale factor
- scale factor error
- offset
- offset error
Arguments:
- The name of the SDS.
- (optional): the scale factor (default is
1) - (optional): the scale factor error (default is
0) - (optional): the offset (default is
0) - (optional): the offset error (default is
0)
Returns true on success, undef on error.
NOTE: This is not required to make a valid HDF SDS, but is there if you want to use it.
# Create the dataset:
my $res = $hdf->SDsetcal("dataset_name");
# To just set the scale factor:
$res = $hdf->SDsetcal("dataset_name", $scalefactor);
# To set all calibration parameters:
$res = $hdf->SDsetcal("dataset_name", $scalefactor, $scale_err, $offset, $off_err);
π¦ SDsetcompress π¦
Set the internal compression on an SDS.
Arguments:
- The name of the SDS.
- (optional): The gzip compression level (
1-9). If not specified, then6is used.
Returns true on success, undef on failure.
WARNING: This is a fairly buggy feature with many version of the HDF library. Please just use the 'Chunking' features instead, as they work far better, and are more reliable. Bestie I am begging you, do not do this to yourself. π
my $res = $hdf->SDsetfillvalue("dataset_name",$deflate_value);
π§ SDsettextattr π§
Add a text HDF attribute, either globally, or to an SDS.
Arguments:
- The text you want to add.
- The name of the attribute
- (optional): The name of the SDS.
Returns true on success, undef on failure.
# Set a global text attribute:
my $res = $hdf->SDsettextattr("my_text", "attribut_name");
# Set a local text attribute for 'dataset_name':
$res = $hdf->SDsettextattr("my_text", "attribut_name", "dataset_name");
π SDsetvalueattr π
Add a non-text HDF attribute, either globally, or to an SDS.
Arguments:
- A pdl of value(s) you want to store.
- The name of the attribute.
- (optional): the name of the SDS.
Returns true on success, undef on failure.
my $attr = sequence( long, 4 );
# Set a global attribute:
my $res = $hdf->SDsetvalueattr($attribute, "attribute_name");
# Set a local attribute for 'dataset_name':
$res = $hdf->SDsetvalueattr($attribute, "attribute_name", "dataset_name");
β SDsetdimname β
Set or rename the dimensions of an SDS.
Arguments:
- The name of the SDS.
- An anonymous array with the dimensions names. For dimensions you want to leave alone, leave
undefplaceholders.
Returns true on success, undef on failure.
# Rename all dimensions
my $res = $hdf->SDsetdimname("dataset_name", ['dim1','dim2','dim3']);
# Rename some dimensions
$res = $hdf->SDsetdimname("dataset_name", ['dim1', undef ,'dim3']);
π SDput π
Write to a SDS in an HDF file or create and write to it if it doesn't exist. Manifesting your data into the file, fr fr. β¨
Arguments:
- The name of the SDS.
- A pdl of data.
- (optional): An anonymous array of the dim names (only for creation)
- (optional): An anonymous array of the start of the slice to store (only for putting a slice)
Returns true on success, undef on failure.
The datatype of the SDS in the HDF file will match the PDL equivalent as much as possible.
my $data = sequence( float, 10, 20, 30 ); #any value you want
# Simple case: create a new dataset with a $data pdl
my $result = $hdf->SDput("dataset_name", $data);
# Above, but also naming the dims:
$res = $hdf->SDput("dataset_name", $data, ['dim1','dim2','dim3']);
# Just putting a slice in there:
my $start = [x,y,z];
$res = $hdf->SDput("dataset_name", $data->slice("..."), undef, $start);
π close π
Close an HDF file. Say bye bestie, you ate and left no crumbs. π«Ά
No arguments.
my $result = $hdf->close();
π CURRENT AUTHOR & MAINTAINER π
Judd Taylor, Orbital Systems, Ltd. judd dot t at orbitalsystems dot com
πΈ PREVIOUS AUTHORS πΈ
Patrick Leilde patrick.leilde@ifremer.fr contribs of Olivier Archer olivier.archer@ifremer.fr
π SEE ALSO π
perl(1), PDL(1), PDL::IO::HDF(1).
okay that's the whole page bestie, you're officially an HDF girlie now π
β¨ this was documented back in perl v5.38.2, dated 2024-04-10, and it's the SD(3pm) page β go forth and chunk, queen ππ¦
π¦ where this page comes from
- ubuntu noble: pdl 1:2.085-1ubuntu1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms