original_docstring: 
  	Save as .nc
  	Open Yasunaka (2019) data from binary to xarray and save to labelled netcdf. 
  	Data obtained from personal communication. I am unable to share this. 
  
  	3 variables: co2flux, error, pco2
  	35 years 1981 - 2015
  	12 months 0 - 11
  	40 lats -19.5 - 19.5
  	200 lons 100 - 300E
  
  	@author: Nic.Pittman@utas.edu.au
  
  	Yasunaka, S., Kouketsu, S., Strutton, P. G., Sutton, A. J., Murata, A., Nakaoka, S., & Nojiri, Y. (2019). Spatio-temporal variability of surface water pCO2 and nutrients in the tropical Pacific from 1981 to 2015. Deep Sea Research Part II: Topical Studies in Oceanography, 169, 104680.
  	
docstring: Save as .nc
  Open Yasunaka (2019) data from binary to xarray and save to labelled netcdf.
  Data obtained from personal communication. I am unable to share this.
  
  
docstring_tokens: Save as . nc Open Yasunaka ( 2019 ) data from binary to xarray and save to labelled netcdf . Data obtained from personal communication . I am unable to share this .
code: def process_yasanaka():
  	"""
  	Save as .nc
  	Open Yasunaka (2019) data from binary to xarray and save to labelled netcdf. 
  	Data obtained from personal communication. I am unable to share this. 
  
  	3 variables: co2flux, error, pco2
  	35 years 1981 - 2015
  	12 months 0 - 11
  	40 lats -19.5 - 19.5
  	200 lons 100 - 300E
  
  	@author: Nic.Pittman@utas.edu.au
  
  	Yasunaka, S., Kouketsu, S., Strutton, P. G., Sutton, A. J., Murata, A., Nakaoka, S., & Nojiri, Y. (2019). Spatio-temporal variability of surface water pCO2 and nutrients in the tropical Pacific from 1981 to 2015. Deep Sea Research Part II: Topical Studies in Oceanography, 169, 104680.
  	"""
  	fps=['datasets/co2/yasanaka_co2/co2flux_1807.bin',                #File paths - Array for the 3 variables.
  	     'datasets/co2/yasanaka_co2/error_1807.bin',
  	     'datasets/co2/yasanaka_co2/pco2_1807.bin']
  	     
  	arrs=[]
  	year=np.arange(1981,2016)            #Setting years
  	month=np.arange(0,12)                #Setting months
  	lat=np.arange(-19.5,20.5)            #Setting lats
  	lon=np.arange(100.5,300.5)  
  	print('Processing')
  	for fp in fps:
  	    data = np.array('B')                        #Make a numpy bytes array
  	    f = open(fp, "r")                           #Open the file as bytes
  	    a = np.fromfile(f, dtype=np.float32)        #Convert into an array of 3360000
  	    count=0                                     #Set count to run through bytes
  	    data=np.ndarray([35,12,40,200])             #Set the data array size 
  	    for iy in range(0,35):                      #Loop through them all to count the bytes in order
  	       for im in range(0,12):
  	           for la in range(0,40):
  	               data[iy,im,la,:]=a[count:count+200]  #Read and append the bytes to the data array
  	               count=count+200                      #Cycle our counts up
  	    piece=xr.DataArray(data,dims=['year','month','lat','lon'])
  	    piece.name=fp.split('/')[1].split('_')[0]
  	    arrs.append(piece) #Make an xarray so we can save as labeled netcdf.
  
  		       
  	  
  	out=xr.merge(arrs)
  	out['year']=year         #Setting years
  	out['month']=month       #Setting months
  	out['lat']=lat        #Setting lats
  	out['lon']=lon       #Setting lons
  	out['flux_masked']=out.co2flux.where(out.error<0.9)
  	#out['var']=['co2flux','error','pco2s']
  	#print(out)                                 #Check it works
  	#out.flux_masked.sel(year=2000).mean(dim='month').plot() #Plot it to check ok
  	
  	#Merge and convert dates
  	print('Merging Dates')
  	datasets=[]
  	month_box=out
  	for y in month_box.year.values:
  	    for m in month_box.month.values:
  	        box=month_box.sel(year=y,month=m)
  	        m+=1
  	        if len(str(m))==1:
  	            m=str(0)+str(m)
  	        box=box.assign_coords(time=(np.datetime64(str(y)+'-'+str(m))))
  	        box=box.drop(['month','year'])
  	        datasets.append(box)
  	out1=xr.concat(datasets,dim='time')
  	#Convert the month and years into a numpy datetime. Best way besides just looping through surely...
  
  	out1.to_netcdf('datasets/co2/yasanaka_co2/Yasunaka_pCO2_flux.nc')           #Save to labelled netcdf. 
  	print('Finished')
  	return True
