How to edit global attributes in netcdf file with NCO - netcdf

I am trying to edit one of the global attributes in my netcdf file:
START_DATE = "2016-05-12_00:00:00"
I want to change the date string to another date. How do you do this with the nco package?
I've seen that I can use
ncatted [-a ...] [-D dbg_lvl] [-h] [-l path] [-O] [-o out.nc] [-p path] [-R] [-r] in.nc [[out.nc]]
I've read the docs, but there are limited examples shown.
This is how I used it:
ncatted -O -h -a START_DATE,,m,c,"2016-06-12_00:00:00" wrfchemi_d01.nc wrfnew.nc
Upon checking the output with ncdump, the global attribute did not change as seen here:
// global attributes:
:TITLE = " OUTPUT FROM * PROGRAM:WRF-Chem V4.1.2 MODEL" ;
:START_DATE = "2016-05-12_00:00:00" ;
:WEST-EAST_GRID_DIMENSION = 70 ;
:SOUTH-NORTH_GRID_DIMENSION = 70 ;
:BOTTOM-TOP_GRID_DIMENSION = 51 ;
:DX = 25000.f ;
:DY = 25000.f ;
:AERCU_OPT = 0 ;
:AERCU_FCT = 1.f ;
:IDEAL_CASE = 0 ;
:DIFF_6TH_SLOPEOPT = 0 ;
:AUTO_LEVELS_OPT = 2 ;
:DIFF_6TH_THRESH = 0.1f ;
:DZBOT = 50.f ;
:DZSTRETCH_S = 1.3f ;
:DZSTRETCH_U = 1.1f ;
:GRIDTYPE = "C" ;
:DIFF_OPT = 1 ;
:KM_OPT = 4 ;
:DAMP_OPT = 3 ;
:DAMPCOEF = 0.2f ;
:KHDIF = 0.f ;
:KVDIF = 0.f ;
:MP_PHYSICS = -1 ;
:RA_LW_PHYSICS = 1 ;
:RA_SW_PHYSICS = 1 ;
:SF_SFCLAY_PHYSICS = 2 ;
:SF_SURFACE_PHYSICS = 2 ;
:BL_PBL_PHYSICS = 2 ;
:CU_PHYSICS = 5 ;
:SF_LAKE_PHYSICS = 0 ;
:SURFACE_INPUT_SOURCE = 1 ;
:SST_UPDATE = 0 ;
:GRID_FDDA = 0 ;
:GFDDA_INTERVAL_M = 0 ;
:GFDDA_END_H = 0 ;
:GRID_SFDDA = 0 ;
:SGFDDA_INTERVAL_M = 0 ;
:SGFDDA_END_H = 0 ;
:HYPSOMETRIC_OPT = 2 ;
:USE_THETA_M = 1 ;
:GWD_OPT = 0 ;
:SF_URBAN_PHYSICS = 0 ;
:SF_SURFACE_MOSAIC = 0 ;
:SF_OCEAN_PHYSICS = 0 ;
:WEST-EAST_PATCH_START_UNSTAG = 1 ;
:WEST-EAST_PATCH_END_UNSTAG = 69 ;
:WEST-EAST_PATCH_START_STAG = 1 ;
:WEST-EAST_PATCH_END_STAG = 70 ;
:SOUTH-NORTH_PATCH_START_UNSTAG = 1 ;
:SOUTH-NORTH_PATCH_END_UNSTAG = 69 ;
:SOUTH-NORTH_PATCH_START_STAG = 1 ;
:SOUTH-NORTH_PATCH_END_STAG = 70 ;
:BOTTOM-TOP_PATCH_START_UNSTAG = 1 ;
:BOTTOM-TOP_PATCH_END_UNSTAG = 50 ;
:BOTTOM-TOP_PATCH_START_STAG = 1 ;
:BOTTOM-TOP_PATCH_END_STAG = 51 ;
:GRID_ID = 1 ;
:PARENT_ID = 1 ;
:I_PARENT_START = 1 ;
:J_PARENT_START = 1 ;
:PARENT_GRID_RATIO = 1 ;
:DT = 150.f ;
:CEN_LAT = 14.60003f ;
:CEN_LON = 120.98f ;
:TRUELAT1 = 14.6f ;
:TRUELAT2 = 14.6f ;
:MOAD_CEN_LAT = 14.60003f ;
:STAND_LON = 120.98f ;
:POLE_LAT = 90.f ;
:POLE_LON = 0.f ;
:GMT = 0.f ;
:JULYR = 2016 ;
:JULDAY = 133 ;
:MAP_PROJ = 1 ;
:MAP_PROJ_CHAR = "Lambert Conformal" ;
:MMINLU = "USGS" ;
:NUM_LAND_CAT = 28 ;
:ISWATER = 16 ;
:ISLAKE = 28 ;
:ISICE = 24 ;
:ISURBAN = 1 ;
:ISOILWATER = 14 ;
:HYBRID_OPT = 2 ;
:ETAC = 0.2f ;
Can someone show me how its done for this simple change?
Thanks!

