Skip to content

Instantly share code, notes, and snippets.

@prl900
Last active November 1, 2018 00:24
Show Gist options
  • Save prl900/fc61f5005ce7fe6ca7979776d13b677a to your computer and use it in GitHub Desktop.
Save prl900/fc61f5005ce7fe6ca7979776d13b677a to your computer and use it in GitHub Desktop.
#!/g/data/v10/public/modules/dea-env/20181015/bin/python
import argparse
import os
locations = """'Yanco',-34.9878,146.2908,2012,2017
'WombatStateForest',-37.4222,144.0944,2010,2017
'Whroo',-36.6732,145.0294,2011,2017
'Warra',-43.09502,146.65452,2015,2017
'WallabyCreek',-34.00206,140.58912,2005,2013
'Tumbarumba',-35.6566,148.1516,2002,2017
'TiTreeEast',-22.287,133.64,2012,2017
'SturtPlains',-17.1507,133.3502,2008,2017
'Samford',-27.38806,152.87778,2010,2017
'RobsonCreek',-17.11746943,145.6301375,2013,2017
'RiggsCreek',-36.656,145.576,2011,2017
'RedDirtMelonFarm',-14.563639,132.477567,2011,2013
'Otway',-38.525,142.81,2007,2010
'Loxton',-34.47035,140.65512,2008,2009
'Litchfield',-13.17904178,130.7945459,2015,2017
'HowardSprings',-12.4952,131.15005,2002,2017
'GreatWesternWoodlands',-30.1914,120.6541667,2013,2017
'Gingin',-31.375,115.65,2011,2017
'FoggDam',-12.5452,131.3072,2006,2008
'Emerald',-23.85872,148.4746,2011,2013
'DryRiver',-15.2588,132.3706,2008,2017
'DalyUncleared',-14.1592,131.3881,2008,2017
'DalyPasture',-17.1507,133.3502,2008,2013
'CumberlandPlain',-33.615278,150.723611,2012,2016
'CowBay',-16.238189,145.42715,2009,2016
'CapeTribulation',-16.103219,145.446922,2010,2017
'Calperum',-34.00206,140.58912,2010,2017
'AliceSpringsMulga',-22.283,133.249,2010,2017
'AdelaideRiver',-13.0769,131.1178,2007,2009"""
variables = {'rain': "http://www.bom.gov.au/jsp/awra/thredds/dodsC/AWRACMS/values/day/rain_day_{}.nc",
'model_landscape_pet': "http://www.bom.gov.au/jsp/awra/thredds/dodsC/AWRACMS/values/day/e0_{}.nc",
'aeral_pet': "http://www.bom.gov.au/jsp/awra/thredds/dodsC/AWRACMS/values/day/ma_wet_{}.nc",
'synth_pan_pet': "http://www.bom.gov.au/jsp/awra/thredds/dodsC/AWRACMS/values/day/pen_pet_{}.nc"}
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="""AWRA THREDDS data extractor""")
parser.add_argument('-dst', '--destination', required=True, type=str, help="Full path to destination.")
args = parser.parse_args()
for line in locations.splitlines():
fields = line.split(',')
station_name = fields[0].strip("\'")
lat = float(fields[1])
lon = float(fields[2])
start_year = int(fields[3])
end_year = int(fields[4])
for key, templ in variables.items():
for year in range(start_year, end_year+1):
thredds_addr = templ.format(year)
os.system("cdo sellonlatbox,{},{},{},{} {} tmp_{}.nc".format(lon-0.05, lon+0.05, lat-0.05, lat+0.05, thredds_addr, year))
os.system("cdo mergetime tmp_*.nc {}_{}.nc".format(key, station_name))
os.system("rm tmp_*.nc")
@prl900
Copy link
Author

prl900 commented Nov 1, 2018

To execute this on the VDI:

1.- Download and make this code executable
chmod u+x nwp_flux_extractor.py

2.- Load the CDO module
module load cdo

3.- Run specifying a path to the destination directory:
./nwp_flux_extractor.py -dst /g/data/xc0/user/Manolo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment