Ejemplo n.º 1
0
def toJSON(args):

    spectrum_file = args.input
    spectrum_data = read_spectra_file_simple(spectrum_file)
    spectrum = SimpleSpectrum('fits2JSON', spectrum_data)
    asjson = utils.toMarzJSON(spectrum)
    print(json.dumps(asjson, indent=2), flush=True)
Ejemplo n.º 2
0
    def reduce(self, argument):
        """Implementation of the Marz CLI

        Parameters
        ----------
        argument : str
            Path to the FITS file containing the spectrum to be fit

        Returns
        -------
        Float
            The fitted redshift of the input spectrum
        String
            The name of the fitted template of the input spectrum
        """

        import os
        from subprocess import run, Popen, PIPE, STDOUT

        spectrum = SimpleSpectrum('fits2JSON', argument)
        spectrum_json = json.dumps(utils.toMarzJSON(spectrum), indent=2)

        plugin_dir = os.path.dirname(os.path.abspath(__file__))

        marzcli_path = plugin_dir + '/marzcli.js'
        cmd = plugin_dir + '/marzcli.sh ' + marzcli_path

        if sys.version_info[:3] >= (3, 7):
            proc = run(cmd,
                       shell=True,
                       input=spectrum_json,
                       text=True,
                       stdout=PIPE,
                       stderr=STDOUT,
                       close_fds=True)
        else:
            proc = run(cmd,
                       shell=True,
                       input=spectrum_json,
                       universal_newlines=True,
                       stdout=PIPE,
                       stderr=STDOUT,
                       close_fds=True)

        lines = proc.stdout.split('\n')

        print("=" * 20 + " Marz CLI Plugin " + "=" * 20)
        for line in lines[:-6:-1]:
            print(line)

        tokens = lines[-5].split(',')
        bestfit_redshift = float(tokens[8])
        bestfit_template = tokens[7].strip()
        print(f"BEST REDSHIFT = {bestfit_redshift}")
        print(f"BEST TEMPLATE = {bestfit_template}")
        return bestfit_redshift, bestfit_template
Ejemplo n.º 3
0
 def test_fits2json_2(self, shared_datadir):
     from ssv.viewer import read_spectra_file, read_spectra_file_simple, SimpleSpectrum
     from ssv import utils
     spectrum_file = shared_datadir / "marz/spec-4444-55538-1000.fits"
     formats = loaders.whatformat(spectrum_file)
     if len(formats) > 1:
         loaders.unregister(formats[0])
     spectrum_data = read_spectra_file_simple(spectrum_file)
     loaders.restore_registered_loaders()
     spectrum = SimpleSpectrum('fits2JSON', spectrum_data)
     asjson = utils.toMarzJSON(spectrum)
Ejemplo n.º 4
0
 def test_fits2json_1(self, shared_datadir):
     from ssv.viewer import SimpleSpectrum
     from ssv import utils
     spectrum_file = shared_datadir / "marz/emlLinearVacuumNoHelio.fits"
     formats = ssv.ssvloaders.whatformat(spectrum_file)
     if len(formats) > 1:
         ssv.ssvloaders.unregister(formats[0])
     spectrum_data = utils.read_spectra_file(spectrum_file)
     ssv.ssvloaders.restore_registered_loaders()
     spectrum = SimpleSpectrum('fits2JSON', spectrum_data)
     asjson = utils.toMarzJSON(spectrum)
Ejemplo n.º 5
0
def jsonFitsFile(request, fits_id):
    fitsfile = FitsFiles.objects.get(pk=fits_id)
    #
    datadir = Path('../../../')

    anyFILE = datadir / fitsfile.filepath

    formats = ssv.loaders.whatformat(anyFILE)
    if len(formats) > 1:
        ssv.loaders.unregister(formats[0])
    spectrum_data = read_spectra_file_simple(anyFILE)
    ssv.loaders.restore_registered_loaders()
    spectrum = SimpleSpectrum('Test SSV', spectrum_data)
    js_data = utils.toMarzJSON(spectrum)
    return JsonResponse(js_data, safe=False)
Ejemplo n.º 6
0
def toJSON(args):

    spectrum_file = args.input
    spectrum_data = read_spectra_file_simple(spectrum_file)
    spectrum = SimpleSpectrum('fits2JSON', spectrum_data)
    asjson = utils.toMarzJSON(spectrum)