How to use the spacepy.pycdf function in spacepy

To help you get started, we’ve selected a few spacepy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nkolot / SPIN / datasets / preprocess / h36m_train.py View on Github external
# go over all the sequences of each user
        seq_list = glob.glob(os.path.join(pose_path, '*.cdf'))
        seq_list.sort()
        for seq_i in seq_list:

            # sequence info
            seq_name = seq_i.split('/')[-1]
            action, camera, _ = seq_name.split('.')
            action = action.replace(' ', '_')
            # irrelevant sequences
            if action == '_ALL':
                continue

            # 3D pose file
            poses_3d = pycdf.CDF(seq_i)['Pose'][0]

            # 2D pose file
            pose2d_file = os.path.join(pose2d_path, seq_name)
            poses_2d = pycdf.CDF(pose2d_file)['Pose'][0]

            # bbox file
            bbox_file = os.path.join(bbox_path, seq_name.replace('cdf', 'mat'))
            bbox_h5py = h5py.File(bbox_file)

            # video file
            if extract_img:
                vid_file = os.path.join(vid_path, seq_name.replace('cdf', 'mp4'))
                imgs_path = os.path.join(dataset_path, 'images')
                vidcap = cv2.VideoCapture(vid_file)

            # go over each frame of the sequence
github ajdillhoff / human36m / human36m / human36m.py View on Github external
def load_targets(target_path, file_name, subject):
    target_prefix = "/MyPoseFeatures/D2_Positions"
    target_path = os.path.join(target_path, subject + target_prefix)
    file_meta = file_name.split("_")
    activity = file_meta[0]
    cdf = pycdf.CDF(os.path.join(target_path, activity + ".cdf"))
    targets = cdf[0]
    targets = targets[0, :, :]
    cdf.close()
    return targets
github nkolot / SPIN / datasets / preprocess / h36m_train.py View on Github external
for seq_i in seq_list:

            # sequence info
            seq_name = seq_i.split('/')[-1]
            action, camera, _ = seq_name.split('.')
            action = action.replace(' ', '_')
            # irrelevant sequences
            if action == '_ALL':
                continue

            # 3D pose file
            poses_3d = pycdf.CDF(seq_i)['Pose'][0]

            # 2D pose file
            pose2d_file = os.path.join(pose2d_path, seq_name)
            poses_2d = pycdf.CDF(pose2d_file)['Pose'][0]

            # bbox file
            bbox_file = os.path.join(bbox_path, seq_name.replace('cdf', 'mat'))
            bbox_h5py = h5py.File(bbox_file)

            # video file
            if extract_img:
                vid_file = os.path.join(vid_path, seq_name.replace('cdf', 'mp4'))
                imgs_path = os.path.join(dataset_path, 'images')
                vidcap = cv2.VideoCapture(vid_file)

            # go over each frame of the sequence
            for frame_i in range(poses_3d.shape[0]):
                # read video frame
                if extract_img:
                    success, image = vidcap.read()
