pochedls / xsearch Goto Github PK
View Code? Open in Web Editor NEWutility to search for CMIP data at LLNL
License: MIT License
utility to search for CMIP data at LLNL
License: MIT License
Hi @pochedls,
This is more of question rather than issue, but I am leaving it here because there might be others who would be also interested in the future.
In the below snippet of a code, I am getting netcdf files for each model and its member. I am newbie user of xsearch so my code might not be written in very efficient way -- e.g., findPaths
is used multiple times, with similar lines being repeated.
I was wondering if there is more efficient way to code this with less lines of code. Would you mind sharing how do you usually use xsearch for this kind of looping?
import glob
import os
import xsearch as xs
# User options ------------------------------------------------------------------
exps = ["historical", "amip"]
var = 'zg'
freq = 'day'
cmipTable = 'day'
mip_era = 'CMIP6'
first_member_only = True
# -------------------------------------------------------------------------------
for exp in exps:
# Search all available models
dpaths = xs.findPaths(exp, var, freq, cmipTable=cmipTable, mip_era=mip_era)
models = xs.natural_sort(xs.getGroupValues(dpaths, 'model'))
print('exp:', exp)
print('models:', models)
print('number of models:', len(models))
for model in models:
dpaths_model = xs.findPaths(exp, var, freq, cmipTable=cmipTable, mip_era=mip_era, model=model)
members = xs.natural_sort(xs.getGroupValues(dpaths_model, 'member'))
if first_member_only:
members = members[0:1]
for member in members:
dpaths_model_member = xs.findPaths(exp, var, freq, cmipTable=cmipTable, mip_era=mip_era, model=model, member=member)
dpaths_model_member_list = list(dpaths_model_member.keys())
if len(dpaths_model_member_list) > 1:
print('Error: multiple paths detected for ', model, member, ': ', dpaths_model_member_list)
else:
dpath = dpaths_model_member_list[0]
ncfiles = xs.natural_sort(glob.glob(os.path.join(dpath, '*.nc')))
print(model, member, ncfiles)
Previously xsearch works well but last week I had trouble import xsearch on LC. Here is the relevant information:
(duan) [shiduan@quartz2306:~]$ echo $PYTHONPATH
/p/climate/user_pub/xclim/persist/software/xsearch/
(duan) [shiduan@quartz2306:~]$ python
Python 3.9.15 | packaged by conda-forge | (main, Nov 22 2022, 08:45:29)
[GCC 10.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import xsearch
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'xsearch'
When I try to see the xsearch path on LC, it shows permission denied.
(duan) [shiduan@quartz2306:~]$ ls /p/climate/user_pub/xclim/persist/software/xsearch/
ls: cannot open directory '/p/climate/user_pub/xclim/persist/software/xsearch/': Permission denied
(duan) [shiduan@quartz2306:~]$ ls /p/climate/user_pub/xclim/persist/software/ -l
total 34
drwxr-x--- 3 89674 1026 4096 Jan 2 11:52 xsearch
-rw-r--r-- 1 89674 1026 10075 Jan 2 11:55 xsearch-0.0.8.zip
drwxr-x--- 3 89674 1026 4096 Oct 26 10:54 xsearch_last
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.