# This short script reads a .shc file into a python dictionary.# Files of geomagnetic core-field models in this format can be found here:# https://www.space.dtu.dk/english/research/scientific_data_and_models/magnetic_field_modelsimportnumpyasnpdefload_shc(fname):f=open(fname,'r')a=f.readlines()f.close()# Read header:whilelen(a)>0:ifa[0][0]=='#':dela[0]# remove commentselse:dela[0]# remove header linetimes=np.fromstring(a[0],sep=' ')# timesdela[0]# remove timesbreak# Read data, one line for each (l,m), into a dictionary, with (l,m) as the key.glm={}whilelen(a)>0:x=np.fromstring(a[0],sep=' ')lm=(int(x[0]),int(x[1]))glm[lm]=x[2:]dela[0]# now we have 'times' and 'glm' containing the datareturntimes,glm# example using COV-OBS.x2 data file from http://www.spacecenter.dk/files/magnetic-models/COV-OBSx2/COV-OBS.x2-int.shc# other models also available here: https://www.space.dtu.dk/english/research/scientific_data_and_models/magnetic_field_modelst,glm=load_shc("COV-OBS.x2-int.shc")print(t.shape,glm.keys())
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.