# Function that plots the time series and the data series from a .mat data file# (in the dB-direction based on the out-variable), that is associated with the observatory code (based on the sta-variable)# It also takes an optional argument 'showdatapoints' so its possible to show data points mainly for debuggingdefplotdata_stations(filename,sta,out,start,stop,*args):# Makes the function use one of the three columns (and thus directions of field) in the data series based on inputifout=='radial':dat=0elifout=='theta':dat=1elifout=='phi':dat=2# If the user inputs something else than one of these three, it returns an error and a hint to resolve the errorelse:print('\nError: Component '+"'"+out+"'"+' not recognized...')print('\nHint: Try using '+"'"+'radial'+"', "+"'"+'theta'+"' or "+"'"+'phi'+"'.")# Try to load file in case the file does not existtry:nam=DataLoad(filename,'obs_all')# If the file does not exist, it returns an error and a hint to resolve the errorexcept:print('\nError: File '+"'"+filename+"'"+' not recognized...')print('\nHint: Try putting your file in the same folder as this script.')# If the observatory code is not in the data file, it returns an error and a hint to resolve the errorifstanotinnamandsta!='all':print('\nError: Observatory Code '+"'"+sta+"'"+' not recognized...')print('\nHint: Try using an Observatory Code from the Observatory Locations map.')# Load data from specific station and direction of fielddat=dB_stations(filename,sta,dat)tim=t_stations(filename,sta)# If start is a string but not 'min' and stop is a string but not 'max', print errorif(isinstance(start,str)==Trueandstart!='min')or(isinstance(stop,str)==Trueandstop!='max'):print('\nError: Time range is out of bounds in regards to data set...')print('\nHint: Try using a time range that is included in data set or use '+"'"+'max'+"'"+' or '+"'"+'min'+"'.")# Set start and stop to min or max of time series of min or max is chosenifstart=='min':start=min(tim)ifstop=='max':stop=max(tim)# Print error if time range is out of bounds in regards to the data setifstartmax(tim):print('\nError: Time range is out of bounds in regards to data set...')print('\nHint: Try using a time range that is included in data set or use '+"'"+'max'+"'"+' or '+"'"+'min'+"'.")# Get all data associated with station in the specific time rangendat=[]ntim=[]forxinrange(0,len(tim)):ifstart<=tim[x]<=stop:ndat.append(dat[x])ntim.append(tim[x])# Sets up the data plot and shows itplt.figure(figsize=(9,5))plt.scatter(ntim,ndat,marker='.')plt.title('Observatory Data from '+sta+' in the dB_'+out+'-direction')plt.xlabel('Years')plt.ylabel('nT/yr')plt.show()# For optional argumentsforxinargs:# If the optional argument 'showdatapoints' is called it will print the data points bellow the plotifx=='showdatapoints':print('\nData series [nT/yr] in the dB_'+out+'-direction = \n')print(dB_stations(filename,sta,dat))print('\nTime series [Years] = \n')print(t_stations(filename,sta))# If the user inputs something else than 'showdatapoints', it returns an error and a hint to resolve the errorelse:print('\nError: Optional argument '+"'"+x+"'"+' not recognized...')print('\nHint: Try using '+"'"+'showdatapoints'+"' or deleting the argument.")
python绘制地图地图cartopy_Python:如何在Cartopy地图上的特定点绘制散点图?
最新推荐文章于 2023-05-19 10:38:15 发布