NOC-MSM / pyBDY

pyBDY: a Python based regional NEMO model configuration toolbox.
GNU General Public License v3.0
7 stars 7 forks source link

【RuntimeError: NetCDF: Write to read only】occurred using tpxo9.2 data #97

Closed banmianyu closed 7 months ago

banmianyu commented 1 year ago

Hi I did not find tpxo7.2 data online. So I replaced it with tpxo9.2 data and ran pynemo -s namelist_local.bdy. Some error message occurred as described in the title. No other files were generated in the output directory except for the coordinates.bdy.nc file. Can you give me some advice on how to solve this problem ? Thanks~ Detailed information is shown below:

Screen output when running pynemo

Didn't find a proxy environment variable
./src_data_local.ncml
Traceback (most recent call last):
  File "/home/wangy/anaconda3/envs/pynemo/bin/pynemo", line 11, in <module>
    load_entry_point('pynemo==0.1.0', 'console_scripts', 'pynemo')()
  File "/home/wangy/anaconda3/envs/pynemo/lib/python3.7/site-packages/pynemo-0.1.0-py3.7.egg/pynemo/pynemo_exe.py", line 46, in main
    cProfile.runctx("f(x, y)",{'f': profiler.process_bdy, 'x': setup_file, 'y': mask_gui}, {}, 'pynemo_stats')
  File "/home/wangy/anaconda3/envs/pynemo/lib/python3.7/cProfile.py", line 20, in runctx
    filename, sort)
  File "/home/wangy/anaconda3/envs/pynemo/lib/python3.7/profile.py", line 62, in runctx
    prof.runctx(statement, globals, locals)
  File "/home/wangy/anaconda3/envs/pynemo/lib/python3.7/cProfile.py", line 100, in runctx
    exec(cmd, globals, locals)
  File "<string>", line 1, in <module>
  File "/home/wangy/anaconda3/envs/pynemo/lib/python3.7/site-packages/pynemo-0.1.0-py3.7.egg/pynemo/profiler.py", line 223, in process_bdy
    settings['clname'])
  File "/home/wangy/anaconda3/envs/pynemo/lib/python3.7/site-packages/pynemo-0.1.0-py3.7.egg/pynemo/tide/nemo_bdy_tide3.py", line 53, in nemo_bdy_tide_rot
    tide_z = tpxo_extract_HC.TpxoExtract(setup.settings, dst_lat, dst_lon, g_type)
  File "/home/wangy/anaconda3/envs/pynemo/lib/python3.7/site-packages/pynemo-0.1.0-py3.7.egg/pynemo/tide/tpxo_extract_HC.py", line 98, in __init__
    height_z[height_z == 0] = np.NaN
  File "netCDF4/_netCDF4.pyx", line 4648, in netCDF4._netCDF4.Variable.__setitem__
  File "netCDF4/_netCDF4.pyx", line 4913, in netCDF4._netCDF4.Variable._put
  File "netCDF4/_netCDF4.pyx", line 1754, in netCDF4._netCDF4._ensure_nc_success
RuntimeError: NetCDF: Write to read only

My namelist_local.bdy

!!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
!! NEMO/OPA  : namelist for BDY generation tool
!!            
!!             User inputs for generating open boundary conditions
!!             employed by the BDY module in NEMO. Boundary data
!!             can be set up for v3.2 NEMO and above.
!!            
!!             More info here.....
!!            
!!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

!------------------------------------------------------------------------------
!   vertical coordinate
!------------------------------------------------------------------------------
   ln_zco      = .false.   !  z-coordinate - full    steps   (T/F)  
   ln_zps      = .true.    !  z-coordinate - partial steps   (T/F)
   ln_sco      = .false.   !  s- or hybrid z-s-coordinate    (T/F)
   rn_hmin     =   -10     !  min depth of the ocean (>0) or 
                           !  min number of ocean level (<0)

!------------------------------------------------------------------------------
!   s-coordinate or hybrid z-s-coordinate
!------------------------------------------------------------------------------
   rn_sbot_min =   10.     !  minimum depth of s-bottom surface (>0) (m)
   rn_sbot_max = 7000.     !  maximum depth of s-bottom surface 
                           !  (= ocean depth) (>0) (m)
   ln_s_sigma  = .false.   !  hybrid s-sigma coordinates
   rn_hc       =  150.0    !  critical depth with s-sigma

!------------------------------------------------------------------------------
!  grid information 
!------------------------------------------------------------------------------
   sn_src_hgr = './benchmark/grid_low_res_C/mesh_hgr.nc' 
   sn_src_zgr = './benchmark/grid_low_res_C/mesh_zgr.nc'
   sn_dst_hgr = './benchmark/grid_C/mesh_hgr_zps.nc'
   sn_dst_zgr = './benchmark/grid_C/mesh_zgr_zps.nc'
   sn_src_msk = './benchmark/grid_low_res_C/mask.nc'
   sn_bathy   = './benchmark/grid_C/NNA_R12_bathy_meter_bench.nc'
!   sn_bathy   = './test/bathy_ORCA_R025_etopo1.nc'
!------------------------------------------------------------------------------
!  I/O 
!------------------------------------------------------------------------------
   sn_src_dir = './src_data_local.ncml' ! src_files/'
   sn_dst_dir = './outputs'
   sn_fn      = 'NNA_R12'             ! prefix for output files
   nn_fv      = -1e20                 !  set fill value for output files
   nn_src_time_adj = 0                ! src time adjustment
   sn_dst_metainfo = 'Benchmarking Data'

!------------------------------------------------------------------------------
!  unstructured open boundaries                         
!------------------------------------------------------------------------------
    ln_coords_file = .true.               !  =T : produce bdy coordinates files
    cn_coords_file = 'coordinates.bdy.nc' !  name of bdy coordinates files 
                                          !  (if ln_coords_file=.TRUE.)
    ln_mask_file   = .false.              !  =T : read mask from file
    cn_mask_file   = 'mask.nc'            !  name of mask file 
                                          !  (if ln_mask_file=.TRUE.)
    ln_dyn2d       = .false.              !  boundary conditions for 
                                          !  barotropic fields
    ln_dyn3d       = .false.              !  boundary conditions for 
                                          !  baroclinic velocities
    ln_tra         = .false.               !  boundary conditions for T and S
    ln_ice         = .false.              !  ice boundary condition   
    nn_rimwidth    = 9                    !  width of the relaxation zone

!------------------------------------------------------------------------------
!  unstructured open boundaries tidal parameters                        
!------------------------------------------------------------------------------
    ln_tide        = .true.              !  =T : produce bdy tidal conditions
    sn_tide_model  = 'TPXO7p2'            !  Name of tidal model (FES2014|TPXO7p2)
    clname(1)      = 'M2'                 !  constituent name
    clname(2)      = 'S2'
    clname(3)      = 'K2'
    clname(4)      = 'O1'
    clname(5)      = 'P1'
    clname(6)      = 'Q1'
    clname(7)      = 'M4'
    ln_trans       = .true.               !  interpolate transport rather than
                                          !  velocities
!------------------------------------------------------------------------------
!  Time information
!------------------------------------------------------------------------------
    nn_year_000     = 1979        !  year start
    nn_year_end     = 1979        !  year end
    nn_month_000    = 11          !  month start (default = 1 is years>1)
    nn_month_end    = 11          !  month end (default = 12 is years>1)
    sn_dst_calendar = 'gregorian' !  output calendar format
    nn_base_year    = 1960        !  base year for time counter
    ! location of TPXO7.2 data
    sn_tide_grid   = './tpxo9.2/grid_tpxo9.2.nc'
    sn_tide_h      = './tpxo9.2/h_tpxo9.2.nc'
    sn_tide_u      = './tpxo9.2/u_tpxo9.2.nc'
    ! location of FES2014 data
    sn_tide_fes      = './inputs/FES2014/'

!--------------------------------------------------------------------------
!  Additional parameters
!--------------------------------------------------------------------------
    nn_wei  = 1                   !  smoothing filter weights 
    rn_r0   = 0.041666666         !  decorrelation distance use in gauss
                                  !  smoothing onto dst points. Need to 
                                  !  make this a funct. of dlon
    sn_history  = 'Benchmarking test case'
                                  !  history for netcdf file
    ln_nemo3p4  = .true.          !  else presume v3.2 or v3.3
    nn_alpha    = 0               !  Euler rotation angle
    nn_beta     = 0               !  Euler rotation angle
    nn_gamma    = 0               !  Euler rotation angle
    rn_mask_max_depth = 100.0     !  Maximum depth to be ignored for the mask
    rn_mask_shelfbreak_dist = 20000.0 !  Distance from the shelf break

The nrct.log

INFO:pynemo.profiler:Start NRCT Logging: Tue Apr  4 09:18:32 2023
INFO:pynemo.profiler:============================================
INFO:pynemo.profiler:Reading grid completed
WARNING:pynemo.profiler:Using default mask with bathymetry!!!!
INFO:pynemo.profiler:Reading mask completed
INFO:pynemo.profiler:Generated BDY t information
INFO:pynemo.profiler:Grid t has shape (6864, 2)
INFO:pynemo.profiler:Generated BDY u information
INFO:pynemo.profiler:Grid u has shape (6815, 2)
INFO:pynemo.profiler:Generated BDY v information
INFO:pynemo.profiler:Grid v has shape (6824, 2)
INFO:pynemo.profiler:File: coordinates.bdy.nc generated and populated
INFO:pynemo.profiler:Gathering grid information
INFO:pynemo.profiler:Depths defined
INFO:pynemo.profiler:Grid coordinates defined
INFO:pynemo.profiler:BDY lons/lats identified from ./benchmark/grid_C/mesh_hgr_zps.nc
INFO:pynemo.reader.ncml:(8,)
jpolton commented 1 year ago
jpolton commented 1 year ago

Started draft pull request #141 to add TPXO9 functionality (TPXO9v5).

jpolton commented 1 year ago

@banmianyu The linked branch (feature/tpxo9) can now do newer versions of TPXO. Specifically TPXO9v5 as that was what I could get. You will have to make (light) edits if you want to use something different from TPXO9v5, so it accepts your version, which I couldn't check but I bet the structure is the same.

Though the branch is "ready" we can't really merge it into master until we have figured out a way for a colleague to verify it and ideally create some unit tests for these tidal extraction routines. That is a problem as the routines are bespoke to the data and the raw dataset is 20Gb, so clearly a bit of thinking needs to be done to make this last step manageable before it is merged.