<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 PyGSLIB
Introduction
This is a simple example on how to use raw pyslib to compute variograms
Step1:  Getting the data ready for work
If the data is in GSLIB format you can use the function pygslib.gslib.read_gslib_file(filename) to import the data into a Pandas DataFrame.
Step2:  Testing variogram function gamv
<ASSISTANT_TASK:>
Python Code:
#general imports
import pygslib                  
Explanation: PyGSLIB
Introduction
This is a simple example on how to use raw pyslib to compute variograms
End of explanation
#get the data in gslib format into a pandas Dataframe
mydata= pygslib.gslib.read_gslib_file('../data/cluster.dat')  
# This is a 2D file, in this GSLIB version we require 3D data and drillhole name or domain code
# so, we are adding constant elevation = 0 and a dummy BHID = 1 
mydata['Zlocation']=0.
mydata['bhid']=1.
# printing to verify results
print (' \n **** 5 first rows in my datafile \n\n  ', mydata.head(n=5))
Explanation: Getting the data ready for work
If the data is in GSLIB format you can use the function pygslib.gslib.read_gslib_file(filename) to import the data into a Pandas DataFrame.
End of explanation
# these are the parameters we need. Note that at difference of GSLIB this dictionary also stores 
# the actual data (ex, X, Y, etc.). 
#important! python is case sensitive 'bhid' is not equal to 'BHID'
parameters = {
            'x'    : mydata['Xlocation'].values,
            'y'    : mydata['Ylocation'].values,
            'z'    : mydata['Zlocation'].values, 
            'bhid' : mydata['bhid'].values,
            'vr'   : mydata['Primary'].values,
            'tmin' : -1.0e21,
            'tmax' :  1.0e21,
            'nlag' :  10,
            'xlag' :  1,
            'ndir' : 10,
            'ndip' :  10,
            'orgdir': 0.,
            'orgdip': 0.,
            'isill' : 1,
            'sills' : [mydata['Primary'].var()],
            'ivtail' : [1],
            'ivhead' : [1],
            'ivtype' : [1]
        }
#Now we are ready to calculate the veriogram
np, dis, gam, hm, tm, hv, tv = pygslib.gslib.gamv3D(parameters)
np
# create structured grid with data 
import vtk
import vtk.util.numpy_support as vtknumpy
import math
import numpy as np
XYZPts = vtk.vtkPoints()
XYZPts.SetNumberOfPoints(parameters['ndip']*parameters['nlag']*parameters['ndir']*2)
angdir = (math.pi/180.)*180./(parameters['ndir'])
angdip = (math.pi/180.)*90./(parameters['ndip'])
orgdir = parameters['orgdir'] * math.pi/180.
orgdip = parameters['orgdip'] * math.pi/180.
id=-1
for k in range(-parameters['ndip']+1,parameters['ndip']+1):
    for j in range(parameters['nlag']):
        for i in range(parameters['ndir']):
            id+=1
             
            x= parameters['xlag']*(j+1)*math.cos(angdir*i-orgdir)*math.cos(angdip*k-orgdip)
            y= parameters['xlag']*(j+1)*math.sin(angdir*i-orgdir)*math.cos(angdip*k-orgdip)
            z= parameters['xlag']*(j+1)*                            math.sin(angdip*k-orgdip)
            
            print (id, i,j,k, angdir*i*(180/math.pi), angdip*k*(180/math.pi),x,y,z)
            #print math.cos(angdip*k-orgdip)
            XYZPts.SetPoint(id,x,y,z)
                     
XYZGrid = vtk.vtkStructuredGrid()
XYZGrid.SetDimensions(parameters['ndir'],parameters['nlag'],parameters['ndip']*2-1)
XYZGrid.SetPoints(XYZPts)
ptid = np.arange(2*parameters['ndip']*parameters['nlag']*(parameters['ndir']))
cscalars = vtknumpy.numpy_to_vtk(ptid)
cscalars.SetName('PointID|') 
XYZGrid.GetPointData().AddArray(cscalars)
#Write file
writer = vtk.vtkXMLStructuredGridWriter()
writer.SetFileName("output.vts")
writer.SetInputData(XYZGrid)
writer.Write()
Explanation: Testing variogram function gamv
End of explanation
<END_TASK>