Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tom Rink
python
Commits
a83e34b3
Commit
a83e34b3
authored
10 months ago
by
tomrink
Browse files
Options
Downloads
Patches
Plain Diff
snapshot...
parent
c10b0129
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/util/hdf5_conversion.py
+5
-12
5 additions, 12 deletions
modules/util/hdf5_conversion.py
with
5 additions
and
12 deletions
modules/util/hdf5_conversion.py
+
5
−
12
View file @
a83e34b3
...
...
@@ -2,6 +2,7 @@ import h5py
import
numpy
as
np
import
pandas
as
pd
import
random
import
os
def
hdf5_to_npz_csv
(
hdf5_filename
,
output_file_prefix
,
chunk_size
=
10000
):
...
...
@@ -14,17 +15,9 @@ def hdf5_to_npz_csv(hdf5_filename, output_file_prefix, chunk_size=10000):
output_file_prefix (str): Prefix for the output NPZ and CSV files.
chunk_size (int): Size of chunks to process at once (default is 1000).
"""
# Get the directory from hdf5_filename
dirpath
=
os
.
path
.
dirname
(
hdf5_filename
)
# # New step: keep only 10 mask values == True
# mask_indices = list(np.nonzero(mask)[0])
# if len(mask_indices) > 10:
# selected_indices = random.sample(mask_indices, 10)
# new_mask = np.zeros(mask.size).astype(np.bool)
# new_mask[selected_indices] = True
# mask = new_mask
# keep_array.append(data[mask])
# Step 1: Open HDF5 file
with
h5py
.
File
(
hdf5_filename
,
"
r
"
)
as
file
:
fov_mask
=
np
.
asarray
(
file
[
"
FOV_mask
"
])
# these are 1D arrays that we'll broadcast from below
...
...
@@ -85,9 +78,9 @@ def hdf5_to_npz_csv(hdf5_filename, output_file_prefix, chunk_size=10000):
df
=
pd
.
DataFrame
(
combined_dict
)
# Write the DataFrame to a file
df
.
to_csv
(
f
"
{
output_file_prefix
}
_1D.csv
"
,
index
=
False
)
df
.
to_csv
(
os
.
path
.
join
(
dirpath
,
f
"
{
output_file_prefix
}
_1D.csv
"
)
,
index
=
False
)
# Write the combined_dict to a new HDF5 file
with
h5py
.
File
(
f
"
{
output_file_prefix
}
_1D.h5
"
,
'
w
'
)
as
output_file
:
with
h5py
.
File
(
os
.
path
.
join
(
dirpath
,
f
"
{
output_file_prefix
}
_1D.h5
"
)
,
'
w
'
)
as
output_file
:
for
key
,
data
in
combined_dict
.
items
():
output_file
.
create_dataset
(
key
,
data
=
data
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment