Issue with Adding DMS to CMAQ Ocean File for 4km Domain (CMAQ_v5.4, cb6r5_ae7_aq)

Hello everyone,

I followed the CMAQ tutorial for creating an ocean file as input to CMAQ and successfully generated an ocean file for the 4km domain using SA_V4.3.1. I then used the attached Python script to add DMS to the ocean file, which I intend to use as input for CMAQ_v5.4 with the cb6r5_ae7_aq mechanism.

However, it appears that no attributes have been defined for the generated file, as confirmed by checking the header with ncdump -h. Additionally, I have uploaded the visualized output file produced by the Python script.

Could you please help me modify the Python script to ensure it generates the ocean file correctly with the necessary attributes?

Thank you in advance for your support!



New_DMS_CMAQ.txt (3.7 KB)

Hello @hhallaji ,

when you worked through the tutorial, did you follow step 3 to add DMS and CHLO to the file generated by the spatial allocator? The python script you attached seems to differ from the code in CMAQ_DMS_ChlorA.ipynb discussed in that step of the tutorial. For example, I don’t see any portion in your script that attempts to regrid the global DMS fields to your domain of interest, while this is one of the steps included in the notebook discussed in the tutorial and distributed with CMAQ.

@hogrefe.christian,

Many thanks for your response. Yes, I did follow Step 3, and I tried to write a code based on the one shared in the tutorial. However, the regridding part seems to have an issue, as I encountered an error stating that it couldn’t extract the grid information to assign for DMS regridding. This specific part is where I need help—I would appreciate guidance on how to correctly add the relevant line to my code.

I’ll tag @barronh for help here, but I was wondering why you decided to write your own code rather than trying to use the CMAQ_DMS_ChlorA.ipynb code described in the tutorial and released with CMAQ. Did you encounter any issues using that code?

Your script does not include several steps in the notebook.

  • Instead of re-writing the notebook, could you provide details about where it failed for you? For example, a screen shot of the first failure and the error text associated with it would be great!
  • Also, if you post an example OCEAN file (just OPEN and SURF), I’d be happy to test the notebook with that file and run (that’s the ocean_file_4km.ncf in your script). I will run the original notebook on Google Colab using the file you provide. That way I can reproduce your error.
1 Like

@barronh and @hogrefe.christian ,

I tried the notebook provided in the tutorial, and it seems that it successfully added DMS to the OCEAN file. I have attached the header of both OCEAN files: one with just OPEN and SURF, and the other with OPEN, SURF & DMS.

However, I have another question: how can I change the date in this notebook? I attempted to run a CMAQ test, but I encountered the following error:

However, I have another question: how can I change the date in this notebook? I attempted to run a CMAQ test, but I encountered the following error:

 "OCEAN_1" opened as OLD:READ-ONLY
 File name "/projects/HAQ_LAB/hhallaji/SA/Spatial-Allocator/output/DC4KM/OCEAN_20230101.nc"
 File type GRDDED3
 Execution ID "????????????????"
 Grid name "DC4KM"
 Dimensions: 288 rows, 288 cols, 1 lays, 3 vbles
 NetCDF ID:   1966080  opened as READONLY
 Starting date and time  2000001:000000 (0:00:00   Jan. 1, 2000)
 Timestep                          010000 (1:00:00 hh:mm:ss)
 Maximum current record number         1
 Requested date & time:            0:000000
 File starting date & time:  2000001:000000
 File time step:           010000

 >>--->> WARNING in subroutine RDTFLAG
 Time step error for file:  OCEAN_1


 >>--->> WARNING in subroutine XTRACT3
 Time step not available for file:  OCEAN_1



 *** ERROR ABORT in subroutine retrieve_ocean_d on PE 122
 Could not read OPEN from OCEAN_1
 PM3EXIT:  date&time specified as 0
 Date&time specified as 0

ocean_file_4km.txt (6.3 KB)
OCEAN_20230101.txt (11.4 KB)

It is possible to run daily specific OCEAN files, but that is usually not recommended. To make a file work for any day, you make it time-independent.

Since you’re working in python, I’ll recommend a couple options to make the file time-independent. Can you run them in order? I want to test which one works. So, try each option and run CMAQ. When it works, tell me which one did it.

Option 1: set TSTEP=0

import netCDF4
import numpy as np

path = 'OCEAN_20230101.nc'
f = netCDF4.Dataset(path, mode='rs')
f.TSTEP = np.int32(0);
f.close()

Option 2: set SDATE=-635 and TSTEP=0

import netCDF4
import numpy as np

path = 'OCEAN_20230101.nc'
f = netCDF4.Dataset(path, mode='rs')
f.SDATE = np.int32(-635);
f.TSTEP = np.int32(0);
f.close()

Option 3: set SDATE=-635 and TSTEP=0 and TFLAG=0

import netCDF4
import numpy as np

path = 'OCEAN_20230101.nc'
f = netCDF4.Dataset(path, mode='rs')
f.SDATE = np.int32(-635);
f.TSTEP = np.int32(0);
f.variables['TFLAG'][:] = 0;
f.close()

Since the file will be time-independent, you should be careful that you don’t accidentally use it inappropriately. So, don’t use a time-independent file for January in July.

I will try them and let you know which one works.

Just a quick question—as I am using the cb6r5_ae7_aq mechanism, I only need to add DMS to the OCEAN file. The notebook code generates a single file with SDATE = 2000001 and STIME = 0. I plan to use this file for several months in 2017, but I’m not sure how to correctly apply this time-independent file for, say, July 2017. Could you clarify?

@barronh,

Option 3 could resolve the error related to the OCEAN file that I encountered while running CMAQ.

Thanks.