It is a global attribute and the syntax you invoked will only change the attribute for all variable attributes of that name, not global attributes. Read the docs on that point and try
ncatted -O -h -a START_DATE,global,m,c,"2016-06-12_00:00:00" wrfchemi_d01.nc wrfnew.nc

Related

netcdf file, delete first 1 and last 2 rows of lat and lon

I have a netcdf input file of following header:
`netcdf file:/Volumes/NSF12KP3CTL_CLM45_surface.nc {
dimensions:
jx = 180;
iy = 165;
kz = 19;
nmon = 12;
lsmpft = 17;
nlevsoi = 10;
gridcell = 12194;
numurbl = 3;
nlevurb = 5;
numrad = 2;`
And I have another output file that has header:
`dimensions:
gridcell = 12194 ;
landunit = 24398 ;
column = 36632 ;
pft = 207348 ;
jx = 177 ;
iy = 162 ;
levgrnd = 15 ;
levurb = 5 ;
levlak = 10 ;
numrad = 2 ;
string_length = 8 ;
levdcmp = 1 ;
hist_interval = 2 ;
time = UNLIMITED ; // (30 currently)`
All I want is to cut the first 1 and last 2 rows of both jx and iy from input file so that I can merge it into the output file to convert together into 2d lat-lon grid.
Thank you,
Y
I tried with cdo, nco. I have a model executable to convert it into 2d.

(Godot Engine) Compute string as PEMDAS

I've been trying to create a function in GDScript to process and calculate a string using PEMDAS rules. Below is my try on the subject. It can so far only use the MDAS rules:
Is there a better way to achieve such a function?
func _ready() -> void:
### USE CASES ###
print(Compute_String("1+2*3+3=")) # Output = 10
print(Compute_String("1+2*3*3=")) # Output = 19
print(Compute_String("1*2*3+3=")) # Output = 9
print(Compute_String("1+2+3*3=")) # Output = 12
print(Compute_String("5*2+7-3/2=")) # Output = 15.5
print(Compute_String("9+5.5*2.25=")) # Output = 21.375
print(Compute_String("5*2+7-3/2")) # Output = 1.#QNAN (Missing equals)
print(Compute_String("5*2+7-/2=")) # Output = 1.#QNAN (Adjacent operators)
print(Compute_String("*2+7-3/2=")) # Output = 1.#QNAN (Begins with operator)
print(Compute_String("")) # Output = 1.#QNAN (Empty)
print(Compute_String("=")) # Output = 1.#QNAN (Considered as empty)
print(Compute_String("1 +2=")) # Output = 1.#QNAN (Contains space)
print(Compute_String("(1+2)*3=")) # Output = 1.#QNAN (Parentheses not supported)
func Compute_String(_string: String) -> float:
var _result: float = NAN
var _elements: Array = []
if not _string.empty() and _string[_string.length() - 1] == "=":
var _current_element: String = ""
for _count in _string.length():
if _string[_count].is_valid_float() or _string[_count] == ".": _current_element += _string[_count]
else:
if _string[_count - 1].is_valid_float() and (_string[_count + 1].is_valid_float() if _string[_count] != "=" else true):
_elements.append_array([_current_element,_string[_count]]) ; _current_element = ""
else: return NAN
if not _elements.empty():
_elements.resize(_elements.size() - 1)
while _get_operators_count(_elements) != 0:
var _id: Array = [0, 0.0, 0.0]
if "*" in _elements:
_id = _add_adjacent(_elements, "*") ; _remove_adjacent(_elements, _id[0]) ; _elements.insert(_id[0] - 1, _id[1] * _id[2])
elif "/" in _elements:
_id = _add_adjacent(_elements, "/") ; _remove_adjacent(_elements, _id[0]) ; _elements.insert(_id[0] - 1, _id[1] / _id[2])
elif "+" in _elements:
_id = _add_adjacent(_elements, "+") ; _remove_adjacent(_elements, _id[0]) ; _elements.insert(_id[0] - 1, _id[1] + _id[2])
elif "-" in _elements:
_id = _add_adjacent(_elements, "-") ; _remove_adjacent(_elements, _id[0]) ; _elements.insert(_id[0] - 1, _id[1] - _id[2])
else: return NAN
if _elements.size() == 1: _result = _elements[0]
return _result
func _get_operators_count(_elements: Array) -> int:
var _result: int = 0 ; for _element in _elements: if not str(_element).is_valid_float(): _result += 1 ; return _result
func _add_adjacent(_elements: Array, _operator) -> Array:
return [_elements.find(_operator), float(_elements[_elements.find(_operator) - 1]), float(_elements[_elements.find(_operator) + 1])]
func _remove_adjacent(_elements: Array, _operator_idx: int) -> void:
_elements.remove(_operator_idx + 1) ; _elements.remove(_operator_idx) ; _elements.remove(_operator_idx - 1)