code_tokens: def process_yasanaka ( ) : fps = [ 'datasets/co2/yasanaka_co2/co2flux_1807.bin' , 'datasets/co2/yasanaka_co2/error_1807.bin' , 'datasets/co2/yasanaka_co2/pco2_1807.bin' ] arrs = [ ] year = np . arange ( 1981 , 2016 ) month = np . arange ( 0 , 12 ) lat = np . arange ( - 19.5 , 20.5 ) lon = np . arange ( 100.5 , 300.5 ) print ( 'Processing' ) for fp in fps : data = np . array ( 'B' ) f = open ( fp , "r" ) a = np . fromfile ( f , dtype = np . float32 ) count = 0 data = np . ndarray ( [ 35 , 12 , 40 , 200 ] ) for iy in range ( 0 , 35 ) : for im in range ( 0 , 12 ) : for la in range ( 0 , 40 ) : data [ iy , im , la , : ] = a [ count : count + 200 ] count = count + 200 piece = xr . DataArray ( data , dims = [ 'year' , 'month' , 'lat' , 'lon' ] ) piece . name = fp . split ( '/' ) [ 1 ] . split ( '_' ) [ 0 ] arrs . append ( piece ) out = xr . merge ( arrs ) out [ 'year' ] = year out [ 'month' ] = month out [ 'lat' ] = lat out [ 'lon' ] = lon out [ 'flux_masked' ] = out . co2flux . where ( out . error < 0.9 ) print ( 'Merging Dates' ) datasets = [ ] month_box = out for y in month_box . year . values : for m in month_box . month . values : box = month_box . sel ( year = y , month = m ) m += 1 if len ( str ( m ) ) == 1 : m = str ( 0 ) + str ( m ) box = box . assign_coords ( time = ( np . datetime64 ( str ( y ) + '-' + str ( m ) ) ) ) box = box . drop ( [ 'month' , 'year' ] ) datasets . append ( box ) out1 = xr . concat ( datasets , dim = 'time' ) out1 . to_netcdf ( 'datasets/co2/yasanaka_co2/Yasunaka_pCO2_flux.nc' ) print ( 'Finished' ) return True
short_docstring: Save as .nc
  Open Yasunaka (2019) data from binary to xarray and save to labelled netcdf.
short_docstring_tokens: Save as . nc Open Yasunaka ( 2019 ) data from binary to xarray and save to labelled netcdf .
comment: """
  	Save as .nc
  	Open Yasunaka (2019) data from binary to xarray and save to labelled netcdf. 
  	Data obtained from personal communication. I am unable to share this. 
  
  	3 variables: co2flux, error, pco2
  	35 years 1981 - 2015
  	12 months 0 - 11
  	40 lats -19.5 - 19.5
  	200 lons 100 - 300E
  
  	@author: Nic.Pittman@utas.edu.au
  
  	Yasunaka, S., Kouketsu, S., Strutton, P. G., Sutton, A. J., Murata, A., Nakaoka, S., & Nojiri, Y. (2019). Spatio-temporal variability of surface water pCO2 and nutrients in the tropical Pacific from 1981 to 2015. Deep Sea Research Part II: Topical Studies in Oceanography, 169, 104680.
  	"""$SEP$#File paths - Array for the 3 variables.$SEP$#Setting years$SEP$#Setting months$SEP$#Setting lats$SEP$#Make a numpy bytes array$SEP$#Open the file as bytes$SEP$#Convert into an array of 3360000$SEP$#Set count to run through bytes$SEP$#Set the data array size $SEP$#Loop through them all to count the bytes in order$SEP$#Read and append the bytes to the data array$SEP$#Cycle our counts up$SEP$#Make an xarray so we can save as labeled netcdf.$SEP$#Setting years$SEP$#Setting months$SEP$#Setting lats$SEP$#Setting lons$SEP$#out['var']=['co2flux','error','pco2s']$SEP$#print(out)                                 #Check it works$SEP$#out.flux_masked.sel(year=2000).mean(dim='month').plot() #Plot it to check ok$SEP$#Merge and convert dates$SEP$#Convert the month and years into a numpy datetime. Best way besides just looping through surely...$SEP$#Save to labelled netcdf. 