sxs-collaboration / catalog_tools

Tools and tutorials for working with waveforms from the SXS waveform catalog
MIT License
21 stars 10 forks source link

sxs.zenodo.download not found in sxs_catalog_download_example.ipynb #9

Open rhaas80 opened 4 years ago

rhaas80 commented 4 years ago

Hello all,

I just wanted to try out sxs_catalog_download_example.ipynb (git hash dac7198) using:

git clone https://github.com/sxs-collaboration/catalog_tools.git
cd catalog_tools/
cd Examples/
jupyter-notebook --browser=no --port 12345 --ip 127.0.0.1 sxs_catalog_download_example.ipynb

but get in the second cell:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-083f8445225d> in <module>
----> 1 zen.download.matching("common-metadata.txt", "metadata.txt", \
      2                       "rhOverM_Asymptotic_GeometricUnits_CoM.h5", \
      3                       "Horizons.h5", \
      4                       sxs_ids = ['SXS:BBH:0444'], \
      5                       dry_run = True, \

AttributeError: module 'sxs.zenodo' has no attribute 'download'

when using pip install sxs. I ended up with sxs 2020.9.19 (so fairly new).

duetosymmetry commented 4 years ago

Please see #8 . We still need to update this repo to reflect that the download mechanisms have been superseded with a new sxs package API. The new API is demonstrated in the repo https://github.com/moble/sxs_notebooks

rhaas80 commented 4 years ago

8 is marked as closed. Shouldn't it be only closed once the issue no longer exists?

duetosymmetry commented 4 years ago

@rhaas80 that's valid, probably it shouldn't have been closed. Or, we should have opened a separate issue like 'Deprecate this repo' instead. @geoffrey4444 thoughts?

rhaas80 commented 4 years ago

If deprecating the whole repo (which would be a shame as having a programmatic interface is quite useful) then care must be taken to remove all references to it on the website. Eg https://data.black-holes.org/waveforms/index.html

KrishnenduGit commented 1 year ago

Is this issue has been resolved? I am facing the same problem with

Name: sxs
Version: 2021.0.5

Many thanks for considering my request.

ijhwlee commented 1 year ago

Is this issue has been resolved? I am facing the same problem with

Name: sxs
Version: 2021.0.5

Many thanks for considering my request.

You may try the following code

from sxs import utilities as utils
def download_file(common_meta, meta, com_file, horizon, sxs_ids=None, dry_run=True, highest_lev_only=False):
    # read all catalog list
    catalog_list_file="sxs_catalog_zen.json"
    json1_file = open(catalog_list_file)
    json1_str = json1_file.read()
    catalog_json = json.loads(json1_str)
    catalog_levels_file="sxs_catalog_zen_resolutions_available.json"
    json2_file = open(catalog_levels_file)
    json2_str = json2_file.read()
    catalog_levels_json = json.loads(json2_str)
    file_list = [common_meta, meta, com_file, horizon]
    if sxs_ids is None:
        sxs_ids=['SXS:BBH:0444']
    for sxs_id in sxs_ids:
        levels_json = catalog_levels_json[sxs_id]
        max_level = len(levels_json)
        max_level_label = 'Lev'+str(max_level)
        dir_name = sxs_id.replace(":", "_", 2)
        for file in np.array(catalog_json[sxs_id]['files']):
            file_name = file['filename']
            if highest_lev_only==False:
                if any(name in file_name for name in file_list):
                    download = file['links']['download']
                    file_path = dir_name + '/' + file_name
                    print("Downloading {0} and writing to file {1}...".format(file_name, file_path))
                    utils.download_file(download, file_path)
            else:
                if any(name in file_name for name in file_list) and max_level_label in file_name:
                    download = file['links']['download']
                    file_path = dir_name + '/' + file_name
                    print("Downloading {0} and writing to file {1}...".format(file_name, file_path))
                    utils.download_file(download, file_path)

and call as

download_file("common-metadata.txt", "metadata.txt", \
                      "rhOverM_Asymptotic_GeometricUnits_CoM.h5", \
                      "Horizons.h5", \
                      sxs_ids = ['SXS:BBH:0444'], \
                      dry_run = True, \
                      highest_lev_only = False)

Before you try the above code, you need to create two files, sxs_catalog_zen.json and sxs_catalog_zen_resolutions_available.json. These files can be generated by executing code Examples/sxs_zenodo_metadata_example.ipynb

Good luck!