<jupyter_start><jupyter_text>sbc<jupyter_code>def resample_frc(hr_grd,lr_grd,hr_sbc,var,gt,time_coord,write=False):

    lr_def = geometry.SwathDefinition(lons=lr_grd['lon_'+gt].values,lats=lr_grd['lat_'+gt].values)
    hr_def = geometry.SwathDefinition(lons=hr_grd['lon_'+gt].values,lats=hr_grd['lat_'+gt].values)

    lr_sbc = hr_sbc.drop(var)
    dummy = np.empty((lr_sbc[time_coord].size,lr_grd['eta_'+gt].size,lr_grd['xi_'+gt].size))
    lr_sbc[var] = xr.DataArray(dummy,dims=[time_coord,'eta_'+gt,'xi_'+gt])

    valid_input_index, valid_output_index, index_array, distance_array = \
    kd_tree.get_neighbour_info(hr_def,lr_def, 2000,neighbours=4,nprocs=16)

    wf = lambda r: 1/r

    for day in log_progress(range(hr_sbc[time_coord].size),name="day"):
    
        lr_sbc[var][day] = kd_tree.get_sample_from_neighbour_info('custom', lr_def.shape, hr_sbc[var][day].values,\
                                                 valid_input_index,\
                                                 valid_output_index,index_array,distance_array,wf)

    lr_sbc[time_coord].attrs = hr_sbc[time_coord].attrs
    lr_sbc[var].attrs = hr_sbc[var].attrs
    
    if write:
        outpath = os.path.join(os.environ.get('prodir'),'waom2_'+var+'.nc')
        lr_sbc.to_netcdf(outpath,unlimited_dmn=time_coord)
    
    return lr_sbc
#for month in ['01','02','03','04','05','06','07','08','09','10','11','12']:
for month in ['12']:
    print('processing month ',month)
    for var,gt,time in zip(['shflux','swflux','sustr','svstr'],['rho','rho','u','v'],['shf_time','swf_time','sms_time','sms_time']):
        print('processing ',var)
        hr_sbc_path =  os.path.join('/home/ubuntu/raijin/g/data2/gh9/oxr581/waom1_frc',var+'_'+month+'.nc')
        hr_sbc = xr.open_dataset(hr_sbc_path)
        lr_sbc = resample_frc(hr_grd,lr_grd,hr_sbc,var,gt,time)
        outpath = os.path.join(os.environ.get('intdir'),'waom10_'+var+'_'+month+'.nc')
        lr_sbc.to_netcdf(outpath,unlimited_dims=time)
        del lr_sbc<jupyter_output>processing month  12
processing  shflux<jupyter_text>nudge<jupyter_code>hr_nudge_path = os.path.join(os.environ.get('prodir'),'waom1_nudge.nc')
hr_nudge = xr.open_dataset(hr_nudge_path)
hr_nudge
lr_nudge = {}
for var,gt,time in zip(['SSS','SST','dQdSST'],['rho','rho','rho'],['sss_time','sst_time','sst_time']):
    print('processing ',var)
    lr_nudge[var] = resample_frc(hr_grd,lr_grd,hr_nudge[var].to_dataset(),var,gt,time,write=False)
lr_nudge = xr.merge([lr_nudge['SSS'],lr_nudge['SST'],lr_nudge['dQdSST']]) 
lr_nudge.attrs = hr_nudge.attrs
lr_out_path = os.path.join(os.environ.get('prodir'),'waom10_nudge.nc')
lr_nudge.to_netcdf(lr_out_path)<jupyter_output>processing  SSS<jupyter_text>tds<jupyter_code>hr_tds_path = os.path.join(os.environ.get('prodir'),'waom1_tds.nc')
hr_tds = xr.open_dataset(hr_tds_path)
#lr_tds = hr_tds.drop(['tide_Eamp','tide_Ephase','tide_Cphase','tide_Cangle','tide_Cmin','tide_Cmax','lat_rho',
                       #'lon_rho','mask_rho'])
    
lr_tds ={}
gt = 'rho'
time = 'tide_period'
for var in ['tide_Ephase','tide_Cphase','tide_Cangle','tide_Cmin','tide_Cmax','tide_Eamp']:
    print('processing ',var)
    lr_tds[var] = resample_frc(hr_grd,lr_grd,hr_tds[var].to_dataset(),var,gt,time,write=False)
lr_tds = xr.merge([lr_tds['tide_Eamp'],lr_tds['tide_Ephase'],lr_tds['tide_Cphase'],lr_tds['tide_Cangle'],lr_tds['tide_Cmin'],lr_tds['tide_Cmax']])
out_path = os.path.join(os.environ.get('prodir'),'waom10_tds.nc')
lr_tds.to_netcdf(out_path)
lr_tds<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18405428329092452, 'fraction_numerical': 0.01441899915182358, 'mean_word_length': 5.527675276752768, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '235203', 'license': 'MIT', 'n_tokens_mistral': 1572, 'n_tokens_neox': 1528, 'n_words': 121, 'path': 'notebooks/preprocessing/resample_frc.ipynb', 'repo_name': 'kuechenrole/tidal_melting', 'size': '3537'}