RISC-V undefined reference to `memcpy'

I am using RISC-V 32E toolchain to compile some standalone CPP code. I got errors below.
/opt/riscv32i/bin/riscv32-unknown-elf-g++ -Os -ffreestanding -o firmware/firmware.elf \
-Wl,-Bstatic,-T,firmware/sections.lds,-Map,firmware/firmware.map,--strip-debug \
firmware/start.o firmware/print.o firmware/stream.o firmware/main.o firmware/accel.o firmware/data_redir_m.o -lgcc -fno-threadsafe-statics -nostdlib
/opt/riscv32i/lib/gcc/riscv32-unknown-elf/8.2.0/../../../../riscv32-unknown-elf/bin/ld: firmware/data_redir_m.o: in function `.L31':
data_redir_m.cpp:(.text+0x442): undefined reference to `memcpy'
collect2: error: ld returned 1 exit status
Makefile:46: recipe for target 'firmware/firmware.elf' failed
make: *** [firmware/firmware.elf] Error 1
I want to keep the hex file as small as possible, so my preference is to not use -lstdc++ library. What confused me a lot is why it still complains about such errors even if I manually add the memcpy() function definition in data_redir_m.cpp file.
#include "typedefs.h"
void * memcpy ( void * destination, const void * source, int num ){
int i=0;
*((int*)destination) = *((int*)source);
}
static int check_clockwise( Triangle_2D triangle_2d )
{
int cw;
cw = (triangle_2d.x2 - triangle_2d.x0) * (triangle_2d.y1 - triangle_2d.y0)
- (triangle_2d.y2 - triangle_2d.y0) * (triangle_2d.x1 - triangle_2d.x0);
return cw;
}
// swap (x0, y0) (x1, y1) of a Triangle_2D
static void clockwise_vertices( Triangle_2D *triangle_2d )
{
bit8 tmp_x, tmp_y;
tmp_x = triangle_2d->x0;
tmp_y = triangle_2d->y0;
triangle_2d->x0 = triangle_2d->x1;
triangle_2d->y0 = triangle_2d->y1;
triangle_2d->x1 = tmp_x;
triangle_2d->y1 = tmp_y;
}
// find the min from 3 integers
static bit8 find_min( bit8 in0, bit8 in1, bit8 in2 )
{
if (in0 < in1)
{
if (in0 < in2)
return in0;
else
return in2;
}
else
{
if (in1 < in2)
return in1;
else
return in2;
}
}
// find the max from 3 integers
static bit8 find_max( bit8 in0, bit8 in1, bit8 in2 )
{
if (in0 > in1)
{
if (in0 > in2)
return in0;
else
return in2;
}
else
{
if (in1 > in2)
return in1;
else
return in2;
}
}
// project a 3D triangle to a 2D triangle
void projection(
bit32 input_lo,
bit32 input_mi,
bit32 input_hi,
Triangle_2D *triangle_2d
)
{
#pragma HLS INLINE off
Triangle_3D triangle_3d;
// Setting camera to (0,0,-1), the canvas at z=0 plane
// The 3D model lies in z>0 space
// The coordinate on canvas is proportional to the corresponding coordinate
// on space
bit2 angle = 0;
triangle_3d.x0 = bit8(input_lo( 7, 0));
triangle_3d.y0 = bit8(input_lo(15, 8));
triangle_3d.z0 = bit8(input_lo(23, 16));
triangle_3d.x1 = bit8(input_lo(31, 24));
triangle_3d.y1 = bit8(input_mi( 7, 0));
triangle_3d.z1 = bit8(input_mi(15, 8));
triangle_3d.x2 = bit8(input_mi(23, 16));
triangle_3d.y2 = bit8(input_mi(31, 24));
triangle_3d.z2 = bit8(input_hi( 7, 0));
if(angle == 0)
{
triangle_2d->x0 = triangle_3d.x0;
triangle_2d->y0 = triangle_3d.y0;
triangle_2d->x1 = triangle_3d.x1;
triangle_2d->y1 = triangle_3d.y1;
triangle_2d->x2 = triangle_3d.x2;
triangle_2d->y2 = triangle_3d.y2;
triangle_2d->z = triangle_3d.z0 / 3 + triangle_3d.z1 / 3 + triangle_3d.z2 / 3;
}
else if(angle == 1)
{
triangle_2d->x0 = triangle_3d.x0;
triangle_2d->y0 = triangle_3d.z0;
triangle_2d->x1 = triangle_3d.x1;
triangle_2d->y1 = triangle_3d.z1;
triangle_2d->x2 = triangle_3d.x2;
triangle_2d->y2 = triangle_3d.z2;
triangle_2d->z = triangle_3d.y0 / 3 + triangle_3d.y1 / 3 + triangle_3d.y2 / 3;
}
else if(angle == 2)
{
triangle_2d->x0 = triangle_3d.z0;
triangle_2d->y0 = triangle_3d.y0;
triangle_2d->x1 = triangle_3d.z1;
triangle_2d->y1 = triangle_3d.y1;
triangle_2d->x2 = triangle_3d.z2;
triangle_2d->y2 = triangle_3d.y2;
triangle_2d->z = triangle_3d.x0 / 3 + triangle_3d.x1 / 3 + triangle_3d.x2 / 3;
}
}
// calculate bounding box for a 2D triangle
void rasterization1 (
Triangle_2D triangle_2d,
hls::stream<ap_uint<32> > & Output_1,
hls::stream<ap_uint<32> > & Output_2
)
{
Triangle_2D triangle_2d_same;
bit8 max_min[5];
max_min[0]=0;
max_min[1]=0;
max_min[2]=0;
max_min[3]=0;
max_min[4]=0;
bit16 max_index[1];
max_index[0]=0;
bit32 tmp1, tmp2, tmp3, tmp4;
static int parity = 0;
#pragma HLS INLINE off
// clockwise the vertices of input 2d triangle
if ( check_clockwise( triangle_2d ) == 0 ){
tmp1(7,0) = 1;
tmp1(15, 8) = triangle_2d_same.x0;
tmp1(23,16) = triangle_2d_same.y0;
tmp1(31,24) = triangle_2d_same.x1;
tmp2(7,0) = triangle_2d_same.y1;
tmp2(15, 8) = triangle_2d_same.x2;
tmp2(23,16) = triangle_2d_same.y2;
tmp2(31,24) = triangle_2d_same.z;
tmp3(15,0) = max_index[0];
tmp3(23,16) = max_min[0];
tmp3(31,24) = max_min[1];
tmp4(7,0) = max_min[2];
tmp4(15, 8) = max_min[3];
tmp4(23,16) = max_min[4];
tmp4(31,24) = 0;
if(parity==0){
Output_1.write(tmp1);
Output_1.write(tmp2);
Output_1.write(tmp3);
Output_1.write(tmp4);
parity = 1;
}else{
Output_2.write(tmp1);
Output_2.write(tmp2);
Output_2.write(tmp3);
Output_2.write(tmp4);
parity = 0;
}
#ifdef PROFILE
data_redir_m_out_1+=4;
#endif
return;
}
if ( check_clockwise( triangle_2d ) < 0 )
clockwise_vertices( &triangle_2d );
// copy the same 2D triangle
triangle_2d_same.x0 = triangle_2d.x0;
triangle_2d_same.y0 = triangle_2d.y0;
triangle_2d_same.x1 = triangle_2d.x1;
triangle_2d_same.y1 = triangle_2d.y1;
triangle_2d_same.x2 = triangle_2d.x2;
triangle_2d_same.y2 = triangle_2d.y2;
triangle_2d_same.z = triangle_2d.z ;
// find the rectangle bounds of 2D triangles
max_min[0] = find_min( triangle_2d.x0, triangle_2d.x1, triangle_2d.x2 );
max_min[1] = find_max( triangle_2d.x0, triangle_2d.x1, triangle_2d.x2 );
max_min[2] = find_min( triangle_2d.y0, triangle_2d.y1, triangle_2d.y2 );
max_min[3] = find_max( triangle_2d.y0, triangle_2d.y1, triangle_2d.y2 );
max_min[4] = max_min[1] - max_min[0];
// calculate index for searching pixels
max_index[0] = (max_min[1] - max_min[0]) * (max_min[3] - max_min[2]);
tmp1(7,0) = 0;
tmp1(15,8) = triangle_2d_same.x0;
tmp1(23,16) = triangle_2d_same.y0;
tmp1(31,24) = triangle_2d_same.x1;
tmp2(7,0) = triangle_2d_same.y1;
tmp2(15,8) = triangle_2d_same.x2;
tmp2(23,16) = triangle_2d_same.y2;
tmp2(31,24) = triangle_2d_same.z;
tmp3(15,0) = max_index[0];
tmp3(23,16) = max_min[0];
tmp3(31,24) = max_min[1];
tmp4(7,0) = max_min[2];
tmp4(15,8) = max_min[3];
tmp4(23, 16) = max_min[4];
tmp4(31, 24) = 0;
if(parity==0){
Output_1.write(tmp1);
Output_1.write(tmp2);
Output_1.write(tmp3);
Output_1.write(tmp4);
parity = 1;
}else{
Output_2.write(tmp1);
Output_2.write(tmp2);
Output_2.write(tmp3);
Output_2.write(tmp4);
parity = 0;
}
return;
}
void data_redir_m (
hls::stream<ap_uint<32> > & Input_1,
hls::stream<ap_uint<32> > & Output_1,
hls::stream<ap_uint<32> > & Output_2
)
{
#pragma HLS INTERFACE ap_hs port=Input_1
#pragma HLS INTERFACE ap_hs port=Output_1
#pragma HLS INTERFACE ap_hs port=Output_2
bit32 input_lo;
bit32 input_mi;
bit32 input_hi;
bit128 input_tmp;
hls::stream<ap_uint<32> > Output_1_1;
hls::stream<ap_uint<32> > Output_2_2;
Triangle_2D triangle_2ds_1;
Triangle_2D triangle_2ds_2;
input_lo = Input_1.read();
input_mi = Input_1.read();
input_hi = Input_1.read();
#ifdef PROFILE
data_redir_m_in_1+=3;
#endif
projection (input_lo,input_mi,input_hi,&triangle_2ds_1);
rasterization1 (triangle_2ds_1, Output_1, Output_2);
}
If you want to build gcc for non-os environment, you need to build newlib in advance. And tell gcc where to find the libc, the way is to declare sysroot when configure the project.
You can use this script(ian910297/build-riscv-gnu-toolchain) to build riscv gnu toolchain. If you choose this method, be care of the directory name.
Otherwise, riscv official also provide similar script to build, like: riscv/riscv-gnu-toolchain)

Performance issue processing NetCDF files

I am using gridMET (http://www.climatologylab.org/gridmet.html) and MACA (http://thredds.northwestknowledge.net:8080/thredds/reacch_climate_CMIP5_macav2_catalog2.html) NetCDF files for a project and facing a performance issue. Implementation of a simple function on the gridMET NetCDF files (time duration: 1979-2015) is around 0.01sec/grid cell. However, processing of MACA NetCDF files (time duration: 2016-2050) with the same function as used for gridMET data is around 0.3sec/grid cell. Processing time over large areas is drastically different for both datasets.
Header information of gridMET file is:
netcdf pr_1980 {
dimensions:
lon = 1386 ;
lat = 585 ;
day = 366 ;
crs = 1 ;
variables:
double lon(lon) ;
lon:units = "degrees_east" ;
lon:description = "longitude" ;
lon:axis = "X" ;
lon:standard_name = "longitude" ;
lon:long_name = "latitude" ;
double lat(lat) ;
lat:units = "degrees_north" ;
lat:description = "latitude" ;
lat:axis = "Y" ;
lat:standard_name = "latitude" ;
lat:long_name = "latitude" ;
float day(day) ;
day:units = "days since 1900-01-01 00:00:00" ;
day:calendar = "gregorian" ;
day:description = "days since 1900-01-01" ;
day:standard_name = "time" ;
day:long_name = "time" ;
float precipitation_amount(day, lat, lon) ;
precipitation_amount:units = "mm" ;
precipitation_amount:description = "Daily Accumulated Precipitation" ;
precipitation_amount:_FillValue = -32767.f ;
precipitation_amount:coordinates = "lon lat" ;
precipitation_amount:cell_methods = "time: sum(interval: 24 hours)" ;
precipitation_amount:missing_value = -32767. ;
precipitation_amount:grid_mapping = "crs" ;
int crs(crs) ;
crs:grid_mapping_name = "latitude_longitude" ;
crs:longitude_of_prime_meridian = 0. ;
crs:semi_major_axis = 6378137. ;
crs:inverse_flattening = 298.257223563 ;
crs:spatial_ref = "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]" ;
crs:long_name = "WGS 84" ;
// global attributes:
:author = "John Abatzoglou - University of Idaho, jabatzoglou#uidaho.edu" ;
:datee = "02 December 2017" ;
:note1 = "The projection information for this file is: GCS WGS 1984." ;
:note2 = "Citation: Abatzoglou, J.T., 2013, Development of gridded surface meteorological data for ecological applications and modeling, International Journal of Climatology, DOI: 10.1002/joc.3413" ;
:last_permanent_slice = "306" ;
:last_provisional_slice = "360" ;
:note3 = "Data in slices after last_permanent_slice (1-based) are considered provisional and subject to change with subsequent updates" ;
:note4 = "Data in slices after last_provisional_slice (1-based) are considered early and subject to change with subsequent updates" ;
:note5 = "Days correspond approximately to calendar days ending at midnight, Mountain Standard Time (7 UTC the next calendar day)" ;
:geospatial_bounds_crs = "EPSG:4326" ;
:Conventions = "CF-1.6" ;
:geospatial_bounds = "POLYGON((-124.7666666333333 49.400000000000000, -124.7666666333333 25.066666666666666, -67.058333300000015 25.066666666666666, -67.058333300000015 49.400000000000000, -124.7666666333333 49.400000000000000))" ;
:geospatial_lat_min = "25.066666666666666" ;
:geospatial_lat_max = "49.40000000000000" ;
:geospatial_lon_min = "-124.7666666333333" ;
:geospatial_lon_max = "-67.058333300000015" ;
:geospatial_lon_resolution = "0.041666666666666" ;
:geospatial_lat_resolution = "0.041666666666666" ;
:geospatial_lat_units = "decimal_degrees north" ;
:geospatial_lon_units = "decimal_degrees east" ;
:coordinate_system = "EPSG:4326" ;
:_Format = "classic" ;
}
Header information of MACA file is:
netcdf pr_CanESM2_macav2_2016 {
dimensions:
crs = 1 ;
lat = 585 ;
lon = 1386 ;
time = 366 ;
variables:
int crs(crs) ;
crs:grid_mapping_name = "latitude_longitude" ;
crs:longitude_of_prime_meridian = 0. ;
crs:semi_major_axis = 6378137. ;
crs:inverse_flattening = 298.257223563 ;
double lat(lat) ;
lat:long_name = "latitude" ;
lat:standard_name = "latitude" ;
lat:units = "degrees_north" ;
lat:axis = "Y" ;
lat:description = "Latitude of the center of the grid cell" ;
double lon(lon) ;
lon:long_name = "longitude" ;
lon:standard_name = "longitude" ;
lon:units = "degrees_east" ;
lon:axis = "X" ;
lon:description = "Longitude of the center of the grid cell" ;
float precipitation(time, lat, lon) ;
precipitation:_FillValue = -9999.f ;
precipitation:long_name = "Precipitation" ;
precipitation:units = "mm" ;
precipitation:grid_mapping = "crs" ;
precipitation:standard_name = "precipitation" ;
precipitation:cell_methods = "time: sum(interval: 24 hours)" ;
precipitation:comments = "Total daily precipitation at surface; includes both liquid and solid phases from all types of clouds (both large-scale and convective)" ;
precipitation:coordinates = "time lon lat" ;
float time(time) ;
time:units = "days since 1900-01-01 00:00:00" ;
time:calendar = "gregorian" ;
time:description = "days since 1900-01-01" ;
// global attributes:
:description = "Multivariate Adaptive Constructed Analogs (MACA) method, version 2.3,Dec 2013." ;
:id = "MACAv2-METDATA" ;
:naming_authority = "edu.uidaho.reacch" ;
:Metadata_Conventions = "Unidata Dataset Discovery v1.0" ;
:Metadata_Link = "" ;
:cdm_data_type = "GRID" ;
:title = "Downscaled daily meteorological data of Precipitation from Canadian Centre for Climate Modelling and Analysis (CanESM2) using the run r1i1p1 of the rcp85 scenario." ;
:summary = "This archive contains daily downscaled meteorological and hydrological projections for the Conterminous United States at 1/24-deg resolution utilizing the Multivariate Adaptive Constructed Analogs (MACA, Abatzoglou, 2012) statistical downscaling method with the METDATA (Abatzoglou,2013) training dataset. The downscaled meteorological variables are maximum/minimum temperature(tasmax/tasmin), maximum/minimum relative humidity (rhsmax/rhsmin)precipitation amount(pr), downward shortwave solar radiation(rsds), eastward wind(uas), northward wind(vas), and specific humidity(huss). The downscaling is based on the 365-day model outputs from different global climate models (GCMs) from Phase 5 of the Coupled Model Inter-comparison Project (CMIP3) utlizing the historical (1950-2005) and future RCP4.5/8.5(2006-2099) scenarios. Leap days have been added to the dataset from the average values between Feb 28 and Mar 1 in order to aid modellers." ;
:keywords = "daily precipitation, daily maximum temperature, daily minimum temperature, daily downward shortwave solar radiation, daily specific humidity, daily wind velocity, CMIP5, Gridded Meteorological Data" ;
:keywords_vocabulary = "" ;
:standard_name_vocabulary = "CF-1.0" ;
:history = "Sat Jun 15 16:07:12 2019: C:\\nco\\ncks.exe -3 -d time,0,365,1 macav2metdata_pr_CanESM2_r1i1p1_rcp85_2016_2020_CONUS_daily.nc pr_CanESM2_macav2_2016.nc\n",
"No revisions." ;
:comment = "Total daily precipitation at surface; includes both liquid and solid phases from all types of clouds (both large-scale and convective)" ;
:geospatial_bounds = "POLYGON((-124.7722 25.0631,-124.7722 49.3960, -67.0648 49.3960,-67.0648, 25.0631, -124.7722,25.0631))" ;
:geospatial_lat_min = "25.0631" ;
:geospatial_lat_max = "49.3960" ;
:geospatial_lon_min = "-124.7722" ;
:geospatial_lon_max = "-67.0648" ;
:geospatial_lat_units = "decimal degrees north" ;
:geospatial_lon_units = "decimal degrees east" ;
:geospatial_lat_resolution = "0.0417" ;
:geospatial_lon_resolution = "0.0417" ;
:geospatial_vertical_min = 0. ;
:geospatial_vertical_max = 0. ;
:geospatial_vertical_resolution = 0. ;
:geospatial_vertical_positive = "up" ;
:time_coverage_start = "2016-01-01T00:0" ;
:time_coverage_end = "2020-12-31T00:00" ;
:time_coverage_duration = "P5Y" ;
:time_coverage_resolution = "P1D" ;
:date_created = "2014-05-15" ;
:date_modified = "2014-05-15" ;
:date_issued = "2014-05-15" ;
:creator_name = "John Abatzoglou" ;
:creator_url = "http://maca.northwestknowledge.net" ;
:creator_email = "jabatzoglou#uidaho.edu" ;
:institution = "University of Idaho" ;
:processing_level = "GRID" ;
:project = "" ;
:contributor_name = "Katherine C. Hegewisch" ;
:contributor_role = "Postdoctoral Fellow" ;
:publisher_name = "" ;
:publisher_email = "" ;
:publisher_url = "" ;
:license = "Creative Commons CC0 1.0 Universal Dedication(http://creativecommons.org/publicdomain/zero/1.0/legalcode)" ;
:coordinate_system = "WGS84,EPSG:4326" ;
:NCO = "netCDF Operators version 4.8.1-alpha03 (Homepage = http://nco.sf.net, Code = http://github.com/nco/nco)" ;
:_Format = "classic" ;
}
gridMET files have 'Classic' format and MACA files have NetCDF4 format. Changing MACA files format to 'Classic' using the following:
ncks -3 in.nc out.nc
still leads to 0.3sec/grid cell processing time for years 2016-2050.
Here is the code I am using to read and process NetCDF files:
ds = xr.open_mfdataset('D:/proj1/*.nc', concat_dim='time')
da = ds.var.sel(lat=273.15, lat=49.4, method='nearest')
da_con = da[(da > 35.5)]
Kindly suggest any modification(s) to NetCDF files to reduce processing overhead.
Interestingly, reordering of dimensions reduced processing time to 0.05sec/grid cell. I used the following command line operation to reorder dimensions:
ncpdq -a lon,lat,time in.nc out.nc
There may be other solutions but this worked for time being.

Autoit get CPU temp and put it into a graph

This is the code i have so far:
#RequireAdmin
#include <GUIConstants.au3>
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$strComputer = "."
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\wmi")
$Instances = $objWMIService.InstancesOf("MSAcpi_ThermalZoneTemperature")
For $Item in $Instances
$temp=($Item.CurrentTemperature - 2732) / 10
Next
Opt("GUIOnEventMode", 1)
GUICreate("", 340, 330)
GUISetOnEvent($GUI_EVENT_CLOSE,"close")
$GraphWidth = 273
$GraphHeight = 273
$graph = GUICtrlCreateGraphic(48, 15, $GraphWidth, $GraphHeight)
GUICtrlSetBkColor(-1,0xFFFFFF)
GUICtrlSetColor(-1,0x000000)
$yMax = 100
$yMin = 0
$xMax = 100
$xMin = 0
GUICtrlCreateLabel($yMax,15,10,20,15,$SS_RIGHT)
GUICtrlCreateLabel($yMin,15,280,20,15,$SS_RIGHT)
GUICtrlCreateLabel($xMax,307,295,20,15,$SS_CENTER)
GUICtrlCreateLabel($xMin,38,295,20,15,$SS_CENTER)
GUICtrlCreateLabel("TEMP",10,120)
$tmp=GUICtrlCreateLabel($temp,20,140)
GUISetState()
while 1
sleep(10000)
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$strComputer = "."
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\wmi")
$Instances = $objWMIService.InstancesOf("MSAcpi_ThermalZoneTemperature")
For $Item in $Instances
$temp=($Item.CurrentTemperature - 2732) / 10
Next
GUICtrlSetData($tmp, $temp)
WEnd
func close()
Exit
EndFunc
The code gets the CPU temperature and makes a graph. My questions is how do i put the temperature in to the graph and make it update every 10 seconds. Thanks for any help.
I have made this script using parts of your code, the getting of the temperature and creating and setting the event of it.
I have added the use of the library GraphGDIPlus.au3 which can be downloaded and put into your program files -> autoit -> include; link to GraphGDIPlus.
Here is the script (commented for understanding):
#RequireAdmin
#include <GraphGDIPlus.au3>
#include <GUIConstants.au3>
AdlibRegister("findTemp", 9000)
AdlibRegister("_Draw_Graph", 10000)
Local $hGUI, $hGraph, $temp, $Counter = 1, $iCheck, $msg, $xVal = 1
$hGUI = GUICreate("", 600, 350) ; create the GUI window
$iCheck = GUICtrlCreateCheckbox("Reset on next interval", 462, 1)
GUISetState() ; show the window
CreateGraph() ; create the graph
findTemp() ; find the temp
_Draw_Graph() ; draw the graph
While 1
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE
Quit()
EndSwitch
WEnd
Func CreateGraph()
If IsArray($hGraph) = 0 Then
$hGraph = _GraphGDIPlus_Create($hGUI, 37, 24, 545, 300, 0xFF000000, 0xFF88B3DD) ; create the graph
EndIf
If $Counter > 24 Then
_GraphGDIPlus_Set_RangeX($hGraph, $xVal, $Counter, 24)
$xVal += 1
Else
_GraphGDIPlus_Set_RangeX($hGraph, 0, 24, 24) ; set the x range from 0 - 24 putting all 24 ticks on screen
_GraphGDIPlus_Set_RangeY($hGraph, 0, 125, 5) ; set the y range from 0 - 125 only putting 5 ticks on screen
_GraphGDIPlus_Set_GridX($hGraph, 1, 0xFF6993BE) ; set the x grid
_GraphGDIPlus_Set_GridY($hGraph, 1, 0xFF6993BE) ; set the y grid
EndIf
EndFunc ;==>CreateGraph
Func _Draw_Graph()
Local $rCheckbox
$rCheckbox = GUICtrlRead($iCheck)
If $rCheckbox = 1 Then
ControlClick($hGUI, "Reset on next interval", $iCheck)
_GraphGDIPlus_Delete($hGUI, $hGraph) ; delete the graph
$Counter = 1 ; reset the counter
$xVal = 1 ; reset the x range counter
CreateGraph() ; and create the graph again
EndIf
If $Counter > 24 Then ; if we've reached the end
CreateGraph() ; and create the graph again
EndIf
_GraphGDIPlus_Set_PenColor($hGraph, 0xFF325D87) ; set the color of the line
_GraphGDIPlus_Set_PenSize($hGraph, 2) ; set the size of the line
_GraphGDIPlus_Plot_Start($hGraph, $Counter, 0) ; set the start on the graph plot
_GraphGDIPlus_Plot_Line($hGraph, $Counter, $temp) ; set the line ending
_GraphGDIPlus_Refresh($hGraph) ; draw it to the screen
$Counter += 1 ; add one to our counter
EndFunc ;==>_Draw_Graph
Func findTemp()
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$strComputer = "."
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\wmi")
$Instances = $objWMIService.InstancesOf("MSAcpi_ThermalZoneTemperature")
For $Item In $Instances
$temp = ($Item.CurrentTemperature - 2732) / 10 ; set the temp
Next
EndFunc ;==>findTemp
Func Quit()
_GraphGDIPlus_Delete($hGUI, $hGraph) ; delete the graph
Exit ; get us out
EndFunc ;==>Quit

Resources