ksmet1977/luxpy

luxpy problems after Azure Function deployment

Closed this issue · 2 comments

Hi, I'm trying to use luxpy package to unload IES data for further calculations. Locally package works prefect, but after deploying to Azure Function using read_lamp_data() function causes errors. Worth to mention that after adding import luxpy I had problems to even succesfully deploy code to functions. Only moving import luxpy to function that uses it solves that problem. After all, I think it helped to add all the packages mentioned in the pdf instructions to a requirements.txt file. Function deploys, but doesn't work :( I've tried both 3.10 and 3.11 versions of Azure Function. My colleague had similar problems with deploying it to AWS Labda.

My python code takes link to EIS file given in request body, downloads it, load from file and use for further calculations. Problematic part looks like this:

logging.info(f'Loading IES file...')
ies = load_ies_from_bytes(ies_data)
if(ies == None):
    raise Exception(f"Failed to load IES file. Update input request body.")
logging.info(f'Succesfully loaded IES file.')

it uses custom load_ies_from_bytes() function:

def load_ies_from_bytes(ies_data):
    '''Function that loads IES file from bytes'''
    try:
        import luxpy as lx
        ies = lx.toolboxes.iolidfiles.read_lamp_data(ies_data)
        return ies
    except Exception as e:
        print(f"[Inside Load IES] Error loading IES file: {e}")
        for args in e.args:
            print(args)
        return None

After sending request to my function with valid link to IES file, logs looks like this:

2024-05-22T10:46:43Z   [Information]   Downloading IES file...
2024-05-22T10:46:44Z   [Information]   Succesfully downloaded IES file.
2024-05-22T10:46:44Z   [Information]   Loading IES file...
2024-05-22T10:46:48Z   [Information]   generated new fontManager
2024-05-22T10:47:05Z   [Warning]   /home/site/wwwroot/.python_packages/lib/site-packages/luxpy/color/cct/cct_legacy.py:624: SyntaxWarning: "is" with a literal. Did you mean "=="?
2024-05-22T10:47:05Z   [Information]     if (cct_search_list is None) or (cct_search_list is 'default'):
2024-05-22T10:47:05Z   [Warning]   /home/site/wwwroot/.python_packages/lib/site-packages/luxpy/color/cct/cct_legacy.py:625: SyntaxWarning: "is not" with a literal. Did you mean "!="?
2024-05-22T10:47:05Z   [Information]     if (cct_search_list_default is None) or (cct_search_list is not 'default'):
2024-05-22T10:47:05Z   [Information]   [Inside Load IES] Error loading IES file: [Errno 30] Read-only file system: '/home/site/wwwroot/.python_packages/lib/site-packages/luxpy/data/cctluts/legacy/cct_lut_cctlist_robertson1968.dat'
2024-05-22T10:47:05Z   [Information]   30
2024-05-22T10:47:05Z   [Information]   Read-only file system
2024-05-22T10:47:05Z   [Error]   Failed to load IES file. Update input request body.
2024-05-22T10:47:05Z   [Information]   Executed 'Functions.cu_calculations' (Succeeded, Id=24cb8b41-f5be-4df4-8024-0dcf96ca7098, Duration=22689ms)

That's not only error I got. I also had things like NameError: name 'spectrum' is not defined or NameError: name 'lp' is not defined. Despite the fact that I do not have such things in my code, so I suspect thats related to luxpy package.

Only task of this function is to decode the ies file and send it on. I've tried ensure to install all packages I've found here, so my requirements.txt looks like this:

azure-functions
scipy
scikit-learn
numpy
pandas
matplotlib
setuptools
imageio
git+https://github.com/ksmet1977/luxpy.git#egg=luxpy

Once again, locally it works perfect, but after deploy to cloud it can't execute. I've tried installing luxpy from this repo (instead of pypi), also ensured to add all packages to requirements.txt. Nothing works.

Any ideas how to deal with it?

edit:
I've temporarly delt with [Errno 30] Read-only file system: '/home/site/wwwroot/.python_packages/lib/site-packages/luxpy/data/cctluts/legacy/cct_lut_cctlist_robertson1968.dat' error by adding Azure configuration setting: "FUNCTION_APP_EDIT_MODE": "readwrite" as showed here: https://learn-attachment.microsoft.com/api/attachments/240163-image.png?platform=QnA

Now I have new errors. Logs:

2024-05-22T12:02:16Z   [Information]   Downloading IES file...
2024-05-22T12:02:16Z   [Information]   Succesfully downloaded IES file.
2024-05-22T12:02:16Z   [Information]   Loading IES file...
2024-05-22T12:02:16Z   [Error]   Failed to load IES file. Update input request body.
2024-05-22T12:02:16Z   [Information]   [Inside Load IES] Error loading IES file: name 'spectrum' is not defined
2024-05-22T12:02:16Z   [Information]   name 'spectrum' is not defined

and also:

2024-05-22T12:18:21Z   [Information]   [Inside Load IES] Error loading IES file: module 'luxpy' has no attribute 'toolboxes'
2024-05-22T12:18:21Z   [Information]   module 'luxpy' has no attribute 'toolboxes'

There is no info where this error occurs in luxpy package. Any ideas how to deal with it?

Thank you in advance,
Karol

In the end, I decided that it would be faster to write my own code that parses the IES format, so my problem was solved like this.

However, the problem of not being able to use the luxpy library in code running in the cloud is still open, both AWS Lambda and Azure Function do not manage to use this package.

I'm not familiar with using Azure. I mainly use it locally, but I've managed to use luxpy on google colab and some other inline jupyter notebooks. I'm afraid I won't be able to help any time soon.