Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions parcels/particlefile/baseparticlefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import string
from abc import ABC
from abc import abstractmethod
import gzip

import numpy as np

Expand Down Expand Up @@ -235,14 +236,14 @@ def dump_dict_to_npy(self, data_dict, data_dict_once):
os.makedirs(self.tempwritedir)

if len(data_dict) > 0:
tmpfilename = os.path.join(self.tempwritedir, str(len(self.file_list)) + ".npy")
with open(tmpfilename, 'wb') as f:
tmpfilename = os.path.join(self.tempwritedir, str(len(self.file_list)) + ".npy.gz")
with gzip.open(tmpfilename, 'wb') as f:
np.save(f, data_dict)
self.file_list.append(tmpfilename)

if len(data_dict_once) > 0:
tmpfilename = os.path.join(self.tempwritedir, str(len(self.file_list)) + '_once.npy')
with open(tmpfilename, 'wb') as f:
tmpfilename = os.path.join(self.tempwritedir, str(len(self.file_list)) + '_once.npy.gz')
with gzip.open(tmpfilename, 'wb') as f:
np.save(f, data_dict_once)
self.file_list_once.append(tmpfilename)

Expand Down
7 changes: 5 additions & 2 deletions parcels/particlefile/particlefileaos.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from glob import glob
import numpy as np
import xarray as xr
import gzip

try:
from mpi4py import MPI
Expand Down Expand Up @@ -85,7 +86,8 @@ def read_from_npy(self, file_list, n_timesteps, var, dtype):
# loop over all files
for npyfile in file_list:
try:
data_dict = np.load(npyfile, allow_pickle=True).item()
with gzip.open(npyfile, 'rb') as f:
data_dict = np.load(f, allow_pickle=True).item()
except NameError:
raise RuntimeError('Cannot combine npy files into netcdf file because your ParticleFile is '
'still open on interpreter shutdown.\nYou can use '
Expand Down Expand Up @@ -138,7 +140,8 @@ def export(self):
if os.path.exists(tempwritedir):
pset_info_local = np.load(os.path.join(tempwritedir, 'pset_info.npy'), allow_pickle=True).item()
for npyfile in pset_info_local['file_list']:
tmp_dict = np.load(npyfile, allow_pickle=True).item()
with gzip.open(npyfile, 'rb') as f:
tmp_dict = np.load(f, allow_pickle=True).item()
for i in tmp_dict['id']:
if i in n_timesteps:
n_timesteps[i] += 1
Expand Down
7 changes: 5 additions & 2 deletions parcels/particlefile/particlefilesoa.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from glob import glob
import numpy as np
import xarray as xr
import gzip

try:
from mpi4py import MPI
Expand Down Expand Up @@ -85,7 +86,8 @@ def read_from_npy(self, file_list, n_timesteps, var, dtype):
# loop over all files
for npyfile in file_list:
try:
data_dict = np.load(npyfile, allow_pickle=True).item()
with gzip.open(npyfile, 'rb') as f:
data_dict = np.load(f, allow_pickle=True).item()
except NameError:
raise RuntimeError('Cannot combine npy files into netcdf file because your ParticleFile is '
'still open on interpreter shutdown.\nYou can use '
Expand Down Expand Up @@ -139,7 +141,8 @@ def export(self):
if os.path.exists(tempwritedir):
pset_info_local = np.load(os.path.join(tempwritedir, 'pset_info.npy'), allow_pickle=True).item()
for npyfile in pset_info_local['file_list']:
tmp_dict = np.load(npyfile, allow_pickle=True).item()
with gzip.open(npyfile, 'rb') as f:
tmp_dict = np.load(f, allow_pickle=True).item()
for i in tmp_dict['id']:
if i in n_timesteps:
n_timesteps[i] += 1
Expand Down