Skip to content

Instantly share code, notes, and snippets.

View guziy's full-sized avatar
🇺🇦
#StandWithUkraine

Oleksandr Huziy guziy

🇺🇦
#StandWithUkraine
View GitHub Profile
#A one liner that tries to extract as generally as possible an integer number value from fortran name list in bash (number of soil layers in this case):
ignd=$(sed -n "/&physics_cfgs/I,/\//p" "${nmlfile}" | grep -i cLass_IG | grep "=" | grep -Eo '[[:digit:]]+')
##Explanation:
#1: select the namelist with sed (note ignoring case on the name of the namelist)
#2: look for the lines containing the parameter name (ignoring case here too)
#3: select only the lines which contain "=" sign.
#4: get only digits from the line
qs | grep -E -o '^[0-9]+'
@guziy
guziy / test_array_stack_mean.py
Created July 21, 2014 22:58
biggus mean of a stack of masked arrays
import biggus
import numpy as np
def main():
x = np.random.randn(10, 10)
y = np.ma.masked_where(x > 0, x)
yinv = np.ma.masked_where(~y.mask, x)
@guziy
guziy / Converter.py
Last active June 30, 2022 04:59
A quick way to copy variables and metadata from one netcdf file to another using netcdf4-python
# -*- coding: utf-8 -*-
from netCDF4 import Dataset
#input file
dsin = Dataset("crop.nc")
#output file
dsout = Dataset("crop.nc3", "w", format="NETCDF3_CLASSIC")
#Copy dimensions
@guziy
guziy / create_folders.py
Last active January 1, 2016 04:08
Automate folder creation for different processes
import os
import sys
"""
Author: Huziy
Purpose: Automate folder creation for different processes
"""
def main():
args = sys.argv
@guziy
guziy / kill.sh
Created October 28, 2013 21:04
Kill all processes containing bootstrap.py in the command
for id in $(ps ax | grep bootstrap.py | cut -d" " -f1)
do
kill -9 $id
done
cdo infov ANUSPLIN_latlon_stmn_2005_11.nc
-1 : Date Time Level Gridsize Miss : Minimum Mean Maximum : Parameter name
1 : 0000-00-01 00:00:00 0 544680 0 : nan nan nan : daily_minimum_temperature
2 : 0000-00-02 00:00:00 0 544680 0 : nan nan nan : daily_minimum_temperature
3 : 0000-00-03 00:00:00 0 544680 0 : nan nan nan : daily_minimum_temperature
4 : 0000-00-04 00:00:00 0 544680 0 : nan nan nan : daily_minimum_temperature
5 : 0000-00-05 00:00:00 0 544680 0 : nan nan nan : daily_minimum_temperature
6 : 0000-00-06 00:00:00 0 544680 0 : nan nan nan : daily_minimum_temperature
7 : 0000-00-07 00:00:00 0 544680 0 : nan nan nan : daily_minimum_temperature
8 : 0000-00-08 00:00:00
cdo infov ANUSPLIN_latlon_stmn_2005_11.nc
-1 : Date Time Level Gridsize Miss : Minimum Mean Maximum : Parameter name
1 : 2005-11-01 00:00:00 0 544680 287417 : -33.800 -10.348 10.620 : daily_minimum_temperature
2 : 2005-11-02 00:00:00 0 544680 287417 : -38.890 -11.761 11.000 : daily_minimum_temperature
3 : 2005-11-03 00:00:00 0 544680 287417 : -42.150 -12.516 11.690 : daily_minimum_temperature
4 : 2005-11-04 00:00:00 0 544680 287417 : -46.670 -12.967 13.740 : daily_minimum_temperature
5 : 2005-11-05 00:00:00 0 544680 287417 : -45.040 -13.658 13.910 : daily_minimum_temperature
6 : 2005-11-06 00:00:00 0 544680 287417 : -45.100 -14.014 11.840 : daily_minimum_temperature
7 : 2005-11-07 00:00:00 0 544680 287417 : -43.120 -13.841 10.800 : daily_minimum_temperature
8 : 2005-11-08 00:00:00
@guziy
guziy / changer.sh
Last active December 21, 2015 03:29
Correcting files using NCO utilities (namely: ncatted and ncap2)
#!/bin/bash
folder=.
prefix=ANUSPLIN_latlon_stmn_
var_name=daily_minimum_temperature
for x in ${folder}/${prefix}*.nc
do
x_name=$(basename $x)
part=$(echo $x_name | cut -d"." -f 1)
#get the year and month from the file name
@guziy
guziy / get_run_interval_from_logs.sh
Last active December 20, 2015 04:48
Parsing model log file
#!/bin/bash
#set -x
echo $1
found=$(fgrep --text "At" $1 | fgrep "User" | fgrep "Time" | fgrep "(sec)")
#echo "$found"
echo "-----------------------------------------------------------------------"
echo "start: " $(echo "$found" | head -1 | cut -f 1 -d"," )