Giter Club home page Giter Club logo

xsearch's People

Contributors

durack1 avatar lee1043 avatar pochedls avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

lee1043

xsearch's Issues

Question for more efficient way

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)

xsearch on LC

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.