Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read uploaded file with astrojsvis and use it in photoz widget #262

Open
volodymyrss opened this issue May 31, 2024 · 9 comments
Open

read uploaded file with astrojsvis and use it in photoz widget #262

volodymyrss opened this issue May 31, 2024 · 9 comments
Assignees

Comments

@volodymyrss
Copy link
Member

volodymyrss commented May 31, 2024

@burnout87 can ask @francoismg

@burnout87
Copy link
Collaborator

@francoismg
Copy link

@burnout87 as discussed by email

changes have been pushed to https://github.com/esg-epfl-apc/fits-reader
you can use the built library fits-reader.js in the dist folder

For reference :

Basically you get a FITSFile object that has an array member called 'hdus' that contains all the file hdus, the fits reader wrapper added methods that let you more easily access the header and data part of each hdu but you won't be needing it now that everything has been moved directly to the FITSFile class.

The FITSFile class has a method getHDU(index) that will return the hdu object at the specified index in the hdus array. All the other methods use the index to let you specify which hdu you want to interact with.

You can use getHDUs() to get an array of json object describing all hdus etc.....

Each hdu object has two object members header and data.

There are library methods that you can call from these objects :

get("card_name") on a header object will get you the value for that specific card

getColumn(column_name, callback) on a table or bintable hdu data object will return the column data

Volodymyr said that you were using the same types of data I'm using (Table and Bintable) so for these kinds of hdu the hdu object data member should have a 'columns' array property that gives you the name of each column that you can use with getColumn to get the data.

I made a few functions that you call directly from the FITSFile object that do that for you :

getHeaderCardValueByNameFromHDU(hdu_index, card_name)
returns the specific card value fro the chosen hdu

getHeaderCardsValueFromHDU(hdu_index)
return all cards (card name + card value) as an array for a specific hdu

getColumnsJSONDataFromHDU(hdu_index)
return an array of json object containing all the data for every columns

@burnout87
Copy link
Collaborator

thanks a lot @francoismg , I will try and let you know

@burnout87
Copy link
Collaborator

hi again @francoismg ,

I just tried your code, and I am not sure I am doing everything correctly:

this is the code I am using:
https://github.com/oda-hub/frontend-tab-generator/blob/e5b98595336a09efac065a0587520d62c04646e7/mmoda_tab_generator/templates/euclid/mmoda_euclid.js

basically, in the frontend I have a file input, once the file is selected, the change event is triggered, and I get the following error:

XHRGET
http://localhost/mmoda/spiacs_lc_query.fits
[HTTP/1.1 404 Not Found 14861ms]

Uncaught (in promise) Error: HTTP error, status = 404
    getFile http://localhost/mmoda/sites/all/modules/mmoda/instruments/mmoda_photoz_euclid/js/mmoda_euclid.js?sepek4:24
    promise callback*getFile http://localhost/mmoda/sites/all/modules/mmoda/instruments/mmoda_photoz_euclid/js/mmoda_euclid.js?sepek4:22
    commonReady http://localhost/mmoda/sites/all/modules/mmoda/instruments/mmoda_photoz_euclid/js/mmoda_euclid.js?sepek4:62
    jQuery 8
    _initField http://localhost/mmoda/sites/all/libraries/bootstrap-form-validator/js/bootstrapValidator.min.js?sepek4:32
    _init http://localhost/mmoda/sites/all/libraries/bootstrap-form-validator/js/bootstrapValidator.min.js?sepek4:17
    BootstrapValidator http://localhost/mmoda/sites/all/libraries/bootstrap-form-validator/js/bootstrapValidator.min.js?sepek4:13
    bootstrapValidator http://localhost/mmoda/sites/all/libraries/bootstrap-form-validator/js/bootstrapValidator.min.js?sepek4:145
    jQuery 2
    bootstrapValidator http://localhost/mmoda/sites/all/libraries/bootstrap-form-validator/js/bootstrapValidator.min.js?sepek4:145
    all_instruments_forms_set_bootstrapValidator http://localhost/mmoda/sites/all/modules/mmoda/js/mmoda.instrument.js?sepek4:685
    commonReady http://localhost/mmoda/sites/all/modules/mmoda/js/mmoda.instrument.js?sepek4:721
    jQuery 8

@francoismg
Copy link

francoismg commented Jun 7, 2024

hi again @francoismg ,

I just tried your code, and I am not sure I am doing everything correctly:

this is the code I am using: https://github.com/oda-hub/frontend-tab-generator/blob/e5b98595336a09efac065a0587520d62c04646e7/mmoda_tab_generator/templates/euclid/mmoda_euclid.js

basically, in the frontend I have a file input, once the file is selected, the change event is triggered, and I get the following error:

XHRGET
http://localhost/mmoda/spiacs_lc_query.fits
[HTTP/1.1 404 Not Found 14861ms]

Uncaught (in promise) Error: HTTP error, status = 404
    getFile http://localhost/mmoda/sites/all/modules/mmoda/instruments/mmoda_photoz_euclid/js/mmoda_euclid.js?sepek4:24
    promise callback*getFile http://localhost/mmoda/sites/all/modules/mmoda/instruments/mmoda_photoz_euclid/js/mmoda_euclid.js?sepek4:22
    commonReady http://localhost/mmoda/sites/all/modules/mmoda/instruments/mmoda_photoz_euclid/js/mmoda_euclid.js?sepek4:62
    jQuery 8
    _initField http://localhost/mmoda/sites/all/libraries/bootstrap-form-validator/js/bootstrapValidator.min.js?sepek4:32
    _init http://localhost/mmoda/sites/all/libraries/bootstrap-form-validator/js/bootstrapValidator.min.js?sepek4:17
    BootstrapValidator http://localhost/mmoda/sites/all/libraries/bootstrap-form-validator/js/bootstrapValidator.min.js?sepek4:13
    bootstrapValidator http://localhost/mmoda/sites/all/libraries/bootstrap-form-validator/js/bootstrapValidator.min.js?sepek4:145
    jQuery 2
    bootstrapValidator http://localhost/mmoda/sites/all/libraries/bootstrap-form-validator/js/bootstrapValidator.min.js?sepek4:145
    all_instruments_forms_set_bootstrapValidator http://localhost/mmoda/sites/all/modules/mmoda/js/mmoda.instrument.js?sepek4:685
    commonReady http://localhost/mmoda/sites/all/modules/mmoda/js/mmoda.instrument.js?sepek4:721
    jQuery 8

hello, is that the file you are trying to fetch http://localhost/mmoda/spiacs_lc_query.fits ?

Given that it's an url I assume you have some kind of custom file select where the user choose a remote file and then you try to fetch it with its url is that it?

If that's the case it should work I just tested it locally with that http://localhost:7100/_test_files/spiacs_lc_query.fits and it was working. I will need to make more tests on my own and get back to you

Just in case if it's a standard file input where you choose a local file I do it like that

file_input.addEventListener('change', function(event) {
            let file = event.target.files[0];

            if(file_type === 'fits') {
                file.arrayBuffer().then(arrayBuffer => {
                    readFile(array_buffer);
                }).catch(error => {
                    console.error('Error reading file as ArrayBuffer:', error);
                });
            } 
        });

@burnout87
Copy link
Collaborator

burnout87 commented Jun 7, 2024

thanks @francoismg , it works. Only change I had to was the following:

// let hdu = fits_file.getHDU(hdu_index);
let hdu = fits_file.hdus[hdu_index];

as the call to the function getHDU throws the following exception:

Error reading file as ArrayBuffer: TypeError: this.file is undefined
    value http://localhost/mmoda/sites/all/modules/mmoda/instruments/mmoda_photoz_euclid/js/fits-reader/dist/fits-reader/fits-reader.js?sepek4:1
    readFile http://localhost/mmoda/sites/all/modules/mmoda/instruments/mmoda_photoz_euclid/js/mmoda_euclid.js?sepek4:21
    commonReady http://localhost/mmoda/sites/all/modules/mmoda/instruments/mmoda_photoz_euclid/js/mmoda_euclid.js?sepek4:44
    promise callback*commonReady/< http://localhost/mmoda/sites/all/modules/mmoda/instruments/mmoda_photoz_euclid/js/mmoda_euclid.js?sepek4:43
    commonReady http://localhost/mmoda/sites/all/modules/mmoda/instruments/mmoda_photoz_euclid/js/mmoda_euclid.js?sepek4:41

am I perhaps missing some import?

@burnout87
Copy link
Collaborator

Just in case if it's a standard file input where you choose a local file I do it like that

And yes, it's a standard file input

@francoismg
Copy link

thanks @francoismg , it works. Only change I had to was the following:

// let hdu = fits_file.getHDU(hdu_index);
let hdu = fits_file.hdus[hdu_index];

as the call to the function getHDU throws the following exception:

Error reading file as ArrayBuffer: TypeError: this.file is undefined
    value http://localhost/mmoda/sites/all/modules/mmoda/instruments/mmoda_photoz_euclid/js/fits-reader/dist/fits-reader/fits-reader.js?sepek4:1
    readFile http://localhost/mmoda/sites/all/modules/mmoda/instruments/mmoda_photoz_euclid/js/mmoda_euclid.js?sepek4:21
    commonReady http://localhost/mmoda/sites/all/modules/mmoda/instruments/mmoda_photoz_euclid/js/mmoda_euclid.js?sepek4:44
    promise callback*commonReady/< http://localhost/mmoda/sites/all/modules/mmoda/instruments/mmoda_photoz_euclid/js/mmoda_euclid.js?sepek4:43
    commonReady http://localhost/mmoda/sites/all/modules/mmoda/instruments/mmoda_photoz_euclid/js/mmoda_euclid.js?sepek4:41

am I perhaps missing some import?

ok yea that's my bad, should be fixed now the updated lib has been pushed

@burnout87
Copy link
Collaborator

ok yea that's my bad, should be fixed now the updated lib has been pushed

just checked, I confirm it works, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants