Convert Mask (txt file) into usable nc Mask
Added by Frosi Ma almost 7 years ago
Hello everyone!
I've got a txt file (Mask.txt) that I want to work with - 0 stands for not significant and 1 for significant values.
Now I want to convert Mask.txt into a usable nc file --> Mask.nc
My idea/wish/dream would be to do something like this:
cdo select Input.nc Mask.nc Significant_Input.nc
This code is of course not working. The idea is to select only the values that are significant and the rest is set to missing.
My final goal is to get a plot of only significant areas.
My question is: How can I convert Mask.txt into Mask.nc?
Mask.txt is attachted. The columns stand for "Longitude" and the Rows for "Latitude".
Thank you very much.
Kind regards,
Frosi
pval_nocean.dat (4 KB) pval_nocean.dat |
Replies (3)
RE: Convert Mask (txt file) into usable nc Mask - Added by Ralf Mueller almost 7 years ago
What about this one
cat pval_nocean.dat | cdo -f nc input,r32x64 pval.ncNot sure, if the grid is correct, please check the output I uploaded.
hth
ralf
RE: Convert Mask (txt file) into usable nc Mask - Added by Karin Meier-Fleischer almost 7 years ago
Hi Frosi,
the data file is not enough. You need the latitude and longitude referring to your data and you have to create an associated time.
I don't know your lat/lon and time but here is the way to create the netCDF file.
First, create a grid describtion file (e.g. gridfile.txt) for your data which should look like:
gridtype = lonlat gridsize = 2048 xsize = 32 ysize = 64 xname = lon xlongname = longitude xunits = degrees_east yname = lat ylongname = latitude yunits = degrees_north xfirst = 0.0 xinc = 1.0 yfirst = 0.0 yinc = 1.0
Then set the name of the variable (e.g. mask), define the time dimension and set missing value to 0:
cdo -f nc -setctomiss,0 -settaxis,2000-01-01,00:00:00,1day -setname,mask -input,gridfile.txt pval_nocean.nc < pval_nocean.dat
-Karin
plot_pval_mask.png (69.5 KB) plot_pval_mask.png |
RE: Convert Mask (txt file) into usable nc Mask - Added by Frosi Ma almost 7 years ago
Thank you so much!
I was able to solve my problem with your help.
I used the code from @Karin because my grid is gaussian - it was easy to change the grid type.
Thank you so much for the hint with the time dimension!