github JanusWind / FC / FC / master / janus_fc_arcv.py View on Github external
ls = ftp.nlst( fl0 )
				fl = ls[-1]
				fl_path = os.path.join( self.path, fl )
				ftp.retrbinary( "RETR " + fl,
					        open( fl_path, 'wb' ).write )
			except :
				self.mesg_txt( 'fail', date_str )
				return

		# If the file now exists, try to load it; otherwise, abort.

		self.mesg_txt( 'load', date_str )

		if ( os.path.isfile( fl_path ) ) :
			try :
				cdf = pycdf.CDF( fl_path )
			except :
				self.mesg_txt( 'fail', date_str )
				return
		else :
			self.mesg_txt( 'fail', date_str )
			return

		# Add the CDF object and tags for each spectrum to the arrays.

		c = len( self.arr_cdf )

		self.arr_cdf  = self.arr_cdf  + [ cdf ]		# arr_cdf and arr_date of same size	
		self.arr_date = self.arr_date + [ date_str ]

		n_spec = len( cdf['Epoch'] )
		self.arr_tag = self.arr_tag + [ fc_tag( c=c, s=s,
github JanusWind / FC / janus_spin_arcv.py View on Github external
except :

				self.mesg_txt( 'fail', date_str )

				return

		# If the file now exists locally, try to load it; otherwise,
		# abort.

		self.mesg_txt( 'load', date_str )

		if ( os.path.isfile( fl_path ) ) :

			try :

				cdf = pycdf.CDF( fl_path )

			except :

				self.mesg_txt( 'fail', date_str )

				return

		else :

			self.mesg_txt( 'fail', date_str )

			return

		# Append the requested date to the list of dates loaded.

		ind = len( self.arr_date )
github drsteve / LANLGeoMag / libLanlGeoMag / QinDenton / FmtQD.py View on Github external
#!/usr/bin/python
import sys
import os
os.putenv("CDF_LIB", "/usr/local/cdf/lib")
import spacepy.pycdf as cdf

#cdf_file        = cdf.CDF('~/Download/QinDenton_1min_merged_20101229-v2.cdf')
cdf_file        = cdf.CDF('~/Download/QinDenton_hour_merged_20120206-v5.cdf')
Epoch           = cdf_file['Epoch']
Year         = cdf_file['Year']
DOY          = cdf_file['DOY']
hour         = cdf_file['hour']
min          = cdf_file['min']
ByIMF        = cdf_file['ByIMF']
BzIMF        = cdf_file['BzIMF']
V_SW         = cdf_file['V_SW']
Den_P        = cdf_file['Den_P']
Pdyn         = cdf_file['Pdyn']
G1           = cdf_file['G1']
G2           = cdf_file['G2']
G3           = cdf_file['G3']
ByIMF_status = cdf_file['ByIMF_status']
BzIMF_status = cdf_file['BzIMF_status']
V_SW_status  = cdf_file['V_SW_status']
github JanusWind / FC / janus_mfi_arcv_lres.py View on Github external
fl = ls[-1]
				fl_path = os.path.join( self.path, fl )
				ftp.retrbinary( "RETR " + fl,
				           open( fl_path, 'wb' ).write )
			except :
				self.mesg_txt( 'fail', date_str )
				return

		# If the file now exists, try to load it; otherwise,
		# abort.

		self.mesg_txt( 'load', date_str )

		if ( os.path.isfile( fl_path ) ) :
			try :
				cdf = pycdf.CDF( fl_path )
			except :
				self.mesg_txt( 'fail', date_str )
				return
		else :
			self.mesg_txt( 'fail', date_str )
			return

		# Extract the data from the loaded file and select those data
		# which seem to have valid (versus fill) values.

		if ( self.use_h2 ) :

			# Extract the data from the loaded file.

			sub_t   = cdf['Epoch'][:,0]
			sub_b_x = cdf['BGSE'][:,0]
github CHUNYUWANG / H36M-Toolbox / generate_labels.py View on Github external
camera_dict['k'] = camera[4]
                    camera_dict['p'] = camera[5]


                    subdir_format = 's_{:02d}_act_{:02d}_subact_{:02d}_ca_{:02d}'
                    subdir = subdir_format.format(s, a, sa, c)

                    basename = metadata.get_base_filename('S{:d}'.format(s), '{:d}'.format(a), '{:d}'.format(sa), metadata.camera_ids[c-1])
                    annotname = basename + '.cdf'

                    subject = 'S' + str(s)
                    annofile3d = osp.join('extracted', subject, 'Poses_D3_Positions_mono_universal', annotname)
                    annofile3d_camera = osp.join('extracted', subject, 'Poses_D3_Positions_mono', annotname)
                    annofile2d = osp.join('extracted', subject, 'Poses_D2_Positions', annotname)

                    with pycdf.CDF(annofile3d) as data:
                        pose3d = np.array(data['Pose'])
                        pose3d = np.reshape(pose3d, (-1, 32, 3))

                    with pycdf.CDF(annofile3d_camera) as data:
                        pose3d_camera = np.array(data['Pose'])
                        pose3d_camera = np.reshape(pose3d_camera, (-1, 32, 3))

                    with pycdf.CDF(annofile2d) as data:
                        pose2d = np.array(data['Pose'])
                        pose2d = np.reshape(pose2d, (-1, 32, 2))

                    nposes = min(pose3d.shape[0], pose2d.shape[0])
                    image_format = 's_{:02d}_act_{:02d}_subact_{:02d}_ca_{:02d}_{:06d}.jpg'

                    for i in range(nposes):
                        datum = {}
github CHUNYUWANG / H36M-Toolbox / generate_labels.py View on Github external
subdir_format = 's_{:02d}_act_{:02d}_subact_{:02d}_ca_{:02d}'
                    subdir = subdir_format.format(s, a, sa, c)

                    basename = metadata.get_base_filename('S{:d}'.format(s), '{:d}'.format(a), '{:d}'.format(sa), metadata.camera_ids[c-1])
                    annotname = basename + '.cdf'

                    subject = 'S' + str(s)
                    annofile3d = osp.join('extracted', subject, 'Poses_D3_Positions_mono_universal', annotname)
                    annofile3d_camera = osp.join('extracted', subject, 'Poses_D3_Positions_mono', annotname)
                    annofile2d = osp.join('extracted', subject, 'Poses_D2_Positions', annotname)

                    with pycdf.CDF(annofile3d) as data:
                        pose3d = np.array(data['Pose'])
                        pose3d = np.reshape(pose3d, (-1, 32, 3))

                    with pycdf.CDF(annofile3d_camera) as data:
                        pose3d_camera = np.array(data['Pose'])
                        pose3d_camera = np.reshape(pose3d_camera, (-1, 32, 3))

                    with pycdf.CDF(annofile2d) as data:
                        pose2d = np.array(data['Pose'])
                        pose2d = np.reshape(pose2d, (-1, 32, 2))

                    nposes = min(pose3d.shape[0], pose2d.shape[0])
                    image_format = 's_{:02d}_act_{:02d}_subact_{:02d}_ca_{:02d}_{:06d}.jpg'

                    for i in range(nposes):
                        datum = {}
                        imagename = image_format.format(s, a, sa, c, i+1)
                        imagepath = osp.join(subdir, imagename)
                        if not osp.isfile(osp.join('images', imagepath)):
                            print(osp.join('images', imagepath))
github jutanke / pak / pak / datasets / human36m.py View on Github external
def get_raw_angles(self, actor, action, sub_action=0):
        """
        :param actor:
        :param action:
        :param sub_action:
        :return:
        """
        cdf_file = self.get_cdf_file('RawAngles',
                                     actor, action, sub_action)
        cdf = pycdf.CDF(cdf_file)
        angles3d = np.squeeze(cdf['Pose'])
        return angles3d