{
  "id": 349837,
  "title": "How to read dicom file on the GCS? ",
  "url": "/competitions/rsna-2022-cervical-spine-fracture-detection/discussion/349837",
  "author_name": "Pandagg",
  "post_date": "2022-09-03T01:37:57.996000",
  "votes": 1,
  "comment_count": 6,
  "views": 0,
  "content": "<p>If you try to read a file using pydicom on the GCS, for example:<br>\ndcom = pydicom.dcmread(f'{GCS_PATH}/train_images/1.2.826.0.1.3680043.10001/1.dcm')<br>\nyou get an error \"FileNotFoundError: [Errno 2] No such file or directory\".</p>\n<p>But if you use Pandas to read the \"train.csv\" under the same GCS_PATH, it works with no problem:<br>\ntrain_df = pd.read_csv(f\"{GCS_PATH}/train.csv\")</p>\n<p>So it appears pydicom refuses to work with files on GCS. Does anyone have a way to read dicom directly from GCS?</p>",
  "messages": [
    {
      "id": 1924562,
      "postDate": "2022-09-03T07:00:31.447Z",
      "content": "<p>What is your output if you print the \"GCS_PATH\"?</p>",
      "rawMarkdown": "What is your output if you print the \"GCS_PATH\"?",
      "votes": 1,
      "replies": [
        {
          "id": 1924833,
          "postDate": "2022-09-03T13:04:19.427Z",
          "content": "<p>gs://kds-ea6df003e64042a4465e34d7079d9b27214085a21968a59e22b53788</p>",
          "rawMarkdown": "gs://kds-ea6df003e64042a4465e34d7079d9b27214085a21968a59e22b53788",
          "votes": 1
        },
        {
          "id": 1925042,
          "postDate": "2022-09-03T15:42:21.453Z",
          "content": "<p>Seems like a strange bug. I ran the following code to check whether the file and folder exist and I can see the file. But when running the dcmread command, I get the same error as you. I will have to do more research on it. </p>\n<pre><code>from kaggle_datasets import KaggleDatasets\nGCS_PATH = KaggleDatasets().get_gcs_path()\nGCS_PATH = GCS_PATH + \"/train_images/1.2.826.0.1.3680043.10001\"\n!gsutil ls $GCS_PATH \n</code></pre>",
          "rawMarkdown": "Seems like a strange bug. I ran the following code to check whether the file and folder exist and I can see the file. But when running the dcmread command, I get the same error as you. I will have to do more research on it. \n\n```\nfrom kaggle_datasets import KaggleDatasets\nGCS_PATH = KaggleDatasets().get_gcs_path()\nGCS_PATH = GCS_PATH + \"/train_images/1.2.826.0.1.3680043.10001\"\n!gsutil ls $GCS_PATH \n```"
        },
        {
          "id": 1925181,
          "postDate": "2022-09-03T17:36:19.793Z",
          "content": "<p>I think the issue is that dcmread uses the python built-in function \"open()\" that can't handle the filepath like this. I think it's the same issue as talked about here:</p>\n<p><a href=\"https://stackoverflow.com/questions/56700236/how-to-load-the-file-use-the-gcs-path-without-ioerror\" target=\"_blank\">https://stackoverflow.com/questions/56700236/how-to-load-the-file-use-the-gcs-path-without-ioerror</a></p>",
          "rawMarkdown": "I think the issue is that dcmread uses the python built-in function \"open()\" that can't handle the filepath like this. I think it's the same issue as talked about here:\n\n[https://stackoverflow.com/questions/56700236/how-to-load-the-file-use-the-gcs-path-without-ioerror](https://stackoverflow.com/questions/56700236/how-to-load-the-file-use-the-gcs-path-without-ioerror)",
          "votes": 1
        },
        {
          "id": 1925205,
          "postDate": "2022-09-03T17:50:33.977Z",
          "content": "<p>That seems to be the problem. Is there other way around this? Any other Python library that can read dicom on the GCS? Pandas can read csv for no problem. </p>",
          "rawMarkdown": "That seems to be the problem. Is there other way around this? Any other Python library that can read dicom on the GCS? Pandas can read csv for no problem. "
        },
        {
          "id": 1925215,
          "postDate": "2022-09-03T18:05:26.183Z",
          "content": "<p>I think the data needs to be imported to work:</p>\n<p><a href=\"https://cloud.google.com/healthcare-api/docs/how-tos/dicom-import-export\" target=\"_blank\">https://cloud.google.com/healthcare-api/docs/how-tos/dicom-import-export</a></p>\n<p>I don't know of any other library. Sorry :(</p>\n<p>Alternatively, use the provided files within the storage.</p>\n<p><code>example_path = \"../input/rsna-2022-cervical-spine-fracture-detection/train_images/1.2.826.0.1.3680043.10443/1.dcm\"</code></p>\n<p>Maybe someone else has another idea or knows of any other library.</p>",
          "rawMarkdown": "I think the data needs to be imported to work:\n\n[https://cloud.google.com/healthcare-api/docs/how-tos/dicom-import-export](https://cloud.google.com/healthcare-api/docs/how-tos/dicom-import-export)\n\nI don't know of any other library. Sorry :(\n\nAlternatively, use the provided files within the storage.\n\n`example_path = \"../input/rsna-2022-cervical-spine-fracture-detection/train_images/1.2.826.0.1.3680043.10443/1.dcm\"`\n\nMaybe someone else has another idea or knows of any other library."
        }
      ]
    },
    {
      "id": 1924345,
      "postDate": "2022-09-03T01:37:57.997Z",
      "content": "<p>If you try to read a file using pydicom on the GCS, for example:<br>\ndcom = pydicom.dcmread(f'{GCS_PATH}/train_images/1.2.826.0.1.3680043.10001/1.dcm')<br>\nyou get an error \"FileNotFoundError: [Errno 2] No such file or directory\".</p>\n<p>But if you use Pandas to read the \"train.csv\" under the same GCS_PATH, it works with no problem:<br>\ntrain_df = pd.read_csv(f\"{GCS_PATH}/train.csv\")</p>\n<p>So it appears pydicom refuses to work with files on GCS. Does anyone have a way to read dicom directly from GCS?</p>",
      "rawMarkdown": "If you try to read a file using pydicom on the GCS, for example:\ndcom = pydicom.dcmread(f'{GCS_PATH}/train_images/1.2.826.0.1.3680043.10001/1.dcm')\nyou get an error \"FileNotFoundError: [Errno 2] No such file or directory\".\n\nBut if you use Pandas to read the \"train.csv\" under the same GCS_PATH, it works with no problem:\ntrain_df = pd.read_csv(f\"{GCS_PATH}/train.csv\")\n\nSo it appears pydicom refuses to work with files on GCS. Does anyone have a way to read dicom directly from GCS?",
      "votes": 1
    }
  ],
  "comments": [
    {
      "id": 1924562,
      "author_name": "Andreas Renz",
      "author_url": "",
      "post_date": "2022-09-03T07:00:31.447000",
      "content": "<p>What is your output if you print the \"GCS_PATH\"?</p>",
      "votes": 1,
      "replies": [
        {
          "id": 1924833,
          "author_name": "Pandagg",
          "author_url": "",
          "post_date": "2022-09-03T13:04:19.427000",
          "content": "<p>gs://kds-ea6df003e64042a4465e34d7079d9b27214085a21968a59e22b53788</p>",
          "votes": 1,
          "replies": []
        },
        {
          "id": 1925042,
          "author_name": "Andreas Renz",
          "author_url": "",
          "post_date": "2022-09-03T15:42:21.453000",
          "content": "<p>Seems like a strange bug. I ran the following code to check whether the file and folder exist and I can see the file. But when running the dcmread command, I get the same error as you. I will have to do more research on it. </p>\n<pre><code>from kaggle_datasets import KaggleDatasets\nGCS_PATH = KaggleDatasets().get_gcs_path()\nGCS_PATH = GCS_PATH + \"/train_images/1.2.826.0.1.3680043.10001\"\n!gsutil ls $GCS_PATH \n</code></pre>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1925181,
          "author_name": "Andreas Renz",
          "author_url": "",
          "post_date": "2022-09-03T17:36:19.793000",
          "content": "<p>I think the issue is that dcmread uses the python built-in function \"open()\" that can't handle the filepath like this. I think it's the same issue as talked about here:</p>\n<p><a href=\"https://stackoverflow.com/questions/56700236/how-to-load-the-file-use-the-gcs-path-without-ioerror\" target=\"_blank\">https://stackoverflow.com/questions/56700236/how-to-load-the-file-use-the-gcs-path-without-ioerror</a></p>",
          "votes": 1,
          "replies": []
        },
        {
          "id": 1925205,
          "author_name": "Pandagg",
          "author_url": "",
          "post_date": "2022-09-03T17:50:33.977000",
          "content": "<p>That seems to be the problem. Is there other way around this? Any other Python library that can read dicom on the GCS? Pandas can read csv for no problem. </p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1925215,
          "author_name": "Andreas Renz",
          "author_url": "",
          "post_date": "2022-09-03T18:05:26.183000",
          "content": "<p>I think the data needs to be imported to work:</p>\n<p><a href=\"https://cloud.google.com/healthcare-api/docs/how-tos/dicom-import-export\" target=\"_blank\">https://cloud.google.com/healthcare-api/docs/how-tos/dicom-import-export</a></p>\n<p>I don't know of any other library. Sorry :(</p>\n<p>Alternatively, use the provided files within the storage.</p>\n<p><code>example_path = \"../input/rsna-2022-cervical-spine-fracture-detection/train_images/1.2.826.0.1.3680043.10443/1.dcm\"</code></p>\n<p>Maybe someone else has another idea or knows of any other library.</p>",
          "votes": 0,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1924562": "What is your output if you print the \"GCS_PATH\"?",
    "1924345": "If you try to read a file using pydicom on the GCS, for example:\ndcom = pydicom.dcmread(f'{GCS_PATH}/train_images/1.2.826.0.1.3680043.10001/1.dcm')\nyou get an error \"FileNotFoundError: [Errno 2] No such file or directory\".\n\nBut if you use Pandas to read the \"train.csv\" under the same GCS_PATH, it works with no problem:\ntrain_df = pd.read_csv(f\"{GCS_PATH}/train.csv\")\n\nSo it appears pydicom refuses to work with files on GCS. Does anyone have a way to read dicom directly from GCS?"
  }
}